You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
lp.lggr.Criticalw("Unexpected state. Current head number is lower than latest finalized block number", "currentHeadNumber", currentHeadNumber, "dbLatestFinalizedBlockNumber", dbLatestFinalizedBlockNumber)
1342
+
returnnil, fmt.Errorf("current head number %d is lower than latest finalized block number %d: %w", currentHeadNumber, dbLatestFinalizedBlockNumber, commontypes.ErrFinalityViolated)
1337
1343
}
1338
-
blockAfterLCA:=current
1344
+
1339
1345
// We expect reorgs up to the block after latestFinalizedBlock
1340
-
// We loop via parent instead of current so current always holds the LCA+1.
1341
1346
// If the parent block number becomes < the first finalized block our reorg is too deep.
1342
-
// This can happen only if finalityTag is not enabled and fixed finalityDepth is provided via config.
// If we do have the blockhash, return blockAfterLCA
1352
-
returnblockAfterLCA, nil
1353
+
iferrors.Is(err, sql.ErrNoRows) {
1354
+
lp.lggr.Warnw("No ancestor block found in db, this means that the reorg is deeper than the number of blocks we have in the db.", "err", err, "currentHeadNumber", currentHeadNumber, "dbLatestFinalizedBlockNumber", dbLatestFinalizedBlockNumber)
1355
+
// we should return currentHeadNumber as the block after LCA, to avoid drifting too far back.
1356
+
returnlp.headerByNumber(ctx, currentHeadNumber)
1357
+
}
1358
+
returnnil, fmt.Errorf("failed to select ancestor for current block %d: %w", currentHeadNumber-1, err)
1353
1359
}
1354
-
// Otherwise get a new parent and update blockAfterLCA.
lp.lggr.Criticalw("Reorg greater than finality depth detected", "finalityTag", lp.useFinalityTag,
1373
+
"current", rpcChild.Number,
1374
+
"latestFinalized", dbLatestFinalizedBlockNumber,
1375
+
"ourParentHash", ourParent.BlockHash,
1376
+
"expectedParentHash", rpcChild.ParentHash,
1377
+
"childHash", rpcChild.Hash)
1378
+
returnnil, fmt.Errorf("%w: finalized block with hash %s is not parent of canonical block at height %d, with parent hash %s", commontypes.ErrFinalityViolated, ourParent.BlockHash, rpcChild.Number, rpcChild.ParentHash)
returnnil, fmt.Errorf("%w: finalized block hash %s does not match RPC's %s at height %d", commontypes.ErrFinalityViolated, ourParentBlockHash, blockAfterLCA.Hash, blockAfterLCA.Number)
1381
+
currentHeadNumber=ourParent.BlockNumber
1382
+
}
1364
1383
}
1365
1384
1366
1385
// PruneOldBlocks removes blocks that are > lp.keepFinalizedBlocksDepth behind the latest finalized block.
0 commit comments