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