Skip to content

Commit

Permalink
Add unstable CLI option for max ommers depth (hyperledger#2584)
Browse files Browse the repository at this point in the history
* Add unstable CLI option for max ommers depth

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>

* Move to a builder pattern for mining parameters

Signed-off-by: Antoine Toulme <antoine@lunar-ocean.com>
  • Loading branch information
atoulme authored Jul 28, 2021
1 parent 41521b6 commit bc697e8
Show file tree
Hide file tree
Showing 24 changed files with 285 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis;
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration;
import org.hyperledger.besu.ethereum.api.tls.FileBasedPasswordProvider;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.MiningParametersTestBuilder;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration;
import org.hyperledger.besu.ethereum.p2p.rlpx.connections.netty.TLSConfiguration;
import org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration;
Expand All @@ -51,7 +52,11 @@ public class BesuNodeConfigurationBuilder {
private String name;
private Optional<Path> dataPath = Optional.empty();
private MiningParameters miningParameters =
new MiningParametersTestBuilder().enabled(false).build();
new MiningParameters.Builder()
.enabled(false)
.coinbase(AddressHelpers.ofValue(1))
.minTransactionGasPrice(Wei.of(1000))
.build();
private JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault();
private WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault();
private MetricsConfiguration metricsConfiguration = MetricsConfiguration.builder().build();
Expand Down Expand Up @@ -98,7 +103,8 @@ public BesuNodeConfigurationBuilder miningEnabled() {
}

public BesuNodeConfigurationBuilder miningEnabled(final boolean enabled) {
this.miningParameters = new MiningParametersTestBuilder().enabled(enabled).build();
this.miningParameters =
new MiningParameters.Builder().enabled(enabled).coinbase(AddressHelpers.ofValue(1)).build();
this.jsonRpcConfiguration.addRpcApi(RpcApis.MINER);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.JsonRpcConfiguration;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi;
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.WebSocketConfiguration;
import org.hyperledger.besu.ethereum.core.AddressHelpers;
import org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.MiningParametersTestBuilder;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Wei;
import org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration;
Expand Down Expand Up @@ -221,7 +221,11 @@ public BesuNode createNodeWithMultiTenantedPrivacy(
.build();

final MiningParameters miningParameters =
new MiningParametersTestBuilder().minTransactionGasPrice(Wei.ZERO).enabled(true).build();
new MiningParameters.Builder()
.minTransactionGasPrice(Wei.ZERO)
.coinbase(AddressHelpers.ofValue(1))
.enabled(true)
.build();

return create(
new BesuNodeConfigurationBuilder()
Expand Down
29 changes: 15 additions & 14 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -1705,20 +1705,21 @@ public BesuControllerBuilder getControllerBuilder() {
.ethProtocolConfiguration(unstableEthProtocolOptions.toDomainObject())
.dataDirectory(dataDir())
.miningParameters(
new MiningParameters(
coinbase,
minTransactionGasPrice,
extraData,
isMiningEnabled,
iStratumMiningEnabled,
stratumNetworkInterface,
stratumPort,
unstableMiningOptions.getStratumExtranonce(),
Optional.empty(),
minBlockOccupancyRatio,
unstableMiningOptions.getRemoteSealersLimit(),
unstableMiningOptions.getRemoteSealersTimeToLive(),
unstableMiningOptions.getPowJobTimeToLive()))
new MiningParameters.Builder()
.coinbase(coinbase)
.minTransactionGasPrice(minTransactionGasPrice)
.extraData(extraData)
.enabled(isMiningEnabled)
.stratumMiningEnabled(iStratumMiningEnabled)
.stratumNetworkInterface(stratumNetworkInterface)
.stratumPort(stratumPort)
.stratumExtranonce(unstableMiningOptions.getStratumExtranonce())
.minBlockOccupancyRatio(minBlockOccupancyRatio)
.remoteSealersLimit(unstableMiningOptions.getRemoteSealersLimit())
.remoteSealersTimeToLive(unstableMiningOptions.getRemoteSealersTimeToLive())
.powJobTimeToLive(unstableMiningOptions.getPowJobTimeToLive())
.maxOmmerDepth(unstableMiningOptions.getMaxOmmersDepth())
.build())
.transactionPoolConfiguration(buildTransactionPoolConfiguration())
.nodeKey(buildNodeKey())
.metricsSystem(metricsSystem.get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.cli.options.unstable;

import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_MAX_OMMERS_DEPTH;
import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_POW_JOB_TTL;
import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_REMOTE_SEALERS_LIMIT;
import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_REMOTE_SEALERS_TTL;
Expand Down Expand Up @@ -43,6 +44,13 @@ public class MiningOptions {
"Specifies the time PoW jobs are kept in cache and will accept a solution from miners (default: ${DEFAULT-VALUE} milliseconds)")
private final Long powJobTimeToLive = DEFAULT_POW_JOB_TTL;

@CommandLine.Option(
hidden = true,
names = {"--Xmax-ommers-depth"},
description =
"Specifies the depth of ommer blocks to accept when receiving solutions (default: ${DEFAULT-VALUE})")
private final Integer maxOmmersDepth = DEFAULT_MAX_OMMERS_DEPTH;

@SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings.
@CommandLine.Option(
hidden = true,
Expand All @@ -69,4 +77,8 @@ public String getStratumExtranonce() {
public Long getPowJobTimeToLive() {
return powJobTimeToLive;
}

public int getMaxOmmersDepth() {
return maxOmmersDepth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static com.google.common.base.Preconditions.checkNotNull;
import static org.hyperledger.besu.cli.subcommands.blocks.BlocksSubCommand.COMMAND_NAME;
import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_MAX_OMMERS_DEPTH;
import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_POW_JOB_TTL;
import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_REMOTE_SEALERS_LIMIT;
import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_REMOTE_SEALERS_TTL;
Expand Down Expand Up @@ -258,20 +259,22 @@ private MiningParameters getMiningParameters() {
// Extradata and coinbase can be configured on a per-block level via the json file
final Address coinbase = Address.ZERO;
final Bytes extraData = Bytes.EMPTY;
return new MiningParameters(
coinbase,
minTransactionGasPrice,
extraData,
false,
false,
"0.0.0.0",
8008,
"080c",
Optional.of(new IncrementingNonceGenerator(0)),
0.0,
DEFAULT_REMOTE_SEALERS_LIMIT,
DEFAULT_REMOTE_SEALERS_TTL,
DEFAULT_POW_JOB_TTL);
return new MiningParameters.Builder()
.coinbase(coinbase)
.minTransactionGasPrice(minTransactionGasPrice)
.extraData(extraData)
.enabled(false)
.stratumMiningEnabled(false)
.stratumNetworkInterface("0.0.0.0")
.stratumPort(8008)
.stratumExtranonce("080c")
.maybeNonceGenerator(new IncrementingNonceGenerator(0))
.minBlockOccupancyRatio(0.0)
.remoteSealersLimit(DEFAULT_REMOTE_SEALERS_LIMIT)
.remoteSealersTimeToLive(DEFAULT_REMOTE_SEALERS_TTL)
.powJobTimeToLive(DEFAULT_POW_JOB_TTL)
.maxOmmerDepth(DEFAULT_MAX_OMMERS_DEPTH)
.build();
}

private void importJsonBlocks(final BesuController controller, final Path path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ protected MiningCoordinator createMiningCoordinator(
clock),
gasLimitCalculator,
epochCalculator,
miningParameters.getPowJobTimeToLive());
miningParameters.getPowJobTimeToLive(),
miningParameters.getMaxOmmerDepth());

final PoWMiningCoordinator miningCoordinator =
new PoWMiningCoordinator(
Expand Down
8 changes: 6 additions & 2 deletions besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider;
import org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider;
import org.hyperledger.besu.ethereum.core.LogsBloomFilter;
import org.hyperledger.besu.ethereum.core.MiningParametersTestBuilder;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.Wei;
Expand Down Expand Up @@ -175,7 +175,11 @@ public void setUp() throws IOException {
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.storageProvider(new InMemoryKeyValueStorageProvider())
.networkId(BigInteger.ONE)
.miningParameters(new MiningParametersTestBuilder().enabled(false).build())
.miningParameters(
new MiningParameters.Builder()
.minTransactionGasPrice(Wei.of(1000))
.enabled(false)
.build())
.nodeKey(NodeKeyUtils.generate())
.metricsSystem(new NoOpMetricsSystem())
.dataDirectory(dataDir)
Expand Down
4 changes: 2 additions & 2 deletions besu/src/test/java/org/hyperledger/besu/PrivacyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.hyperledger.besu.ethereum.core.Account;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider;
import org.hyperledger.besu.ethereum.core.MiningParametersTestBuilder;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
Expand Down Expand Up @@ -107,7 +107,7 @@ private BesuController setUpControllerWithPrivacyEnabled(final boolean onChainEn
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.storageProvider(new InMemoryKeyValueStorageProvider())
.networkId(BigInteger.ONE)
.miningParameters(new MiningParametersTestBuilder().enabled(false).build())
.miningParameters(new MiningParameters.Builder().enabled(false).build())
.nodeKey(NodeKeyUtils.generate())
.metricsSystem(new NoOpMetricsSystem())
.dataDirectory(dataDir)
Expand Down
8 changes: 4 additions & 4 deletions besu/src/test/java/org/hyperledger/besu/RunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.hyperledger.besu.ethereum.core.BlockImporter;
import org.hyperledger.besu.ethereum.core.BlockSyncTestUtils;
import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider;
import org.hyperledger.besu.ethereum.core.MiningParametersTestBuilder;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.sync.SyncMode;
Expand Down Expand Up @@ -162,7 +162,7 @@ private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesi
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.dataDirectory(dataDirAhead)
.networkId(networkId)
.miningParameters(new MiningParametersTestBuilder().enabled(false).build())
.miningParameters(new MiningParameters.Builder().enabled(false).build())
.nodeKey(aheadDbNodeKey)
.metricsSystem(noOpMetricsSystem)
.privacyParameters(PrivacyParameters.DEFAULT)
Expand All @@ -182,7 +182,7 @@ private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesi
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.dataDirectory(dataDirAhead)
.networkId(networkId)
.miningParameters(new MiningParametersTestBuilder().enabled(false).build())
.miningParameters(new MiningParameters.Builder().enabled(false).build())
.nodeKey(aheadDbNodeKey)
.metricsSystem(noOpMetricsSystem)
.privacyParameters(PrivacyParameters.DEFAULT)
Expand Down Expand Up @@ -249,7 +249,7 @@ private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesi
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.dataDirectory(dataDirBehind)
.networkId(networkId)
.miningParameters(new MiningParametersTestBuilder().enabled(false).build())
.miningParameters(new MiningParameters.Builder().enabled(false).build())
.nodeKey(NodeKeyUtils.generate())
.storageProvider(new InMemoryKeyValueStorageProvider())
.metricsSystem(noOpMetricsSystem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.hyperledger.besu.ethereum.core.BlockBody;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider;
import org.hyperledger.besu.ethereum.core.MiningParametersTestBuilder;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
Expand Down Expand Up @@ -84,7 +84,7 @@ private static BesuController createController() throws IOException {
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.storageProvider(new InMemoryKeyValueStorageProvider())
.networkId(BigInteger.ONE)
.miningParameters(new MiningParametersTestBuilder().enabled(false).build())
.miningParameters(new MiningParameters.Builder().enabled(false).build())
.nodeKey(NodeKeyUtils.generate())
.metricsSystem(new NoOpMetricsSystem())
.privacyParameters(PrivacyParameters.DEFAULT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.hyperledger.besu.ethereum.core.BlockBody;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider;
import org.hyperledger.besu.ethereum.core.MiningParametersTestBuilder;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.Wei;
Expand Down Expand Up @@ -418,10 +418,7 @@ protected BesuController createController(final GenesisConfigFile genesisConfigF
.storageProvider(new InMemoryKeyValueStorageProvider())
.networkId(BigInteger.valueOf(10))
.miningParameters(
new MiningParametersTestBuilder()
.minTransactionGasPrice(Wei.ZERO)
.enabled(true)
.build())
new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).enabled(true).build())
.nodeKey(NodeKeyUtils.generate())
.metricsSystem(new NoOpMetricsSystem())
.privacyParameters(PrivacyParameters.DEFAULT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.hyperledger.besu.crypto.NodeKeyUtils;
import org.hyperledger.besu.ethereum.blockcreation.GasLimitCalculator;
import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider;
import org.hyperledger.besu.ethereum.core.MiningParametersTestBuilder;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration;
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
Expand Down Expand Up @@ -64,7 +64,7 @@ public void blockImport() throws IOException {
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.storageProvider(new InMemoryKeyValueStorageProvider())
.networkId(BigInteger.ONE)
.miningParameters(new MiningParametersTestBuilder().enabled(false).build())
.miningParameters(new MiningParameters.Builder().enabled(false).build())
.nodeKey(NodeKeyUtils.generate())
.metricsSystem(new NoOpMetricsSystem())
.privacyParameters(PrivacyParameters.DEFAULT)
Expand Down Expand Up @@ -92,7 +92,7 @@ public void blockImportRejectsBadPow() throws IOException {
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.storageProvider(new InMemoryKeyValueStorageProvider())
.networkId(BigInteger.ONE)
.miningParameters(new MiningParametersTestBuilder().enabled(false).build())
.miningParameters(new MiningParameters.Builder().enabled(false).build())
.nodeKey(NodeKeyUtils.generate())
.metricsSystem(new NoOpMetricsSystem())
.privacyParameters(PrivacyParameters.DEFAULT)
Expand Down Expand Up @@ -120,7 +120,7 @@ public void blockImportCanSkipPow() throws IOException {
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.storageProvider(new InMemoryKeyValueStorageProvider())
.networkId(BigInteger.ONE)
.miningParameters(new MiningParametersTestBuilder().enabled(false).build())
.miningParameters(new MiningParameters.Builder().enabled(false).build())
.nodeKey(NodeKeyUtils.generate())
.metricsSystem(new NoOpMetricsSystem())
.privacyParameters(PrivacyParameters.DEFAULT)
Expand Down Expand Up @@ -160,7 +160,7 @@ public void ibftImport() throws IOException {
.ethProtocolConfiguration(EthProtocolConfiguration.defaultConfig())
.storageProvider(new InMemoryKeyValueStorageProvider())
.networkId(BigInteger.valueOf(10))
.miningParameters(new MiningParametersTestBuilder().enabled(false).build())
.miningParameters(new MiningParameters.Builder().enabled(false).build())
.nodeKey(NodeKeyUtils.generate())
.metricsSystem(new NoOpMetricsSystem())
.privacyParameters(PrivacyParameters.DEFAULT)
Expand Down
22 changes: 12 additions & 10 deletions besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -843,11 +843,12 @@ public void envVariableOverridesValueFromConfigFile() {

verify(mockControllerBuilder)
.miningParameters(
new MiningParameters(
Address.fromHexString(expectedCoinbase),
DefaultCommandValues.DEFAULT_MIN_TRANSACTION_GAS_PRICE,
DefaultCommandValues.DEFAULT_EXTRA_DATA,
false));
new MiningParameters.Builder()
.coinbase(Address.fromHexString(expectedCoinbase))
.minTransactionGasPrice(DefaultCommandValues.DEFAULT_MIN_TRANSACTION_GAS_PRICE)
.extraData(DefaultCommandValues.DEFAULT_EXTRA_DATA)
.enabled(false)
.build());
}

@Test
Expand All @@ -859,11 +860,12 @@ public void cliOptionOverridesEnvVariableAndConfig() {

verify(mockControllerBuilder)
.miningParameters(
new MiningParameters(
Address.fromHexString(expectedCoinbase),
DefaultCommandValues.DEFAULT_MIN_TRANSACTION_GAS_PRICE,
DefaultCommandValues.DEFAULT_EXTRA_DATA,
false));
new MiningParameters.Builder()
.coinbase(Address.fromHexString(expectedCoinbase))
.minTransactionGasPrice(DefaultCommandValues.DEFAULT_MIN_TRANSACTION_GAS_PRICE)
.extraData(DefaultCommandValues.DEFAULT_EXTRA_DATA)
.enabled(false)
.build());
}

@Test
Expand Down
Loading

0 comments on commit bc697e8

Please sign in to comment.