From 0203092d19146405a6ddd7f18be63c10030627b3 Mon Sep 17 00:00:00 2001 From: Matt Whitehead Date: Wed, 8 Nov 2023 11:47:03 +0000 Subject: [PATCH 1/4] Reverse sort order (#6106) * Reverse added order and sequence number Signed-off-by: Matthew Whitehead * Remove extraneous 'addedAt' check Signed-off-by: Matthew Whitehead --------- Signed-off-by: Matthew Whitehead --- .../sorter/GasPricePendingTransactionsSorter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/GasPricePendingTransactionsSorter.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/GasPricePendingTransactionsSorter.java index ce8f880259..4726574a40 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/GasPricePendingTransactionsSorter.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/sorter/GasPricePendingTransactionsSorter.java @@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfigurati import org.hyperledger.besu.plugin.services.MetricsSystem; import java.time.Clock; +import java.util.Comparator; import java.util.Iterator; import java.util.NavigableSet; import java.util.TreeSet; @@ -39,8 +40,7 @@ public class GasPricePendingTransactionsSorter extends AbstractPendingTransactio new TreeSet<>( comparing(PendingTransaction::hasPriority) .thenComparing(PendingTransaction::getGasPrice) - .thenComparing(PendingTransaction::getAddedAt) - .thenComparing(PendingTransaction::getSequence) + .thenComparing(PendingTransaction::getSequence, Comparator.reverseOrder()) .reversed()); public GasPricePendingTransactionsSorter( From 636ad8a65a061d8a66686b5fb86de86958197308 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Wed, 8 Nov 2023 15:26:22 +0100 Subject: [PATCH 2/4] Force tx replacement price bump to zero when zero base fee market is configured (#6079) Signed-off-by: Fabio Di Fabio --- CHANGELOG.md | 2 +- .../org/hyperledger/besu/cli/BesuCommand.java | 37 ++-- .../{stable => }/TransactionPoolOptions.java | 68 ++++++- .../unstable/TransactionPoolOptions.java | 94 ---------- .../besu/cli/util/CommandLineUtils.java | 13 ++ .../hyperledger/besu/cli/BesuCommandTest.java | 53 ++++++ .../besu/cli/CommandTestAbstract.java | 11 +- .../TransactionPoolOptionsTest.java | 55 +++++- .../unstable/TransactionPoolOptionsTest.java | 105 ----------- ...TransactionReplacementByFeeMarketRule.java | 7 +- .../TransactionReplacementByGasPriceRule.java | 2 +- .../AbstractTransactionPoolTest.java | 175 ++++++++++++++++-- .../AbstractTransactionReplacementTest.java | 53 ++++++ ...sactionReplacementByFeeMarketRuleTest.java | 100 ++++++++++ ...nsactionReplacementByGasPriceRuleTest.java | 87 +++++++++ .../TransactionReplacementRulesTest.java | 56 ++---- .../LegacyTransactionPoolBaseFeeTest.java | 7 +- .../LegacyTransactionPoolGasPriceTest.java | 7 +- .../besu/util/number/Percentage.java | 2 + 19 files changed, 635 insertions(+), 299 deletions(-) rename besu/src/main/java/org/hyperledger/besu/cli/options/{stable => }/TransactionPoolOptions.java (81%) delete mode 100644 besu/src/main/java/org/hyperledger/besu/cli/options/unstable/TransactionPoolOptions.java rename besu/src/test/java/org/hyperledger/besu/cli/options/{stable => }/TransactionPoolOptionsTest.java (82%) delete mode 100644 besu/src/test/java/org/hyperledger/besu/cli/options/unstable/TransactionPoolOptionsTest.java create mode 100644 ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionReplacementTest.java create mode 100644 ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionReplacementByFeeMarketRuleTest.java create mode 100644 ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionReplacementByGasPriceRuleTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index d3ee7a889c..69ac2df1d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,9 +17,9 @@ - Clique config option `createemptyblocks` to not create empty blocks [#6082](https://github.com/hyperledger/besu/pull/6082) - Upgrade EVM Reference Tests to v13 (Cancun) [#6114](https://github.com/hyperledger/besu/pull/6114) - Add `yParity` to GraphQL and JSON-RPC for relevant querise. [6119](https://github.com/hyperledger/besu/pull/6119) +- Force tx replacement price bump to zero when zero base fee market is configured or `--min-gas-price` is set to 0. This allows for easier tx replacement in networks where there is not gas price. [#6079](https://github.com/hyperledger/besu/pull/6079) ### Bug fixes - - Upgrade netty to address CVE-2023-44487, CVE-2023-34462 [#6100](https://github.com/hyperledger/besu/pull/6100) - Upgrade grpc to address CVE-2023-32731, CVE-2023-33953, CVE-2023-44487, CVE-2023-4785 [#6100](https://github.com/hyperledger/besu/pull/6100) - Fix blob gas calculation in reference tests [#6107](https://github.com/hyperledger/besu/pull/6107) 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 5a6fc38671..d1af3efe7f 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -54,12 +54,12 @@ import org.hyperledger.besu.cli.custom.RpcAuthFileValidator; import org.hyperledger.besu.cli.error.BesuExecutionExceptionHandler; import org.hyperledger.besu.cli.error.BesuParameterExceptionHandler; import org.hyperledger.besu.cli.options.MiningOptions; +import org.hyperledger.besu.cli.options.TransactionPoolOptions; 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.NodePrivateKeyFileOption; import org.hyperledger.besu.cli.options.stable.P2PTLSConfigOptions; -import org.hyperledger.besu.cli.options.stable.TransactionPoolOptions; import org.hyperledger.besu.cli.options.unstable.ChainPruningOptions; import org.hyperledger.besu.cli.options.unstable.DnsOptions; import org.hyperledger.besu.cli.options.unstable.EthProtocolOptions; @@ -283,9 +283,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable { final SynchronizerOptions unstableSynchronizerOptions = SynchronizerOptions.create(); final EthProtocolOptions unstableEthProtocolOptions = EthProtocolOptions.create(); final MetricsCLIOptions unstableMetricsCLIOptions = MetricsCLIOptions.create(); - final org.hyperledger.besu.cli.options.unstable.TransactionPoolOptions - unstableTransactionPoolOptions = - org.hyperledger.besu.cli.options.unstable.TransactionPoolOptions.create(); private final DnsOptions unstableDnsOptions = DnsOptions.create(); private final NatOptions unstableNatOptions = NatOptions.create(); private final NativeLibraryOptions unstableNativeLibraryOptions = NativeLibraryOptions.create(); @@ -303,8 +300,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { private final LoggingLevelOption loggingLevelOption = LoggingLevelOption.create(); @CommandLine.ArgGroup(validate = false, heading = "@|bold Tx Pool Common Options|@%n") - final org.hyperledger.besu.cli.options.stable.TransactionPoolOptions - stableTransactionPoolOptions = TransactionPoolOptions.create(); + final TransactionPoolOptions transactionPoolOptions = TransactionPoolOptions.create(); @CommandLine.ArgGroup(validate = false, heading = "@|bold Block Builder Options|@%n") final MiningOptions miningOptions = MiningOptions.create(); @@ -1525,7 +1521,6 @@ public class BesuCommand implements DefaultCommandValues, Runnable { .put("NAT Configuration", unstableNatOptions) .put("Privacy Plugin Configuration", unstablePrivacyPluginOptions) .put("Synchronizer", unstableSynchronizerOptions) - .put("TransactionPool", unstableTransactionPoolOptions) .put("Native Library", unstableNativeLibraryOptions) .put("EVM Options", unstableEvmOptions) .put("IPC Options", unstableIpcOptions) @@ -1794,7 +1789,7 @@ public class BesuCommand implements DefaultCommandValues, Runnable { } private void validateTransactionPoolOptions() { - stableTransactionPoolOptions.validate(commandLine); + transactionPoolOptions.validate(commandLine, getActualGenesisConfigOptions()); } private void validateRequiredOptions() { @@ -2811,12 +2806,26 @@ public class BesuCommand implements DefaultCommandValues, Runnable { } private TransactionPoolConfiguration buildTransactionPoolConfiguration() { - final var stableTxPoolOption = stableTransactionPoolOptions.toDomainObject(); - return ImmutableTransactionPoolConfiguration.builder() - .from(stableTxPoolOption) - .unstable(unstableTransactionPoolOptions.toDomainObject()) - .saveFile((dataPath.resolve(stableTxPoolOption.getSaveFile().getPath()).toFile())) - .build(); + final var txPoolConf = transactionPoolOptions.toDomainObject(); + final var txPoolConfBuilder = + ImmutableTransactionPoolConfiguration.builder() + .from(txPoolConf) + .saveFile((dataPath.resolve(txPoolConf.getSaveFile().getPath()).toFile())); + + if (getActualGenesisConfigOptions().isZeroBaseFee()) { + logger.info( + "Forcing price bump for transaction replacement to 0, since we are on a zero basefee network"); + txPoolConfBuilder.priceBump(Percentage.ZERO); + } + + if (getMiningParameters().getMinTransactionGasPrice().equals(Wei.ZERO) + && !transactionPoolOptions.isPriceBumpSet(commandLine)) { + logger.info( + "Forcing price bump for transaction replacement to 0, since min-gas-price is set to 0"); + txPoolConfBuilder.priceBump(Percentage.ZERO); + } + + return txPoolConfBuilder.build(); } private MiningParameters getMiningParameters() { diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/TransactionPoolOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java similarity index 81% rename from besu/src/main/java/org/hyperledger/besu/cli/options/stable/TransactionPoolOptions.java rename to besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java index d481e0453a..a8a50025f5 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/TransactionPoolOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options.stable; +package org.hyperledger.besu.cli.options; import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_DOUBLE_FORMAT_HELP; import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_INTEGER_FORMAT_HELP; @@ -20,10 +20,11 @@ import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_LONG_FORMA import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED; import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LEGACY; +import org.hyperledger.besu.cli.converter.DurationMillisConverter; import org.hyperledger.besu.cli.converter.FractionConverter; import org.hyperledger.besu.cli.converter.PercentageConverter; -import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.cli.util.CommandLineUtils; +import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; @@ -32,6 +33,7 @@ import org.hyperledger.besu.util.number.Fraction; import org.hyperledger.besu.util.number.Percentage; import java.io.File; +import java.time.Duration; import java.util.List; import java.util.Set; @@ -195,6 +197,39 @@ public class TransactionPoolOptions implements CLIOptions