Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement miner_setMinPriorityFee and miner_getMinPriorityFee #6080

Merged
merged 40 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c57c2ac
Refactor mining options
fab-10 Oct 10, 2023
b408b64
Fix null pointer exception
fab-10 Oct 10, 2023
da79e09
fix another null pointer exception
fab-10 Oct 10, 2023
7684d7e
uncomment code
fab-10 Oct 10, 2023
78741da
Move miner options tests
fab-10 Oct 11, 2023
18bcce3
Unit test fixes
fab-10 Oct 12, 2023
59fbe8e
Removed the commented code
fab-10 Oct 12, 2023
8f14dd3
WIP
fab-10 Oct 13, 2023
2280e02
Merge branch 'main' into mining-options-refactor
fab-10 Oct 13, 2023
65bdabd
WIP
fab-10 Oct 13, 2023
5e012d0
New miner option: min-priority-fee
fab-10 Oct 16, 2023
84919f4
Remove not relevant for this feature
fab-10 Oct 16, 2023
e89a244
Remove not relevant for this feature
fab-10 Oct 16, 2023
20e498b
Merge branch 'main' into mining-options-refactor
fab-10 Oct 16, 2023
a260a7d
Merge branch 'mining-options-refactor' into min-priority-fee
fab-10 Oct 16, 2023
86b9a6e
Merge branch 'main' into mining-options-refactor
fab-10 Oct 17, 2023
2267bc7
Fix javadoc
fab-10 Oct 17, 2023
c6b56d2
Remove code not belonging to this PR
fab-10 Oct 17, 2023
477acf9
coinbase is an updatable parameter
fab-10 Oct 17, 2023
4626230
Move MiningOptions to upper package
fab-10 Oct 17, 2023
25b1522
Fix coinbase for *bft
fab-10 Oct 17, 2023
38feb6d
Merge branch 'mining-options-refactor' into min-priority-fee
fab-10 Oct 17, 2023
b7f4213
Implement methods to get and set min priority fee
Gabriel-Trintinalia Oct 18, 2023
ae775ae
Merge branch 'main' into mining-options-refactor
fab-10 Oct 18, 2023
31f2183
Fix spotless
Gabriel-Trintinalia Oct 19, 2023
16315a4
Merge branch 'main' into mining-options-refactor
macfarla Oct 20, 2023
2700930
Merge branch 'mining-options-refactor' of github.com:fab-10/besu into…
fab-10 Oct 23, 2023
e55392b
Apply suggestions from code review
fab-10 Oct 23, 2023
d710e5c
Merge branch 'main' into mining-options-refactor
fab-10 Oct 24, 2023
639af82
Update besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
fab-10 Oct 24, 2023
232caa6
Merge branch 'mining-options-refactor' of github.com:fab-10/besu into…
fab-10 Oct 24, 2023
878969d
Merge branch 'main' into mining-options-refactor
fab-10 Oct 24, 2023
07dc4e0
Merge branch 'mining-options-refactor' into min-priority-fee
fab-10 Oct 24, 2023
4cb4f6c
Merge branch 'min-priority-fee' into change-min-priority-fee
Gabriel-Trintinalia Oct 24, 2023
e2bf4e4
Add new config option to everything config
Gabriel-Trintinalia Oct 24, 2023
65b84e5
Fix unit test
Gabriel-Trintinalia Oct 25, 2023
2e823ac
Merge branch 'main' into change-min-priority-fee
Gabriel-Trintinalia Oct 25, 2023
9027349
Merge branch 'main' into change-min-priority-fee
pinges Oct 25, 2023
f0a4c97
Accept PR suggestions
Gabriel-Trintinalia Oct 25, 2023
dca9676
Merge branch 'change-min-priority-fee' of https://github.com/Gabriel-…
Gabriel-Trintinalia Oct 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move miner options tests
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
  • Loading branch information
