mirror of
https://github.com/mempool/mempool.git
synced 2025-09-25 18:01:56 +02:00
Merge pull request #5901 from mempool/nymkappa/tape-fix-hashrate-indexing
[mining] fix potential bug where we try to index hashrate even if there are no blocks
This commit is contained in:
@@ -256,31 +256,36 @@ class Mining {
|
|||||||
|
|
||||||
const blockStats: any = await BlocksRepository.$blockCountBetweenTimestamp(
|
const blockStats: any = await BlocksRepository.$blockCountBetweenTimestamp(
|
||||||
null, fromTimestamp / 1000, toTimestamp / 1000);
|
null, fromTimestamp / 1000, toTimestamp / 1000);
|
||||||
const lastBlockHashrate = await bitcoinClient.getNetworkHashPs(blockStats.blockCount,
|
|
||||||
blockStats.lastBlockHeight);
|
|
||||||
|
|
||||||
let pools = await PoolsRepository.$getPoolsInfoBetween(fromTimestamp / 1000, toTimestamp / 1000);
|
if (blockStats.blockCount <= 0) {
|
||||||
const totalBlocks = pools.reduce((acc, pool) => acc + pool.blockCount, 0);
|
logger.debug(`No block found between ${fromTimestamp / 1000} and ${toTimestamp / 1000}, skipping hashrate indexing for this period`, logger.tags.mining);
|
||||||
if (totalBlocks > 0) {
|
} else {
|
||||||
pools = pools.map((pool: any) => {
|
const lastBlockHashrate = await bitcoinClient.getNetworkHashPs(blockStats.blockCount,
|
||||||
pool.hashrate = (pool.blockCount / totalBlocks) * lastBlockHashrate;
|
blockStats.lastBlockHeight);
|
||||||
pool.share = (pool.blockCount / totalBlocks);
|
|
||||||
return pool;
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const pool of pools) {
|
let pools = await PoolsRepository.$getPoolsInfoBetween(fromTimestamp / 1000, toTimestamp / 1000);
|
||||||
hashrates.push({
|
const totalBlocks = pools.reduce((acc, pool) => acc + pool.blockCount, 0);
|
||||||
hashrateTimestamp: toTimestamp / 1000,
|
if (totalBlocks > 0) {
|
||||||
avgHashrate: pool['hashrate'] ,
|
pools = pools.map((pool: any) => {
|
||||||
poolId: pool.poolId,
|
pool.hashrate = (pool.blockCount / totalBlocks) * lastBlockHashrate;
|
||||||
share: pool['share'],
|
pool.share = (pool.blockCount / totalBlocks);
|
||||||
type: 'weekly',
|
return pool;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
newlyIndexed += hashrates.length / Math.max(1, pools.length);
|
for (const pool of pools) {
|
||||||
await HashratesRepository.$saveHashrates(hashrates);
|
hashrates.push({
|
||||||
hashrates.length = 0;
|
hashrateTimestamp: toTimestamp / 1000,
|
||||||
|
avgHashrate: pool['hashrate'] ,
|
||||||
|
poolId: pool.poolId,
|
||||||
|
share: pool['share'],
|
||||||
|
type: 'weekly',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
newlyIndexed += hashrates.length / Math.max(1, pools.length);
|
||||||
|
await HashratesRepository.$saveHashrates(hashrates);
|
||||||
|
hashrates.length = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - timer));
|
const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - timer));
|
||||||
|
Reference in New Issue
Block a user