mirror of
https://github.com/mempool/mempool.git
synced 2025-01-01 03:04:27 +01:00
Merge pull request #1300 from nymkappa/bugfix/stop-block-chunk-indexing-upon-error
Pause block indexing chunk upon error and retry later
This commit is contained in:
commit
f990d30a22
@ -218,31 +218,28 @@ class Blocks {
|
|||||||
if (blockHeight < lastBlockToIndex) {
|
if (blockHeight < lastBlockToIndex) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
try {
|
++indexedThisRun;
|
||||||
++indexedThisRun;
|
if (++totaIndexed % 100 === 0 || blockHeight === lastBlockToIndex) {
|
||||||
if (++totaIndexed % 100 === 0 || blockHeight === lastBlockToIndex) {
|
const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - startedAt));
|
||||||
const elapsedSeconds = Math.max(1, Math.round((new Date().getTime() / 1000) - startedAt));
|
const blockPerSeconds = Math.max(1, Math.round(indexedThisRun / elapsedSeconds));
|
||||||
const blockPerSeconds = Math.max(1, Math.round(indexedThisRun / elapsedSeconds));
|
const progress = Math.round(totaIndexed / indexingBlockAmount * 100);
|
||||||
const progress = Math.round(totaIndexed / indexingBlockAmount * 100);
|
const timeLeft = Math.round((indexingBlockAmount - totaIndexed) / blockPerSeconds);
|
||||||
const timeLeft = Math.round((indexingBlockAmount - totaIndexed) / blockPerSeconds);
|
logger.debug(`Indexing block #${blockHeight} | ~${blockPerSeconds} blocks/sec | total: ${totaIndexed}/${indexingBlockAmount} (${progress}%) | elapsed: ${elapsedSeconds} seconds | left: ~${timeLeft} seconds`);
|
||||||
logger.debug(`Indexing block #${blockHeight} | ~${blockPerSeconds} blocks/sec | total: ${totaIndexed}/${indexingBlockAmount} (${progress}%) | elapsed: ${elapsedSeconds} seconds | left: ~${timeLeft} seconds`);
|
|
||||||
}
|
|
||||||
const blockHash = await bitcoinApi.$getBlockHash(blockHeight);
|
|
||||||
const block = await bitcoinApi.$getBlock(blockHash);
|
|
||||||
const transactions = await this.$getTransactionsExtended(blockHash, block.height, true, true);
|
|
||||||
const blockExtended = await this.$getBlockExtended(block, transactions);
|
|
||||||
await blocksRepository.$saveBlockInDatabase(blockExtended);
|
|
||||||
} catch (e) {
|
|
||||||
logger.err(`Something went wrong while indexing blocks.` + e);
|
|
||||||
}
|
}
|
||||||
|
const blockHash = await bitcoinApi.$getBlockHash(blockHeight);
|
||||||
|
const block = await bitcoinApi.$getBlock(blockHash);
|
||||||
|
const transactions = await this.$getTransactionsExtended(blockHash, block.height, true, true);
|
||||||
|
const blockExtended = await this.$getBlockExtended(block, transactions);
|
||||||
|
await blocksRepository.$saveBlockInDatabase(blockExtended);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentBlockHeight -= chunkSize;
|
currentBlockHeight -= chunkSize;
|
||||||
}
|
}
|
||||||
logger.info('Block indexing completed');
|
logger.info('Block indexing completed');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.err('An error occured in $generateBlockDatabase(). Skipping block indexing. ' + e);
|
logger.err('An error occured in $generateBlockDatabase(). Trying again later. ' + e);
|
||||||
console.log(e);
|
this.blockIndexingStarted = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.blockIndexingCompleted = true;
|
this.blockIndexingCompleted = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user