Improve hashrate indexing logs
This commit is contained in:
parent
ac118141ce
commit
e4721e8574
@ -118,18 +118,21 @@ class Mining {
|
|||||||
}
|
}
|
||||||
this.hashrateIndexingStarted = true;
|
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);
|
const indexedTimestamp = (await HashratesRepository.$get(null)).map(hashrate => hashrate.timestamp);
|
||||||
|
let startedAt = new Date().getTime() / 1000;
|
||||||
const genesisTimestamp = 1231006505; // bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
|
const genesisTimestamp = 1231006505; // bitcoin-cli getblock 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
|
||||||
const lastMidnight = new Date();
|
const lastMidnight = new Date();
|
||||||
lastMidnight.setUTCHours(0); lastMidnight.setUTCMinutes(0); lastMidnight.setUTCSeconds(0); lastMidnight.setUTCMilliseconds(0);
|
lastMidnight.setUTCHours(0); lastMidnight.setUTCMinutes(0); lastMidnight.setUTCSeconds(0); lastMidnight.setUTCMilliseconds(0);
|
||||||
let toTimestamp = Math.round(lastMidnight.getTime() / 1000);
|
let toTimestamp = Math.round(lastMidnight.getTime() / 1000);
|
||||||
|
let indexedThisRun = 0;
|
||||||
|
let totalIndexed = 0;
|
||||||
|
|
||||||
while (toTimestamp > genesisTimestamp) {
|
while (toTimestamp > genesisTimestamp) {
|
||||||
const fromTimestamp = toTimestamp - 86400;
|
const fromTimestamp = toTimestamp - 86400;
|
||||||
if (indexedTimestamp.includes(fromTimestamp)) {
|
if (indexedTimestamp.includes(fromTimestamp)) {
|
||||||
toTimestamp -= 86400;
|
toTimestamp -= 86400;
|
||||||
|
++totalIndexed;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,10 +148,14 @@ class Mining {
|
|||||||
lastBlockHashrate = await bitcoinClient.getNetworkHashPs(blockStats.blockCount,
|
lastBlockHashrate = await bitcoinClient.getNetworkHashPs(blockStats.blockCount,
|
||||||
blockStats.lastBlockHeight);
|
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 formattedDate = new Date(fromTimestamp * 1000).toUTCString();
|
||||||
const blocksLeft = blockStats.lastBlockHeight - oldestIndexedBlockHeight;
|
const daysLeft = Math.round(totalDayIndexed - totalIndexed);
|
||||||
logger.debug(`Counting blocks and hashrate for ${formattedDate}. ${blocksLeft} blocks left`);
|
logger.debug(`Getting hashrate for ${formattedDate} | ~${daysPerSeconds} days/sec | ~${daysLeft} days left to index`);
|
||||||
|
startedAt = new Date().getTime() / 1000;
|
||||||
|
indexedThisRun = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
await HashratesRepository.$saveDailyStat({
|
await HashratesRepository.$saveDailyStat({
|
||||||
@ -158,6 +165,8 @@ class Mining {
|
|||||||
});
|
});
|
||||||
|
|
||||||
toTimestamp -= 86400;
|
toTimestamp -= 86400;
|
||||||
|
++indexedThisRun;
|
||||||
|
++totalIndexed;
|
||||||
}
|
}
|
||||||
|
|
||||||
await HashratesRepository.$setLatestRunTimestamp();
|
await HashratesRepository.$setLatestRunTimestamp();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user