Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bonsai limit trie logs enabled true #6561

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
- Requesting the Ethereum Node Record (ENR) to acquire the fork id from bonded peers is now enabled by default, so the following change has been made [#5628](https://github.com/hyperledger/besu/pull/5628):
- `--Xfilter-on-enr-fork-id` has been removed. To disable the feature use `--filter-on-enr-fork-id=false`.
- `--engine-jwt-enabled` has been removed. Use `--engine-jwt-disabled` instead. [#6491](https://github.com/hyperledger/besu/pull/6491)
- SNAP sync is now the default for named networks [#6530](https://github.com/hyperledger/besu/pull/6530)
- `--Xbonsai-limit-trie-logs-enabled` has been removed. Use `--bonsai-limit-trie-logs-enabled` instead. Additionally, this limit is now enabled by default.
- If you do not want the limit enabled (eg you have `--bonsai-historical-block-limit` set < 512), you need to explicitly disable it using `--bonsai-limit-trie-logs-enabled=false` or increase the limit. [#6561](https://github.com/hyperledger/besu/pull/6561)

### Deprecations
- X_SNAP and X_CHECKPOINT are marked for deprecation and will be removed in 24.4.0 in favor of SNAP and CHECKPOINT [#6405](https://github.com/hyperledger/besu/pull/6405)
Expand Down
6 changes: 3 additions & 3 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ private InetAddress autoDiscoverDefaultIP() {
names = {"--sync-mode"},
paramLabel = MANDATORY_MODE_FORMAT_HELP,
description =
"Synchronization mode, possible values are ${COMPLETION-CANDIDATES} (default: FAST if a --network is supplied and privacy isn't enabled. FULL otherwise.)")
"Synchronization mode, possible values are ${COMPLETION-CANDIDATES} (default: SNAP if a --network is supplied and privacy isn't enabled. FULL otherwise.)")
private SyncMode syncMode = null;

@Option(
Expand Down Expand Up @@ -2659,8 +2659,8 @@ private SyncMode getDefaultSyncModeIfNotSet() {
.orElse(
genesisFile == null
&& !privacyOptionGroup.isPrivacyEnabled
&& Optional.ofNullable(network).map(NetworkName::canFastSync).orElse(false)
? SyncMode.FAST
&& Optional.ofNullable(network).map(NetworkName::canSnapSync).orElse(false)
? SyncMode.SNAP
: SyncMode.FULL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ public enum NetworkName {

private final String genesisFile;
private final BigInteger networkId;
private final boolean canFastSync;
private final boolean canSnapSync;
private final String deprecationDate;

NetworkName(final String genesisFile, final BigInteger networkId) {
this(genesisFile, networkId, true);
}

NetworkName(final String genesisFile, final BigInteger networkId, final boolean canFastSync) {
NetworkName(final String genesisFile, final BigInteger networkId, final boolean canSnapSync) {
this.genesisFile = genesisFile;
this.networkId = networkId;
this.canFastSync = canFastSync;
this.canSnapSync = canSnapSync;
// no deprecations planned
this.deprecationDate = null;
}
Expand All @@ -77,12 +77,12 @@ public BigInteger getNetworkId() {
}

/**
* Can fast sync boolean.
* Can SNAP sync boolean.
*
* @return the boolean
*/
public boolean canFastSync() {
return canFastSync;
public boolean canSnapSync() {
return canSnapSync;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public class DataStorageOptions implements CLIOptions<DataStorageConfiguration>

/** The unstable options for data storage. */
public static class Unstable {
private static final String BONSAI_LIMIT_TRIE_LOGS_ENABLED =
"--Xbonsai-limit-trie-logs-enabled";
private static final String BONSAI_LIMIT_TRIE_LOGS_ENABLED = "--bonsai-limit-trie-logs-enabled";

/** The bonsai trie logs pruning window size. */
public static final String BONSAI_TRIE_LOG_PRUNING_WINDOW_SIZE =
Expand All @@ -76,6 +75,7 @@ public static class Unstable {
@CommandLine.Option(
hidden = true,
names = {BONSAI_LIMIT_TRIE_LOGS_ENABLED, "--Xbonsai-trie-log-pruning-enabled"},
fallbackValue = "true",
description =
"Limit the number of trie logs that are retained. (default: ${DEFAULT-VALUE})")
private boolean bonsaiLimitTrieLogsEnabled = DEFAULT_BONSAI_LIMIT_TRIE_LOGS_ENABLED;
Expand Down
18 changes: 15 additions & 3 deletions besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public void callingBesuCommandWithoutOptionsMustSyncWithDefaultValues() {
verify(mockControllerBuilder).build();

assertThat(storageProviderArgumentCaptor.getValue()).isNotNull();
assertThat(syncConfigurationCaptor.getValue().getSyncMode()).isEqualTo(SyncMode.FAST);
assertThat(syncConfigurationCaptor.getValue().getSyncMode()).isEqualTo(SyncMode.SNAP);
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
assertThat(miningArg.getValue().getCoinbase()).isEqualTo(Optional.empty());
assertThat(miningArg.getValue().getMinTransactionGasPrice()).isEqualTo(Wei.of(1000));
Expand Down Expand Up @@ -1149,6 +1149,18 @@ public void syncMode_full_by_default_for_dev() {
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
public void syncMode_snap_by_default() {
parseCommand();
verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture());

final SynchronizerConfiguration syncConfig = syncConfigurationCaptor.getValue();
assertThat(syncConfig.getSyncMode()).isEqualTo(SyncMode.SNAP);

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
public void helpShouldDisplayFastSyncOptions() {
parseCommand("--help");
Expand Down Expand Up @@ -1283,14 +1295,14 @@ public void ethStatsContactOptionCannotBeUsedWithoutEthStatsServerProvided() {

@Test
public void parsesValidBonsaiTrieLimitBackLayersOption() {
parseCommand("--data-storage-format", "BONSAI", "--bonsai-historical-block-limit", "11");
parseCommand("--data-storage-format", "BONSAI", "--bonsai-historical-block-limit", "1024");
verify(mockControllerBuilder)
.dataStorageConfiguration(dataStorageConfigurationArgumentCaptor.capture());

final DataStorageConfiguration dataStorageConfiguration =
dataStorageConfigurationArgumentCaptor.getValue();
assertThat(dataStorageConfiguration.getDataStorageFormat()).isEqualTo(BONSAI);
assertThat(dataStorageConfiguration.getBonsaiMaxLayersToLoad()).isEqualTo(11);
assertThat(dataStorageConfiguration.getBonsaiMaxLayersToLoad()).isEqualTo(1024);
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void noOverrideDefaultValuesIfKeyIsNotPresentInConfigFile() {
verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture());

final SynchronizerConfiguration syncConfig = syncConfigurationCaptor.getValue();
assertThat(syncConfig.getSyncMode()).isEqualTo(SyncMode.FAST);
assertThat(syncConfig.getSyncMode()).isEqualTo(SyncMode.SNAP);
assertThat(syncConfig.getFastSyncMinimumPeerCount()).isEqualTo(5);

assertThat(commandOutput.toString(UTF_8)).isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,36 @@ public void bonsaiTrieLogPruningLimitOption() {
dataStorageConfiguration ->
assertThat(dataStorageConfiguration.getUnstable().getBonsaiTrieLogPruningWindowSize())
.isEqualTo(600),
"--Xbonsai-limit-trie-logs-enabled",
"--bonsai-limit-trie-logs-enabled",
"--Xbonsai-trie-logs-pruning-window-size",
"600");
}

@Test
public void bonsaiTrieLogsEnabled_explicitlySetToFalse() {
internalTestSuccess(
dataStorageConfiguration ->
assertThat(dataStorageConfiguration.getUnstable().getBonsaiLimitTrieLogsEnabled())
.isEqualTo(false),
"--bonsai-limit-trie-logs-enabled=false");
}

@Test
public void bonsaiTrieLogPruningWindowSizeShouldBePositive() {
internalTestFailure(
"--Xbonsai-trie-logs-pruning-window-size=0 must be greater than 0",
"--Xbonsai-limit-trie-logs-enabled",
"--bonsai-limit-trie-logs-enabled",
"--Xbonsai-trie-logs-pruning-window-size",
"0");
}

@Test
public void bonsaiTrieLogPruningWindowSizeShouldBeAboveRetentionLimit() {
internalTestFailure(
"--Xbonsai-trie-logs-pruning-window-size=512 must be greater than --bonsai-historical-block-limit=512",
"--Xbonsai-limit-trie-logs-enabled",
"--Xbonsai-trie-logs-pruning-window-size=127 must be greater than --bonsai-historical-block-limit=512",
"--bonsai-limit-trie-logs-enabled",
"--Xbonsai-trie-logs-pruning-window-size",
"512");
"127");
}

@Test
Expand All @@ -63,9 +72,9 @@ public void bonsaiTrieLogRetentionLimitOption() {
dataStorageConfiguration ->
assertThat(dataStorageConfiguration.getBonsaiMaxLayersToLoad())
.isEqualTo(MINIMUM_BONSAI_TRIE_LOG_RETENTION_LIMIT + 1),
"--Xbonsai-limit-trie-logs-enabled",
"--bonsai-limit-trie-logs-enabled",
"--bonsai-historical-block-limit",
"513");
"129");
}

@Test
Expand All @@ -74,18 +83,18 @@ public void bonsaiTrieLogRetentionLimitOption_boundaryTest() {
dataStorageConfiguration ->
assertThat(dataStorageConfiguration.getBonsaiMaxLayersToLoad())
.isEqualTo(MINIMUM_BONSAI_TRIE_LOG_RETENTION_LIMIT),
"--Xbonsai-limit-trie-logs-enabled",
"--bonsai-limit-trie-logs-enabled",
"--bonsai-historical-block-limit",
"512");
"128");
}

@Test
public void bonsaiTrieLogRetentionLimitShouldBeAboveMinimum() {
internalTestFailure(
"--bonsai-historical-block-limit minimum value is 512",
"--Xbonsai-limit-trie-logs-enabled",
"--bonsai-historical-block-limit minimum value is 128",
"--bonsai-limit-trie-logs-enabled",
"--bonsai-historical-block-limit",
"511");
"127");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public void trieLogRetentionLimitShouldBeAboveMinimum() {
DataStorageConfiguration dataStorageConfiguration =
ImmutableDataStorageConfiguration.builder()
.dataStorageFormat(BONSAI)
.bonsaiMaxLayersToLoad(511L)
.bonsaiMaxLayersToLoad(127L)
.unstable(
ImmutableDataStorageConfiguration.Unstable.builder()
.bonsaiLimitTrieLogsEnabled(true)
Expand All @@ -315,7 +315,7 @@ public void trieLogRetentionLimitShouldBeAboveMinimum() {
() ->
helper.prune(dataStorageConfiguration, inMemoryWorldState, blockchain, Path.of("")))
.isInstanceOf(RuntimeException.class)
.hasMessage("--bonsai-historical-block-limit minimum value is 512");
.hasMessage("--bonsai-historical-block-limit minimum value is 128");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier;
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage;
import org.hyperledger.besu.ethereum.storage.keyvalue.VariablesKeyValueStorage;
import org.hyperledger.besu.ethereum.trie.bonsai.BonsaiWorldStateProvider;
import org.hyperledger.besu.ethereum.trie.bonsai.cache.CachedMerkleTrieLoader;
import org.hyperledger.besu.ethereum.trie.bonsai.storage.BonsaiWorldStateKeyValueStorage;
import org.hyperledger.besu.ethereum.trie.bonsai.trielog.TrieLogManager;
import org.hyperledger.besu.ethereum.trie.bonsai.worldview.BonsaiWorldState;
import org.hyperledger.besu.ethereum.trie.forest.pruner.PrunerConfiguration;
import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration;
import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat;
import org.hyperledger.besu.ethereum.worldstate.ImmutableDataStorageConfiguration;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.ethereum.worldstate.WorldStatePreimageStorage;
import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage;
import org.hyperledger.besu.evm.internal.EvmConfiguration;
Expand Down Expand Up @@ -90,7 +91,8 @@ public class BesuControllerBuilderTest {
@Mock StorageProvider storageProvider;
@Mock GasLimitCalculator gasLimitCalculator;
@Mock WorldStateStorage worldStateStorage;
@Mock WorldStateArchive worldStateArchive;
@Mock BonsaiWorldStateProvider bonsaiWorldStateProvider;
@Mock TrieLogManager trieLogManager;
@Mock BonsaiWorldStateKeyValueStorage bonsaiWorldStateStorage;
@Mock WorldStatePreimageStorage worldStatePreimageStorage;
private final TransactionPoolConfiguration poolConfiguration =
Expand Down Expand Up @@ -167,11 +169,12 @@ BesuControllerBuilder visitWithMockConfigs(final BesuControllerBuilder builder)
@Test
public void shouldDisablePruningIfBonsaiIsEnabled() {
BonsaiWorldState mockWorldState = mock(BonsaiWorldState.class, Answers.RETURNS_DEEP_STUBS);
doReturn(worldStateArchive)
doReturn(bonsaiWorldStateProvider)
.when(besuControllerBuilder)
.createWorldStateArchive(
any(WorldStateStorage.class), any(Blockchain.class), any(CachedMerkleTrieLoader.class));
doReturn(mockWorldState).when(worldStateArchive).getMutable();
doReturn(mockWorldState).when(bonsaiWorldStateProvider).getMutable();
when(bonsaiWorldStateProvider.getTrieLogManager()).thenReturn(trieLogManager);

when(storageProvider.createWorldStateStorage(DataStorageConfiguration.DEFAULT_BONSAI_CONFIG))
.thenReturn(bonsaiWorldStateStorage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ default Unstable getUnstable() {
@Value.Immutable
interface Unstable {

boolean DEFAULT_BONSAI_LIMIT_TRIE_LOGS_ENABLED = false;
long MINIMUM_BONSAI_TRIE_LOG_RETENTION_LIMIT = DEFAULT_BONSAI_MAX_LAYERS_TO_LOAD;
boolean DEFAULT_BONSAI_LIMIT_TRIE_LOGS_ENABLED = true;
long MINIMUM_BONSAI_TRIE_LOG_RETENTION_LIMIT = 128;
int DEFAULT_BONSAI_TRIE_LOG_PRUNING_WINDOW_SIZE = 30_000;
boolean DEFAULT_BONSAI_CODE_USING_CODE_HASH_ENABLED = false;

Expand Down
Loading