From 0eae34a447cc1c12a0c52505ec3f88f589a0e1fe Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Thu, 17 Aug 2023 16:26:20 +0200 Subject: [PATCH 1/9] Add option to choose the txpool implementation and make layered the default Signed-off-by: Fabio Di Fabio --- .../org/hyperledger/besu/cli/BesuCommand.java | 4 +-- .../cli/ConfigurationOverviewBuilder.java | 12 ++++---- .../unstable/TransactionPoolOptions.java | 29 +++++++++---------- .../cli/ConfigurationOverviewBuilderTest.java | 22 ++++++++------ .../options/TransactionPoolOptionsTest.java | 5 ++-- .../TransactionPoolConfiguration.java | 11 +++++-- .../transactions/TransactionPoolFactory.java | 5 ++-- 7 files changed, 48 insertions(+), 40 deletions(-) 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 e0330170b7f..fca7f1bf2bd 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -3612,9 +3612,7 @@ private String generateConfigurationOverview() { builder.setHighSpecEnabled(); } - if (buildTransactionPoolConfiguration().getLayeredTxPoolEnabled()) { - builder.setLayeredTxPoolEnabled(); - } + builder.setTxPoolImplementation(buildTransactionPoolConfiguration().getTxPoolImplementation()); return builder.build(); } diff --git a/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java b/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java index 2cd374a2f57..8ddeee286dd 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilder.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.cli; import org.hyperledger.besu.BesuInfo; +import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; import org.hyperledger.besu.util.log.FramedLogMessage; import org.hyperledger.besu.util.platform.PlatformDetector; @@ -47,7 +48,7 @@ public class ConfigurationOverviewBuilder { private Collection engineApis; private String engineJwtFilePath; private boolean isHighSpec = false; - private boolean isLayeredTxPool = false; + private TransactionPoolConfiguration.Implementation txPoolImplementation; private Map environment; /** @@ -171,8 +172,9 @@ public ConfigurationOverviewBuilder setHighSpecEnabled() { * * @return the builder */ - public ConfigurationOverviewBuilder setLayeredTxPoolEnabled() { - isLayeredTxPool = true; + public ConfigurationOverviewBuilder setTxPoolImplementation( + final TransactionPoolConfiguration.Implementation implementation) { + txPoolImplementation = implementation; return this; } @@ -251,9 +253,7 @@ public String build() { lines.add("Experimental high spec configuration enabled"); } - if (isLayeredTxPool) { - lines.add("Experimental layered transaction pool configuration enabled"); - } + lines.add("Using " + txPoolImplementation + " transaction pool implementation"); lines.add(""); lines.add("Host:"); diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/TransactionPoolOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/TransactionPoolOptions.java index e199966c25f..a98eef7ac28 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/TransactionPoolOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/TransactionPoolOptions.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.cli.options.unstable; +import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED; + import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.cli.options.OptionParser; import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; @@ -41,13 +43,12 @@ public class TransactionPoolOptions private static final String STRICT_TX_REPLAY_PROTECTION_ENABLED_FLAG = "--strict-tx-replay-protection-enabled"; - private static final String LAYERED_TX_POOL_ENABLED_FLAG = "--Xlayered-tx-pool"; + private static final String TX_POOL_IMPLEMENTATION = "--tx-pool"; private static final String LAYERED_TX_POOL_LAYER_MAX_CAPACITY = - "--Xlayered-tx-pool-layer-max-capacity"; - private static final String LAYERED_TX_POOL_MAX_PRIORITIZED = - "--Xlayered-tx-pool-max-prioritized"; + "--layered-tx-pool-layer-max-capacity"; + private static final String LAYERED_TX_POOL_MAX_PRIORITIZED = "--layered-tx-pool-max-prioritized"; private static final String LAYERED_TX_POOL_MAX_FUTURE_BY_SENDER = - "--Xlayered-tx-pool-max-future-by-sender"; + "--layered-tx-pool-max-future-by-sender"; @CommandLine.Option( names = {STRICT_TX_REPLAY_PROTECTION_ENABLED_FLAG}, @@ -79,13 +80,11 @@ public class TransactionPoolOptions TransactionPoolConfiguration.ETH65_TRX_ANNOUNCED_BUFFERING_PERIOD.toMillis(); @CommandLine.Option( - names = {LAYERED_TX_POOL_ENABLED_FLAG}, - paramLabel = "", - hidden = true, - description = "Enable the Layered Transaction Pool (default: ${DEFAULT-VALUE})", + names = {TX_POOL_IMPLEMENTATION}, + paramLabel = "", + description = "The Transaction Pool implementation to use(default: ${DEFAULT-VALUE})", arity = "0..1") - private Boolean layeredTxPoolEnabled = - TransactionPoolConfiguration.DEFAULT_LAYERED_TX_POOL_ENABLED; + private TransactionPoolConfiguration.Implementation txPoolImplementation = LAYERED; @CommandLine.Option( names = {LAYERED_TX_POOL_LAYER_MAX_CAPACITY}, @@ -140,7 +139,7 @@ public static TransactionPoolOptions fromConfig(final TransactionPoolConfigurati options.eth65TrxAnnouncedBufferingPeriod = config.getEth65TrxAnnouncedBufferingPeriod().toMillis(); options.strictTxReplayProtectionEnabled = config.getStrictTransactionReplayProtectionEnabled(); - options.layeredTxPoolEnabled = config.getLayeredTxPoolEnabled(); + options.txPoolImplementation = config.getTxPoolImplementation(); options.layeredTxPoolLayerMaxCapacity = config.getPendingTransactionsLayerMaxCapacityBytes(); options.layeredTxPoolMaxPrioritized = config.getMaxPrioritizedTransactions(); options.layeredTxPoolMaxFutureBySender = config.getMaxFutureBySender(); @@ -149,7 +148,7 @@ public static TransactionPoolOptions fromConfig(final TransactionPoolConfigurati @Override public ImmutableTransactionPoolConfiguration.Builder toDomainObject() { - if (layeredTxPoolEnabled) { + if (txPoolImplementation.equals(LAYERED)) { LOG.warn( "Layered transaction pool enabled, ignoring settings for " + "--tx-pool-max-size and --tx-pool-limit-by-account-percentage"); @@ -159,7 +158,7 @@ public ImmutableTransactionPoolConfiguration.Builder toDomainObject() { .strictTransactionReplayProtectionEnabled(strictTxReplayProtectionEnabled) .txMessageKeepAliveSeconds(txMessageKeepAliveSeconds) .eth65TrxAnnouncedBufferingPeriod(Duration.ofMillis(eth65TrxAnnouncedBufferingPeriod)) - .layeredTxPoolEnabled(layeredTxPoolEnabled) + .txPoolImplementation(txPoolImplementation) .pendingTransactionsLayerMaxCapacityBytes(layeredTxPoolLayerMaxCapacity) .maxPrioritizedTransactions(layeredTxPoolMaxPrioritized) .maxFutureBySender(layeredTxPoolMaxFutureBySender); @@ -173,7 +172,7 @@ public List getCLIOptions() { OptionParser.format(txMessageKeepAliveSeconds), ETH65_TX_ANNOUNCED_BUFFERING_PERIOD_FLAG, OptionParser.format(eth65TrxAnnouncedBufferingPeriod), - LAYERED_TX_POOL_ENABLED_FLAG + "=" + layeredTxPoolEnabled, + TX_POOL_IMPLEMENTATION + "=" + txPoolImplementation, LAYERED_TX_POOL_LAYER_MAX_CAPACITY, OptionParser.format(layeredTxPoolLayerMaxCapacity), LAYERED_TX_POOL_MAX_PRIORITIZED, diff --git a/besu/src/test/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilderTest.java index 33ed9bc2d16..4fff2b36f58 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilderTest.java @@ -15,6 +15,8 @@ package org.hyperledger.besu.cli; import static org.assertj.core.api.Assertions.assertThat; +import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED; +import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LEGACY; import static org.mockito.Mockito.mock; import java.math.BigInteger; @@ -145,14 +147,16 @@ void setHighSpecEnabled() { } @Test - void setLayeredTxPoolEnabled() { - final String layeredTxPoolDisabled = builder.build(); - assertThat(layeredTxPoolDisabled) - .doesNotContain("Experimental layered transaction pool configuration enabled"); - - builder.setLayeredTxPoolEnabled(); - final String layeredTxPoolEnabled = builder.build(); - assertThat(layeredTxPoolEnabled) - .contains("Experimental layered transaction pool configuration enabled"); + void setTxPoolImplementationLayered() { + builder.setTxPoolImplementation(LAYERED); + final String layeredTxPoolSelected = builder.build(); + assertThat(layeredTxPoolSelected).contains("Using LAYERED transaction pool implementation"); + } + + @Test + void setTxPoolImplementationLegacy() { + builder.setTxPoolImplementation(LEGACY); + final String legacyTxPoolSelected = builder.build(); + assertThat(legacyTxPoolSelected).contains("Using LEGACY transaction pool implementation"); } } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java index 5a235524c6a..992e3737e51 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java @@ -16,6 +16,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; +import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED; import org.hyperledger.besu.cli.options.unstable.TransactionPoolOptions; import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; @@ -121,7 +122,7 @@ ImmutableTransactionPoolConfiguration.Builder createDefaultDomainObject() { .strictTransactionReplayProtectionEnabled(false) .txMessageKeepAliveSeconds(defaultValue.getTxMessageKeepAliveSeconds()) .eth65TrxAnnouncedBufferingPeriod(defaultValue.getEth65TrxAnnouncedBufferingPeriod()) - .layeredTxPoolEnabled(defaultValue.getLayeredTxPoolEnabled()) + .txPoolImplementation(defaultValue.getTxPoolImplementation()) .pendingTransactionsLayerMaxCapacityBytes( defaultValue.getPendingTransactionsLayerMaxCapacityBytes()) .maxPrioritizedTransactions(defaultValue.getMaxPrioritizedTransactions()) @@ -136,7 +137,7 @@ ImmutableTransactionPoolConfiguration.Builder createCustomizedDomainObject() { .eth65TrxAnnouncedBufferingPeriod( TransactionPoolConfiguration.ETH65_TRX_ANNOUNCED_BUFFERING_PERIOD.plus( Duration.ofMillis(100))) - .layeredTxPoolEnabled(true) + .txPoolImplementation(LAYERED) .pendingTransactionsLayerMaxCapacityBytes(1_000_000L) .maxPrioritizedTransactions(1000) .maxFutureBySender(10); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolConfiguration.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolConfiguration.java index ddcb06f8a9d..4f03570cf43 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolConfiguration.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolConfiguration.java @@ -25,6 +25,11 @@ @Value.Immutable @Value.Style(allParameters = true) public interface TransactionPoolConfiguration { + enum Implementation { + LEGACY, + LAYERED; + } + String DEFAULT_SAVE_FILE_NAME = "txpool.dump"; int DEFAULT_TX_MSG_KEEP_ALIVE = 60; int DEFAULT_MAX_PENDING_TRANSACTIONS = 4096; @@ -41,7 +46,7 @@ public interface TransactionPoolConfiguration { long DEFAULT_PENDING_TRANSACTIONS_LAYER_MAX_CAPACITY_BYTES = 50_000_000L; int DEFAULT_MAX_PRIORITIZED_TRANSACTIONS = 2000; int DEFAULT_MAX_FUTURE_BY_SENDER = 200; - boolean DEFAULT_LAYERED_TX_POOL_ENABLED = false; + Implementation DEFAULT_TX_POOL_IMPLEMENTATION = Implementation.LAYERED; TransactionPoolConfiguration DEFAULT = ImmutableTransactionPoolConfiguration.builder().build(); @@ -106,8 +111,8 @@ default File getSaveFile() { } @Value.Default - default Boolean getLayeredTxPoolEnabled() { - return DEFAULT_LAYERED_TX_POOL_ENABLED; + default Implementation getTxPoolImplementation() { + return DEFAULT_TX_POOL_IMPLEMENTATION; } @Value.Default diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactory.java index 16a05922864..2a31a429c67 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactory.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.ethereum.eth.transactions; +import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED; + import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -194,8 +196,7 @@ private static PendingTransactions createPendingTransactions( protocolSchedule.anyMatch( scheduledSpec -> scheduledSpec.spec().getFeeMarket().implementsBaseFee()); - if (transactionPoolConfiguration.getLayeredTxPoolEnabled()) { - LOG.info("Using layered transaction pool"); + if (transactionPoolConfiguration.getTxPoolImplementation().equals(LAYERED)) { return createLayeredPendingTransactions( protocolSchedule, protocolContext, From 3e0a037735d9059fda0975a693e02f8e6fdc5924 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Thu, 17 Aug 2023 20:00:38 +0200 Subject: [PATCH 2/9] Re-organize stable and unstable txpool options Signed-off-by: Fabio Di Fabio --- .../org/hyperledger/besu/cli/BesuCommand.java | 202 +++++++-------- .../besu/cli/DefaultCommandValues.java | 4 - .../stable/TransactionPoolOptions.java | 230 ++++++++++++++++++ .../unstable/TransactionPoolOptions.java | 94 +------ .../hyperledger/besu/cli/BesuCommandTest.java | 4 +- .../besu/cli/CommandTestAbstract.java | 7 +- .../cli/options/AbstractCLIOptionsTest.java | 8 +- .../cli/options/EthProtocolOptionsTest.java | 9 +- .../cli/options/MetricsCLIOptionsTest.java | 9 +- .../cli/options/NetworkingOptionsTest.java | 8 +- .../cli/options/SynchronizerOptionsTest.java | 8 +- .../TransactionPoolOptionsTest.java | 77 ++---- .../unstable/TransactionPoolOptionsTest.java | 98 ++++++++ 13 files changed, 487 insertions(+), 271 deletions(-) create mode 100644 besu/src/main/java/org/hyperledger/besu/cli/options/stable/TransactionPoolOptions.java rename besu/src/test/java/org/hyperledger/besu/cli/options/{ => stable}/TransactionPoolOptionsTest.java (59%) create mode 100644 besu/src/test/java/org/hyperledger/besu/cli/options/unstable/TransactionPoolOptionsTest.java 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 fca7f1bf2bd..91305a62402 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -46,7 +46,6 @@ import org.hyperledger.besu.chainimport.RlpBlockImporter; import org.hyperledger.besu.cli.config.EthNetworkConfig; import org.hyperledger.besu.cli.config.NetworkName; -import org.hyperledger.besu.cli.converter.FractionConverter; import org.hyperledger.besu.cli.converter.MetricCategoryConverter; import org.hyperledger.besu.cli.converter.PercentageConverter; import org.hyperledger.besu.cli.custom.CorsAllowedOriginsProperty; @@ -59,6 +58,7 @@ 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; @@ -73,7 +73,6 @@ import org.hyperledger.besu.cli.options.unstable.PrivacyPluginOptions; import org.hyperledger.besu.cli.options.unstable.RPCOptions; import org.hyperledger.besu.cli.options.unstable.SynchronizerOptions; -import org.hyperledger.besu.cli.options.unstable.TransactionPoolOptions; import org.hyperledger.besu.cli.presynctasks.PreSynchronizationTaskRunner; import org.hyperledger.besu.cli.presynctasks.PrivateDatabaseMigrationPreSyncTask; import org.hyperledger.besu.cli.subcommands.PasswordSubCommand; @@ -127,6 +126,7 @@ import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.sync.SyncMode; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; +import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; import org.hyperledger.besu.ethereum.mainnet.FrontierTargetingGasLimitCalculator; import org.hyperledger.besu.ethereum.p2p.config.DiscoveryConfiguration; @@ -194,7 +194,6 @@ import org.hyperledger.besu.util.NetworkUtility; import org.hyperledger.besu.util.PermissioningConfigurationValidator; import org.hyperledger.besu.util.number.Fraction; -import org.hyperledger.besu.util.number.Percentage; import org.hyperledger.besu.util.number.PositiveNumber; import java.io.File; @@ -280,7 +279,9 @@ public class BesuCommand implements DefaultCommandValues, Runnable { final SynchronizerOptions unstableSynchronizerOptions = SynchronizerOptions.create(); final EthProtocolOptions unstableEthProtocolOptions = EthProtocolOptions.create(); final MetricsCLIOptions unstableMetricsCLIOptions = MetricsCLIOptions.create(); - final TransactionPoolOptions unstableTransactionPoolOptions = TransactionPoolOptions.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 MiningOptions unstableMiningOptions = MiningOptions.create(); private final NatOptions unstableNatOptions = NatOptions.create(); @@ -298,6 +299,10 @@ public class BesuCommand implements DefaultCommandValues, Runnable { NodePrivateKeyFileOption.create(); private final LoggingLevelOption loggingLevelOption = LoggingLevelOption.create(); + @CommandLine.ArgGroup(validate = false, heading = "@|bold Tx Pool Options|@%n") + final org.hyperledger.besu.cli.options.stable.TransactionPoolOptions + stableTransactionPoolOptions = TransactionPoolOptions.create(); + private final RunnerBuilder runnerBuilder; private final BesuController.Builder controllerBuilderFactory; private final BesuPluginContextImpl besuPluginContext; @@ -1111,12 +1116,13 @@ static class MinerOptionGroup { arity = "1") private final Wei minTransactionGasPrice = DEFAULT_MIN_TRANSACTION_GAS_PRICE; - @Option( - names = {"--rpc-tx-feecap"}, - description = - "Maximum transaction fees (in Wei) accepted for transaction submitted through RPC (default: ${DEFAULT-VALUE})", - arity = "1") - private final Wei txFeeCap = DEFAULT_RPC_TX_FEE_CAP; + // @Option( + // names = {"--rpc-tx-feecap"}, + // description = + // "Maximum transaction fees (in Wei) accepted for transaction submitted through RPC + // (default: ${DEFAULT-VALUE})", + // arity = "1") + // private final Wei txFeeCap = DEFAULT_RPC_TX_FEE_CAP; @Option( names = {"--min-block-occupancy-ratio"}, @@ -1210,73 +1216,82 @@ static class PermissionsOptionGroup { private final Long targetGasLimit = null; // Tx Pool Option Group - @CommandLine.ArgGroup(validate = false, heading = "@|bold Tx Pool Options|@%n") - TxPoolOptionGroup txPoolOptionGroup = new TxPoolOptionGroup(); - - static class TxPoolOptionGroup { - @CommandLine.Option( - names = {"--tx-pool-disable-locals"}, - paramLabel = "", - description = - "Set to true if transactions sent via RPC should have the same checks and not be prioritized over remote ones (default: ${DEFAULT-VALUE})", - fallbackValue = "true", - arity = "0..1") - private Boolean disableLocalTxs = TransactionPoolConfiguration.DEFAULT_DISABLE_LOCAL_TXS; - - @CommandLine.Option( - names = {"--tx-pool-enable-save-restore"}, - paramLabel = "", - description = - "Set to true to enable saving the txpool content to file on shutdown and reloading it on startup (default: ${DEFAULT-VALUE})", - fallbackValue = "true", - arity = "0..1") - private Boolean saveRestoreEnabled = TransactionPoolConfiguration.DEFAULT_ENABLE_SAVE_RESTORE; - - @CommandLine.Option( - names = {"--tx-pool-limit-by-account-percentage"}, - paramLabel = "", - converter = FractionConverter.class, - description = - "Maximum portion of the transaction pool which a single account may occupy with future transactions (default: ${DEFAULT-VALUE})", - arity = "1") - private Float txPoolLimitByAccountPercentage = - TransactionPoolConfiguration.DEFAULT_LIMIT_TX_POOL_BY_ACCOUNT_PERCENTAGE; - - @CommandLine.Option( - names = {"--tx-pool-save-file"}, - paramLabel = "", - description = - "If saving the txpool content is enabled, define a custom path for the save file (default: ${DEFAULT-VALUE} in the data-dir)", - arity = "1") - private File saveFile = TransactionPoolConfiguration.DEFAULT_SAVE_FILE; - - @Option( - names = {"--tx-pool-max-size"}, - paramLabel = MANDATORY_INTEGER_FORMAT_HELP, - description = - "Maximum number of pending transactions that will be kept in the transaction pool (default: ${DEFAULT-VALUE})", - arity = "1") - private final Integer txPoolMaxSize = - TransactionPoolConfiguration.DEFAULT_MAX_PENDING_TRANSACTIONS; - - @Option( - names = {"--tx-pool-retention-hours"}, - paramLabel = MANDATORY_INTEGER_FORMAT_HELP, - description = - "Maximum retention period of pending transactions in hours (default: ${DEFAULT-VALUE})", - arity = "1") - private final Integer pendingTxRetentionPeriod = - TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS; - - @Option( - names = {"--tx-pool-price-bump"}, - paramLabel = MANDATORY_INTEGER_FORMAT_HELP, - converter = PercentageConverter.class, - description = - "Price bump percentage to replace an already existing transaction (default: ${DEFAULT-VALUE})", - arity = "1") - private final Integer priceBump = TransactionPoolConfiguration.DEFAULT_PRICE_BUMP.getValue(); - } + // @CommandLine.ArgGroup(validate = false, heading = "@|bold Tx Pool Options|@%n") + // TxPoolOptionGroup txPoolOptionGroup = new TxPoolOptionGroup(); + + // static class TxPoolOptionGroup { + // @CommandLine.Option( + // names = {"--tx-pool-disable-locals"}, + // paramLabel = "", + // description = + // "Set to true if transactions sent via RPC should have the same checks and not be + // prioritized over remote ones (default: ${DEFAULT-VALUE})", + // fallbackValue = "true", + // arity = "0..1") + // private Boolean disableLocalTxs = TransactionPoolConfiguration.DEFAULT_DISABLE_LOCAL_TXS; + // + // @CommandLine.Option( + // names = {"--tx-pool-enable-save-restore"}, + // paramLabel = "", + // description = + // "Set to true to enable saving the txpool content to file on shutdown and reloading + // it on startup (default: ${DEFAULT-VALUE})", + // fallbackValue = "true", + // arity = "0..1") + // private Boolean saveRestoreEnabled = + // TransactionPoolConfiguration.DEFAULT_ENABLE_SAVE_RESTORE; + // + // @CommandLine.Option( + // names = {"--tx-pool-limit-by-account-percentage"}, + // paramLabel = "", + // converter = FractionConverter.class, + // description = + // "Maximum portion of the transaction pool which a single account may occupy with + // future transactions (default: ${DEFAULT-VALUE})", + // arity = "1") + // private Float txPoolLimitByAccountPercentage = + // TransactionPoolConfiguration.DEFAULT_LIMIT_TX_POOL_BY_ACCOUNT_PERCENTAGE; + // + // @CommandLine.Option( + // names = {"--tx-pool-save-file"}, + // paramLabel = "", + // description = + // "If saving the txpool content is enabled, define a custom path for the save file + // (default: ${DEFAULT-VALUE} in the data-dir)", + // arity = "1") + // private File saveFile = TransactionPoolConfiguration.DEFAULT_SAVE_FILE; + // + // @Option( + // names = {"--tx-pool-max-size"}, + // paramLabel = MANDATORY_INTEGER_FORMAT_HELP, + // description = + // "Maximum number of pending transactions that will be kept in the transaction pool + // (default: ${DEFAULT-VALUE})", + // arity = "1") + // private final Integer txPoolMaxSize = + // TransactionPoolConfiguration.DEFAULT_MAX_PENDING_TRANSACTIONS; + // + // @Option( + // names = {"--tx-pool-retention-hours"}, + // paramLabel = MANDATORY_INTEGER_FORMAT_HELP, + // description = + // "Maximum retention period of pending transactions in hours (default: + // ${DEFAULT-VALUE})", + // arity = "1") + // private final Integer pendingTxRetentionPeriod = + // TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS; + // + // @Option( + // names = {"--tx-pool-price-bump"}, + // paramLabel = MANDATORY_INTEGER_FORMAT_HELP, + // converter = PercentageConverter.class, + // description = + // "Price bump percentage to replace an already existing transaction (default: + // ${DEFAULT-VALUE})", + // arity = "1") + // private final Integer priceBump = + // TransactionPoolConfiguration.DEFAULT_PRICE_BUMP.getValue(); + // } @SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings. @Option( @@ -2987,26 +3002,21 @@ private SynchronizerConfiguration buildSyncConfig() { } private TransactionPoolConfiguration buildTransactionPoolConfiguration() { - return unstableTransactionPoolOptions - .toDomainObject() - .enableSaveRestore(txPoolOptionGroup.saveRestoreEnabled) - .disableLocalTransactions(txPoolOptionGroup.disableLocalTxs) - .txPoolLimitByAccountPercentage(txPoolOptionGroup.txPoolLimitByAccountPercentage) - .txPoolMaxSize(txPoolOptionGroup.txPoolMaxSize) - .pendingTxRetentionPeriod(txPoolOptionGroup.pendingTxRetentionPeriod) - .priceBump(Percentage.fromInt(txPoolOptionGroup.priceBump)) - .txFeeCap(txFeeCap) - .saveFile(dataPath.resolve(txPoolOptionGroup.saveFile.getPath()).toFile()) + final var stableTxPoolOption = stableTransactionPoolOptions.toDomainObject(); + return ImmutableTransactionPoolConfiguration.builder() + .from(unstableTransactionPoolOptions.toDomainObject()) + .from(stableTxPoolOption) + .saveFile(dataPath.resolve(stableTxPoolOption.getSaveFile().getPath()).toFile()) .build(); - } - - /** - * Return the file where to save txpool content if the relative option is enabled. - * - * @return the save file - */ - public File getSaveFile() { - return txPoolOptionGroup.saveFile; + // .enableSaveRestore(txPoolOptionGroup.saveRestoreEnabled) + // .disableLocalTransactions(txPoolOptionGroup.disableLocalTxs) + // .txPoolLimitByAccountPercentage(txPoolOptionGroup.txPoolLimitByAccountPercentage) + // .txPoolMaxSize(txPoolOptionGroup.txPoolMaxSize) + // .pendingTxRetentionPeriod(txPoolOptionGroup.pendingTxRetentionPeriod) + // .priceBump(Percentage.fromInt(txPoolOptionGroup.priceBump)) + // .txFeeCap(txFeeCap) + // .saveFile(dataPath.resolve(txPoolOptionGroup.saveFile.getPath()).toFile()) + // .build(); } private boolean isPruningEnabled() { diff --git a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java index 887e6120419..8b837268327 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java @@ -16,7 +16,6 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.jsonrpc.authentication.JwtAlgorithm; -import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; import org.hyperledger.besu.ethereum.p2p.config.RlpxConfiguration; import org.hyperledger.besu.nat.NatMethod; @@ -61,9 +60,6 @@ public interface DefaultCommandValues { String MANDATORY_NODE_ID_FORMAT_HELP = ""; /** The constant DEFAULT_MIN_TRANSACTION_GAS_PRICE. */ Wei DEFAULT_MIN_TRANSACTION_GAS_PRICE = Wei.of(1000); - /** The constant DEFAULT_RPC_TX_FEE_CAP. */ - Wei DEFAULT_RPC_TX_FEE_CAP = TransactionPoolConfiguration.DEFAULT_RPC_TX_FEE_CAP; - /** The constant DEFAULT_MIN_BLOCK_OCCUPANCY_RATIO. */ Double DEFAULT_MIN_BLOCK_OCCUPANCY_RATIO = 0.8; /** The constant DEFAULT_EXTRA_DATA. */ 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/stable/TransactionPoolOptions.java new file mode 100644 index 00000000000..e28d2ffe4b4 --- /dev/null +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/stable/TransactionPoolOptions.java @@ -0,0 +1,230 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.cli.options.stable; + +import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_DOUBLE_FORMAT_HELP; +import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_INTEGER_FORMAT_HELP; +import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_LONG_FORMAT_HELP; +import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED; + +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.options.OptionParser; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; +import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; +import org.hyperledger.besu.util.number.Percentage; + +import java.io.File; +import java.util.Arrays; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import picocli.CommandLine; + +public class TransactionPoolOptions implements CLIOptions { + private static final Logger LOG = LoggerFactory.getLogger(TransactionPoolOptions.class); + private static final String TX_POOL_IMPLEMENTATION = "--tx-pool"; + private static final String STRICT_TX_REPLAY_PROTECTION_ENABLED_FLAG = + "--strict-tx-replay-protection-enabled"; + private static final String LAYERED_TX_POOL_LAYER_MAX_CAPACITY = + "--layered-tx-pool-layer-max-capacity"; + private static final String LAYERED_TX_POOL_MAX_PRIORITIZED = "--layered-tx-pool-max-prioritized"; + private static final String LAYERED_TX_POOL_MAX_FUTURE_BY_SENDER = + "--layered-tx-pool-max-future-by-sender"; + + @CommandLine.Option( + names = {"--tx-pool-disable-locals"}, + paramLabel = "", + description = + "Set to true if transactions sent via RPC should have the same checks and not be prioritized over remote ones (default: ${DEFAULT-VALUE})", + fallbackValue = "true", + arity = "0..1") + private Boolean disableLocalTxs = TransactionPoolConfiguration.DEFAULT_DISABLE_LOCAL_TXS; + + @CommandLine.Option( + names = {"--tx-pool-enable-save-restore"}, + paramLabel = "", + description = + "Set to true to enable saving the txpool content to file on shutdown and reloading it on startup (default: ${DEFAULT-VALUE})", + fallbackValue = "true", + arity = "0..1") + private Boolean saveRestoreEnabled = TransactionPoolConfiguration.DEFAULT_ENABLE_SAVE_RESTORE; + + @CommandLine.Option( + names = {"--tx-pool-save-file"}, + paramLabel = "", + description = + "If saving the txpool content is enabled, define a custom path for the save file (default: ${DEFAULT-VALUE} in the data-dir)", + arity = "1") + private File saveFile = TransactionPoolConfiguration.DEFAULT_SAVE_FILE; + + @CommandLine.Option( + names = {"--tx-pool-limit-by-account-percentage"}, + paramLabel = MANDATORY_DOUBLE_FORMAT_HELP, + converter = FractionConverter.class, + description = + "Maximum portion of the transaction pool which a single account may occupy with future transactions (default: ${DEFAULT-VALUE})", + arity = "1") + private Float txPoolLimitByAccountPercentage = + TransactionPoolConfiguration.DEFAULT_LIMIT_TX_POOL_BY_ACCOUNT_PERCENTAGE; + + @CommandLine.Option( + names = {"--tx-pool-max-size"}, + paramLabel = MANDATORY_INTEGER_FORMAT_HELP, + description = + "Maximum number of pending transactions that will be kept in the transaction pool (default: ${DEFAULT-VALUE})", + arity = "1") + private final Integer txPoolMaxSize = + TransactionPoolConfiguration.DEFAULT_MAX_PENDING_TRANSACTIONS; + + @CommandLine.Option( + names = {"--tx-pool-retention-hours"}, + paramLabel = MANDATORY_INTEGER_FORMAT_HELP, + description = + "Maximum retention period of pending transactions in hours (default: ${DEFAULT-VALUE})", + arity = "1") + private final Integer pendingTxRetentionPeriod = + TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS; + + @CommandLine.Option( + names = {"--tx-pool-price-bump"}, + paramLabel = MANDATORY_INTEGER_FORMAT_HELP, + converter = PercentageConverter.class, + description = + "Price bump percentage to replace an already existing transaction (default: ${DEFAULT-VALUE})", + arity = "1") + private final Integer priceBump = TransactionPoolConfiguration.DEFAULT_PRICE_BUMP.getValue(); + + @CommandLine.Option( + names = {STRICT_TX_REPLAY_PROTECTION_ENABLED_FLAG}, + paramLabel = "", + description = + "Require transactions submitted via JSON-RPC to use replay protection in accordance with EIP-155 (default: ${DEFAULT-VALUE})", + fallbackValue = "true", + arity = "0..1") + private Boolean strictTxReplayProtectionEnabled = false; + + @CommandLine.Option( + names = {TX_POOL_IMPLEMENTATION}, + paramLabel = "", + description = "The Transaction Pool implementation to use(default: ${DEFAULT-VALUE})", + arity = "0..1") + private TransactionPoolConfiguration.Implementation txPoolImplementation = LAYERED; + + @CommandLine.Option( + names = {LAYERED_TX_POOL_LAYER_MAX_CAPACITY}, + paramLabel = MANDATORY_LONG_FORMAT_HELP, + hidden = true, + description = + "Max amount of memory space, in bytes, that any layer within the transaction pool could occupy (default: ${DEFAULT-VALUE})", + arity = "1") + private long layeredTxPoolLayerMaxCapacity = + TransactionPoolConfiguration.DEFAULT_PENDING_TRANSACTIONS_LAYER_MAX_CAPACITY_BYTES; + + @CommandLine.Option( + names = {LAYERED_TX_POOL_MAX_PRIORITIZED}, + paramLabel = MANDATORY_INTEGER_FORMAT_HELP, + hidden = true, + description = + "Max number of pending transactions that are prioritized and thus kept sorted (default: ${DEFAULT-VALUE})", + arity = "1") + private int layeredTxPoolMaxPrioritized = + TransactionPoolConfiguration.DEFAULT_MAX_PRIORITIZED_TRANSACTIONS; + + @CommandLine.Option( + names = {LAYERED_TX_POOL_MAX_FUTURE_BY_SENDER}, + paramLabel = MANDATORY_INTEGER_FORMAT_HELP, + hidden = true, + description = + "Max number of future pending transactions allowed for a single sender (default: ${DEFAULT-VALUE})", + arity = "1") + private int layeredTxPoolMaxFutureBySender = + TransactionPoolConfiguration.DEFAULT_MAX_FUTURE_BY_SENDER; + + @CommandLine.Option( + names = {"--rpc-tx-feecap"}, + description = + "Maximum transaction fees (in Wei) accepted for transaction submitted through RPC (default: ${DEFAULT-VALUE})", + arity = "1") + private final Wei txFeeCap = TransactionPoolConfiguration.DEFAULT_RPC_TX_FEE_CAP; + + private TransactionPoolOptions() {} + + /** + * Create transaction pool options. + * + * @return the transaction pool options + */ + public static TransactionPoolOptions create() { + return new TransactionPoolOptions(); + } + + /** + * Create Transaction Pool Options from Transaction Pool Configuration. + * + * @param config the Transaction Pool Configuration + * @return the transaction pool options + */ + public static TransactionPoolOptions fromConfig(final TransactionPoolConfiguration config) { + final TransactionPoolOptions options = TransactionPoolOptions.create(); + options.strictTxReplayProtectionEnabled = config.getStrictTransactionReplayProtectionEnabled(); + options.txPoolImplementation = config.getTxPoolImplementation(); + options.layeredTxPoolLayerMaxCapacity = config.getPendingTransactionsLayerMaxCapacityBytes(); + options.layeredTxPoolMaxPrioritized = config.getMaxPrioritizedTransactions(); + options.layeredTxPoolMaxFutureBySender = config.getMaxFutureBySender(); + return options; + } + + @Override + public TransactionPoolConfiguration toDomainObject() { + if (txPoolImplementation.equals(LAYERED)) { + LOG.warn( + "Layered transaction pool enabled, ignoring settings for " + + "--tx-pool-max-size and --tx-pool-limit-by-account-percentage"); + } + + return ImmutableTransactionPoolConfiguration.builder() + .enableSaveRestore(saveRestoreEnabled) + .disableLocalTransactions(disableLocalTxs) + .txPoolLimitByAccountPercentage(txPoolLimitByAccountPercentage) + .txPoolMaxSize(txPoolMaxSize) + .pendingTxRetentionPeriod(pendingTxRetentionPeriod) + .priceBump(Percentage.fromInt(priceBump)) + .txFeeCap(txFeeCap) + .saveFile(saveFile) + .strictTransactionReplayProtectionEnabled(strictTxReplayProtectionEnabled) + .txPoolImplementation(txPoolImplementation) + .pendingTransactionsLayerMaxCapacityBytes(layeredTxPoolLayerMaxCapacity) + .maxPrioritizedTransactions(layeredTxPoolMaxPrioritized) + .maxFutureBySender(layeredTxPoolMaxFutureBySender) + .build(); + } + + @Override + public List getCLIOptions() { + return Arrays.asList( + STRICT_TX_REPLAY_PROTECTION_ENABLED_FLAG + "=" + strictTxReplayProtectionEnabled, + TX_POOL_IMPLEMENTATION + "=" + txPoolImplementation, + LAYERED_TX_POOL_LAYER_MAX_CAPACITY, + OptionParser.format(layeredTxPoolLayerMaxCapacity), + LAYERED_TX_POOL_MAX_PRIORITIZED, + OptionParser.format(layeredTxPoolMaxPrioritized), + LAYERED_TX_POOL_MAX_FUTURE_BY_SENDER, + OptionParser.format(layeredTxPoolMaxFutureBySender)); + } +} diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/TransactionPoolOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/TransactionPoolOptions.java index a98eef7ac28..536608c07a9 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/TransactionPoolOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/TransactionPoolOptions.java @@ -14,8 +14,6 @@ */ package org.hyperledger.besu.cli.options.unstable; -import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED; - import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.cli.options.OptionParser; import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; @@ -25,40 +23,16 @@ import java.util.Arrays; import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import picocli.CommandLine; /** The Transaction pool Cli options. */ -public class TransactionPoolOptions - implements CLIOptions { - private static final Logger LOG = LoggerFactory.getLogger(TransactionPoolOptions.class); - +public class TransactionPoolOptions implements CLIOptions { private static final String TX_MESSAGE_KEEP_ALIVE_SEC_FLAG = "--Xincoming-tx-messages-keep-alive-seconds"; private static final String ETH65_TX_ANNOUNCED_BUFFERING_PERIOD_FLAG = "--Xeth65-tx-announced-buffering-period-milliseconds"; - private static final String STRICT_TX_REPLAY_PROTECTION_ENABLED_FLAG = - "--strict-tx-replay-protection-enabled"; - - private static final String TX_POOL_IMPLEMENTATION = "--tx-pool"; - private static final String LAYERED_TX_POOL_LAYER_MAX_CAPACITY = - "--layered-tx-pool-layer-max-capacity"; - private static final String LAYERED_TX_POOL_MAX_PRIORITIZED = "--layered-tx-pool-max-prioritized"; - private static final String LAYERED_TX_POOL_MAX_FUTURE_BY_SENDER = - "--layered-tx-pool-max-future-by-sender"; - - @CommandLine.Option( - names = {STRICT_TX_REPLAY_PROTECTION_ENABLED_FLAG}, - paramLabel = "", - description = - "Require transactions submitted via JSON-RPC to use replay protection in accordance with EIP-155 (default: ${DEFAULT-VALUE})", - fallbackValue = "true", - arity = "0..1") - private Boolean strictTxReplayProtectionEnabled = false; - @CommandLine.Option( names = {TX_MESSAGE_KEEP_ALIVE_SEC_FLAG}, paramLabel = "", @@ -79,43 +53,6 @@ public class TransactionPoolOptions private long eth65TrxAnnouncedBufferingPeriod = TransactionPoolConfiguration.ETH65_TRX_ANNOUNCED_BUFFERING_PERIOD.toMillis(); - @CommandLine.Option( - names = {TX_POOL_IMPLEMENTATION}, - paramLabel = "", - description = "The Transaction Pool implementation to use(default: ${DEFAULT-VALUE})", - arity = "0..1") - private TransactionPoolConfiguration.Implementation txPoolImplementation = LAYERED; - - @CommandLine.Option( - names = {LAYERED_TX_POOL_LAYER_MAX_CAPACITY}, - paramLabel = "", - hidden = true, - description = - "Max amount of memory space, in bytes, that any layer within the transaction pool could occupy (default: ${DEFAULT-VALUE})", - arity = "1") - private long layeredTxPoolLayerMaxCapacity = - TransactionPoolConfiguration.DEFAULT_PENDING_TRANSACTIONS_LAYER_MAX_CAPACITY_BYTES; - - @CommandLine.Option( - names = {LAYERED_TX_POOL_MAX_PRIORITIZED}, - paramLabel = "", - hidden = true, - description = - "Max number of pending transactions that are prioritized and thus kept sorted (default: ${DEFAULT-VALUE})", - arity = "1") - private int layeredTxPoolMaxPrioritized = - TransactionPoolConfiguration.DEFAULT_MAX_PRIORITIZED_TRANSACTIONS; - - @CommandLine.Option( - names = {LAYERED_TX_POOL_MAX_FUTURE_BY_SENDER}, - paramLabel = "", - hidden = true, - description = - "Max number of future pending transactions allowed for a single sender (default: ${DEFAULT-VALUE})", - arity = "1") - private int layeredTxPoolMaxFutureBySender = - TransactionPoolConfiguration.DEFAULT_MAX_FUTURE_BY_SENDER; - private TransactionPoolOptions() {} /** @@ -138,46 +75,23 @@ public static TransactionPoolOptions fromConfig(final TransactionPoolConfigurati options.txMessageKeepAliveSeconds = config.getTxMessageKeepAliveSeconds(); options.eth65TrxAnnouncedBufferingPeriod = config.getEth65TrxAnnouncedBufferingPeriod().toMillis(); - options.strictTxReplayProtectionEnabled = config.getStrictTransactionReplayProtectionEnabled(); - options.txPoolImplementation = config.getTxPoolImplementation(); - options.layeredTxPoolLayerMaxCapacity = config.getPendingTransactionsLayerMaxCapacityBytes(); - options.layeredTxPoolMaxPrioritized = config.getMaxPrioritizedTransactions(); - options.layeredTxPoolMaxFutureBySender = config.getMaxFutureBySender(); return options; } @Override - public ImmutableTransactionPoolConfiguration.Builder toDomainObject() { - if (txPoolImplementation.equals(LAYERED)) { - LOG.warn( - "Layered transaction pool enabled, ignoring settings for " - + "--tx-pool-max-size and --tx-pool-limit-by-account-percentage"); - } - + public TransactionPoolConfiguration toDomainObject() { return ImmutableTransactionPoolConfiguration.builder() - .strictTransactionReplayProtectionEnabled(strictTxReplayProtectionEnabled) .txMessageKeepAliveSeconds(txMessageKeepAliveSeconds) .eth65TrxAnnouncedBufferingPeriod(Duration.ofMillis(eth65TrxAnnouncedBufferingPeriod)) - .txPoolImplementation(txPoolImplementation) - .pendingTransactionsLayerMaxCapacityBytes(layeredTxPoolLayerMaxCapacity) - .maxPrioritizedTransactions(layeredTxPoolMaxPrioritized) - .maxFutureBySender(layeredTxPoolMaxFutureBySender); + .build(); } @Override public List getCLIOptions() { return Arrays.asList( - STRICT_TX_REPLAY_PROTECTION_ENABLED_FLAG + "=" + strictTxReplayProtectionEnabled, TX_MESSAGE_KEEP_ALIVE_SEC_FLAG, OptionParser.format(txMessageKeepAliveSeconds), ETH65_TX_ANNOUNCED_BUFFERING_PERIOD_FLAG, - OptionParser.format(eth65TrxAnnouncedBufferingPeriod), - TX_POOL_IMPLEMENTATION + "=" + txPoolImplementation, - LAYERED_TX_POOL_LAYER_MAX_CAPACITY, - OptionParser.format(layeredTxPoolLayerMaxCapacity), - LAYERED_TX_POOL_MAX_PRIORITIZED, - OptionParser.format(layeredTxPoolMaxPrioritized), - LAYERED_TX_POOL_MAX_FUTURE_BY_SENDER, - OptionParser.format(layeredTxPoolMaxFutureBySender)); + OptionParser.format(eth65TrxAnnouncedBufferingPeriod)); } } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index 9a4fcc0fdda..cfa642f90ea 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -4693,9 +4693,9 @@ public void senderLimitedTxPoolFloor_derived() { public void senderLimitedTxPoolCeiling_violated() { TestBesuCommand commandTest = parseCommand("--tx-pool-limit-by-account-percentage=1.00002341"); - TransactionPoolOptions txPoolOption = commandTest.getTransactionPoolOptions(); + TransactionPoolOptions txPoolOption = commandTest.getUnstableTransactionPoolOptions(); - final TransactionPoolConfiguration config = txPoolOption.toDomainObject().build(); + final TransactionPoolConfiguration config = txPoolOption.toDomainObject(); assertThat(config.getTxPoolLimitByAccountPercentage()) .isEqualTo(TransactionPoolConfiguration.DEFAULT_LIMIT_TX_POOL_BY_ACCOUNT_PERCENTAGE); assertThat(commandOutput.toString(UTF_8)).isEmpty(); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java index fc6f013b2da..d089ceaceb7 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java @@ -519,7 +519,12 @@ public EthProtocolOptions getEthProtocolOptions() { return unstableEthProtocolOptions; } - public TransactionPoolOptions getTransactionPoolOptions() { + public org.hyperledger.besu.cli.options.stable.TransactionPoolOptions + getStableTransactionPoolOptions() { + return stableTransactionPoolOptions; + } + + public TransactionPoolOptions getUnstableTransactionPoolOptions() { return unstableTransactionPoolOptions; } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/AbstractCLIOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/AbstractCLIOptionsTest.java index 91d7e35c39c..9b2147a8b5c 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/AbstractCLIOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/AbstractCLIOptionsTest.java @@ -87,9 +87,9 @@ public void defaultValues() { .isEqualTo(defaultOptions); } - abstract D createDefaultDomainObject(); + protected abstract D createDefaultDomainObject(); - abstract D createCustomizedDomainObject(); + protected abstract D createCustomizedDomainObject(); protected List getFieldsWithComputedDefaults() { return Collections.emptyList(); @@ -99,7 +99,7 @@ protected List getFieldsToIgnore() { return Collections.emptyList(); } - abstract T optionsFromDomainObject(D domainObject); + protected abstract T optionsFromDomainObject(D domainObject); - abstract T getOptionsFromBesuCommand(final TestBesuCommand besuCommand); + protected abstract T getOptionsFromBesuCommand(final TestBesuCommand besuCommand); } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java index 1dc6f0329fb..9d1d696ab43 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/EthProtocolOptionsTest.java @@ -165,12 +165,12 @@ public void parsesValidEthMinProtocol() { } @Override - EthProtocolConfiguration createDefaultDomainObject() { + protected EthProtocolConfiguration createDefaultDomainObject() { return EthProtocolConfiguration.builder().build(); } @Override - EthProtocolConfiguration createCustomizedDomainObject() { + protected EthProtocolConfiguration createCustomizedDomainObject() { return EthProtocolConfiguration.builder() .maxMessageSize(EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE * 2) .maxGetBlockHeaders(EthProtocolConfiguration.DEFAULT_MAX_GET_BLOCK_HEADERS + 2) @@ -184,12 +184,13 @@ EthProtocolConfiguration createCustomizedDomainObject() { } @Override - EthProtocolOptions optionsFromDomainObject(final EthProtocolConfiguration domainObject) { + protected EthProtocolOptions optionsFromDomainObject( + final EthProtocolConfiguration domainObject) { return EthProtocolOptions.fromConfig(domainObject); } @Override - EthProtocolOptions getOptionsFromBesuCommand(final TestBesuCommand besuCommand) { + protected EthProtocolOptions getOptionsFromBesuCommand(final TestBesuCommand besuCommand) { return besuCommand.getEthProtocolOptions(); } } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsCLIOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsCLIOptionsTest.java index 5bcaaa553fc..8044770a9b4 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsCLIOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/MetricsCLIOptionsTest.java @@ -25,24 +25,25 @@ public class MetricsCLIOptionsTest extends AbstractCLIOptionsTest { @Override - MetricsConfiguration.Builder createDefaultDomainObject() { + protected MetricsConfiguration.Builder createDefaultDomainObject() { return MetricsConfiguration.builder(); } @Override - MetricsConfiguration.Builder createCustomizedDomainObject() { + protected MetricsConfiguration.Builder createCustomizedDomainObject() { return MetricsConfiguration.builder() .timersEnabled(!MetricsConfiguration.DEFAULT_METRICS_TIMERS_ENABLED) .idleTimeout(MetricsConfiguration.DEFAULT_METRICS_IDLE_TIMEOUT_SECONDS); } @Override - MetricsCLIOptions optionsFromDomainObject(final MetricsConfiguration.Builder domainObject) { + protected MetricsCLIOptions optionsFromDomainObject( + final MetricsConfiguration.Builder domainObject) { return MetricsCLIOptions.fromConfiguration(domainObject.build()); } @Override - MetricsCLIOptions getOptionsFromBesuCommand(final TestBesuCommand besuCommand) { + protected MetricsCLIOptions getOptionsFromBesuCommand(final TestBesuCommand besuCommand) { return besuCommand.getMetricsCLIOptions(); } } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java index c59747dac73..a2cbdc5942b 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java @@ -165,12 +165,12 @@ public void checkFilterByForkIdSetToFalse() { } @Override - NetworkingConfiguration createDefaultDomainObject() { + protected NetworkingConfiguration createDefaultDomainObject() { return NetworkingConfiguration.create(); } @Override - NetworkingConfiguration createCustomizedDomainObject() { + protected NetworkingConfiguration createCustomizedDomainObject() { final NetworkingConfiguration config = NetworkingConfiguration.create(); config.setInitiateConnectionsFrequency( NetworkingConfiguration.DEFAULT_INITIATE_CONNECTIONS_FREQUENCY_SEC + 10); @@ -181,12 +181,12 @@ NetworkingConfiguration createCustomizedDomainObject() { } @Override - NetworkingOptions optionsFromDomainObject(final NetworkingConfiguration domainObject) { + protected NetworkingOptions optionsFromDomainObject(final NetworkingConfiguration domainObject) { return NetworkingOptions.fromConfig(domainObject); } @Override - NetworkingOptions getOptionsFromBesuCommand(final TestBesuCommand besuCommand) { + protected NetworkingOptions getOptionsFromBesuCommand(final TestBesuCommand besuCommand) { return besuCommand.getNetworkingOptions(); } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/SynchronizerOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/SynchronizerOptionsTest.java index affb5a9d4d3..0e814a07e26 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/SynchronizerOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/SynchronizerOptionsTest.java @@ -31,12 +31,12 @@ public class SynchronizerOptionsTest extends AbstractCLIOptionsTest { @Override - SynchronizerConfiguration.Builder createDefaultDomainObject() { + protected SynchronizerConfiguration.Builder createDefaultDomainObject() { return SynchronizerConfiguration.builder(); } @Override - SynchronizerConfiguration.Builder createCustomizedDomainObject() { + protected SynchronizerConfiguration.Builder createCustomizedDomainObject() { return SynchronizerConfiguration.builder() .fastSyncPivotDistance(SynchronizerConfiguration.DEFAULT_PIVOT_DISTANCE_FROM_HEAD + 10) .fastSyncFullValidationRate(SynchronizerConfiguration.DEFAULT_FULL_VALIDATION_RATE / 2) @@ -87,7 +87,7 @@ protected List getFieldsWithComputedDefaults() { } @Override - SynchronizerOptions getOptionsFromBesuCommand(final TestBesuCommand besuCommand) { + protected SynchronizerOptions getOptionsFromBesuCommand(final TestBesuCommand besuCommand) { return besuCommand.getSynchronizerOptions(); } @@ -97,7 +97,7 @@ protected List getFieldsToIgnore() { } @Override - SynchronizerOptions optionsFromDomainObject( + protected SynchronizerOptions optionsFromDomainObject( final SynchronizerConfiguration.Builder domainObject) { return SynchronizerOptions.fromConfig(domainObject.build()); } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/stable/TransactionPoolOptionsTest.java similarity index 59% rename from besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java rename to besu/src/test/java/org/hyperledger/besu/cli/options/stable/TransactionPoolOptionsTest.java index 992e3737e51..e1f4f2e4596 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/TransactionPoolOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/stable/TransactionPoolOptionsTest.java @@ -12,33 +12,30 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.options; +package org.hyperledger.besu.cli.options.stable; import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.LAYERED; -import org.hyperledger.besu.cli.options.unstable.TransactionPoolOptions; +import org.hyperledger.besu.cli.options.AbstractCLIOptionsTest; import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; -import java.time.Duration; - import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class TransactionPoolOptionsTest - extends AbstractCLIOptionsTest< - ImmutableTransactionPoolConfiguration.Builder, TransactionPoolOptions> { + extends AbstractCLIOptionsTest { @Test public void strictTxReplayProtection_enabled() { final TestBesuCommand cmd = parseCommand("--strict-tx-replay-protection-enabled"); final TransactionPoolOptions options = getOptionsFromBesuCommand(cmd); - final TransactionPoolConfiguration config = options.toDomainObject().build(); + final TransactionPoolConfiguration config = options.toDomainObject(); assertThat(config.getStrictTransactionReplayProtectionEnabled()).isTrue(); assertThat(commandOutput.toString(UTF_8)).isEmpty(); @@ -50,7 +47,7 @@ public void strictTxReplayProtection_enabledWithBooleanArg() { final TestBesuCommand cmd = parseCommand("--strict-tx-replay-protection-enabled=true"); final TransactionPoolOptions options = getOptionsFromBesuCommand(cmd); - final TransactionPoolConfiguration config = options.toDomainObject().build(); + final TransactionPoolConfiguration config = options.toDomainObject(); assertThat(config.getStrictTransactionReplayProtectionEnabled()).isTrue(); assertThat(commandOutput.toString(UTF_8)).isEmpty(); @@ -62,7 +59,7 @@ public void strictTxReplayProtection_disabled() { final TestBesuCommand cmd = parseCommand("--strict-tx-replay-protection-enabled=false"); final TransactionPoolOptions options = getOptionsFromBesuCommand(cmd); - final TransactionPoolConfiguration config = options.toDomainObject().build(); + final TransactionPoolConfiguration config = options.toDomainObject(); assertThat(config.getStrictTransactionReplayProtectionEnabled()).isFalse(); assertThat(commandOutput.toString(UTF_8)).isEmpty(); @@ -74,83 +71,47 @@ public void strictTxReplayProtection_default() { final TestBesuCommand cmd = parseCommand(); final TransactionPoolOptions options = getOptionsFromBesuCommand(cmd); - final TransactionPoolConfiguration config = options.toDomainObject().build(); + final TransactionPoolConfiguration config = options.toDomainObject(); assertThat(config.getStrictTransactionReplayProtectionEnabled()).isFalse(); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); } - @Test - public void txMessageKeepAliveSeconds() { - final int txMessageKeepAliveSeconds = 999; - final TestBesuCommand cmd = - parseCommand( - "--Xincoming-tx-messages-keep-alive-seconds", - String.valueOf(txMessageKeepAliveSeconds)); - - final TransactionPoolOptions options = getOptionsFromBesuCommand(cmd); - final TransactionPoolConfiguration config = options.toDomainObject().build(); - assertThat(config.getTxMessageKeepAliveSeconds()).isEqualTo(txMessageKeepAliveSeconds); - - assertThat(commandOutput.toString(UTF_8)).isEmpty(); - assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); - } - - @Test - public void eth65TrxAnnouncedBufferingPeriod() { - final long eth65TrxAnnouncedBufferingPeriod = 999; - final TestBesuCommand cmd = - parseCommand( - "--Xeth65-tx-announced-buffering-period-milliseconds", - String.valueOf(eth65TrxAnnouncedBufferingPeriod)); - - final TransactionPoolOptions options = getOptionsFromBesuCommand(cmd); - final TransactionPoolConfiguration config = options.toDomainObject().build(); - assertThat(config.getEth65TrxAnnouncedBufferingPeriod()) - .hasMillis(eth65TrxAnnouncedBufferingPeriod); - - assertThat(commandOutput.toString(UTF_8)).isEmpty(); - assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); - } - @Override - ImmutableTransactionPoolConfiguration.Builder createDefaultDomainObject() { + protected TransactionPoolConfiguration createDefaultDomainObject() { final ImmutableTransactionPoolConfiguration defaultValue = ImmutableTransactionPoolConfiguration.builder().build(); return ImmutableTransactionPoolConfiguration.builder() + .from(defaultValue) .strictTransactionReplayProtectionEnabled(false) - .txMessageKeepAliveSeconds(defaultValue.getTxMessageKeepAliveSeconds()) - .eth65TrxAnnouncedBufferingPeriod(defaultValue.getEth65TrxAnnouncedBufferingPeriod()) .txPoolImplementation(defaultValue.getTxPoolImplementation()) .pendingTransactionsLayerMaxCapacityBytes( defaultValue.getPendingTransactionsLayerMaxCapacityBytes()) .maxPrioritizedTransactions(defaultValue.getMaxPrioritizedTransactions()) - .maxFutureBySender(defaultValue.getMaxFutureBySender()); + .maxFutureBySender(defaultValue.getMaxFutureBySender()) + .build(); } @Override - ImmutableTransactionPoolConfiguration.Builder createCustomizedDomainObject() { + protected TransactionPoolConfiguration createCustomizedDomainObject() { return ImmutableTransactionPoolConfiguration.builder() .strictTransactionReplayProtectionEnabled(true) - .txMessageKeepAliveSeconds(TransactionPoolConfiguration.DEFAULT_TX_MSG_KEEP_ALIVE + 1) - .eth65TrxAnnouncedBufferingPeriod( - TransactionPoolConfiguration.ETH65_TRX_ANNOUNCED_BUFFERING_PERIOD.plus( - Duration.ofMillis(100))) .txPoolImplementation(LAYERED) .pendingTransactionsLayerMaxCapacityBytes(1_000_000L) .maxPrioritizedTransactions(1000) - .maxFutureBySender(10); + .maxFutureBySender(10) + .build(); } @Override - TransactionPoolOptions optionsFromDomainObject( - final ImmutableTransactionPoolConfiguration.Builder domainObject) { - return TransactionPoolOptions.fromConfig(domainObject.build()); + protected TransactionPoolOptions optionsFromDomainObject( + final TransactionPoolConfiguration domainObject) { + return TransactionPoolOptions.fromConfig(domainObject); } @Override - TransactionPoolOptions getOptionsFromBesuCommand(final TestBesuCommand besuCommand) { - return besuCommand.getTransactionPoolOptions(); + protected TransactionPoolOptions getOptionsFromBesuCommand(final TestBesuCommand besuCommand) { + return besuCommand.getStableTransactionPoolOptions(); } } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/unstable/TransactionPoolOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/unstable/TransactionPoolOptionsTest.java new file mode 100644 index 00000000000..1862bed0ec8 --- /dev/null +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/unstable/TransactionPoolOptionsTest.java @@ -0,0 +1,98 @@ +/* + * Copyright ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.cli.options.unstable; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.cli.options.AbstractCLIOptionsTest; +import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; +import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; + +import java.time.Duration; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.junit.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class TransactionPoolOptionsTest + extends AbstractCLIOptionsTest { + + @Test + public void txMessageKeepAliveSeconds() { + final int txMessageKeepAliveSeconds = 999; + final TestBesuCommand cmd = + parseCommand( + "--Xincoming-tx-messages-keep-alive-seconds", + String.valueOf(txMessageKeepAliveSeconds)); + + final TransactionPoolOptions options = getOptionsFromBesuCommand(cmd); + final TransactionPoolConfiguration config = options.toDomainObject(); + assertThat(config.getTxMessageKeepAliveSeconds()).isEqualTo(txMessageKeepAliveSeconds); + + assertThat(commandOutput.toString(UTF_8)).isEmpty(); + assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); + } + + @Test + public void eth65TrxAnnouncedBufferingPeriod() { + final long eth65TrxAnnouncedBufferingPeriod = 999; + final TestBesuCommand cmd = + parseCommand( + "--Xeth65-tx-announced-buffering-period-milliseconds", + String.valueOf(eth65TrxAnnouncedBufferingPeriod)); + + final TransactionPoolOptions options = getOptionsFromBesuCommand(cmd); + final TransactionPoolConfiguration config = options.toDomainObject(); + assertThat(config.getEth65TrxAnnouncedBufferingPeriod()) + .hasMillis(eth65TrxAnnouncedBufferingPeriod); + + assertThat(commandOutput.toString(UTF_8)).isEmpty(); + assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); + } + + @Override + protected TransactionPoolConfiguration createDefaultDomainObject() { + final ImmutableTransactionPoolConfiguration defaultValue = + ImmutableTransactionPoolConfiguration.builder().build(); + return ImmutableTransactionPoolConfiguration.builder() + .from(defaultValue) + .txMessageKeepAliveSeconds(defaultValue.getTxMessageKeepAliveSeconds()) + .eth65TrxAnnouncedBufferingPeriod(defaultValue.getEth65TrxAnnouncedBufferingPeriod()) + .build(); + } + + @Override + protected TransactionPoolConfiguration createCustomizedDomainObject() { + return ImmutableTransactionPoolConfiguration.builder() + .txMessageKeepAliveSeconds(TransactionPoolConfiguration.DEFAULT_TX_MSG_KEEP_ALIVE + 1) + .eth65TrxAnnouncedBufferingPeriod( + TransactionPoolConfiguration.ETH65_TRX_ANNOUNCED_BUFFERING_PERIOD.plus( + Duration.ofMillis(100))) + .build(); + } + + @Override + protected TransactionPoolOptions optionsFromDomainObject( + final TransactionPoolConfiguration domainObject) { + return TransactionPoolOptions.fromConfig(domainObject); + } + + @Override + protected TransactionPoolOptions getOptionsFromBesuCommand(final TestBesuCommand besuCommand) { + return besuCommand.getUnstableTransactionPoolOptions(); + } +} From ee7712cbc6647d29be5e4b5dce1fe636d1f4f55d Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Thu, 17 Aug 2023 20:00:38 +0200 Subject: [PATCH 3/9] Re-organize stable and unstable txpool options Signed-off-by: Fabio Di Fabio --- besu/src/test/resources/everything_config.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/besu/src/test/resources/everything_config.toml b/besu/src/test/resources/everything_config.toml index 459346dc537..f0d199cee5f 100644 --- a/besu/src/test/resources/everything_config.toml +++ b/besu/src/test/resources/everything_config.toml @@ -170,6 +170,7 @@ privacy-onchain-groups-enabled=false privacy-flexible-groups-enabled=false # Transaction Pool +tx-pool="layered" tx-pool-retention-hours=999 tx-pool-price-bump=13 tx-pool-max-size=1234 From 43dc0fa40a0fff32544a6eab151bafaf63ef5e78 Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Fri, 18 Aug 2023 15:09:13 +0200 Subject: [PATCH 4/9] More refactoring of txpool options Signed-off-by: Fabio Di Fabio --- .../org/hyperledger/besu/cli/BesuCommand.java | 106 +----------------- .../besu/cli/converter/FractionConverter.java | 6 +- .../cli/converter/PercentageConverter.java | 6 +- .../besu/cli/options/OptionParser.java | 12 ++ .../stable/TransactionPoolOptions.java | 92 +++++++++------ .../unstable/TransactionPoolOptions.java | 13 ++- .../hyperledger/besu/cli/BesuCommandTest.java | 5 +- .../cli/converter/FractionConverterTest.java | 5 +- .../converter/PercentageConverterTest.java | 5 +- .../unstable/TransactionPoolOptionsTest.java | 25 +++-- .../blockcreation/MergeCoordinatorTest.java | 3 +- ...FeeMarketBlockTransactionSelectorTest.java | 3 +- ...FeeMarketBlockTransactionSelectorTest.java | 3 +- ...oledTransactionHashesMessageProcessor.java | 8 +- .../TransactionPoolConfiguration.java | 46 +++++--- .../transactions/TransactionPoolFactory.java | 4 +- ...TransactionHashesMessageProcessorTest.java | 8 +- .../TransactionPoolFactoryTest.java | 53 +++++++-- .../TransactionPoolLegacyTest.java | 3 +- .../TransactionPoolLondonTest.java | 3 +- .../AbstractPendingTransactionsTestBase.java | 12 +- .../ethereum/retesteth/RetestethContext.java | 3 +- 22 files changed, 219 insertions(+), 205 deletions(-) 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 91305a62402..bc5cadc2a60 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -194,6 +194,7 @@ import org.hyperledger.besu.util.NetworkUtility; import org.hyperledger.besu.util.PermissioningConfigurationValidator; import org.hyperledger.besu.util.number.Fraction; +import org.hyperledger.besu.util.number.Percentage; import org.hyperledger.besu.util.number.PositiveNumber; import java.io.File; @@ -459,10 +460,8 @@ static class P2PDiscoveryOptionGroup { "The maximum percentage of P2P connections that can be initiated remotely. Must be between 0 and 100 inclusive. (default: ${DEFAULT-VALUE})", arity = "1", converter = PercentageConverter.class) - private final Integer maxRemoteConnectionsPercentage = - Fraction.fromFloat(DEFAULT_FRACTION_REMOTE_WIRE_CONNECTIONS_ALLOWED) - .toPercentage() - .getValue(); + private final Percentage maxRemoteConnectionsPercentage = + Fraction.fromFloat(DEFAULT_FRACTION_REMOTE_WIRE_CONNECTIONS_ALLOWED).toPercentage(); @SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings. @CommandLine.Option( @@ -1116,14 +1115,6 @@ static class MinerOptionGroup { arity = "1") private final Wei minTransactionGasPrice = DEFAULT_MIN_TRANSACTION_GAS_PRICE; - // @Option( - // names = {"--rpc-tx-feecap"}, - // description = - // "Maximum transaction fees (in Wei) accepted for transaction submitted through RPC - // (default: ${DEFAULT-VALUE})", - // arity = "1") - // private final Wei txFeeCap = DEFAULT_RPC_TX_FEE_CAP; - @Option( names = {"--min-block-occupancy-ratio"}, description = "Minimum occupancy ratio for a mined block (default: ${DEFAULT-VALUE})", @@ -1215,84 +1206,6 @@ static class PermissionsOptionGroup { "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; - // Tx Pool Option Group - // @CommandLine.ArgGroup(validate = false, heading = "@|bold Tx Pool Options|@%n") - // TxPoolOptionGroup txPoolOptionGroup = new TxPoolOptionGroup(); - - // static class TxPoolOptionGroup { - // @CommandLine.Option( - // names = {"--tx-pool-disable-locals"}, - // paramLabel = "", - // description = - // "Set to true if transactions sent via RPC should have the same checks and not be - // prioritized over remote ones (default: ${DEFAULT-VALUE})", - // fallbackValue = "true", - // arity = "0..1") - // private Boolean disableLocalTxs = TransactionPoolConfiguration.DEFAULT_DISABLE_LOCAL_TXS; - // - // @CommandLine.Option( - // names = {"--tx-pool-enable-save-restore"}, - // paramLabel = "", - // description = - // "Set to true to enable saving the txpool content to file on shutdown and reloading - // it on startup (default: ${DEFAULT-VALUE})", - // fallbackValue = "true", - // arity = "0..1") - // private Boolean saveRestoreEnabled = - // TransactionPoolConfiguration.DEFAULT_ENABLE_SAVE_RESTORE; - // - // @CommandLine.Option( - // names = {"--tx-pool-limit-by-account-percentage"}, - // paramLabel = "", - // converter = FractionConverter.class, - // description = - // "Maximum portion of the transaction pool which a single account may occupy with - // future transactions (default: ${DEFAULT-VALUE})", - // arity = "1") - // private Float txPoolLimitByAccountPercentage = - // TransactionPoolConfiguration.DEFAULT_LIMIT_TX_POOL_BY_ACCOUNT_PERCENTAGE; - // - // @CommandLine.Option( - // names = {"--tx-pool-save-file"}, - // paramLabel = "", - // description = - // "If saving the txpool content is enabled, define a custom path for the save file - // (default: ${DEFAULT-VALUE} in the data-dir)", - // arity = "1") - // private File saveFile = TransactionPoolConfiguration.DEFAULT_SAVE_FILE; - // - // @Option( - // names = {"--tx-pool-max-size"}, - // paramLabel = MANDATORY_INTEGER_FORMAT_HELP, - // description = - // "Maximum number of pending transactions that will be kept in the transaction pool - // (default: ${DEFAULT-VALUE})", - // arity = "1") - // private final Integer txPoolMaxSize = - // TransactionPoolConfiguration.DEFAULT_MAX_PENDING_TRANSACTIONS; - // - // @Option( - // names = {"--tx-pool-retention-hours"}, - // paramLabel = MANDATORY_INTEGER_FORMAT_HELP, - // description = - // "Maximum retention period of pending transactions in hours (default: - // ${DEFAULT-VALUE})", - // arity = "1") - // private final Integer pendingTxRetentionPeriod = - // TransactionPoolConfiguration.DEFAULT_TX_RETENTION_HOURS; - // - // @Option( - // names = {"--tx-pool-price-bump"}, - // paramLabel = MANDATORY_INTEGER_FORMAT_HELP, - // converter = PercentageConverter.class, - // description = - // "Price bump percentage to replace an already existing transaction (default: - // ${DEFAULT-VALUE})", - // arity = "1") - // private final Integer priceBump = - // TransactionPoolConfiguration.DEFAULT_PRICE_BUMP.getValue(); - // } - @SuppressWarnings({"FieldCanBeFinal", "FieldMayBeFinal"}) // PicoCLI requires non-final Strings. @Option( names = {"--key-value-storage"}, @@ -3004,19 +2917,10 @@ private SynchronizerConfiguration buildSyncConfig() { private TransactionPoolConfiguration buildTransactionPoolConfiguration() { final var stableTxPoolOption = stableTransactionPoolOptions.toDomainObject(); return ImmutableTransactionPoolConfiguration.builder() - .from(unstableTransactionPoolOptions.toDomainObject()) .from(stableTxPoolOption) - .saveFile(dataPath.resolve(stableTxPoolOption.getSaveFile().getPath()).toFile()) + .unstable(unstableTransactionPoolOptions.toDomainObject()) + .saveFile((dataPath.resolve(stableTxPoolOption.getSaveFile().getPath()).toFile())) .build(); - // .enableSaveRestore(txPoolOptionGroup.saveRestoreEnabled) - // .disableLocalTransactions(txPoolOptionGroup.disableLocalTxs) - // .txPoolLimitByAccountPercentage(txPoolOptionGroup.txPoolLimitByAccountPercentage) - // .txPoolMaxSize(txPoolOptionGroup.txPoolMaxSize) - // .pendingTxRetentionPeriod(txPoolOptionGroup.pendingTxRetentionPeriod) - // .priceBump(Percentage.fromInt(txPoolOptionGroup.priceBump)) - // .txFeeCap(txFeeCap) - // .saveFile(dataPath.resolve(txPoolOptionGroup.saveFile.getPath()).toFile()) - // .build(); } private boolean isPruningEnabled() { diff --git a/besu/src/main/java/org/hyperledger/besu/cli/converter/FractionConverter.java b/besu/src/main/java/org/hyperledger/besu/cli/converter/FractionConverter.java index 969a6be8e9e..64edf7cd9ce 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/converter/FractionConverter.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/converter/FractionConverter.java @@ -20,12 +20,12 @@ import picocli.CommandLine; /** The Fraction converter to convert floats in CLI. */ -public class FractionConverter implements CommandLine.ITypeConverter { +public class FractionConverter implements CommandLine.ITypeConverter { @Override - public Float convert(final String value) throws FractionConversionException { + public Fraction convert(final String value) throws FractionConversionException { try { - return Fraction.fromString(value).getValue(); + return Fraction.fromString(value); } catch (final NullPointerException | IllegalArgumentException e) { throw new FractionConversionException(value); } diff --git a/besu/src/main/java/org/hyperledger/besu/cli/converter/PercentageConverter.java b/besu/src/main/java/org/hyperledger/besu/cli/converter/PercentageConverter.java index 23a2d94d33d..410ec83a21d 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/converter/PercentageConverter.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/converter/PercentageConverter.java @@ -20,12 +20,12 @@ import picocli.CommandLine; /** The Percentage Cli type converter. */ -public class PercentageConverter implements CommandLine.ITypeConverter { +public class PercentageConverter implements CommandLine.ITypeConverter { @Override - public Integer convert(final String value) throws PercentageConversionException { + public Percentage convert(final String value) throws PercentageConversionException { try { - return Percentage.fromString(value).getValue(); + return Percentage.fromString(value); } catch (NullPointerException | IllegalArgumentException e) { throw new PercentageConversionException(value); } diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/OptionParser.java b/besu/src/main/java/org/hyperledger/besu/cli/options/OptionParser.java index 73161742f90..2daafe06a68 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/OptionParser.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/OptionParser.java @@ -16,6 +16,8 @@ import static com.google.common.base.Preconditions.checkArgument; +import org.hyperledger.besu.datatypes.Wei; + import java.util.Iterator; import com.google.common.base.Splitter; @@ -96,4 +98,14 @@ public static String format(final float value) { public static String format(final UInt256 value) { return value.toBigInteger().toString(10); } + + /** + * Format Wei to string. + * + * @param value the value + * @return the string + */ + public static String format(final Wei value) { + return format(value.toUInt256()); + } } 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/stable/TransactionPoolOptions.java index e28d2ffe4b4..1ca094e499c 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/stable/TransactionPoolOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/stable/TransactionPoolOptions.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; +import org.hyperledger.besu.util.number.Fraction; import org.hyperledger.besu.util.number.Percentage; import java.io.File; @@ -39,8 +40,18 @@ public class TransactionPoolOptions implements CLIOptions { private static final Logger LOG = LoggerFactory.getLogger(TransactionPoolOptions.class); private static final String TX_POOL_IMPLEMENTATION = "--tx-pool"; + private static final String TX_POOL_DISABLE_LOCALS = "--tx-pool-disable-locals"; + private static final String TX_POOL_ENABLE_SAVE_RESTORE = "--tx-pool-enable-save-restore"; + private static final String TX_POOL_SAVE_FILE = "--tx-pool-save-file"; + private static final String TX_POOL_LIMIT_BY_ACCOUNT_PERCENTAGE = + "--tx-pool-limit-by-account-percentage"; + private static final String TX_POOL_MAX_SIZE = "--tx-pool-max-size"; + private static final String TX_POOL_RETENTION_HOURS = "--tx-pool-retention-hours"; + private static final String TX_POOL_PRICE_BUMP = "--tx-pool-price-bump"; + private static final String RPC_TX_FEECAP = "--rpc-tx-feecap"; private static final String STRICT_TX_REPLAY_PROTECTION_ENABLED_FLAG = "--strict-tx-replay-protection-enabled"; + private static final String LAYERED_TX_POOL_LAYER_MAX_CAPACITY = "--layered-tx-pool-layer-max-capacity"; private static final String LAYERED_TX_POOL_MAX_PRIORITIZED = "--layered-tx-pool-max-prioritized"; @@ -48,7 +59,14 @@ public class TransactionPoolOptions implements CLIOptions