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..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,8 +708,8 @@ 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 +1157,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..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,8 +99,8 @@ 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 +145,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..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 @@ -27,35 +27,13 @@ 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)); } public static boolean isFullSync(final SyncMode syncMode) { - return !EnumSet.of( - SyncMode.FAST, - SyncMode.SNAP, - SyncMode.X_SNAP, - SyncMode.CHECKPOINT, - SyncMode.X_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); + return !EnumSet.of(SyncMode.FAST, SyncMode.SNAP, SyncMode.CHECKPOINT).contains(syncMode); } }