Update fast-sync-min-peers default value for post merge (#4298)

Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
pull/4310/head
matkt 2 years ago committed by GitHub
parent c0af9619b2
commit a44cb1cabc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 20
      besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
  3. 1
      besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java
  4. 12
      besu/src/main/java/org/hyperledger/besu/cli/config/NetworkName.java
  5. 60
      besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java

@ -6,6 +6,7 @@
- Upgrade besu-native to 0.6.0 and use Blake2bf native implementation if available by default [#4264](https://github.com/hyperledger/besu/pull/4264)
- Better management of jemalloc presence/absence in startup script [#4237](https://github.com/hyperledger/besu/pull/4237)
- Filter out disconnected peers when fetching available peers [#4269](https://github.com/hyperledger/besu/pull/4269)
- Updated the default value of fast-sync-min-peers post merge [#4298](https://github.com/hyperledger/besu/pull/4298)
### Bug Fixes
- Accept wit/80 from Nethermind [#4279](https://github.com/hyperledger/besu/pull/4279)

@ -20,6 +20,7 @@ import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.hyperledger.besu.cli.DefaultCommandValues.getDefaultBesuDataPath;
import static org.hyperledger.besu.cli.config.NetworkName.MAINNET;
import static org.hyperledger.besu.cli.config.NetworkName.isMergedNetwork;
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPENDENCY_WARNING_MSG;
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPRECATED_AND_USELESS_WARNING_MSG;
import static org.hyperledger.besu.cli.util.CommandLineUtils.DEPRECATION_WARNING_MSG;
@ -507,8 +508,12 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
names = {"--fast-sync-min-peers"},
paramLabel = MANDATORY_INTEGER_FORMAT_HELP,
description =
"Minimum number of peers required before starting fast sync. (default: ${DEFAULT-VALUE})")
private final Integer fastSyncMinPeerCount = FAST_SYNC_MIN_PEER_COUNT;
"Minimum number of peers required before starting fast sync. (default pre-merge: "
+ FAST_SYNC_MIN_PEER_COUNT
+ " and post-merge: "
+ FAST_SYNC_MIN_PEER_COUNT_POST_MERGE
+ ")")
private final Integer fastSyncMinPeerCount = null;
@Option(
names = {"--network"},
@ -2783,10 +2788,19 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
}
private SynchronizerConfiguration buildSyncConfig() {
Integer fastSyncMinPeers = fastSyncMinPeerCount;
if (fastSyncMinPeers == null) {
if (isMergedNetwork(network)) {
fastSyncMinPeers = FAST_SYNC_MIN_PEER_COUNT_POST_MERGE;
} else {
fastSyncMinPeers = FAST_SYNC_MIN_PEER_COUNT;
}
}
return unstableSynchronizerOptions
.toDomainObject()
.syncMode(syncMode)
.fastSyncMinimumPeerCount(fastSyncMinPeerCount)
.fastSyncMinimumPeerCount(fastSyncMinPeers)
.build();
}

@ -57,6 +57,7 @@ public interface DefaultCommandValues {
NatMethod DEFAULT_NAT_METHOD = NatMethod.AUTO;
JwtAlgorithm DEFAULT_JWT_ALGORITHM = JwtAlgorithm.RS256;
int FAST_SYNC_MIN_PEER_COUNT = 5;
int FAST_SYNC_MIN_PEER_COUNT_POST_MERGE = 1;
int DEFAULT_MAX_PEERS = 25;
int DEFAULT_P2P_PEER_LOWER_BOUND = 25;
int DEFAULT_HTTP_MAX_CONNECTIONS = 80;

@ -86,4 +86,16 @@ public enum NetworkName {
public Optional<String> getDeprecationDate() {
return Optional.ofNullable(deprecationDate);
}
public static boolean isMergedNetwork(final NetworkName networkName) {
switch (networkName) {
case GOERLI:
case ROPSTEN:
case SEPOLIA:
case KILN:
return true;
default:
return false;
}
}
}

@ -1706,6 +1706,42 @@ public class BesuCommandTest extends CommandTestAbstract {
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
@Test
public void checkValidDefaultFastSyncMinPeersOption() {
parseCommand("--sync-mode", "FAST");
verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture());
final SynchronizerConfiguration syncConfig = syncConfigurationCaptor.getValue();
assertThat(syncConfig.getSyncMode()).isEqualTo(SyncMode.FAST);
assertThat(syncConfig.getFastSyncMinimumPeerCount()).isEqualTo(5);
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
@Test
public void checkValidDefaultFastSyncMinPeersPreMergeOption() {
parseCommand("--sync-mode", "FAST", "--network", "CLASSIC");
verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture());
final SynchronizerConfiguration syncConfig = syncConfigurationCaptor.getValue();
assertThat(syncConfig.getSyncMode()).isEqualTo(SyncMode.FAST);
assertThat(syncConfig.getFastSyncMinimumPeerCount()).isEqualTo(5);
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
@Test
public void checkValidDefaultFastSyncMinPeersPostMergeOption() {
parseCommand("--sync-mode", "FAST", "--network", "GOERLI");
verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture());
final SynchronizerConfiguration syncConfig = syncConfigurationCaptor.getValue();
assertThat(syncConfig.getSyncMode()).isEqualTo(SyncMode.FAST);
assertThat(syncConfig.getFastSyncMinimumPeerCount()).isEqualTo(1);
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
@Test
public void parsesValidFastSyncMinPeersOption() {
parseCommand("--sync-mode", "FAST", "--fast-sync-min-peers", "11");
@ -1718,6 +1754,30 @@ public class BesuCommandTest extends CommandTestAbstract {
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
@Test
public void parsesValidFastSyncMinPeersOptionPreMerge() {
parseCommand("--sync-mode", "FAST", "--network", "CLASSIC", "--fast-sync-min-peers", "11");
verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture());
final SynchronizerConfiguration syncConfig = syncConfigurationCaptor.getValue();
assertThat(syncConfig.getSyncMode()).isEqualTo(SyncMode.FAST);
assertThat(syncConfig.getFastSyncMinimumPeerCount()).isEqualTo(11);
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
@Test
public void parsesValidFastSyncMinPeersOptionPostMerge() {
parseCommand("--sync-mode", "FAST", "--network", "GOERLI", "--fast-sync-min-peers", "11");
verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture());
final SynchronizerConfiguration syncConfig = syncConfigurationCaptor.getValue();
assertThat(syncConfig.getSyncMode()).isEqualTo(SyncMode.FAST);
assertThat(syncConfig.getFastSyncMinimumPeerCount()).isEqualTo(11);
assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}
@Test
public void parsesInvalidFastSyncMinPeersOptionWrongFormatShouldFail() {

Loading…
Cancel
Save