From 75e57cc6d91172f17e99d989947e476edad46aeb Mon Sep 17 00:00:00 2001 From: Matthew Whitehead Date: Tue, 8 Oct 2024 12:53:15 +0100 Subject: [PATCH] Remove pre-startup catchup. Start on first block import instead Signed-off-by: Matthew Whitehead --- .../besu/controller/BesuControllerBuilder.java | 4 ++-- .../diffbased/bonsai/worldview/BonsaiArchiver.java | 13 +++---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java index 72ff58afe16..f274177ce46 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -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; } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/worldview/BonsaiArchiver.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/worldview/BonsaiArchiver.java index 08e01dff357..47e62185da7 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/worldview/BonsaiArchiver.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/worldview/BonsaiArchiver.java @@ -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() { @@ -232,6 +224,7 @@ public int moveBlockStateToArchive() { @Override public void onBlockAdded(final BlockAddedEvent addedBlockContext) { + initialize(); final Optional blockNumber = Optional.of(addedBlockContext.getBlock().getHeader().getNumber()); blockNumber.ifPresent(