Skip to content

Commit

Permalink
merge rebase squash commit for preimage store
Browse files Browse the repository at this point in the history
Signed-off-by: garyschulte <garyschulte@gmail.com>
  • Loading branch information
garyschulte committed Oct 25, 2024
1 parent a3b8863 commit 84cf9c7
Show file tree
Hide file tree
Showing 34 changed files with 406 additions and 283 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
- Added isLabelsObserved to LabelledGauge in plugin-api. Default implementation returns false.

### Breaking Changes
- 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 @@ -2624,6 +2624,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 @@ -220,6 +220,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 @@ -248,4 +249,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 @@ -996,7 +996,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 @@ -23,6 +23,9 @@
import org.hyperledger.besu.plugin.services.storage.KeyValueStorageFactory;
import org.hyperledger.besu.services.kvstore.LimitedInMemoryKeyValueStorage;

import java.util.ArrayList;
import java.util.EnumSet;

public class KeyValueStorageProviderBuilder {

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

// TODO: unhack this storage pre-init hack, maybe a memoized supplier
storageFactory.create(
new ArrayList<>(EnumSet.allOf(KeyValueSegmentIdentifier.class)),
commonConfiguration,
metricsSystem);

final KeyValueStorage worldStatePreImageStorage =
new LimitedInMemoryKeyValueStorage(DEFAULT_WORLD_STATE_PRE_IMAGE_CACHE_SIZE);
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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;

/**
* This store is used in Forest storage format, and expects to use an Updater to insert and commit
* changes to storage, adjacent to worldstate commits. By not being part of the worldstate
* transaction and commit data in this implementation can become out-of-sync (by failing to commit
* preimages by hash) on abnormal exits of besu.
*
* <p>This implementation remains here for the deprecated forest storage format, and should be
* retired along with Forest.
*/
@Deprecated
public class WorldStatePreimageKeyValueStorage implements WorldStatePreimageStorage {
private final KeyValueStorage keyValueStorage;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.hyperledger.besu.ethereum.worldstate.FlatDbMode;
import org.hyperledger.besu.ethereum.worldstate.StateTrieAccountValue;
import org.hyperledger.besu.ethereum.worldstate.WorldStateKeyValueStorage;
import org.hyperledger.besu.evm.account.AccountStorageEntry;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;
import org.hyperledger.besu.plugin.services.storage.KeyValueStorage;
Expand All @@ -41,7 +40,6 @@
import org.hyperledger.besu.plugin.services.storage.SegmentedKeyValueStorageTransaction;

import java.util.List;
import java.util.NavigableMap;
import java.util.Optional;
import java.util.function.Supplier;

Expand Down Expand Up @@ -156,11 +154,6 @@ public Optional<Bytes> getStorageValueByStorageSlotKey(
composedWorldStateStorage);
}

public NavigableMap<Bytes32, AccountStorageEntry> storageEntriesFrom(
final Hash addressHash, final Bytes32 startKeyHash, final int limit) {
throw new RuntimeException("Bonsai Tries does not currently support enumerating storage");
}

public void upgradeToFullFlatDbMode() {
flatDbStrategyProvider.upgradeToFullFlatDbMode(composedWorldStateStorage);
}
Expand Down
Loading

0 comments on commit 84cf9c7

Please sign in to comment.