From 88e1e201b90a02c3b2c99fe303eb514b5d0631d5 Mon Sep 17 00:00:00 2001 From: Matilda-Clerke Date: Fri, 12 Jul 2024 13:34:27 +1000 Subject: [PATCH 1/3] 6612: Remove deprecated sync modes and related helper methods Signed-off-by: Matilda-Clerke --- .../org/hyperledger/besu/cli/BesuCommand.java | 10 ++++----- .../besu/controller/BesuController.java | 4 +--- .../controller/BesuControllerBuilder.java | 5 ++--- .../hyperledger/besu/cli/BesuCommandTest.java | 2 +- .../besu/ethereum/eth/manager/EthPeers.java | 2 +- .../eth/sync/DefaultSynchronizer.java | 5 ++--- .../besu/ethereum/eth/sync/SyncMode.java | 22 ++----------------- 7 files changed, 14 insertions(+), 36 deletions(-) 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 427cac92480..118e586b178 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -1566,11 +1566,11 @@ private void validateConsensusSyncCompatibilityOptions() { || genesisConfigOptionsSupplier.get().isQbft()) && !unstableSynchronizerOptions.isSnapSyncBftEnabled()) { final String errorSuffix = "can't be used with BFT networks"; - if (SyncMode.CHECKPOINT.equals(syncMode) || SyncMode.X_CHECKPOINT.equals(syncMode)) { + if (SyncMode.CHECKPOINT.equals(syncMode)) { throw new ParameterException( commandLine, String.format("%s %s", "Checkpoint sync", errorSuffix)); } - if (syncMode == SyncMode.SNAP || syncMode == SyncMode.X_SNAP) { + if (syncMode == SyncMode.SNAP) { throw new ParameterException(commandLine, String.format("%s %s", "Snap sync", errorSuffix)); } } @@ -1753,7 +1753,7 @@ && isOptionSet(commandLine, "--sync-min-peers")) { CommandLineUtils.failIfOptionDoesntMeetRequirement( commandLine, "--Xcheckpoint-post-merge-enabled can only be used with CHECKPOINT sync-mode", - SyncMode.isCheckpointSync(getDefaultSyncModeIfNotSet()), + getDefaultSyncModeIfNotSet() == SyncMode.CHECKPOINT, singletonList("--Xcheckpoint-post-merge-enabled")); CommandLineUtils.failIfOptionDoesntMeetRequirement( @@ -2043,10 +2043,10 @@ private PrivacyParameters privacyParameters() { if (syncMode == SyncMode.FAST) { throw new ParameterException(commandLine, String.format("%s %s", "Fast sync", errorSuffix)); } - if (syncMode == SyncMode.SNAP || syncMode == SyncMode.X_SNAP) { + if (syncMode == SyncMode.SNAP) { throw new ParameterException(commandLine, String.format("%s %s", "Snap sync", errorSuffix)); } - if (syncMode == SyncMode.CHECKPOINT || syncMode == SyncMode.X_CHECKPOINT) { + if (syncMode == SyncMode.CHECKPOINT) { throw new ParameterException( commandLine, String.format("%s %s", "Checkpoint sync", errorSuffix)); } diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java index 6942fda3166..fb99318905a 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java @@ -14,8 +14,6 @@ */ package org.hyperledger.besu.controller; -import static org.hyperledger.besu.ethereum.eth.sync.SyncMode.isCheckpointSync; - import org.hyperledger.besu.cli.config.EthNetworkConfig; import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.config.GenesisConfigOptions; @@ -361,7 +359,7 @@ public BesuControllerBuilder fromGenesisFile( // wrap with TransitionBesuControllerBuilder if we have a terminal total difficulty: if (configOptions.getTerminalTotalDifficulty().isPresent()) { // Enable start with vanilla MergeBesuControllerBuilder for PoS checkpoint block - if (isCheckpointSync(syncMode) && isCheckpointPoSBlock(configOptions)) { + if (syncMode == SyncMode.CHECKPOINT && isCheckpointPoSBlock(configOptions)) { return new MergeBesuControllerBuilder().genesisConfigFile(genesisConfigFile); } else { // TODO this should be changed to vanilla MergeBesuControllerBuilder and the Transition* diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java index 6123535f637..9a3db952ef5 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -708,8 +708,7 @@ public BesuController build() { ethPeers.setTrailingPeerRequirementsSupplier(synchronizer::calculateTrailingPeerRequirements); - if (SyncMode.isSnapSync(syncConfig.getSyncMode()) - || SyncMode.isCheckpointSync(syncConfig.getSyncMode())) { + if (syncConfig.getSyncMode() == SyncMode.SNAP || syncConfig.getSyncMode() == SyncMode.CHECKPOINT) { synchronizer.subscribeInSync((b) -> ethPeers.snapServerPeersNeeded(!b)); ethPeers.snapServerPeersNeeded(true); } else { @@ -1157,7 +1156,7 @@ protected List createPeerValidators(final ProtocolSchedule protoc final CheckpointConfigOptions checkpointConfigOptions = genesisConfigOptions.getCheckpointOptions(); - if (SyncMode.isCheckpointSync(syncConfig.getSyncMode()) && checkpointConfigOptions.isValid()) { + if (syncConfig.getSyncMode() == SyncMode.CHECKPOINT && checkpointConfigOptions.isValid()) { validators.add( new CheckpointBlocksPeerValidator( protocolSchedule, diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index c6ffbdc1759..efeff412d62 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -1107,7 +1107,7 @@ public void syncMode_invalid() { assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) .contains( - "Invalid value for option '--sync-mode': expected one of [FULL, FAST, SNAP, CHECKPOINT, X_SNAP, X_CHECKPOINT] (case-insensitive) but was 'bogus'"); + "Invalid value for option '--sync-mode': expected one of [FULL, FAST, SNAP, CHECKPOINT] (case-insensitive) but was 'bogus'"); } @Test diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java index 851c075290e..d1a54d4d3d3 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java @@ -525,7 +525,7 @@ private void ethPeerStatusExchanged(final EthPeer peer) { peer.chainState().updateHeightEstimate(peerHeadBlockHeader.getNumber()); CompletableFuture isServingSnapFuture; - if (SyncMode.isCheckpointSync(syncMode) || SyncMode.isSnapSync(syncMode)) { + if (syncMode == SyncMode.SNAP || syncMode == SyncMode.CHECKPOINT) { // even if we have finished the snap sync, we still want to know if the peer is a snap // server isServingSnapFuture = diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java index 7605754a65c..5125501ddd7 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java @@ -99,8 +99,7 @@ public DefaultSynchronizer( this::calculateTrailingPeerRequirements, metricsSystem); - if (SyncMode.isSnapSync(syncConfig.getSyncMode()) - || SyncMode.isCheckpointSync(syncConfig.getSyncMode())) { + if (syncConfig.getSyncMode() == SyncMode.SNAP || syncConfig.getSyncMode() == SyncMode.CHECKPOINT) { SnapServerChecker.createAndSetSnapServerChecker(ethContext, metricsSystem); } @@ -145,7 +144,7 @@ public DefaultSynchronizer( worldStateStorageCoordinator, syncState, clock); - } else if (SyncMode.isCheckpointSync(syncConfig.getSyncMode())) { + } else if (syncConfig.getSyncMode() == SyncMode.CHECKPOINT) { this.fastSyncFactory = () -> CheckpointDownloaderFactory.createCheckpointDownloader( diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/SyncMode.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/SyncMode.java index 4f3affbe555..ec36384f44e 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/SyncMode.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/SyncMode.java @@ -27,17 +27,9 @@ public enum SyncMode { // Perform snapsync SNAP, // Perform snapsync but starting from a checkpoint instead of starting from genesis - CHECKPOINT, - // Deprecated and will be removed in 24.4.0 (X_SNAP and X_CHECKPOINT) - X_SNAP, - X_CHECKPOINT; + CHECKPOINT; public String normalize() { - if (this.toString().startsWith("X_")) { - // removes X_ at the beginning - return StringUtils.capitalize(this.toString().substring(2).toLowerCase(Locale.ROOT)); - } - return StringUtils.capitalize(this.toString().toLowerCase(Locale.ROOT)); } @@ -45,17 +37,7 @@ public static boolean isFullSync(final SyncMode syncMode) { return !EnumSet.of( SyncMode.FAST, SyncMode.SNAP, - SyncMode.X_SNAP, - SyncMode.CHECKPOINT, - SyncMode.X_CHECKPOINT) + SyncMode.CHECKPOINT) .contains(syncMode); } - - public static boolean isCheckpointSync(final SyncMode syncMode) { - return X_CHECKPOINT.equals(syncMode) || CHECKPOINT.equals(syncMode); - } - - public static boolean isSnapSync(final SyncMode syncMode) { - return X_SNAP.equals(syncMode) || SNAP.equals(syncMode); - } } From 1d26b9035552d20e8e0e93d8585e9151303386fa Mon Sep 17 00:00:00 2001 From: Matilda-Clerke Date: Fri, 12 Jul 2024 15:10:45 +1000 Subject: [PATCH 2/3] run spotless Signed-off-by: Matilda-Clerke --- .../org/hyperledger/besu/controller/BesuControllerBuilder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java index 9a3db952ef5..73bc76608b3 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -708,7 +708,8 @@ public BesuController build() { ethPeers.setTrailingPeerRequirementsSupplier(synchronizer::calculateTrailingPeerRequirements); - if (syncConfig.getSyncMode() == SyncMode.SNAP || syncConfig.getSyncMode() == SyncMode.CHECKPOINT) { + if (syncConfig.getSyncMode() == SyncMode.SNAP + || syncConfig.getSyncMode() == SyncMode.CHECKPOINT) { synchronizer.subscribeInSync((b) -> ethPeers.snapServerPeersNeeded(!b)); ethPeers.snapServerPeersNeeded(true); } else { From 60f8a9dc246a7240462b4c81848f7bac2d6d381e Mon Sep 17 00:00:00 2001 From: Matilda-Clerke Date: Fri, 12 Jul 2024 15:24:18 +1000 Subject: [PATCH 3/3] run spotless Signed-off-by: Matilda-Clerke --- .../besu/ethereum/eth/sync/DefaultSynchronizer.java | 3 ++- .../org/hyperledger/besu/ethereum/eth/sync/SyncMode.java | 6 +----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java index 5125501ddd7..a41ad1812b5 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java @@ -99,7 +99,8 @@ public DefaultSynchronizer( this::calculateTrailingPeerRequirements, metricsSystem); - if (syncConfig.getSyncMode() == SyncMode.SNAP || syncConfig.getSyncMode() == SyncMode.CHECKPOINT) { + if (syncConfig.getSyncMode() == SyncMode.SNAP + || syncConfig.getSyncMode() == SyncMode.CHECKPOINT) { SnapServerChecker.createAndSetSnapServerChecker(ethContext, metricsSystem); } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/SyncMode.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/SyncMode.java index ec36384f44e..c69a128c54d 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/SyncMode.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/SyncMode.java @@ -34,10 +34,6 @@ public String normalize() { } public static boolean isFullSync(final SyncMode syncMode) { - return !EnumSet.of( - SyncMode.FAST, - SyncMode.SNAP, - SyncMode.CHECKPOINT) - .contains(syncMode); + return !EnumSet.of(SyncMode.FAST, SyncMode.SNAP, SyncMode.CHECKPOINT).contains(syncMode); } }