From 34fc5eed583ec6df7903f452da3b7e0be04b6417 Mon Sep 17 00:00:00 2001 From: garyschulte Date: Fri, 29 Mar 2024 19:27:33 -0700 Subject: [PATCH] Snap server rebase (#6640) * initial snap server implementation Signed-off-by: garyschulte Co-authored-by: Sally MacFarlane --- CHANGELOG.md | 1 + .../org/hyperledger/besu/cli/BesuCommand.java | 2 + .../cli/ConfigurationOverviewBuilder.java | 16 + .../options/unstable/SynchronizerOptions.java | 23 +- .../controller/BesuControllerBuilder.java | 28 +- .../org/hyperledger/besu/datatypes/Hash.java | 3 + ethereum/core/build.gradle | 1 + .../proof/WorldStateProofProvider.java | 30 +- .../NoOpBonsaiCachedWorldStorageManager.java | 2 +- .../BonsaiWorldStateKeyValueStorage.java | 4 +- .../common/DiffBasedWorldStateProvider.java | 2 +- .../DiffBasedCachedWorldStorageManager.java | 50 +- .../DiffBasedWorldStateKeyValueStorage.java | 26 +- .../common/storage/flat/FlatDbStrategy.java | 101 ++- .../storage/flat/FlatDbStrategyProvider.java | 2 +- .../worldstate/WorldStateArchive.java | 3 - .../WorldStateStorageCoordinator.java | 5 + .../bonsai/BonsaiSnapshotIsolationTests.java | 8 +- .../eth/EthProtocolConfiguration.java | 2 +- .../eth/manager/snap/SnapProtocolManager.java | 12 +- .../ethereum/eth/manager/snap/SnapServer.java | 626 ++++++++++++++++- .../messages/snap/GetAccountRangeMessage.java | 3 + .../messages/snap/GetStorageRangeMessage.java | 2 +- .../eth/sync/DefaultSynchronizer.java | 9 + .../sync/snapsync/SnapSyncConfiguration.java | 7 + .../ethereum/eth/sync/snapsync/StackTrie.java | 65 +- .../request/AccountRangeDataRequest.java | 6 + .../request/StorageRangeDataRequest.java | 7 + ...torageFlatDatabaseHealingRangeRequest.java | 2 +- .../eth/manager/snap/SnapServerTest.java | 629 ++++++++++++++++++ .../task/SnapProtocolManagerTestUtil.java | 61 -- .../besu/ethereum/trie/CompactEncoding.java | 32 + .../kvstore/InMemoryKeyValueStorage.java | 10 +- .../kvstore/LayeredKeyValueStorage.java | 119 +++- .../SegmentedInMemoryKeyValueStorage.java | 52 +- 35 files changed, 1714 insertions(+), 237 deletions(-) create mode 100644 ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/snap/SnapServerTest.java delete mode 100644 ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/task/SnapProtocolManagerTestUtil.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 09e2439489..59828b7e24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ - Dedicated log marker for invalid txs removed from the txpool [#6826](https://github.com/hyperledger/besu/pull/6826) - Prevent startup with BONSAI and privacy enabled [#6809](https://github.com/hyperledger/besu/pull/6809) - Remove deprecated Forest pruning [#6810](https://github.com/hyperledger/besu/pull/6810) +- Experimental Snap Sync Server [#6640](https://github.com/hyperledger/besu/pull/6640) ### Bug fixes - Fix txpool dump/restore race condition [#6665](https://github.com/hyperledger/besu/pull/6665) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 26422b0f66..624699f70c 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -2732,6 +2732,8 @@ public class BesuCommand implements DefaultCommandValues, Runnable { getDataStorageConfiguration().getUnstable().getBonsaiTrieLogPruningWindowSize()); } + builder.setSnapServerEnabled(this.unstableSynchronizerOptions.isSnapsyncServerEnabled()); + builder.setTxPoolImplementation(buildTransactionPoolConfiguration().getTxPoolImplementation()); builder.setWorldStateUpdateMode(unstableEvmOptions.toDomainObject().worldUpdaterMode()); diff --git a/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java b/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java index bf03c675d8..2b3dfd7dd5 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java @@ -55,6 +55,7 @@ public class ConfigurationOverviewBuilder { private boolean isBonsaiLimitTrieLogsEnabled = false; private long trieLogRetentionLimit = 0; private Integer trieLogsPruningWindowSize = null; + private boolean isSnapServerEnabled = false; private TransactionPoolConfiguration.Implementation txPoolImplementation; private EvmConfiguration.WorldUpdaterMode worldStateUpdateMode; private Map environment; @@ -219,6 +220,17 @@ public class ConfigurationOverviewBuilder { return this; } + /** + * Sets snap server enabled/disabled + * + * @param snapServerEnabled bool to indicate if snap server is enabled + * @return the builder + */ + public ConfigurationOverviewBuilder setSnapServerEnabled(final boolean snapServerEnabled) { + isSnapServerEnabled = snapServerEnabled; + return this; + } + /** * Sets trie logs pruning window size * @@ -339,6 +351,10 @@ public class ConfigurationOverviewBuilder { lines.add("Using " + worldStateUpdateMode + " worldstate update mode"); + if (isSnapServerEnabled) { + lines.add("Experimental Snap Sync server enabled"); + } + if (isBonsaiLimitTrieLogsEnabled) { final StringBuilder trieLogPruningString = new StringBuilder(); trieLogPruningString diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/SynchronizerOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/SynchronizerOptions.java index 7c9de81579..da5199f85d 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/SynchronizerOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/SynchronizerOptions.java @@ -82,6 +82,8 @@ public class SynchronizerOptions implements CLIOptions