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

Feature/preimage store #7800

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

### Breaking Changes
- Removed Retesteth rpc service and commands [#7833](https://github.com/hyperledger/besu/pull/7783)
- Removed deprecated experimental feature names
- `--Xsnapsync-synchronizer-flat-db-healing-enabled` in favor of `--Xbonsai-full-flat-db-enabled`
- `--Xbonsai-limit-trie-logs-enabled` and `--Xbonsai-trie-log-pruning-enabled` in favor of `--bonsai-limit-trie-logs-enabled`
- `--Xbonsai-trie-logs-pruning-window-size` in favor of `--bonsai-trie-logs-pruning-window-size`


### Upcoming Breaking Changes

Expand Down
3 changes: 3 additions & 0 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2620,6 +2620,9 @@ public void setIgnorableStorageSegments() {
if (!unstableChainPruningOptions.getChainDataPruningEnabled()) {
rocksDBPlugin.addIgnorableSegmentIdentifier(KeyValueSegmentIdentifier.CHAIN_PRUNER_STATE);
}
if (!dataStorageOptions.toDomainObject().getHashPreImageStorageEnabled()) {
rocksDBPlugin.addIgnorableSegmentIdentifier(KeyValueSegmentIdentifier.HASH_PREIMAGE_STORE);
}
}

private void validatePostMergeCheckpointBlockRequirements() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.cli.options.storage;

import static org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration.DEFAULT_HASH_PREIMAGE_STORAGE_ENABLED;
import static org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration.DEFAULT_RECEIPT_COMPACTION_ENABLED;

import org.hyperledger.besu.cli.options.CLIOptions;
Expand All @@ -35,6 +36,9 @@ public class DataStorageOptions implements CLIOptions<DataStorageConfiguration>

private static final String DATA_STORAGE_FORMAT = "--data-storage-format";

/** Feature to store hash preimages as part of worldstate */
public static final String HASH_STORE_PREIMAGE_ENABLED = "--hash-preimage-storage-enabled";

// Use Bonsai DB
@Option(
names = {DATA_STORAGE_FORMAT},
Expand All @@ -49,6 +53,13 @@ public class DataStorageOptions implements CLIOptions<DataStorageConfiguration>
fallbackValue = "true")
private Boolean receiptCompactionEnabled = DEFAULT_RECEIPT_COMPACTION_ENABLED;

@CommandLine.Option(
names = {HASH_STORE_PREIMAGE_ENABLED},
description =
"Format to store trie data in. Either FOREST or BONSAI (default: ${DEFAULT-VALUE}).",
arity = "1")
private Boolean hashStorePreimagesEnabled = DEFAULT_HASH_PREIMAGE_STORAGE_ENABLED;

/**
* Options specific to diff-based storage modes. Holds the necessary parameters to configure
* diff-based storage, such as the Bonsai mode or Verkle in the future.
Expand Down Expand Up @@ -88,6 +99,7 @@ public static DataStorageOptions fromConfig(final DataStorageConfiguration domai
final DataStorageOptions dataStorageOptions = DataStorageOptions.create();
dataStorageOptions.dataStorageFormat = domainObject.getDataStorageFormat();
dataStorageOptions.receiptCompactionEnabled = domainObject.getReceiptCompactionEnabled();
dataStorageOptions.hashStorePreimagesEnabled = domainObject.getHashPreImageStorageEnabled();
dataStorageOptions.diffBasedSubStorageOptions =
DiffBasedSubStorageOptions.fromConfig(domainObject.getDiffBasedSubStorageConfiguration());
return dataStorageOptions;
Expand All @@ -99,6 +111,7 @@ public DataStorageConfiguration toDomainObject() {
ImmutableDataStorageConfiguration.builder()
.dataStorageFormat(dataStorageFormat)
.receiptCompactionEnabled(receiptCompactionEnabled)
.hashPreImageStorageEnabled(hashStorePreimagesEnabled)
.diffBasedSubStorageConfiguration(diffBasedSubStorageOptions.toDomainObject());
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,16 @@ public class DiffBasedSubStorageOptions implements CLIOptions<DiffBasedSubStorag
public static final String TRIE_LOG_PRUNING_WINDOW_SIZE =
"--bonsai-trie-logs-pruning-window-size";

// TODO --Xbonsai-limit-trie-logs-enabled and --Xbonsai-trie-log-pruning-enabled are deprecated,
// remove in a future release
@SuppressWarnings("ExperimentalCliOptionMustBeCorrectlyDisplayed")
@Option(
names = {
LIMIT_TRIE_LOGS_ENABLED,
"--Xbonsai-limit-trie-logs-enabled", // deprecated
"--Xbonsai-trie-log-pruning-enabled" // deprecated
},
names = {LIMIT_TRIE_LOGS_ENABLED},
fallbackValue = "true",
description = "Limit the number of trie logs that are retained. (default: ${DEFAULT-VALUE})")
private Boolean limitTrieLogsEnabled = DEFAULT_LIMIT_TRIE_LOGS_ENABLED;

// TODO --Xbonsai-trie-logs-pruning-window-size is deprecated, remove in a future release
@SuppressWarnings("ExperimentalCliOptionMustBeCorrectlyDisplayed")
@Option(
names = {
TRIE_LOG_PRUNING_WINDOW_SIZE,
"--Xbonsai-trie-logs-pruning-window-size" // deprecated
},
names = {TRIE_LOG_PRUNING_WINDOW_SIZE},
description =
"The max number of blocks to load and prune trie logs for at startup. (default: ${DEFAULT-VALUE})")
private Integer trieLogPruningWindowSize = DEFAULT_TRIE_LOG_PRUNING_WINDOW_SIZE;
Expand All @@ -88,13 +78,11 @@ public class DiffBasedSubStorageOptions implements CLIOptions<DiffBasedSubStorag
/** The unstable options for data storage. */
public static class Unstable {

// TODO: --Xsnapsync-synchronizer-flat-db-healing-enabled is deprecated, remove it in a future
// release
@Option(
hidden = true,
names = {
"--Xbonsai-full-flat-db-enabled",
"--Xsnapsync-synchronizer-flat-db-healing-enabled"
},
arity = "1",
description = "Enables bonsai full flat database strategy. (default: ${DEFAULT-VALUE})")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,18 @@ public DataStoreConfigurationImpl(final DataStorageConfiguration dataStorageConf
}

@Override
public DataStorageFormat getDatabaseFormat() {
public DataStorageFormat getDataStorageFormat() {
return dataStorageConfiguration.getDataStorageFormat();
}

@Override
public boolean getReceiptCompactionEnabled() {
return dataStorageConfiguration.getReceiptCompactionEnabled();
}

@Override
public boolean getHashPreImageStorageEnabled() {
return dataStorageConfiguration.getHashPreImageStorageEnabled();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,6 @@ public void bonsaiTrieLogPruningLimitOption() {
"600");
}

@Test
public void bonsaiTrieLogPruningLimitLegacyOption() {
internalTestSuccess(
dataStorageConfiguration ->
assertThat(
dataStorageConfiguration
.getDiffBasedSubStorageConfiguration()
.getTrieLogPruningWindowSize())
.isEqualTo(600),
"--Xbonsai-limit-trie-logs-enabled",
"--Xbonsai-trie-logs-pruning-window-size",
"600");
}

@Test
public void bonsaiTrieLogsEnabled_explicitlySetToFalse() {
internalTestSuccess(
Expand Down
3 changes: 2 additions & 1 deletion besu/src/test/resources/everything_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ bonsai-historical-block-limit=512
bonsai-limit-trie-logs-enabled=true
bonsai-trie-logs-pruning-window-size=100_000
receipt-compaction-enabled=true
hash-preimage-storage-enabled=true

# feature flags
Xsecp256k1-native-enabled=false
Expand Down Expand Up @@ -261,4 +262,4 @@ Xevm-jumpdest-cache-weight-kb=32000
# plugins
Xplugins-external-enabled=true
plugins=["none"]
plugin-continue-on-error=false
plugin-continue-on-error=false
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ def calculateVersion() {
return "${project.version}"
} else {
// If no version is supplied or it doesn't match the semantic versioning, calculate from git
println("Generating project version as supplied is version not semver: ${project.version}")
println("Generating project version as supplied version is not semver: ${project.version}")
def gitDetails = getGitCommitDetails(7) // Adjust length as needed
return "${gitDetails.date}-develop-${gitDetails.hash}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public enum KeyValueSegmentIdentifier implements SegmentIdentifier {
BACKWARD_SYNC_CHAIN(new byte[] {15}),
SNAPSYNC_MISSING_ACCOUNT_RANGE(new byte[] {16}),
SNAPSYNC_ACCOUNT_TO_FIX(new byte[] {17}),
CHAIN_PRUNER_STATE(new byte[] {18});
CHAIN_PRUNER_STATE(new byte[] {18}),
HASH_PREIMAGE_STORE(new byte[] {19}, EnumSet.of(BONSAI), true, false, false);

private final byte[] id;
private final EnumSet<DataStorageFormat> formats;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import com.google.common.base.Suppliers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -47,17 +49,17 @@ public class KeyValueStorageProvider implements StorageProvider {

protected final Function<List<SegmentIdentifier>, SegmentedKeyValueStorage>
segmentedStorageCreator;
private final KeyValueStorage worldStatePreimageStorage;
private final Supplier<KeyValueStorage> preimageStorageSupplier;
protected final Map<List<SegmentIdentifier>, SegmentedKeyValueStorage> storageInstances =
new HashMap<>();
private final ObservableMetricsSystem metricsSystem;

public KeyValueStorageProvider(
final Function<List<SegmentIdentifier>, SegmentedKeyValueStorage> segmentedStorageCreator,
final KeyValueStorage worldStatePreimageStorage,
final Supplier<KeyValueStorage> worldStatePreimageStorage,
final ObservableMetricsSystem metricsSystem) {
this.segmentedStorageCreator = segmentedStorageCreator;
this.worldStatePreimageStorage = worldStatePreimageStorage;
this.preimageStorageSupplier = Suppliers.memoize(worldStatePreimageStorage::get);
this.metricsSystem = metricsSystem;
}

Expand Down Expand Up @@ -99,7 +101,7 @@ public WorldStateStorageCoordinator createWorldStateStorageCoordinator(

@Override
public WorldStatePreimageStorage createWorldStatePreimageStorage() {
return new WorldStatePreimageKeyValueStorage(worldStatePreimageStorage);
return new WorldStatePreimageKeyValueStorage(preimageStorageSupplier.get());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.hyperledger.besu.plugin.services.storage.KeyValueStorageFactory;
import org.hyperledger.besu.services.kvstore.LimitedInMemoryKeyValueStorage;

import java.util.function.Supplier;

public class KeyValueStorageProviderBuilder {

private static final long DEFAULT_WORLD_STATE_PRE_IMAGE_CACHE_SIZE = 5_000L;
Expand Down Expand Up @@ -55,12 +57,19 @@ public KeyValueStorageProvider build() {
"Cannot build a storage provider without the plugin common configuration.");
checkNotNull(metricsSystem, "Cannot build a storage provider without a metrics system.");

final KeyValueStorage worldStatePreImageStorage =
new LimitedInMemoryKeyValueStorage(DEFAULT_WORLD_STATE_PRE_IMAGE_CACHE_SIZE);
final Supplier<KeyValueStorage> preimageStorageSupplier =
commonConfiguration.getDataStorageConfiguration().getHashPreImageStorageEnabled()
? () ->
storageFactory.create(
KeyValueSegmentIdentifier.HASH_PREIMAGE_STORE,
commonConfiguration,
metricsSystem)
: () -> new LimitedInMemoryKeyValueStorage(DEFAULT_WORLD_STATE_PRE_IMAGE_CACHE_SIZE);
;

return new KeyValueStorageProvider(
segments -> storageFactory.create(segments, commonConfiguration, metricsSystem),
worldStatePreImageStorage,
preimageStorageSupplier,
(ObservableMetricsSystem) metricsSystem);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static MutableWorldState createGenesisBonsaiWorldState() {
new BonsaiWorldStateKeyValueStorage(
new KeyValueStorageProvider(
segmentIdentifiers -> new SegmentedInMemoryKeyValueStorage(),
new InMemoryKeyValueStorage(),
() -> new InMemoryKeyValueStorage(),
new NoOpMetricsSystem()),
new NoOpMetricsSystem(),
DataStorageConfiguration.DEFAULT_BONSAI_CONFIG);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public BonsaiSnapshotWorldStateKeyValueStorage(
final SnappedKeyValueStorage segmentedWorldStateStorage,
final KeyValueStorage trieLogStorage) {
super(
parentWorldStateStorage.flatDbStrategyProvider, segmentedWorldStateStorage, trieLogStorage);
parentWorldStateStorage.flatDbStrategyProvider,
segmentedWorldStateStorage,
trieLogStorage,
parentWorldStateStorage.getPreimageStorage());
this.parentWorldStateStorage = parentWorldStateStorage;
this.subscribeParentId = parentWorldStateStorage.subscribe(this);
}
Expand Down
Loading
Loading