Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -388,18 +388,16 @@ export class ServerWorldStateSynchronizer

private async handleChainFinalized(blockNumber: BlockNumber) {
this.log.verbose(`Finalized chain is now at block ${blockNumber}`);
// Clamp to the oldest block still available in world state. The finalized block number can
// jump backwards (e.g. when the finalization heuristic changes) and try to read block data
// that has already been pruned, which causes the native world state to throw.
// If the finalized block number is older than the oldest available block in world state,
// skip entirely. The finalized block number can jump backwards (e.g. when the finalization
// heuristic changes) and try to read block data that has already been pruned. When this
// happens, there is nothing useful to do — the native world state is already finalized
// past this point and pruning has already happened.
const currentSummary = await this.merkleTreeDb.getStatusSummary();
if (blockNumber < currentSummary.oldestHistoricalBlock) {
if (blockNumber < currentSummary.oldestHistoricalBlock || blockNumber < 1) {
this.log.warn(
`Finalized block ${blockNumber} is older than the oldest available block ${currentSummary.oldestHistoricalBlock}. ` +
`Clamping to oldest available block.`,
`Finalized block ${blockNumber} is older than the oldest available block ${currentSummary.oldestHistoricalBlock}. Skipping.`,
);
blockNumber = currentSummary.oldestHistoricalBlock;
}
if (blockNumber < 1) {
return;
}
const summary = await this.merkleTreeDb.setFinalized(blockNumber);
Expand Down Expand Up @@ -435,6 +433,12 @@ export class ServerWorldStateSynchronizer
}
// Find the block at the start of the checkpoint and remove blocks up to this one
const newHistoricBlock = historicCheckpoint.checkpoint.blocks[0];
if (newHistoricBlock.number <= currentSummary.oldestHistoricalBlock) {
this.log.debug(
`Historic block ${newHistoricBlock.number} is not newer than oldest available ${currentSummary.oldestHistoricalBlock}. Skipping prune.`,
);
return;
}
this.log.verbose(`Pruning historic blocks to ${newHistoricBlock.number}`);
const status = await this.merkleTreeDb.removeHistoricalBlocks(BlockNumber(newHistoricBlock.number));
this.log.debug(`World state summary `, status.summary);
Expand Down
Loading