Skip to content

Commit

Permalink
Default to fast sync for named networks (#384)
Browse files Browse the repository at this point in the history
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 <ratan.r.sur@gmail.com>
  • Loading branch information
RatanRSur authored Jun 4, 2020
1 parent 091ab97 commit c570c05
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down
7 changes: 5 additions & 2 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ void setBannedNodeIds(final List<String> 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"},
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -52,7 +51,6 @@ public interface DefaultCommandValues {
String PERMISSIONING_CONFIG_LOCATION = "permissions_config.toml";
String MANDATORY_HOST_FORMAT_HELP = "<HOST>";
String MANDATORY_PORT_FORMAT_HELP = "<PORT>";
SyncMode DEFAULT_SYNC_MODE = SyncMode.FULL;
NatMethod DEFAULT_NAT_METHOD = NatMethod.AUTO;
int FAST_SYNC_MIN_PEER_COUNT = 5;
int DEFAULT_MAX_PEERS = 25;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public BesuController<C> 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> eip1559;
final GenesisConfigOptions genesisConfigOptions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c570c05

Please sign in to comment.