Manually re-index the last 10 blocks when the new block previoushash does not match latest block hash
This commit is contained in:
parent
900e02d9a5
commit
84b72f8b32
@ -332,15 +332,17 @@ class Blocks {
|
|||||||
if (Common.indexingEnabled()) {
|
if (Common.indexingEnabled()) {
|
||||||
if (!fastForwarded) {
|
if (!fastForwarded) {
|
||||||
const lastBlock = await blocksRepository.$getBlockByHeight(blockExtended.height - 1);
|
const lastBlock = await blocksRepository.$getBlockByHeight(blockExtended.height - 1);
|
||||||
if (lastBlock !== null && blockExtended.id !== lastBlock['previousblockhash']) {
|
if (lastBlock !== null && blockExtended.previousblockhash !== lastBlock['hash']) {
|
||||||
logger.warn(`Chain divergence detected at block ${lastBlock['height']}, re-indexing most recent data`);
|
logger.warn(`Chain divergence detected at block ${lastBlock['height']}, re-indexing most recent data`);
|
||||||
await BlocksRepository.$deleteBlocksFrom(lastBlock['height'] - 2);
|
// We assume there won't be a reorg with more than 10 block depth
|
||||||
|
await BlocksRepository.$deleteBlocksFrom(lastBlock['height'] - 10);
|
||||||
await HashratesRepository.$deleteLastEntries();
|
await HashratesRepository.$deleteLastEntries();
|
||||||
this.reindexFlag = true;
|
for (let i = 10; i >= 0; --i) {
|
||||||
} else {
|
await this.$indexBlock(lastBlock['height'] - i);
|
||||||
await blocksRepository.$saveBlockInDatabase(blockExtended);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
await blocksRepository.$saveBlockInDatabase(blockExtended);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block.height % 2016 === 0) {
|
if (block.height % 2016 === 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user