fab-10 committed Oct 11, 2023
commit 78741da750a5d5ffa2faa358b6ae5b33a5df5bad
93 changes: 46 additions & 47 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.hyperledger.besu.cli.options.stable.DataStorageOptions;
import org.hyperledger.besu.cli.options.stable.EthstatsOptions;
import org.hyperledger.besu.cli.options.stable.LoggingLevelOption;
import org.hyperledger.besu.cli.options.stable.MiningOptions;
import org.hyperledger.besu.cli.options.stable.NodePrivateKeyFileOption;
import org.hyperledger.besu.cli.options.stable.P2PTLSConfigOptions;
import org.hyperledger.besu.cli.options.stable.TransactionPoolOptions;
Expand All @@ -65,7 +66,6 @@
import org.hyperledger.besu.cli.options.unstable.EvmOptions;
import org.hyperledger.besu.cli.options.unstable.IpcOptions;
import org.hyperledger.besu.cli.options.unstable.MetricsCLIOptions;
import org.hyperledger.besu.cli.options.unstable.MiningOptions;
import org.hyperledger.besu.cli.options.unstable.NatOptions;
import org.hyperledger.besu.cli.options.unstable.NativeLibraryOptions;
import org.hyperledger.besu.cli.options.unstable.NetworkingOptions;
Expand Down Expand Up @@ -287,7 +287,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
unstableTransactionPoolOptions =
org.hyperledger.besu.cli.options.unstable.TransactionPoolOptions.create();
private final DnsOptions unstableDnsOptions = DnsOptions.create();
private final MiningOptions unstableMiningOptions = MiningOptions.create();
// private final MiningOptions unstableMiningOptions = MiningOptions.create();
private final NatOptions unstableNatOptions = NatOptions.create();
private final NativeLibraryOptions unstableNativeLibraryOptions = NativeLibraryOptions.create();
private final RPCOptions unstableRPCOptions = RPCOptions.create();
Expand All @@ -308,8 +308,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable {
stableTransactionPoolOptions = TransactionPoolOptions.create();

@CommandLine.ArgGroup(validate = false, heading = "@|bold Miner Options|@%n")
final org.hyperledger.besu.cli.options.stable.MiningOptions stableMiningOptions =
org.hyperledger.besu.cli.options.stable.MiningOptions.create();
final MiningOptions miningOptions = MiningOptions.create();

private final RunnerBuilder runnerBuilder;
private final BesuController.Builder controllerBuilderFactory;
Expand Down Expand Up @@ -1489,7 +1488,7 @@ public void run() {

// Need to create vertx after cmdline has been parsed, such that metricsSystem is configurable
vertx = createVertx(createVertxOptions(metricsSystem.get()));
miningParameters = buildMininingParameters();
miningParameters = buildMiningParameters();

validateOptions();
configure();
Expand Down Expand Up @@ -1587,7 +1586,7 @@ private void handleUnstableOptions() {
.put("Privacy Plugin Configuration", unstablePrivacyPluginOptions)
.put("Synchronizer", unstableSynchronizerOptions)
.put("TransactionPool", unstableTransactionPoolOptions)
.put("Mining", unstableMiningOptions)
// .put("Mining", unstableMiningOptions)
.put("Native Library", unstableNativeLibraryOptions)
.put("EVM Options", unstableEvmOptions)
.put("IPC Options", unstableIpcOptions)
Expand Down Expand Up @@ -1872,9 +1871,9 @@ private void validateRequiredOptions() {
});
}

@SuppressWarnings("ConstantConditions")
// @SuppressWarnings("ConstantConditions")
private void validateMiningParams() {
stableMiningOptions.validate(
miningOptions.validate(
commandLine, logger, isMergeEnabled(), getActualGenesisConfigOptions().isEthHash());
// if (Boolean.TRUE.equals(minerOptionGroup.isMiningEnabled)
// && minerOptionGroup.coinbase == null) {
Expand All @@ -1892,19 +1891,19 @@ private void validateMiningParams() {
// (remove --miner-stratum-enabled) "
// + "or specify mining is enabled (--miner-enabled)");
// }
if (unstableMiningOptions.getPosBlockCreationMaxTime() <= 0
|| unstableMiningOptions.getPosBlockCreationMaxTime()
> MiningParameters.DEFAULT_POS_BLOCK_CREATION_MAX_TIME) {
throw new ParameterException(
this.commandLine, "--Xpos-block-creation-max-time must be positive and ≤ 12000");
}

if (unstableMiningOptions.getPosBlockCreationRepetitionMinDuration() <= 0
|| unstableMiningOptions.getPosBlockCreationRepetitionMinDuration() > 2000) {
throw new ParameterException(
this.commandLine,
"--Xpos-block-creation-repetition-min-duration must be positive and ≤ 2000");
}
// if (unstableMiningOptions.getPosBlockCreationMaxTime() <= 0
// || unstableMiningOptions.getPosBlockCreationMaxTime()
// > MiningParameters.DEFAULT_POS_BLOCK_CREATION_MAX_TIME) {
// throw new ParameterException(
// this.commandLine, "--Xpos-block-creation-max-time must be positive and ≤ 12000");
// }
//
// if (unstableMiningOptions.getPosBlockCreationRepetitionMinDuration() <= 0
// || unstableMiningOptions.getPosBlockCreationRepetitionMinDuration() > 2000) {
// throw new ParameterException(
// this.commandLine,
// "--Xpos-block-creation-repetition-min-duration must be positive and ≤ 2000");
// }
}

/**
Expand Down Expand Up @@ -2077,30 +2076,30 @@ private void issueOptionWarnings() {
"--p2p-port",
"--remote-connections-max-percentage"));

// Check that block producer options work
if (!isMergeEnabled() && getActualGenesisConfigOptions().isEthHash()) {
CommandLineUtils.checkOptionDependencies(
logger,
commandLine,
"--miner-enabled",
!miningParameters.isMiningEnabled(),
asList(
"--miner-coinbase",
"--min-gas-price",
"--min-block-occupancy-ratio",
"--miner-extra-data"));

// Check that mining options are able to work
CommandLineUtils.checkOptionDependencies(
logger,
commandLine,
"--miner-enabled",
!miningParameters.isMiningEnabled(),
asList(
"--miner-stratum-enabled",
"--Xminer-remote-sealers-limit",
"--Xminer-remote-sealers-hashrate-ttl"));
}
// // Check that block producer options work
// if (!isMergeEnabled() && getActualGenesisConfigOptions().isEthHash()) {
// CommandLineUtils.checkOptionDependencies(
// logger,
// commandLine,
// "--miner-enabled",
// !miningParameters.isMiningEnabled(),
// asList(
// "--miner-coinbase",
// "--min-gas-price",
// "--min-block-occupancy-ratio",
// "--miner-extra-data"));
//
// // Check that mining options are able to work
// CommandLineUtils.checkOptionDependencies(
// logger,
// commandLine,
// "--miner-enabled",
// !miningParameters.isMiningEnabled(),
// asList(
// "--miner-stratum-enabled",
// "--Xminer-remote-sealers-limit",
// "--Xminer-remote-sealers-hashrate-ttl"));
// }

CommandLineUtils.failIfOptionDoesntMeetRequirement(
commandLine,
Expand Down Expand Up @@ -2959,8 +2958,8 @@ private TransactionPoolConfiguration buildTransactionPoolConfiguration() {
.build();
}

private MiningParameters buildMininingParameters() {
return stableMiningOptions.toDomainObject();
private MiningParameters buildMiningParameters() {
return miningOptions.toDomainObject();
}

private boolean isPruningEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
package org.hyperledger.besu.cli.options.stable;

import static java.util.Arrays.asList;
import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_MAX_OMMERS_DEPTH;
import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_POS_BLOCK_CREATION_MAX_TIME;
import static org.hyperledger.besu.ethereum.core.MiningParameters.DEFAULT_POS_BLOCK_CREATION_REPETITION_MIN_DURATION;
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;
import static org.hyperledger.besu.ethereum.core.MiningParameters.Dynamic.DEFAULT_EXTRA_DATA;
import static org.hyperledger.besu.ethereum.core.MiningParameters.Dynamic.DEFAULT_MIN_BLOCK_OCCUPANCY_RATIO;
import static org.hyperledger.besu.ethereum.core.MiningParameters.Dynamic.DEFAULT_MIN_TRANSACTION_GAS_PRICE;
Expand All @@ -32,19 +38,20 @@
import org.slf4j.Logger;
import picocli.CommandLine;
import picocli.CommandLine.Option;
import picocli.CommandLine.ParameterException;

/** The Mining CLI options. */
public class MiningOptions implements CLIOptions<MiningParameters> {

@Option(
names = {"--miner-enabled"},
description = "Set if node will perform mining (default: ${DEFAULT-VALUE})")
private final Boolean isMiningEnabled = false;
private Boolean isMiningEnabled = false;

@Option(
names = {"--miner-stratum-enabled"},
description = "Set if node will perform Stratum mining (default: ${DEFAULT-VALUE})")
private final Boolean iStratumMiningEnabled = false;
private Boolean iStratumMiningEnabled = false;

@SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings.
@Option(
Expand All @@ -55,45 +62,103 @@ public class MiningOptions implements CLIOptions<MiningParameters> {
@Option(
names = {"--miner-stratum-port"},
description = "Stratum port binding (default: ${DEFAULT-VALUE})")
private final Integer stratumPort = 8008;
private Integer stratumPort = 8008;

@Option(
names = {"--miner-coinbase"},
description =
"Account to which mining rewards are paid. You must specify a valid coinbase if "
+ "mining is enabled using --miner-enabled option",
arity = "1")
private final Address coinbase = null;
private Address coinbase = null;

@Option(
names = {"--miner-extra-data"},
description =
"A hex string representing the (32) bytes to be included in the extra data "
+ "field of a mined block (default: ${DEFAULT-VALUE})",
arity = "1")
private final Bytes extraData = DEFAULT_EXTRA_DATA;
private Bytes extraData = DEFAULT_EXTRA_DATA;

@Option(
names = {"--min-block-occupancy-ratio"},
description = "Minimum occupancy ratio for a mined block (default: ${DEFAULT-VALUE})",
arity = "1")
private final Double minBlockOccupancyRatio = DEFAULT_MIN_BLOCK_OCCUPANCY_RATIO;
private Double minBlockOccupancyRatio = DEFAULT_MIN_BLOCK_OCCUPANCY_RATIO;

@Option(
names = {"--min-gas-price"},
description =
"Minimum price (in Wei) offered by a transaction for it to be included in a mined "
+ "block (default: ${DEFAULT-VALUE})",
arity = "1")
private final Wei minTransactionGasPrice = DEFAULT_MIN_TRANSACTION_GAS_PRICE;
private Wei minTransactionGasPrice = DEFAULT_MIN_TRANSACTION_GAS_PRICE;

@Option(
names = {"--target-gas-limit"},
description =
"Sets target gas limit per block. If set, each block's gas limit will approach this setting over time if the current gas limit is different.")
private final Long targetGasLimit = null;
private Long targetGasLimit = null;

private MiningOptions() {}
@CommandLine.ArgGroup(
validate = false)
private final Unstable unstableOptions = new Unstable();

static class Unstable {
@CommandLine.Option(
hidden = true,
names = {"--Xminer-remote-sealers-limit"},
description =
"Limits the number of remote sealers that can submit their hashrates (default: ${DEFAULT-VALUE})")
private Integer remoteSealersLimit = DEFAULT_REMOTE_SEALERS_LIMIT;

@CommandLine.Option(
hidden = true,
names = {"--Xminer-remote-sealers-hashrate-ttl"},
description =
"Specifies the lifetime of each entry in the cache. An entry will be automatically deleted if no update has been received before the deadline (default: ${DEFAULT-VALUE} minutes)")
private Long remoteSealersTimeToLive = DEFAULT_REMOTE_SEALERS_TTL;

@CommandLine.Option(
hidden = true,
names = {"--Xminer-pow-job-ttl"},
description =
"Specifies the time PoW jobs are kept in cache and will accept a solution from miners (default: ${DEFAULT-VALUE} milliseconds)")
private 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 Integer maxOmmersDepth = DEFAULT_MAX_OMMERS_DEPTH;

@CommandLine.Option(
hidden = true,
names = {"--Xminer-stratum-extranonce"},
description = "Extranonce for Stratum network miners (default: ${DEFAULT-VALUE})")
private String stratumExtranonce = "080c";

@CommandLine.Option(
hidden = true,
names = {"--Xpos-block-creation-max-time"},
description =
"Specifies the maximum time, in milliseconds, a PoS block creation jobs is allowed to run. Must be positive and ≤ 12000 (default: ${DEFAULT-VALUE} milliseconds)")
private Long posBlockCreationMaxTime = DEFAULT_POS_BLOCK_CREATION_MAX_TIME;

@CommandLine.Option(
hidden = true,
names = {"--Xpos-block-creation-repetition-min-duration"},
description =
"If a PoS block creation repetition takes less than this duration, in milliseconds,"
+ " then it waits before next repetition. Must be positive and ≤ 2000 (default: ${DEFAULT-VALUE} milliseconds)")
private Long posBlockCreationRepetitionMinDuration =
DEFAULT_POS_BLOCK_CREATION_REPETITION_MIN_DURATION;
}

private MiningOptions() {

}

/**
* Create mining options.
Expand All @@ -119,13 +184,13 @@ public void validate(
final boolean isMergeEnabled,
final boolean isEthHash) {
if (Boolean.TRUE.equals(isMiningEnabled) && coinbase == null) {
throw new CommandLine.ParameterException(
throw new ParameterException(
commandLine,
"Unable to mine without a valid coinbase. Either disable mining (remove --miner-enabled) "
+ "or specify the beneficiary of mining (via --miner-coinbase <Address>)");
}
if (Boolean.FALSE.equals(isMiningEnabled) && Boolean.TRUE.equals(iStratumMiningEnabled)) {
throw new CommandLine.ParameterException(
throw new ParameterException(
commandLine,
"Unable to mine with Stratum if mining is disabled. Either disable Stratum mining (remove --miner-stratum-enabled) "
+ "or specify mining is enabled (--miner-enabled)");
Expand Down Expand Up @@ -155,6 +220,42 @@ public void validate(
"--Xminer-remote-sealers-limit",
"--Xminer-remote-sealers-hashrate-ttl"));
}

if (unstableOptions.posBlockCreationMaxTime <= 0
|| unstableOptions.posBlockCreationMaxTime
> MiningParameters.DEFAULT_POS_BLOCK_CREATION_MAX_TIME) {
throw new ParameterException(
commandLine, "--Xpos-block-creation-max-time must be positive and ≤ 12000");
}

if (unstableOptions.posBlockCreationRepetitionMinDuration <= 0
|| unstableOptions.posBlockCreationRepetitionMinDuration > 2000) {
throw new ParameterException(
commandLine,
"--Xpos-block-creation-repetition-min-duration must be positive and ≤ 2000");
}
}

static MiningOptions fromConfig(final MiningParameters miningParameters) {
final MiningOptions miningOptions = MiningOptions.create();
miningOptions.isMiningEnabled = miningParameters.isMiningEnabled();
miningOptions.iStratumMiningEnabled = miningParameters.isStratumMiningEnabled();
miningOptions.stratumNetworkInterface = miningParameters.getStratumNetworkInterface();
miningOptions.stratumPort = miningParameters.getStratumPort();
miningOptions.extraData = miningParameters.getDynamic().getExtraData();
miningOptions.minTransactionGasPrice = miningParameters.getDynamic().getMinTransactionGasPrice();
miningOptions.minBlockOccupancyRatio = miningParameters.getDynamic().getMinBlockOccupancyRatio();
miningOptions.unstableOptions.remoteSealersLimit = miningParameters.getRemoteSealersLimit();
miningOptions.unstableOptions.remoteSealersTimeToLive = miningParameters.getRemoteSealersTimeToLive();
miningOptions.unstableOptions.powJobTimeToLive = miningParameters.getPowJobTimeToLive();
miningOptions.unstableOptions.maxOmmersDepth = miningParameters.getMaxOmmerDepth();
miningOptions.unstableOptions.stratumExtranonce = miningParameters.getStratumExtranonce();
miningOptions.unstableOptions.posBlockCreationMaxTime = miningParameters.getPosBlockCreationMaxTime();
miningOptions.unstableOptions.posBlockCreationRepetitionMinDuration = miningParameters.getPosBlockCreationRepetitionMinDuration();

miningParameters.getCoinbase().ifPresent(coinbase -> miningOptions.coinbase = coinbase);
miningParameters.getDynamic().getTargetGasLimit().ifPresent(tgl -> miningOptions.targetGasLimit = tgl);
return miningOptions;
}

@Override
Expand All @@ -164,7 +265,14 @@ public MiningParameters toDomainObject() {
.isMiningEnabled(isMiningEnabled)
.isStratumMiningEnabled(iStratumMiningEnabled)
.stratumNetworkInterface(stratumNetworkInterface)
.stratumPort(stratumPort);
.stratumPort(stratumPort)
.remoteSealersLimit(unstableOptions.remoteSealersLimit)
.remoteSealersTimeToLive(unstableOptions.remoteSealersTimeToLive)
.powJobTimeToLive(unstableOptions.powJobTimeToLive)
.maxOmmerDepth(unstableOptions.maxOmmersDepth)
.stratumExtranonce(unstableOptions.stratumExtranonce)
.posBlockCreationMaxTime(unstableOptions.posBlockCreationMaxTime)
.posBlockCreationRepetitionMinDuration(unstableOptions.posBlockCreationRepetitionMinDuration);

if (coinbase != null) {
miningParametersBuilder.coinbase(coinbase);
Expand Down
Loading