From b399ad3e2c86d0f55e4e8435dff045e02840c15b Mon Sep 17 00:00:00 2001 From: Matt Whitehead Date: Tue, 12 Dec 2023 17:43:17 +0000 Subject: [PATCH] Sequenced pool synonym for legacy pool (#6274) * Sequenced pool synonym for legacy pool Signed-off-by: Matthew Whitehead * Class rename Signed-off-by: Matthew Whitehead * Spotless fixes Signed-off-by: Matthew Whitehead * Add SEQUENCED to config overview test Signed-off-by: Matthew Whitehead * Update CHANGELOG.md Co-authored-by: Sally MacFarlane Signed-off-by: Matt Whitehead * add a fix to load correctly the storage trie in the Bonsai WorldState (#6205) revert some modification that was made to pass tests #5686 and fix this tests by loading the storage with EMPTY_TRIE_HASH if we detect that it has been cleared before pushing the new slots after recreation. --------- Signed-off-by: Karim TAAM --------- Signed-off-by: Matthew Whitehead Signed-off-by: Matt Whitehead Signed-off-by: Karim TAAM Co-authored-by: Sally MacFarlane Co-authored-by: matkt --- CHANGELOG.md | 1 + .../cli/options/TransactionPoolOptions.java | 27 +++++++------- .../cli/ConfigurationOverviewBuilderTest.java | 8 +++++ .../options/TransactionPoolOptionsTest.java | 35 ++++++++++++++++--- .../src/test/resources/everything_config.toml | 2 +- .../TransactionPoolConfiguration.java | 5 +-- 6 files changed, 58 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 927fbf2f90d..f0d66a9cf07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Additions and Improvements - Add error messages on authentication failures with username and password [#6212](https://github.com/hyperledger/besu/pull/6212) +- New `Sequenced` transaction pool. The pool is an evolution of the `legacy` pool and is likely to be more suitable to enterprise or permissioned chains than the `layered` transaction pool. Select to use this pool with `--tx-pool=sequenced`. Supports the same options as the `legacy` pool [#6211](https://github.com/hyperledger/besu/issues/6211) ### Bug fixes diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java index 3b34c4d2a61..0b6718387b1 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/TransactionPoolOptions.java @@ -19,6 +19,7 @@ import static org.hyperledger.besu.cli.DefaultCommandValues.MANDATORY_LONG_FORMAT_HELP; 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.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.SEQUENCED; import org.hyperledger.besu.cli.converter.DurationMillisConverter; import org.hyperledger.besu.cli.converter.FractionConverter; @@ -171,10 +172,10 @@ static class Layered { @CommandLine.ArgGroup( validate = false, - heading = "@|bold Tx Pool Legacy Implementation Options|@%n") - private final Legacy legacyOptions = new Legacy(); + heading = "@|bold Tx Pool Sequenced Implementation Options|@%n") + private final Sequenced sequencedOptions = new Sequenced(); - static class Legacy { + static class Sequenced { private static final String TX_POOL_RETENTION_HOURS = "--tx-pool-retention-hours"; private static final String TX_POOL_LIMIT_BY_ACCOUNT_PERCENTAGE = "--tx-pool-limit-by-account-percentage"; @@ -272,10 +273,10 @@ public static TransactionPoolOptions fromConfig(final TransactionPoolConfigurati config.getPendingTransactionsLayerMaxCapacityBytes(); options.layeredOptions.txPoolMaxPrioritized = config.getMaxPrioritizedTransactions(); options.layeredOptions.txPoolMaxFutureBySender = config.getMaxFutureBySender(); - options.legacyOptions.txPoolLimitByAccountPercentage = + options.sequencedOptions.txPoolLimitByAccountPercentage = config.getTxPoolLimitByAccountPercentage(); - options.legacyOptions.txPoolMaxSize = config.getTxPoolMaxSize(); - options.legacyOptions.pendingTxRetentionPeriod = config.getPendingTxRetentionPeriod(); + options.sequencedOptions.txPoolMaxSize = config.getTxPoolMaxSize(); + options.sequencedOptions.pendingTxRetentionPeriod = config.getPendingTxRetentionPeriod(); options.unstableOptions.txMessageKeepAliveSeconds = config.getUnstable().getTxMessageKeepAliveSeconds(); options.unstableOptions.eth65TrxAnnouncedBufferingPeriod = @@ -295,14 +296,14 @@ public void validate( final CommandLine commandLine, final GenesisConfigOptions genesisConfigOptions) { CommandLineUtils.failIfOptionDoesntMeetRequirement( commandLine, - "Could not use legacy transaction pool options with layered implementation", + "Could not use legacy or sequenced transaction pool options with layered implementation", !txPoolImplementation.equals(LAYERED), - CommandLineUtils.getCLIOptionNames(Legacy.class)); + CommandLineUtils.getCLIOptionNames(Sequenced.class)); CommandLineUtils.failIfOptionDoesntMeetRequirement( commandLine, - "Could not use layered transaction pool options with legacy implementation", - !txPoolImplementation.equals(LEGACY), + "Could not use layered transaction pool options with legacy or sequenced implementation", + !txPoolImplementation.equals(LEGACY) && !txPoolImplementation.equals(SEQUENCED), CommandLineUtils.getCLIOptionNames(Layered.class)); CommandLineUtils.failIfOptionDoesntMeetRequirement( @@ -327,9 +328,9 @@ public TransactionPoolConfiguration toDomainObject() { .pendingTransactionsLayerMaxCapacityBytes(layeredOptions.txPoolLayerMaxCapacity) .maxPrioritizedTransactions(layeredOptions.txPoolMaxPrioritized) .maxFutureBySender(layeredOptions.txPoolMaxFutureBySender) - .txPoolLimitByAccountPercentage(legacyOptions.txPoolLimitByAccountPercentage) - .txPoolMaxSize(legacyOptions.txPoolMaxSize) - .pendingTxRetentionPeriod(legacyOptions.pendingTxRetentionPeriod) + .txPoolLimitByAccountPercentage(sequencedOptions.txPoolLimitByAccountPercentage) + .txPoolMaxSize(sequencedOptions.txPoolMaxSize) + .pendingTxRetentionPeriod(sequencedOptions.pendingTxRetentionPeriod) .unstable( ImmutableTransactionPoolConfiguration.Unstable.builder() .txMessageKeepAliveSeconds(unstableOptions.txMessageKeepAliveSeconds) 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 44718e96c67..ae00587c04d 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/ConfigurationOverviewBuilderTest.java @@ -17,6 +17,7 @@ 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.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.SEQUENCED; import static org.mockito.Mockito.mock; import org.hyperledger.besu.evm.internal.EvmConfiguration; @@ -180,6 +181,13 @@ void setTxPoolImplementationLegacy() { assertThat(legacyTxPoolSelected).contains("Using LEGACY transaction pool implementation"); } + @Test + void setTxPoolImplementationSequenced() { + builder.setTxPoolImplementation(SEQUENCED); + final String sequencedTxPoolSelected = builder.build(); + assertThat(sequencedTxPoolSelected).contains("Using SEQUENCED transaction pool implementation"); + } + @Test void setWorldStateUpdateModeDefault() { builder.setWorldStateUpdateMode(EvmConfiguration.DEFAULT.worldUpdaterMode()); 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 5b5fff5014e..d7031eb9a4f 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 @@ -17,6 +17,7 @@ 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.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.Implementation.SEQUENCED; import org.hyperledger.besu.cli.converter.DurationMillisConverter; import org.hyperledger.besu.datatypes.Address; @@ -63,7 +64,7 @@ public void strictTxReplayProtection_default() { } @Test - public void pendingTransactionRetentionPeriod() { + public void pendingTransactionRetentionPeriodLegacy() { final int pendingTxRetentionHours = 999; internalTestSuccess( config -> @@ -73,6 +74,17 @@ public void pendingTransactionRetentionPeriod() { "--tx-pool=legacy"); } + @Test + public void pendingTransactionRetentionPeriodSequenced() { + final int pendingTxRetentionHours = 999; + internalTestSuccess( + config -> + assertThat(config.getPendingTxRetentionPeriod()).isEqualTo(pendingTxRetentionHours), + "--tx-pool-retention-hours", + String.valueOf(pendingTxRetentionHours), + "--tx-pool=sequenced"); + } + @Test public void disableLocalsDefault() { internalTestSuccess(config -> assertThat(config.getNoLocalPriority()).isFalse()); @@ -193,17 +205,24 @@ public void selectLegacyImplementationByArg() { "--tx-pool=legacy"); } + @Test + public void selectSequencedImplementationByArg() { + internalTestSuccess( + config -> assertThat(config.getTxPoolImplementation()).isEqualTo(SEQUENCED), + "--tx-pool=sequenced"); + } + @Test public void failIfLegacyOptionsWhenLayeredSelectedByDefault() { internalTestFailure( - "Could not use legacy transaction pool options with layered implementation", + "Could not use legacy or sequenced transaction pool options with layered implementation", "--tx-pool-max-size=1000"); } @Test public void failIfLegacyOptionsWhenLayeredSelectedByArg() { internalTestFailure( - "Could not use legacy transaction pool options with layered implementation", + "Could not use legacy or sequenced transaction pool options with layered implementation", "--tx-pool=layered", "--tx-pool-max-size=1000"); } @@ -211,11 +230,19 @@ public void failIfLegacyOptionsWhenLayeredSelectedByArg() { @Test public void failIfLayeredOptionsWhenLegacySelectedByArg() { internalTestFailure( - "Could not use layered transaction pool options with legacy implementation", + "Could not use layered transaction pool options with legacy or sequenced implementation", "--tx-pool=legacy", "--tx-pool-max-prioritized=1000"); } + @Test + public void failIfLayeredOptionsWhenSequencedSelectedByArg() { + internalTestFailure( + "Could not use layered transaction pool options with legacy or sequenced implementation", + "--tx-pool=sequenced", + "--tx-pool-max-prioritized=1000"); + } + @Test public void byDefaultNoPrioritySenders() { internalTestSuccess(config -> assertThat(config.getPrioritySenders()).isEmpty()); diff --git a/besu/src/test/resources/everything_config.toml b/besu/src/test/resources/everything_config.toml index be337272e97..e516060da86 100644 --- a/besu/src/test/resources/everything_config.toml +++ b/besu/src/test/resources/everything_config.toml @@ -185,7 +185,7 @@ tx-pool-save-file="txpool.dump" tx-pool-layer-max-capacity=12345678 tx-pool-max-prioritized=9876 tx-pool-max-future-by-sender=321 -## Legacy +## Legacy/Sequenced tx-pool-retention-hours=999 tx-pool-max-size=1234 tx-pool-limit-by-account-percentage=0.017 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 e30d24c158f..f6ef30667e6 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 @@ -50,8 +50,9 @@ default int getTxMessageKeepAliveSeconds() { } enum Implementation { - LEGACY, - LAYERED; + LEGACY, // Remove in future version + LAYERED, + SEQUENCED; // Synonym for LEGACY } String DEFAULT_SAVE_FILE_NAME = "txpool.dump";