Skip to content

Commit e238489

Browse files
AndresElizondoAndrés Elizondo
and
Andrés Elizondo
authored
Adds reorg detection within RPCs reponse. (#171)
* Adds reorg detection within RPCs reponse. * Bugfix: Adds checks for newBlocks size. --------- Co-authored-by: Andrés Elizondo <[email protected]>
1 parent 5578514 commit e238489

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/scripts/pull_and_save_block_events.ts

+12
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,18 @@ export class BlockEventsScraper {
487487
throw Error(`Big reorg detected, of more than ${lookback}, manual intervention needed`);
488488
}
489489

490+
// Finding reorgs within RPC's response
491+
if (newBlocks.length > 1) {
492+
var prevBlock = newBlocks[0];
493+
for (const currBlock of newBlocks.slice(1)) {
494+
if (currBlock.parentHash !== prevBlock.hash) {
495+
logger.warn(`Reorg detected within RPC's response. Ignoring invalid response and retrying.`);
496+
return;
497+
}
498+
prevBlock = currBlock;
499+
}
500+
}
501+
490502
try {
491503
const tmpBlockNumbers = newBlocks.map((block) => block?.number);
492504
logger.debug(`response blockNumbers: ${JSON.stringify(tmpBlockNumbers)}`);

0 commit comments

Comments
 (0)