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 b5b32f23a9c..7dde1a04962 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -371,7 +371,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable { description = "Identification for this node in the Client ID", arity = "1") private final Optional identityString = Optional.empty(); - // P2P Discovery Option Group @CommandLine.ArgGroup(validate = false, heading = "@|bold P2P Discovery Options|@%n") P2PDiscoveryOptionGroup p2PDiscoveryOptionGroup = new P2PDiscoveryOptionGroup(); @@ -1451,7 +1450,6 @@ public void run() { // Need to create vertx after cmdline has been parsed, such that metricsSystem is configurable vertx = createVertx(createVertxOptions(metricsSystem.get())); - postCreationOptionSetup(); validateOptions(); configure(); configureNativeLibs(); @@ -1798,13 +1796,6 @@ private void configureNativeLibs() { } } - /** Use this method to pass data, that was not yet available, at options object creation time */ - private void postCreationOptionSetup() { - // set the optional genesis block period time needed by mining options - final var actualGenesisOptions = getActualGenesisConfigOptions(); - miningOptions.setGenesisBlockPeriodSeconds(getGenesisBlockPeriodSeconds(actualGenesisOptions)); - } - private void validateOptions() { validateRequiredOptions(); issueOptionWarnings(); @@ -2912,6 +2903,8 @@ private TransactionPoolConfiguration buildTransactionPoolConfiguration() { private MiningParameters getMiningParameters() { if (miningParameters == null) { + miningOptions.setGenesisBlockPeriodSeconds( + getGenesisBlockPeriodSeconds(getActualGenesisConfigOptions())); miningParameters = miningOptions.toDomainObject(); } return miningParameters; @@ -3405,6 +3398,11 @@ private Optional getEcCurveFromGenesisFile() { return genesisConfigOptions.getEcCurve(); } + /** + * Return the genesis config options after applying any specified config overrides + * + * @return the genesis config options after applying any specified config overrides + */ protected GenesisConfigOptions getActualGenesisConfigOptions() { return Optional.ofNullable(genesisConfigOptions) .orElseGet( diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java index cfb861405af..5716d45fe6e 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/MiningOptions.java @@ -202,6 +202,12 @@ public static MiningOptions create() { return new MiningOptions(); } + /** + * Set the optional genesis block period per seconds + * + * @param genesisBlockPeriodSeconds if the network is PoA then the block period in seconds + * specified in the genesis file, otherwise empty. + */ public void setGenesisBlockPeriodSeconds(final OptionalInt genesisBlockPeriodSeconds) { maybeGenesisBlockPeriodSeconds = genesisBlockPeriodSeconds; } @@ -220,10 +226,6 @@ public void validate( final GenesisConfigOptions genesisConfigOptions, final boolean isMergeEnabled, final Logger logger) { - if (maybeGenesisBlockPeriodSeconds == null) { - throw new IllegalStateException( - "genesisBlockPeriodSeconds must be set before using this object"); - } if (Boolean.TRUE.equals(isMiningEnabled) && coinbase == null) { throw new ParameterException(