Skip to content

Commit

Permalink
Remove pre-startup catchup. Start on first block import instead
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
  • Loading branch information
matthew1001 committed Oct 8, 2024
1 parent b8facef commit 75e57cc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,8 @@ private BonsaiArchiver createBonsaiArchiver(
trieLogManager,
metricsSystem);

long archivedBlocks = archiver.initialize();
LOG.info("Bonsai archiver initialised, caught up {} blocks", archivedBlocks);
archiver.initialize();
LOG.info("Bonsai archiver initialised");
return archiver;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,9 @@ public BonsaiArchiver(
"Total number of blocks for which state has been archived");
}

public long initialize() {
// On startup there will be recent blocks whose state and storage hasn't been archived yet.
// Start archiving them straight away to catch up with the chain head.
// long totalBlocksCaughtUp = 0;
public void initialize() {
// Read from the DB where we got to previously
latestArchivedBlock.set(rootWorldStateStorage.getLatestArchivedBlock().orElse(0L));
long startingBlock = latestArchivedBlock.get();
while (blockchain.getChainHeadBlockNumber() - latestArchivedBlock.get()
> DISTANCE_FROM_HEAD_BEFORE_ARCHIVING_OLD_STATE) {
moveBlockStateToArchive();
}
return latestArchivedBlock.get() - startingBlock;
}

public long getPendingBlocksCount() {
Expand Down Expand Up @@ -232,6 +224,7 @@ public int moveBlockStateToArchive() {

@Override
public void onBlockAdded(final BlockAddedEvent addedBlockContext) {
initialize();
final Optional<Long> blockNumber =
Optional.of(addedBlockContext.getBlock().getHeader().getNumber());
blockNumber.ifPresent(
Expand Down

0 comments on commit 75e57cc

Please sign in to comment.