[mining] fix potential bug where we try to index hashrate even if there are no blocks

This commit is contained in:
nymkappa
2025-05-08 11:32:51 +02:00
parent 9560d44abd
commit e5082863de

View File

@@ -256,6 +256,10 @@ class Mining {
const blockStats: any = await BlocksRepository.$blockCountBetweenTimestamp(
null, fromTimestamp / 1000, toTimestamp / 1000);
if (blockStats.blockCount <= 0) {
logger.debug(`No block found between ${fromTimestamp / 1000} and ${toTimestamp / 1000}, skipping hashrate indexing for this period`, logger.tags.mining);
} else {
const lastBlockHashrate = await bitcoinClient.getNetworkHashPs(blockStats.blockCount,
blockStats.lastBlockHeight);
@@ -282,6 +286,7 @@ class Mining {
await HashratesRepository.$saveHashrates(hashrates);
hashrates.length = 0;
}
}
const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - timer));
if (elapsedSeconds > 1) {