Skip to content

Commit

Permalink
6612: Remove deprecated sync modes and related helper methods (#7309)
Browse files Browse the repository at this point in the history
* 6612: Remove deprecated sync modes and related helper methods

Signed-off-by: Matilda-Clerke <matilda.shay.clerke@gmail.com>
  • Loading branch information
Matilda-Clerke authored Jul 12, 2024
1 parent d35c6d7 commit 41f007f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 40 deletions.
10 changes: 5 additions & 5 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1157,7 +1157,7 @@ protected List<PeerValidator> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ private void ethPeerStatusExchanged(final EthPeer peer) {

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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 41f007f

Please sign in to comment.