Improve hashrate indexing logs

This commit is contained in:
nymkappa 2022-02-21 14:36:48 +09:00
parent ac118141ce
commit e4721e8574
No known key found for this signature in database
GPG Key ID: E155910B16E8BD04

View File

@ -118,18 +118,21 @@ class Mining {
}
this.hashrateIndexingStarted = true;
const oldestIndexedBlockHeight = await BlocksRepository.$getOldestIndexedBlockHeight();
const totalDayIndexed = (await BlocksRepository.$blockCount(null, null)) / 144;
const indexedTimestamp = (await HashratesRepository.$get(null)).map(hashrate => hashrate.timestamp);
let startedAt = new Date().getTime() / 1000;
const genesisTimestamp = 1231006505; // bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
const lastMidnight = new Date();
lastMidnight.setUTCHours(0); lastMidnight.setUTCMinutes(0); lastMidnight.setUTCSeconds(0); lastMidnight.setUTCMilliseconds(0);
let toTimestamp = Math.round(lastMidnight.getTime() / 1000);
let indexedThisRun = 0;
let totalIndexed = 0;
while (toTimestamp > genesisTimestamp) {
const fromTimestamp = toTimestamp - 86400;
if (indexedTimestamp.includes(fromTimestamp)) {
toTimestamp -= 86400;
++totalIndexed;
continue;
}
@ -145,10 +148,14 @@ class Mining {
lastBlockHashrate = await bitcoinClient.getNetworkHashPs(blockStats.blockCount,
blockStats.lastBlockHeight);
if (toTimestamp % 864000 === 0) { // Log every 10 days during initial indexing
const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - startedAt));
if (elapsedSeconds > 1) {
const daysPerSeconds = Math.max(1, Math.round(indexedThisRun / elapsedSeconds));
const formattedDate = new Date(fromTimestamp * 1000).toUTCString();
const blocksLeft = blockStats.lastBlockHeight - oldestIndexedBlockHeight;
logger.debug(`Counting blocks and hashrate for ${formattedDate}. ${blocksLeft} blocks left`);
const daysLeft = Math.round(totalDayIndexed - totalIndexed);
logger.debug(`Getting hashrate for ${formattedDate} | ~${daysPerSeconds} days/sec | ~${daysLeft} days left to index`);
startedAt = new Date().getTime() / 1000;
indexedThisRun = 0;
}
await HashratesRepository.$saveDailyStat({
@ -158,6 +165,8 @@ class Mining {
});
toTimestamp -= 86400;
++indexedThisRun;
++totalIndexed;
}
await HashratesRepository.$setLatestRunTimestamp();