From a7e1f6ace0167bbaff89f00f7a0e94747160a06b Mon Sep 17 00:00:00 2001 From: kingnhcomcast <114761064+kingnhcomcast@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:46:58 -0400 Subject: [PATCH 1/2] 7536 use head for snap sync (#7718) * Add support to sync to head instead of safe block during snapsync Signed-off-by: Kevin King Signed-off-by: kingnhcomcast <114761064+kingnhcomcast@users.noreply.github.com> --- CHANGELOG.md | 3 +- .../org/hyperledger/besu/cli/BesuCommand.java | 1 + .../cli/ConfigurationOverviewBuilder.java | 17 ++ .../options/unstable/SynchronizerOptions.java | 26 ++- .../controller/BesuControllerBuilder.java | 30 +++- .../MergeBesuControllerBuilderTest.java | 39 +++- .../sync/fastsync/PivotSelectorFromBlock.java | 167 ++++++++++++++++++ .../fastsync/PivotSelectorFromHeadBlock.java | 58 ++++++ .../fastsync/PivotSelectorFromSafeBlock.java | 138 ++------------- .../sync/snapsync/SnapSyncConfiguration.java | 7 + .../sync/snapsync/SnapSyncMetricsManager.java | 4 +- .../sync/fastsync/FastSyncActionsTest.java | 52 +++++- 12 files changed, 408 insertions(+), 134 deletions(-) create mode 100644 ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotSelectorFromBlock.java create mode 100644 ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotSelectorFromHeadBlock.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 379c87ee08..5bcbfa51b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,8 @@ - Add configuration of Consolidation Request Contract Address via genesis configuration [#7647](https://github.com/hyperledger/besu/pull/7647) - Interrupt pending transaction processing on block creation timeout [#7673](https://github.com/hyperledger/besu/pull/7673) - Align gas cap calculation for transaction simulation to Geth approach [#7703](https://github.com/hyperledger/besu/pull/7703) -- Expose chainId in the `BlockchainService` [#7702](https://github.com/hyperledger/besu/pull/7702) +- Expose chainId in the `BlockchainService` [7702](https://github.com/hyperledger/besu/pull/7702) +- Use head block instead of safe block for snap sync [7536](https://github.com/hyperledger/besu/issues/7536) - Add support for `chainId` in `CallParameters` [#7720](https://github.com/hyperledger/besu/pull/7720) ### Bug fixes 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 41402fa04b..125cf3435c 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -2738,6 +2738,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { builder.setSnapServerEnabled(this.unstableSynchronizerOptions.isSnapsyncServerEnabled()); builder.setSnapSyncBftEnabled(this.unstableSynchronizerOptions.isSnapSyncBftEnabled()); + builder.setSnapSyncToHeadEnabled(this.unstableSynchronizerOptions.isSnapSyncToHeadEnabled()); 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 b2f89a349e..8cb815e770 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java @@ -57,6 +57,7 @@ public class ConfigurationOverviewBuilder { private Integer trieLogsPruningWindowSize = null; private boolean isSnapServerEnabled = false; private boolean isSnapSyncBftEnabled = false; + private boolean isSnapSyncToHeadEnabled = true; private TransactionPoolConfiguration.Implementation txPoolImplementation; private EvmConfiguration.WorldUpdaterMode worldStateUpdateMode; private Map environment; @@ -245,6 +246,18 @@ public class ConfigurationOverviewBuilder { return this; } + /** + * Sets snap sync to head enabled/disabled + * + * @param snapSyncToHeadEnabled bool to indicate if snap sync to head is enabled + * @return the builder + */ + public ConfigurationOverviewBuilder setSnapSyncToHeadEnabled( + final boolean snapSyncToHeadEnabled) { + isSnapSyncToHeadEnabled = snapSyncToHeadEnabled; + return this; + } + /** * Sets trie logs pruning window size * @@ -373,6 +386,10 @@ public class ConfigurationOverviewBuilder { lines.add("Experimental Snap Sync for BFT enabled"); } + if (isSnapSyncToHeadEnabled) { + lines.add("Snap Sync to Head 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 816d9df00a..e8a330c2ef 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 @@ -87,6 +87,8 @@ public class SynchronizerOptions implements CLIOptions