@ -14,6 +14,8 @@ package tech.pegasys.pantheon.cli;
import static com.google.common.base.Preconditions.checkNotNull ;
import static java.nio.charset.StandardCharsets.UTF_8 ;
import static java.util.Arrays.asList ;
import static tech.pegasys.pantheon.cli.CommandLineUtils.checkOptionDependencies ;
import static tech.pegasys.pantheon.cli.DefaultCommandValues.getDefaultPantheonDataPath ;
import static tech.pegasys.pantheon.cli.NetworkName.MAINNET ;
import static tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration.DEFAULT_JSON_RPC_PORT ;
@ -72,8 +74,8 @@ import java.net.InetAddress;
import java.net.URI ;
import java.nio.file.Path ;
import java.nio.file.Paths ;
import java.time.Duration ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Collection ;
import java.util.List ;
import java.util.Optional ;
@ -228,6 +230,22 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
"Synchronization mode, possible values are ${COMPLETION-CANDIDATES} (default: ${DEFAULT-VALUE})" )
private final SyncMode syncMode = DEFAULT_SYNC_MODE ;
@Option (
hidden = true ,
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 ;
@Option (
hidden = true ,
names = { "--fast-sync-max-wait-time" } ,
paramLabel = MANDATORY_INTEGER_FORMAT_HELP ,
description =
"Maximum time to wait for the required number of peers before starting fast sync, expressed in seconds, 0 means no timeout (default: ${DEFAULT-VALUE})" )
private final Integer fastSyncMaxWaitTime = FAST_SYNC_MAX_WAIT_TIME ;
@Option (
names = { "--network" } ,
paramLabel = MANDATORY_NETWORK_FORMAT_HELP ,
@ -590,12 +608,12 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
}
// Check that P2P options are able to work or send an error
CommandLineUtils . checkOptionDependencies (
checkOptionDependencies (
logger ,
commandLine ,
"--p2p-enabled" ,
! p2pEnabled ,
Arrays . asList (
asList (
"--bootnodes" ,
"--discovery-enabled" ,
"--max-peers" ,
@ -603,12 +621,24 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
"--banned-node-ids" ) ) ;
// Check that mining options are able to work or send an error
CommandLineUtils . checkOptionDependencies (
checkOptionDependencies (
logger ,
commandLine ,
"--miner-enabled" ,
! isMiningEnabled ,
Arrays . asList ( "--miner-coinbase" , "--min-gas-price" , "--miner-extra-data" ) ) ;
asList ( "--miner-coinbase" , "--min-gas-price" , "--miner-extra-data" ) ) ;
// Check that fast sync options are able to work or send an error
if ( fastSyncMaxWaitTime < 0 ) {
throw new ParameterException (
commandLine , "--fast-sync-max-wait-time must be greater than or equal to 0" ) ;
}
checkOptionDependencies (
logger ,
commandLine ,
"--sync-mode" ,
SyncMode . FAST . equals ( syncMode ) ,
asList ( "--fast-sync-num-peers" , "--fast-sync-timeout" ) ) ;
//noinspection ConstantConditions
if ( isMiningEnabled & & coinbase = = null ) {
@ -697,12 +727,12 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
private JsonRpcConfiguration jsonRpcConfiguration ( ) {
CommandLineUtils . checkOptionDependencies (
checkOptionDependencies (
logger ,
commandLine ,
"--rpc-http-enabled" ,
! isRpcHttpEnabled ,
Arrays . asList (
asList (
"--rpc-http-api" ,
"--rpc-http-apis" ,
"--rpc-http-cors-origins" ,
@ -731,12 +761,12 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
private WebSocketConfiguration webSocketConfiguration ( ) {
CommandLineUtils . checkOptionDependencies (
checkOptionDependencies (
logger ,
commandLine ,
"--rpc-ws-enabled" ,
! isRpcWsEnabled ,
Arrays . asList (
asList (
"--rpc-ws-api" ,
"--rpc-ws-apis" ,
"--rpc-ws-host" ,
@ -769,19 +799,19 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
+ "time. Please refer to CLI reference for more details about this constraint." ) ;
}
CommandLineUtils . checkOptionDependencies (
checkOptionDependencies (
logger ,
commandLine ,
"--metrics-enabled" ,
! isMetricsEnabled ,
Arrays . asList ( "--metrics-host" , "--metrics-port" ) ) ;
asList ( "--metrics-host" , "--metrics-port" ) ) ;
CommandLineUtils . checkOptionDependencies (
checkOptionDependencies (
logger ,
commandLine ,
"--metrics-push-enabled" ,
! isMetricsPushEnabled ,
Arrays . asList (
asList (
"--metrics-push-host" ,
"--metrics-push-port" ,
"--metrics-push-interval" ,
@ -882,13 +912,12 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
private PrivacyParameters privacyParameters ( ) throws IOException {
CommandLineUtils . checkOptionDependencies (
checkOptionDependencies (
logger ,
commandLine ,
"--privacy-enabled" ,
! isPrivacyEnabled ,
Arrays . asList (
"--privacy-url" , "--privacy-public-key-file" , "--privacy-precompiled-address" ) ) ;
asList ( "--privacy-url" , "--privacy-public-key-file" , "--privacy-precompiled-address" ) ) ;
final PrivacyParameters privacyParameters = PrivacyParameters . noPrivacy ( ) ;
if ( isPrivacyEnabled ) {
@ -909,6 +938,8 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
private SynchronizerConfiguration buildSyncConfig ( ) {
return synchronizerConfigurationBuilder
. syncMode ( syncMode )
. fastSyncMinimumPeerCount ( fastSyncMinPeerCount )
. fastSyncMaximumPeerWaitTime ( Duration . ofSeconds ( fastSyncMaxWaitTime ) )
. maxTrailingPeers ( TrailingPeerRequirements . calculateMaxTrailingPeers ( maxPeers ) )
. build ( ) ;
}