mirror of
https://github.com/mempool/mempool.git
synced 2025-03-04 01:54:14 +01:00
Fix chain divergence detection upon new block (use the new interface)
This commit is contained in:
parent
76ae9d4ccb
commit
a67656389e
2 changed files with 16 additions and 9 deletions
|
@ -570,18 +570,18 @@ 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.previousblockhash !== lastBlock['hash']) {
|
if (lastBlock !== null && blockExtended.previousblockhash !== lastBlock.id) {
|
||||||
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`);
|
||||||
// We assume there won't be a reorg with more than 10 block depth
|
// We assume there won't be a reorg with more than 10 block depth
|
||||||
await BlocksRepository.$deleteBlocksFrom(lastBlock['height'] - 10);
|
await BlocksRepository.$deleteBlocksFrom(lastBlock.height - 10);
|
||||||
await HashratesRepository.$deleteLastEntries();
|
await HashratesRepository.$deleteLastEntries();
|
||||||
await BlocksSummariesRepository.$deleteBlocksFrom(lastBlock['height'] - 10);
|
await BlocksSummariesRepository.$deleteBlocksFrom(lastBlock.height - 10);
|
||||||
await cpfpRepository.$deleteClustersFrom(lastBlock['height'] - 10);
|
await cpfpRepository.$deleteClustersFrom(lastBlock.height - 10);
|
||||||
for (let i = 10; i >= 0; --i) {
|
for (let i = 10; i >= 0; --i) {
|
||||||
const newBlock = await this.$indexBlock(lastBlock['height'] - i);
|
const newBlock = await this.$indexBlock(lastBlock.height - i);
|
||||||
await this.$getStrippedBlockTransactions(newBlock.id, true, true);
|
await this.$getStrippedBlockTransactions(newBlock.id, true, true);
|
||||||
if (config.MEMPOOL.CPFP_INDEXING) {
|
if (config.MEMPOOL.CPFP_INDEXING) {
|
||||||
await this.$indexCPFP(newBlock.id, lastBlock['height'] - i);
|
await this.$indexCPFP(newBlock.id, lastBlock.height - i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await mining.$indexDifficultyAdjustments();
|
await mining.$indexDifficultyAdjustments();
|
||||||
|
|
|
@ -525,8 +525,15 @@ class BlocksRepository {
|
||||||
public async $validateChain(): Promise<boolean> {
|
public async $validateChain(): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
const start = new Date().getTime();
|
const start = new Date().getTime();
|
||||||
const [blocks]: any[] = await DB.query(`SELECT height, hash, previous_block_hash,
|
const [blocks]: any[] = await DB.query(`
|
||||||
UNIX_TIMESTAMP(blockTimestamp) as timestamp FROM blocks ORDER BY height`);
|
SELECT
|
||||||
|
height,
|
||||||
|
hash,
|
||||||
|
previous_block_hash,
|
||||||
|
UNIX_TIMESTAMP(blockTimestamp) AS timestamp
|
||||||
|
FROM blocks
|
||||||
|
ORDER BY height
|
||||||
|
`);
|
||||||
|
|
||||||
let partialMsg = false;
|
let partialMsg = false;
|
||||||
let idx = 1;
|
let idx = 1;
|
||||||
|
|
Loading…
Add table
Reference in a new issue