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)
1331
+
returnnil, fmt.Errorf("current head number %d is lower than latest finalized block number %d: %w", currentHeadNumber, dbLatestFinalizedBlockNumber, commontypes.ErrFinalityViolated)
1326
1332
}
1327
-
blockAfterLCA:=current
1333
+
1328
1334
// We expect reorgs up to the block after latestFinalizedBlock
1329
-
// We loop via parent instead of current so current always holds the LCA+1.
1330
1335
// If the parent block number becomes < the first finalized block our reorg is too deep.
1331
-
// This can happen only if finalityTag is not enabled and fixed finalityDepth is provided via config.
// If we do have the blockhash, return blockAfterLCA
1341
-
returnblockAfterLCA, nil
1342
+
iferrors.Is(err, sql.ErrNoRows) {
1343
+
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)
1344
+
// we should return currentHeadNumber as the block after LCA, to avoid drifting too far back.
1345
+
returnlp.headerByNumber(ctx, currentHeadNumber)
1346
+
}
1347
+
returnnil, fmt.Errorf("failed to select ancestor for current block %d: %w", currentHeadNumber-1, err)
1342
1348
}
1343
-
// Otherwise get a new parent and update blockAfterLCA.
lp.lggr.Criticalw("Reorg greater than finality depth detected", "finalityTag", lp.useFinalityTag,
1362
+
"current", rpcChild.Number,
1363
+
"latestFinalized", dbLatestFinalizedBlockNumber,
1364
+
"ourParentHash", ourParent.BlockHash,
1365
+
"expectedParentHash", rpcChild.ParentHash,
1366
+
"childHash", rpcChild.Hash)
1367
+
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)
1370
+
currentHeadNumber=ourParent.BlockNumber
1371
+
}
1353
1372
}
1354
1373
1355
1374
// PruneOldBlocks removes blocks that are > lp.keepFinalizedBlocksDepth behind the latest finalized block.
0 commit comments