6612: Remove deprecated sync modes and related helper methods (#7309)

* 6612: Remove deprecated sync modes and related helper methods

Signed-off-by: Matilda-Clerke <matilda.shay.clerke@gmail.com>
pull/7315/head
Matilda-Clerke 4 months ago committed by GitHub
parent d35c6d7875
commit 41f007fb80
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
  2. 4
      besu/src/main/java/org/hyperledger/besu/controller/BesuController.java
  3. 6
      besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java
  4. 2
      besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
  5. 2
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java
  6. 6
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java
  7. 26
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/SyncMode.java

@ -1566,11 +1566,11 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
|| 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 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
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 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
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));
}

@ -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 class BesuController implements java.io.Closeable {
// 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*

@ -708,8 +708,8 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
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 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides
final CheckpointConfigOptions checkpointConfigOptions =
genesisConfigOptions.getCheckpointOptions();
if (SyncMode.isCheckpointSync(syncConfig.getSyncMode()) && checkpointConfigOptions.isValid()) {
if (syncConfig.getSyncMode() == SyncMode.CHECKPOINT && checkpointConfigOptions.isValid()) {
validators.add(
new CheckpointBlocksPeerValidator(
protocolSchedule,

@ -1107,7 +1107,7 @@ public class BesuCommandTest extends CommandTestAbstract {
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

@ -525,7 +525,7 @@ public class EthPeers {
peer.chainState().updateHeightEstimate(peerHeadBlockHeader.getNumber());
CompletableFuture<Void> 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 =

@ -99,8 +99,8 @@ public class DefaultSynchronizer implements Synchronizer, UnverifiedForkchoiceLi
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 class DefaultSynchronizer implements Synchronizer, UnverifiedForkchoiceLi
worldStateStorageCoordinator,
syncState,
clock);
} else if (SyncMode.isCheckpointSync(syncConfig.getSyncMode())) {
} else if (syncConfig.getSyncMode() == SyncMode.CHECKPOINT) {
this.fastSyncFactory =
() ->
CheckpointDownloaderFactory.createCheckpointDownloader(

@ -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);
}
}

Loading…
Cancel
Save