Skip to content

Commit

Permalink
Layered Transaction Pool (hyperledger#5290)
Browse files Browse the repository at this point in the history
* Introduce experimental layered transaction pool

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* new Xlayered-tx-pool flag to enabled the new tx pool

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Move pending transaction sorter tests in the sorter folder

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Unit tests for new and old transaction pool

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix: do not decrease size when promoting ready txs

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix: remove tx from orderByFee when replaced

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix: decrease size when removing confirmed txs

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix: always recreate orderByFee for London fee market

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix: transaction removal counter when txs added to block

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix: update expected nonce when demoting a prioritized transaction

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix: correctly remove expected nonce entry when removing the last prioritized transaction for the sender
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix NullPointerException when the replaced tx is not prioritized

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Replace postponed with spare transactions

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* WIP

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* WIP

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix merge from main

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fixed most tests

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix more tests

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Rename and reorg some classes

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* More renaming and code clean up

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Refactor transaction pool metrics

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Stats log refined

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Cleanup unit tests

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Improve stats log

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Remove unnecessary test parameters

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix unit test

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

# Conflicts:
#	ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java
#	ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java

* Cancel older block creation tasks upon receiving a new one

Signed-off-by: Simon Dudley <simon.dudley@consensys.net>

* Fixes to expected next nonce for sender

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix promotion filter and use synchronized methods instead of blocks

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix metrics concurrent access issue

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fixes

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Configuration options for the layered txpool

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Use long instead of Instant for PendingTransaction add time

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fixes

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Move layered txpool clasess in a dedicated package

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fixes

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* WIP

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Remove confirmed transaction from sparse set too

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* WIP

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* WIP

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fill gap on added tx

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix eviction on sparse layer

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix remove from ready layer

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix remove from sparse layer

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix for block added and confirmed txs

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fixes to sparse layer

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix the filling of the gap when adding transactions

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Layered pending transactions test and fixes

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Distinguish between layer and comulative space used

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* unit tests for expected next nonce for sender

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Adding test for transaction selection

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Re-enable prioritized transaction tests and more fixes

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* log stats

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* syncronized some methods, metrics update and dump transactions for replay

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Test that replay tx and fix for tx replacement across layers

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Add missing copyright and fix replay test

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Add consistency check asserts

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix ready internalRemove

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Metrics tests improvements

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* WIP: Transaction memory size estimation

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Complete pending transaction memory used computation

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Improve metrics

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Rename to specify that the limit is per layer

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Update metric names in tests

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Adjust tx layer max capacity according to new tx memory size calculation

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix legacy transaction expiration tests

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix IndexOutOfBoundsException in sparse layer

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Unique senders metric

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Ignore ReplayTest by default, fix logging of stats

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Log for replay renamings

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Document howto generate txpool replay

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Reduce max layer capacity

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* exclude transaction replay resource

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Improve compareByFee when effectivePriorityFee is 0

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* More debug logs during transaction selection for a block

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Use only one thread for building blocks so there is no risk of overlapping

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Improve transaction trace log making wei human readable

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Use List instead of Set when getting all pending transactions

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* More detailed log on adding remote txs

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Execute transaction broadcast aysnc after adding them to the txpool

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Log time taken to add remote txs before their broadcast

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix test

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Add missing header

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix unit tests

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Add CHANGELOG entry

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Delete unneeded file

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Rename some layered txpool metrics to avoid conflict with existing metrics
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix pushing to next layers txs following an invalid one

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* In case of an unexpected error, log more data and do a consistency check

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix null check on wrong var

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix some codeql alerts

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix sparse gap calculation when invalidating

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Apply suggestions from doce review

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Only trigger consistency check if trace log is enable in case of unexpected error

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix replay of blocks with no transactions

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix for negative gap when there is a reorg

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Implement code review suggestions

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix for a case when deleting tx with zero gap in sparse layer

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Delete redoundant tests

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Update CHANGELOG.md

Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Update ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPool.java

Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Update ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolMetrics.java

Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Update ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/ReadyTransactions.java

Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Update ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/layered/AbstractPrioritizedTransactionsTestBase.java

Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Update ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/SparseTransactions.java

Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Update besu/src/main/java/org/hyperledger/besu/cli/options/unstable/TransactionPoolOptions.java

Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Update besu/src/main/java/org/hyperledger/besu/cli/options/unstable/TransactionPoolOptions.java

Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Address code review suggestions

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Improve logSender when there are no sparse txs

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix off by one error

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Update ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/transactions/layered/TransactionsLayer.java

Co-authored-by: Simon Dudley <simon.dudley@consensys.net>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Address code review suggestions

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Rename fix

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Simplify the way reorgs are handled, by detecting a negative gap and deleting and readding all the txs for that sender

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Do not run consistency check on internal error since it is too expensive,
instead force a reorg of the sender txs

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Remove invalid txs after the selection is complete to avoid ConcurrentModificationException

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Update txpool defaults

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Tune default

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

* Fix merge

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>

---------

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
Co-authored-by: Simon Dudley <simon.dudley@consensys.net>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Co-authored-by: garyschulte <garyschulte@gmail.com>
  • Loading branch information
4 people authored and eum602 committed Nov 3, 2023
1 parent 951356c commit 131ca23
Show file tree
Hide file tree
Showing 81 changed files with 8,339 additions and 922 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*~.nib
*.iml
*.launch
*.swp
*.log
.classpath
.DS_Store
Expand All @@ -29,4 +28,5 @@ site/
/kubernetes/reports/
/kubernetes/besu-*.tar.gz
**/src/*/generated
jitpack.yml
jitpack.yml
/ethereum/eth/src/test/resources/tx.csv.gz
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- EIP-4844: Zero blob transactions are invalid [#5425](https://github.com/hyperledger/besu/pull/5425)
- Transaction pool flag to disable specific behaviors for locally submitted transactions [#5418](https://github.com/hyperledger/besu/pull/5418)
- New optional feature to save the txpool content to file on shutdown and reloading it on startup [#5434](https://github.com/hyperledger/besu/pull/5434)
- Early access - layered transaction pool implementation [#5290](https://github.com/hyperledger/besu/pull/5290)

### Bug Fixes
- Fix eth_feeHistory response for the case in which blockCount is higher than highestBlock requested. [#5397](https://github.com/hyperledger/besu/pull/5397)
Expand Down
3 changes: 2 additions & 1 deletion besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,8 @@ static class TxPoolOptionGroup {
description =
"Maximum number of pending transactions that will be kept in the transaction pool (default: ${DEFAULT-VALUE})",
arity = "1")
private final Integer txPoolMaxSize = TransactionPoolConfiguration.MAX_PENDING_TRANSACTIONS;
private final Integer txPoolMaxSize =
TransactionPoolConfiguration.DEFAULT_MAX_PENDING_TRANSACTIONS;

@Option(
names = {"--tx-pool-retention-hours"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@
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<ImmutableTransactionPoolConfiguration.Builder> {
private static final Logger LOG = LoggerFactory.getLogger(TransactionPoolOptions.class);

private static final String TX_MESSAGE_KEEP_ALIVE_SEC_FLAG =
"--Xincoming-tx-messages-keep-alive-seconds";

Expand All @@ -47,6 +51,14 @@ public class TransactionPoolOptions
private static final String SAVE_RESTORE_FLAG = "--tx-pool-enable-save-restore";
private static final String SAVE_FILE = "--tx-pool-save-file";

private static final String LAYERED_TX_POOL_ENABLED_FLAG = "--Xlayered-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";
private static final String LAYERED_TX_POOL_MAX_FUTURE_BY_SENDER =
"--Xlayered-tx-pool-max-future-by-sender";

@CommandLine.Option(
names = {STRICT_TX_REPLAY_PROTECTION_ENABLED_FLAG},
paramLabel = "<Boolean>",
Expand Down Expand Up @@ -84,7 +96,46 @@ public class TransactionPoolOptions
"Maximum portion of the transaction pool which a single account may occupy with future transactions (default: ${DEFAULT-VALUE})",
arity = "1")
private Float txPoolLimitByAccountPercentage =
TransactionPoolConfiguration.LIMIT_TXPOOL_BY_ACCOUNT_PERCENTAGE;
TransactionPoolConfiguration.DEFAULT_LIMIT_TX_POOL_BY_ACCOUNT_PERCENTAGE;

@CommandLine.Option(
names = {LAYERED_TX_POOL_ENABLED_FLAG},
paramLabel = "<Boolean>",
hidden = true,
description = "Enable the Layered Transaction Pool (default: ${DEFAULT-VALUE})",
arity = "0..1")
private Boolean layeredTxPoolEnabled =
TransactionPoolConfiguration.DEFAULT_LAYERED_TX_POOL_ENABLED;

@CommandLine.Option(
names = {LAYERED_TX_POOL_LAYER_MAX_CAPACITY},
paramLabel = "<Long>",
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 = "<Int>",
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 = "<Int>",
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 = {DISABLE_LOCAL_TXS_FLAG},
Expand Down Expand Up @@ -139,19 +190,34 @@ public static TransactionPoolOptions fromConfig(final TransactionPoolConfigurati
options.disableLocalTxs = config.getDisableLocalTransactions();
options.saveRestoreEnabled = config.getEnableSaveRestore();
options.saveFile = config.getSaveFile();
options.layeredTxPoolEnabled = config.getLayeredTxPoolEnabled();
options.layeredTxPoolLayerMaxCapacity = config.getPendingTransactionsLayerMaxCapacityBytes();
options.layeredTxPoolMaxPrioritized = config.getMaxPrioritizedTransactions();
options.layeredTxPoolMaxFutureBySender = config.getMaxFutureBySender();
return options;
}

@Override
public ImmutableTransactionPoolConfiguration.Builder toDomainObject() {
if (layeredTxPoolEnabled) {
LOG.warn(
"Layered transaction pool enabled, ignoring settings for "
+ "--tx-pool-max-size and --tx-pool-limit-by-account-percentage");
}

return ImmutableTransactionPoolConfiguration.builder()
.strictTransactionReplayProtectionEnabled(strictTxReplayProtectionEnabled)
.txMessageKeepAliveSeconds(txMessageKeepAliveSeconds)
.eth65TrxAnnouncedBufferingPeriod(Duration.ofMillis(eth65TrxAnnouncedBufferingPeriod))
.txPoolLimitByAccountPercentage(txPoolLimitByAccountPercentage)
.disableLocalTransactions(disableLocalTxs)
.enableSaveRestore(saveRestoreEnabled)
.saveFile(saveFile);
.saveFile(saveFile)
.txPoolLimitByAccountPercentage(txPoolLimitByAccountPercentage)
.layeredTxPoolEnabled(layeredTxPoolEnabled)
.pendingTransactionsLayerMaxCapacityBytes(layeredTxPoolLayerMaxCapacity)
.maxPrioritizedTransactions(layeredTxPoolMaxPrioritized)
.maxFutureBySender(layeredTxPoolMaxFutureBySender);
}

@Override
Expand All @@ -166,7 +232,14 @@ public List<String> getCLIOptions() {
TX_MESSAGE_KEEP_ALIVE_SEC_FLAG,
OptionParser.format(txMessageKeepAliveSeconds),
ETH65_TX_ANNOUNCED_BUFFERING_PERIOD_FLAG,
OptionParser.format(eth65TrxAnnouncedBufferingPeriod));
OptionParser.format(eth65TrxAnnouncedBufferingPeriod),
LAYERED_TX_POOL_ENABLED_FLAG + "=" + layeredTxPoolEnabled,
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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +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.LIMIT_TXPOOL_BY_ACCOUNT_PERCENTAGE;
import static org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration.DEFAULT_LIMIT_TX_POOL_BY_ACCOUNT_PERCENTAGE;

import org.hyperledger.besu.cli.options.unstable.TransactionPoolOptions;
import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration;
Expand Down Expand Up @@ -101,7 +101,7 @@ public void senderLimitedTxPoolCeiling_violated() {
final TransactionPoolOptions options = getOptionsFromBesuCommand(cmd);
final TransactionPoolConfiguration config = options.toDomainObject().build();
assertThat(config.getTxPoolLimitByAccountPercentage())
.isEqualTo(LIMIT_TXPOOL_BY_ACCOUNT_PERCENTAGE);
.isEqualTo(DEFAULT_LIMIT_TX_POOL_BY_ACCOUNT_PERCENTAGE);

assertThat(commandOutput.toString(UTF_8)).isEmpty();
assertThat(commandErrorOutput.toString(UTF_8))
Expand Down Expand Up @@ -239,7 +239,13 @@ ImmutableTransactionPoolConfiguration.Builder createDefaultDomainObject() {
.txPoolLimitByAccountPercentage(defaultValue.getTxPoolLimitByAccountPercentage())
.disableLocalTransactions(defaultValue.getDisableLocalTransactions())
.enableSaveRestore(defaultValue.getEnableSaveRestore())
.saveFile(defaultValue.getSaveFile());
.saveFile(defaultValue.getSaveFile())
.txPoolLimitByAccountPercentage(defaultValue.getTxPoolLimitByAccountPercentage())
.layeredTxPoolEnabled(defaultValue.getLayeredTxPoolEnabled())
.pendingTransactionsLayerMaxCapacityBytes(
defaultValue.getPendingTransactionsLayerMaxCapacityBytes())
.maxPrioritizedTransactions(defaultValue.getMaxPrioritizedTransactions())
.maxFutureBySender(defaultValue.getMaxFutureBySender());
}

@Override
Expand All @@ -253,7 +259,12 @@ ImmutableTransactionPoolConfiguration.Builder createCustomizedDomainObject() {
.txPoolLimitByAccountPercentage(0.5f)
.disableLocalTransactions(true)
.enableSaveRestore(true)
.saveFile(new File("abc.xyz"));
.saveFile(new File("abc.xyz"))
.txPoolLimitByAccountPercentage(0.5f)
.layeredTxPoolEnabled(true)
.pendingTransactionsLayerMaxCapacityBytes(1_000_000L)
.maxPrioritizedTransactions(1000)
.maxFutureBySender(10);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@
import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration;
import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactions;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionBroadcaster;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolMetrics;
import org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.data.TransactionType;
Expand Down Expand Up @@ -84,7 +86,7 @@ public class EthGetFilterChangesIntegrationTest {
private TransactionPool transactionPool;
private final MetricsSystem metricsSystem = new NoOpMetricsSystem();

private GasPricePendingTransactionsSorter transactions;
private PendingTransactions transactions;

private static final int MAX_TRANSACTIONS = 5;
private static final KeyPair keyPair = SignatureAlgorithmFactory.getInstance().generateKeyPair();
Expand Down Expand Up @@ -116,7 +118,7 @@ public void setUp() {
batchAddedListener,
ethContext,
new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).build(),
metricsSystem,
new TransactionPoolMetrics(metricsSystem),
TransactionPoolConfiguration.DEFAULT);
final BlockchainQueries blockchainQueries =
new BlockchainQueries(blockchain, protocolContext.getWorldStateArchive());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@
import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.transactions.ImmutableTransactionPoolConfiguration;
import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactions;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionBroadcaster;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolMetrics;
import org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.data.TransactionType;
Expand Down Expand Up @@ -84,7 +86,7 @@ public class EthGetFilterChangesIntegrationTest {
private TransactionPool transactionPool;
private final MetricsSystem metricsSystem = new NoOpMetricsSystem();

private BaseFeePendingTransactionsSorter transactions;
private PendingTransactions transactions;

private static final int MAX_TRANSACTIONS = 5;
private static final KeyPair keyPair = SignatureAlgorithmFactory.getInstance().generateKeyPair();
Expand Down Expand Up @@ -116,7 +118,7 @@ public void setUp() {
batchAddedListener,
ethContext,
new MiningParameters.Builder().minTransactionGasPrice(Wei.ZERO).build(),
metricsSystem,
new TransactionPoolMetrics(metricsSystem),
TransactionPoolConfiguration.DEFAULT);
final BlockchainQueries blockchainQueries =
new BlockchainQueries(blockchain, protocolContext.getWorldStateArchive());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactions;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class TxPoolBesuPendingTransactions implements JsonRpcMethod {
Expand Down Expand Up @@ -56,7 +56,7 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
.map(PendingTransactionsParams::filters)
.orElse(Collections.emptyList());

final Set<Transaction> pendingTransactionsFiltered =
final Collection<Transaction> pendingTransactionsFiltered =
pendingTransactionFilter.reduce(
pendingTransactions.getPendingTransactions(), filters, limit);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction;
import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactions;

import java.util.Set;
import java.util.Collection;

public class TxPoolBesuStatistics implements JsonRpcMethod {

Expand All @@ -43,7 +43,8 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
}

private PendingTransactionsStatisticsResult statistics() {
final Set<PendingTransaction> pendingTransaction = pendingTransactions.getPendingTransactions();
final Collection<PendingTransaction> pendingTransaction =
pendingTransactions.getPendingTransactions();
final long localCount =
pendingTransaction.stream().filter(PendingTransaction::isReceivedFromLocalSource).count();
final long remoteCount = pendingTransaction.size() - localCount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class PendingTransactionResult implements TransactionResult {
public PendingTransactionResult(final PendingTransaction pendingTransaction) {
hash = pendingTransaction.getHash().toString();
isReceivedFromLocalSource = pendingTransaction.isReceivedFromLocalSource();
addedToPoolAt = pendingTransaction.getAddedToPoolAt();
addedToPoolAt = Instant.ofEpochMilli(pendingTransaction.getAddedAt());
}

@JsonGetter(value = "hash")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,22 @@

import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction;

import java.util.Set;
import java.util.stream.Collectors;
import java.util.Collection;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonValue;

public class PendingTransactionsResult implements TransactionResult {

private final Set<PendingTransactionResult> pendingTransactionResults;
private final List<PendingTransactionResult> pendingTransactionResults;

public PendingTransactionsResult(final Set<PendingTransaction> pendingTransactionSet) {
public PendingTransactionsResult(final Collection<PendingTransaction> pendingTransactionSet) {
pendingTransactionResults =
pendingTransactionSet.stream()
.map(PendingTransactionResult::new)
.collect(Collectors.toSet());
pendingTransactionSet.stream().map(PendingTransactionResult::new).toList();
}

@JsonValue
public Set<PendingTransactionResult> getResults() {
public List<PendingTransactionResult> getResults() {
return pendingTransactionResults;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction;

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

/**
* This class allows to filter a list of pending transactions
Expand All @@ -43,16 +42,16 @@ public class PendingTransactionFilter {
public static final String VALUE_FIELD = "value";
public static final String NONCE_FIELD = "nonce";

public Set<Transaction> reduce(
final Set<PendingTransaction> pendingTransactions,
public Collection<Transaction> reduce(
final Collection<PendingTransaction> pendingTransactions,
final List<Filter> filters,
final int limit)
throws InvalidJsonRpcParameters {
return pendingTransactions.stream()
.filter(pendingTx -> applyFilters(pendingTx, filters))
.limit(limit)
.map(PendingTransaction::getTransaction)
.collect(Collectors.toSet());
.toList();
}

private boolean applyFilters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionManager;
import org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.SubscriptionType;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactionListener;
import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactionAddedListener;

import java.util.List;

public class PendingTransactionSubscriptionService implements PendingTransactionListener {
public class PendingTransactionSubscriptionService implements PendingTransactionAddedListener {

private final SubscriptionManager subscriptionManager;

Expand Down
Loading

0 comments on commit 131ca23

Please sign in to comment.