Skip to content

Commit

Permalink
Revert "Add Miner Effort"
Browse files Browse the repository at this point in the history
This reverts commit 965bfde.
  • Loading branch information
xiaolin1579 committed Oct 11, 2023
1 parent 965bfde commit 030ce71
Show file tree
Hide file tree
Showing 12 changed files with 1 addition and 90 deletions.
9 changes: 0 additions & 9 deletions src/Miningcore/Api/Controllers/PoolApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,6 @@ public async Task<MinerPerformanceStats[]> PagePoolMinersAsync(
stats.LastPaymentLink = string.Format(baseUrl, statsResult.LastPayment.TransactionConfirmationData);
}

var lastBlockTime = await cf.Run(con => blocksRepo.GetLastMinerBlockTimeAsync(con, pool.Id, address));
if(lastBlockTime.HasValue)
{
var startTime = lastBlockTime.Value;
var minerEffort = await cf.Run(con => shareRepo.GetMinerEffortBetweenCreatedAsync(con, pool.Id, address, startTime, clock.Now));
if(minerEffort.HasValue)
stats.MinerEffort = minerEffort.Value;
}

stats.PerformanceSamples = await GetMinerPerformanceInternal(perfMode, pool, address, ct);
}

Expand Down
1 change: 0 additions & 1 deletion src/Miningcore/Api/Responses/GetBlocksResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class Block
public string Type { get; set; }
public double ConfirmationProgress { get; set; }
public double? Effort { get; set; }
public double? MinerEffort { get; set; }
public string TransactionConfirmationData { get; set; }
public decimal Reward { get; set; }
public string InfoLink { get; set; }
Expand Down
1 change: 0 additions & 1 deletion src/Miningcore/Api/Responses/GetMinerStatsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class MinerStats
public decimal PendingBalance { get; set; }
public decimal TotalPaid { get; set; }
public decimal TodayPaid { get; set; }
public double MinerEffort { get; set; }
public DateTime? LastPayment { get; set; }
public string LastPaymentLink { get; set; }
public WorkerPerformanceStatsContainer Performance { get; set; }
Expand Down
31 changes: 0 additions & 31 deletions src/Miningcore/Payments/PayoutManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ await cf.RunTx(async (con, tx) =>
if(!block.Effort.HasValue) // fill block effort if empty
await CalculateBlockEffortAsync(pool, poolConfig, block, handler, ct);

if(!block.MinerEffort.HasValue) // fill block effort if empty
await CalculateMinerEffortAsync(pool, poolConfig, block, handler, ct);

switch(block.Status)
{
case BlockStatus.Confirmed:
Expand Down Expand Up @@ -250,34 +247,6 @@ private async Task CalculateBlockEffortAsync(IMiningPool pool, PoolConfig poolCo
block.Effort = handler.AdjustBlockEffort(block.Effort.Value);
}

private async Task CalculateMinerEffortAsync(IMiningPool pool, PoolConfig poolConfig, Block block, IPayoutHandler handler, CancellationToken ct)
{

// get share date-range
var from = DateTime.MinValue;
var to = block.Created;

var miner = block.Miner;

// get last block for pool
var lastBlock = await cf.Run(con => blockRepo.GetMinerBlockBeforeAsync(con, poolConfig.Id, miner, new[]
{
BlockStatus.Confirmed,
BlockStatus.Orphaned,
BlockStatus.Pending,
}, block.Created));

if(lastBlock != null)
from = lastBlock.Created;

block.MinerEffort = await cf.Run(con => shareRepo.GetMinerShareDifficultyBetweenAsync(con, pool.Config.Id, miner, from, to, ct));

if(block.MinerEffort.HasValue)
block.MinerEffort = handler.AdjustBlockEffort(block.MinerEffort.Value);


}

protected override async Task ExecuteAsync(CancellationToken ct)
{
try
Expand Down
1 change: 0 additions & 1 deletion src/Miningcore/Persistence/Model/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class Block
public string Type { get; set; }
public double ConfirmationProgress { get; set; }
public double? Effort { get; set; }
public double? MinerEffort { get; set; }
public string TransactionConfirmationData { get; set; }
public string Miner { get; set; }
public decimal Reward { get; set; }
Expand Down
2 changes: 0 additions & 2 deletions src/Miningcore/Persistence/Model/Projections/MinerStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public class MinerStats
public decimal TotalPaid { get; init; }
public decimal TodayPaid { get; init; }
public Payment LastPayment { get; set; }
public double MinerEffort { get; set; }
public DateTime? LastMinerBlockTime { get; set; }
public WorkerPerformanceStatsContainer Performance { get; set; }
public MinerWorkerPerformanceStats[] PerformanceStats { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task UpdateBlockAsync(IDbConnection con, IDbTransaction tx, Block b
var mapped = mapper.Map<Entities.Block>(block);

const string query = @"UPDATE blocks SET blockheight = @blockheight, status = @status, type = @type,
reward = @reward, effort = @effort, minereffort = @minereffort, confirmationprogress = @confirmationprogress, hash = @hash WHERE id = @id";
reward = @reward, effort = @effort, confirmationprogress = @confirmationprogress, hash = @hash WHERE id = @id";

await con.ExecuteAsync(query, mapped, tx);
}
Expand Down Expand Up @@ -118,22 +118,6 @@ public async Task<Block> GetBlockBeforeAsync(IDbConnection con, string poolId, B
.FirstOrDefault();
}

public async Task<Block> GetMinerBlockBeforeAsync(IDbConnection con, string poolId, string miner, BlockStatus[] status, DateTime before)
{
const string query = @"SELECT * FROM blocks WHERE poolid = @poolid AND miner = @miner AND status = ANY(@status) AND created < @before
ORDER BY created DESC FETCH NEXT 1 ROWS ONLY";

return (await con.QueryAsync<Entities.Block>(query, new
{
poolId,
miner,
before,
status = status.Select(x => x.ToString().ToLower()).ToArray()
}))
.Select(mapper.Map<Block>)
.FirstOrDefault();
}

public Task<uint> GetPoolBlockCountAsync(IDbConnection con, string poolId, CancellationToken ct)
{
const string query = @"SELECT COUNT(*) FROM blocks WHERE poolid = @poolId";
Expand All @@ -148,13 +132,6 @@ public Task<uint> GetPoolBlockCountAsync(IDbConnection con, string poolId, Cance
return con.ExecuteScalarAsync<DateTime?>(query, new { poolId });
}

public Task<DateTime?> GetLastMinerBlockTimeAsync(IDbConnection con, string poolId, string address)
{
const string query = @"SELECT created FROM blocks WHERE poolid = @poolId AND miner = @address ORDER BY created DESC LIMIT 1";

return con.ExecuteScalarAsync<DateTime?>(query, new { poolId, address });
}

public async Task<Block> GetBlockByPoolHeightAndTypeAsync(IDbConnection con, string poolId, long height, string type)
{
const string query = @"SELECT * FROM blocks WHERE poolid = @poolId AND blockheight = @height AND type = @type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ public Task<long> CountSharesByMinerAsync(IDbConnection con, IDbTransaction tx,
return con.QuerySingleAsync<double?>(query, new { poolId, start, end });
}

public Task<double?> GetMinerEffortBetweenCreatedAsync(IDbConnection con, string poolId, string miner, DateTime start, DateTime end)
{
const string query = "SELECT SUM(difficulty / networkdifficulty) FROM shares WHERE poolid = @poolId AND miner = @miner AND created > @start AND created < @end";

return con.QuerySingleAsync<double?>(query, new { poolId, miner, start, end });
}

public async Task DeleteSharesByMinerAsync(IDbConnection con, IDbTransaction tx, string poolId, string miner, CancellationToken ct)
{
const string query = "DELETE FROM shares WHERE poolid = @poolId AND miner = @miner";
Expand All @@ -110,13 +103,6 @@ public async Task DeleteSharesBeforeAsync(IDbConnection con, IDbTransaction tx,
return con.QuerySingleAsync<double?>(new CommandDefinition(query, new { poolId, start, end }, cancellationToken: ct));
}

public Task<double?> GetMinerShareDifficultyBetweenAsync(IDbConnection con, string poolId, string miner, DateTime start, DateTime end, CancellationToken ct)
{
const string query = "SELECT SUM(difficulty / networkdifficulty) FROM shares WHERE poolid = @poolId AND miner = @miner AND created > @start AND created < @end";

return con.QuerySingleAsync<double?>(new CommandDefinition(query, new { poolId, miner, start, end }, cancellationToken: ct));
}

public Task<double?> GetEffectiveAccumulatedShareDifficultyBetweenAsync(IDbConnection con, string poolId, DateTime start, DateTime end, CancellationToken ct)
{
const string query = "SELECT SUM(difficulty / networkdifficulty) FROM shares WHERE poolid = @poolId AND created > @start AND created < @end";
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion src/Miningcore/Persistence/Postgres/Scripts/createdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ CREATE TABLE blocks
type TEXT NULL,
confirmationprogress FLOAT NOT NULL DEFAULT 0,
effort FLOAT NULL,
minereffort FLOAT NULL,
transactionconfirmationdata TEXT NOT NULL,
miner TEXT NULL,
reward decimal(28,12) NULL,
Expand Down
2 changes: 0 additions & 2 deletions src/Miningcore/Persistence/Repositories/IBlockRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ public interface IBlockRepository
Task<Block[]> PageBlocksAsync(IDbConnection con, BlockStatus[] status, int page, int pageSize, CancellationToken ct);
Task<Block[]> GetPendingBlocksForPoolAsync(IDbConnection con, string poolId);
Task<Block> GetBlockBeforeAsync(IDbConnection con, string poolId, BlockStatus[] status, DateTime before);
Task<Block> GetMinerBlockBeforeAsync(IDbConnection con, string poolId, string miner, BlockStatus[] status, DateTime before);
Task<uint> GetPoolBlockCountAsync(IDbConnection con, string poolId, CancellationToken ct);
Task<DateTime?> GetLastPoolBlockTimeAsync(IDbConnection con, string poolId);
Task<DateTime?> GetLastMinerBlockTimeAsync(IDbConnection con, string poolId, string address);
Task<Block> GetBlockByPoolHeightAndTypeAsync(IDbConnection con, string poolId, long height, string type);
Task<uint> GetPoolDuplicateBlockCountByPoolHeightNoTypeAndStatusAsync(IDbConnection con, string poolId, long height, BlockStatus[] status);
Task<uint> GetPoolDuplicateBlockBeforeCountByPoolHeightNoTypeAndStatusAsync(IDbConnection con, string poolId, long height, BlockStatus[] status, DateTime before);
Expand Down
2 changes: 0 additions & 2 deletions src/Miningcore/Persistence/Repositories/IShareRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ public interface IShareRepository
Task<long> CountSharesByMinerAsync(IDbConnection con, IDbTransaction tx, string poolId, string miner, CancellationToken ct);
Task DeleteSharesByMinerAsync(IDbConnection con, IDbTransaction tx, string poolId, string miner, CancellationToken ct);
Task<double?> GetAccumulatedShareDifficultyBetweenAsync(IDbConnection con, string poolId, DateTime start, DateTime end, CancellationToken ct);
Task<double?> GetMinerShareDifficultyBetweenAsync(IDbConnection con, string poolId, string miner, DateTime start, DateTime end, CancellationToken ct);
Task<double?> GetEffectiveAccumulatedShareDifficultyBetweenAsync(IDbConnection con, string poolId, DateTime start, DateTime end, CancellationToken ct);
Task<double?> GetEffortBetweenCreatedAsync(IDbConnection con, string poolId, DateTime start, DateTime end);
Task<double?> GetMinerEffortBetweenCreatedAsync(IDbConnection con, string poolId, string miner,DateTime start, DateTime end);
Task<MinerWorkerHashes[]> GetHashAccumulationBetweenAsync(IDbConnection con, string poolId, DateTime start, DateTime end, CancellationToken ct);
Task<string[]> GetRecentyUsedIpAddressesAsync(IDbConnection con, IDbTransaction tx, string poolId, string miner, CancellationToken ct);

Expand Down

0 comments on commit 030ce71

Please sign in to comment.