From c570c05a02affb902c020554a878370b14ddf7ba Mon Sep 17 00:00:00 2001 From: Ratan Rai Sur Date: Thu, 4 Jun 2020 12:23:23 -0400 Subject: [PATCH] Default to fast sync for named networks (#384) We consider the named network condition to be satisfied when --network is explicitly used OR when it isn't supplied but neither are --genesis-file nor --privacy-enabled Signed-off-by: Ratan Rai Sur --- .../tests/acceptance/dsl/node/ProcessBesuNodeRunner.java | 3 +++ .../main/java/org/hyperledger/besu/cli/BesuCommand.java | 7 +++++-- .../org/hyperledger/besu/cli/DefaultCommandValues.java | 2 -- .../hyperledger/besu/controller/BesuControllerBuilder.java | 2 +- .../java/org/hyperledger/besu/cli/BesuCommandTest.java | 4 ++-- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java index 58d0c0a99e8..f6054e8ee90 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ProcessBesuNodeRunner.java @@ -85,6 +85,9 @@ public void startNode(final BesuNode node) { params.add("DEV"); } + params.add("--sync-mode"); + params.add("FULL"); + params.add("--discovery-enabled"); params.add(Boolean.toString(node.isDiscoveryEnabled())); 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 f103e18b1da..594c89c060e 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -368,8 +368,8 @@ void setBannedNodeIds(final List values) { names = {"--sync-mode"}, paramLabel = MANDATORY_MODE_FORMAT_HELP, description = - "Synchronization mode, possible values are ${COMPLETION-CANDIDATES} (default: ${DEFAULT-VALUE})") - private final SyncMode syncMode = DEFAULT_SYNC_MODE; + "Synchronization mode, possible values are ${COMPLETION-CANDIDATES} (default: FAST if a --network is supplied and privacy isn't enabled. FULL otherwise.)") + private SyncMode syncMode = null; @Option( names = {"--fast-sync-min-peers"}, @@ -1338,6 +1338,9 @@ private void issueOptionWarnings() { } private BesuCommand configure() throws Exception { + syncMode = + Optional.ofNullable(syncMode) + .orElse(genesisFile == null && !isPrivacyEnabled ? SyncMode.FAST : SyncMode.FULL); ethNetworkConfig = updateNetworkConfig(getNetwork()); jsonRpcConfiguration = jsonRpcConfiguration(); graphQLConfiguration = graphQLConfiguration(); diff --git a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java index b19f2fb898f..cbf2fc0740b 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java @@ -15,7 +15,6 @@ package org.hyperledger.besu.cli; import org.hyperledger.besu.ethereum.core.Wei; -import org.hyperledger.besu.ethereum.eth.sync.SyncMode; import org.hyperledger.besu.ethereum.p2p.config.RlpxConfiguration; import org.hyperledger.besu.nat.NatMethod; @@ -52,7 +51,6 @@ public interface DefaultCommandValues { String PERMISSIONING_CONFIG_LOCATION = "permissions_config.toml"; String MANDATORY_HOST_FORMAT_HELP = ""; String MANDATORY_PORT_FORMAT_HELP = ""; - SyncMode DEFAULT_SYNC_MODE = SyncMode.FULL; NatMethod DEFAULT_NAT_METHOD = NatMethod.AUTO; int FAST_SYNC_MIN_PEER_COUNT = 5; int DEFAULT_MAX_PEERS = 25; 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 0a9aea25b36..72c593f6c6f 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -250,7 +250,7 @@ public BesuController build() { metricsSystem); final EthContext ethContext = new EthContext(ethPeers, ethMessages, scheduler); final SyncState syncState = new SyncState(blockchain, ethPeers); - final boolean fastSyncEnabled = syncConfig.getSyncMode().equals(SyncMode.FAST); + final boolean fastSyncEnabled = SyncMode.FAST.equals(syncConfig.getSyncMode()); final Optional eip1559; final GenesisConfigOptions genesisConfigOptions = 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 a81b5177400..2a65d0fcbb5 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -192,7 +192,7 @@ public void callingBesuCommandWithoutOptionsMustSyncWithDefaultValues() throws E verify(mockControllerBuilder).build(); assertThat(storageProviderArgumentCaptor.getValue()).isNotNull(); - assertThat(syncConfigurationCaptor.getValue().getSyncMode()).isEqualTo(SyncMode.FULL); + assertThat(syncConfigurationCaptor.getValue().getSyncMode()).isEqualTo(SyncMode.FAST); assertThat(commandErrorOutput.toString()).isEmpty(); assertThat(miningArg.getValue().getCoinbase()).isEqualTo(Optional.empty()); assertThat(miningArg.getValue().getMinTransactionGasPrice()).isEqualTo(Wei.of(1000)); @@ -739,7 +739,7 @@ public void noOverrideDefaultValuesIfKeyIsNotPresentInConfigFile() throws IOExce verify(mockControllerBuilder).synchronizerConfiguration(syncConfigurationCaptor.capture()); final SynchronizerConfiguration syncConfig = syncConfigurationCaptor.getValue(); - assertThat(syncConfig.getSyncMode()).isEqualTo(SyncMode.FULL); + assertThat(syncConfig.getSyncMode()).isEqualTo(SyncMode.FAST); assertThat(syncConfig.getFastSyncMinimumPeerCount()).isEqualTo(5); assertThat(commandErrorOutput.toString()).isEmpty();