Skip to content

Commit

Permalink
remove initial sync delay for chain pruner
Browse files Browse the repository at this point in the history
Signed-off-by: garyschulte <garyschulte@gmail.com>
  • Loading branch information
garyschulte committed Mar 4, 2024
1 parent d104afe commit b9dd7f5
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public class ChainPruningOptions implements CLIOptions<ChainPrunerConfiguration>
private static final String CHAIN_PRUNING_BLOCKS_RETAINED_LIMIT_FLAG =
"--Xchain-pruning-blocks-retained-limit";
private static final String CHAIN_PRUNING_FREQUENCY_FLAG = "--Xchain-pruning-frequency";
/** The constant DEFAULT_CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED. */
public static final long DEFAULT_CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED = 7200;

/**
* The "CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED_LIMIT" field sets the minimum limit for the
* "DEFAULT_CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED" value. For most networks, the default value of
Expand All @@ -57,11 +54,10 @@ public class ChainPruningOptions implements CLIOptions<ChainPrunerConfiguration>
hidden = true,
names = {CHAIN_PRUNING_BLOCKS_RETAINED_FLAG},
description =
"The number of recent blocks for which to keep the chain data. Must be >= "
"The number of recent blocks for which to keep the chain data. Should be >= "
+ CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED_LIMIT
+ " (default: ${DEFAULT-VALUE})")
private final Long chainDataPruningBlocksRetained =
DEFAULT_CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED;
private final Long chainDataPruningBlocksRetained = CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED_LIMIT;

@CommandLine.Option(
hidden = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ public BesuController build() {
protocolContext
.safeConsensusContext(MergeContext.class)
.ifPresent(mergeContext -> mergeContext.setIsChainPruningEnabled(true));
final ChainDataPruner chainDataPruner = createChainPruner(syncState, blockchainStorage);
final ChainDataPruner chainDataPruner = createChainPruner(blockchainStorage);
blockchain.observeBlockAdded(chainDataPruner);
LOG.info(
"Chain data pruning enabled with recent blocks retained to be: "
Expand Down Expand Up @@ -1080,16 +1080,14 @@ WorldStateArchive createWorldStateArchive(
};
}

private ChainDataPruner createChainPruner(
final SyncState syncState, final BlockchainStorage blockchainStorage) {
private ChainDataPruner createChainPruner(final BlockchainStorage blockchainStorage) {
return new ChainDataPruner(
blockchainStorage,
new ChainDataPrunerStorage(
storageProvider.getStorageBySegmentIdentifier(
KeyValueSegmentIdentifier.CHAIN_PRUNER_STATE)),
chainPrunerConfiguration.getChainPruningBlocksRetained(),
chainPrunerConfiguration.getChainPruningBlocksFrequency(),
syncState::isInitialSyncPhaseDone,
MonitoredExecutors.newBoundedThreadPool(
ChainDataPruner.class.getSimpleName(),
1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.util.Collection;
import java.util.concurrent.ExecutorService;
import java.util.function.Supplier;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -33,29 +32,22 @@ public class ChainDataPruner implements BlockAddedObserver {
private final long blocksToRetain;
private final long pruningFrequency;
private final ExecutorService pruningExecutor;
private final Supplier<Boolean> isInitialSyncPhaseDoneSupplier;

public ChainDataPruner(
final BlockchainStorage blockchainStorage,
final ChainDataPrunerStorage prunerStorage,
final long blocksToRetain,
final long pruningFrequency,
final Supplier<Boolean> isInitialSyncPhaseDoneSupplier,
final ExecutorService pruningExecutor) {
this.blockchainStorage = blockchainStorage;
this.prunerStorage = prunerStorage;
this.blocksToRetain = blocksToRetain;
this.pruningFrequency = pruningFrequency;
this.isInitialSyncPhaseDoneSupplier = isInitialSyncPhaseDoneSupplier;
this.pruningExecutor = pruningExecutor;
}

@Override
public void onBlockAdded(final BlockAddedEvent event) {
if (!isInitialSyncPhaseDoneSupplier.get()) {
// not run block pruning because the initial synchronization is still in progress.
return;
}
final long blockNumber = event.getBlock().getHeader().getNumber();
final long storedPruningMark = prunerStorage.getPruningMark().orElse(blockNumber);
if (blockNumber < storedPruningMark) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public void singleChainPruning() {
new ChainDataPrunerStorage(new InMemoryKeyValueStorage()),
512,
0,
() -> true, // Set to 'true' to indicate that the initial synchronization phase has
// completed
new BlockingExecutor());
Block genesisBlock = gen.genesisBlock();
Expand Down Expand Up @@ -88,7 +87,6 @@ public void forkPruning() {
new ChainDataPrunerStorage(new InMemoryKeyValueStorage()),
512,
0,
() -> true, // Set to 'true' to indicate that the initial synchronization phase has
// completed
new BlockingExecutor());
Block genesisBlock = gen.genesisBlock();
Expand Down Expand Up @@ -135,7 +133,6 @@ public void disablePruningWhenInitialSyncPhaseRunning() {
new ChainDataPrunerStorage(new InMemoryKeyValueStorage()),
512,
0,
() -> false, // Set to 'false' to indicate that the initial synchronization phase is
// running.
new BlockingExecutor());
Block genesisBlock = gen.genesisBlock();
Expand Down

0 comments on commit b9dd7f5

Please sign in to comment.