From 8e5de8d03ea47510941f79ac5ccb8cf19ac1979e Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Wed, 25 Oct 2023 18:35:00 +1100 Subject: [PATCH 1/9] Add transaction selector based on min priority fee parameter Signed-off-by: Gabriel-Trintinalia --- .../txselection/BlockTransactionSelector.java | 2 + ...nPriorityFeePerGasTransactionSelector.java | 83 +++++++++++++++++ ...orityFeePerGasTransactionSelectorTest.java | 88 +++++++++++++++++++ .../data/TransactionSelectionResult.java | 9 +- 4 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/MinPriorityFeePerGasTransactionSelector.java create mode 100644 ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockTransactionSelector.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockTransactionSelector.java index 2c4382234dc..5e4f5caa552 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockTransactionSelector.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/BlockTransactionSelector.java @@ -21,6 +21,7 @@ import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.AllAcceptingTransactionSelector; import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.BlobPriceTransactionSelector; import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.BlockSizeTransactionSelector; +import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.MinPriorityFeePerGasTransactionSelector; import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.PriceTransactionSelector; import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.ProcessingResultTransactionSelector; import org.hyperledger.besu.ethereum.chain.Blockchain; @@ -132,6 +133,7 @@ private List createTransactionSelectors( new BlockSizeTransactionSelector(context), new PriceTransactionSelector(context), new BlobPriceTransactionSelector(context), + new MinPriorityFeePerGasTransactionSelector(context), new ProcessingResultTransactionSelector(context)); } diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/MinPriorityFeePerGasTransactionSelector.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/MinPriorityFeePerGasTransactionSelector.java new file mode 100644 index 00000000000..c142463e305 --- /dev/null +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/MinPriorityFeePerGasTransactionSelector.java @@ -0,0 +1,83 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * 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.ethereum.blockcreation.txselection.selectors; + +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.blockcreation.txselection.BlockSelectionContext; +import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults; +import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction; +import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; +import org.hyperledger.besu.plugin.data.TransactionSelectionResult; + +/** This class is responsible for selecting transactions based on the minimum priority fee. */ +public class MinPriorityFeePerGasTransactionSelector extends AbstractTransactionSelector { + + /** + * Constructor for MinPriorityFeeSelector. + * + * @param context The context of block selection. + */ + public MinPriorityFeePerGasTransactionSelector(final BlockSelectionContext context) { + super(context); + } + + /** + * Evaluates a transaction before processing. + * + * @param pendingTransaction The transaction to be evaluated. + * @param transactionSelectionResults The results of other transaction evaluations in the same + * block. + * @return TransactionSelectionResult. If the priority fee is below the minimum, it returns an + * invalid transient result. Otherwise, it returns a selected result. + */ + @Override + public TransactionSelectionResult evaluateTransactionPreProcessing( + final PendingTransaction pendingTransaction, + final TransactionSelectionResults transactionSelectionResults) { + if (isPriorityFeePriceBelowMinimum(pendingTransaction.getTransaction())) { + return TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN; + } + return TransactionSelectionResult.SELECTED; + } + + /** + * Checks if the priority fee price is below the minimum. + * + * @param transaction The transaction to check. + * @return boolean. Returns true if the minimum priority fee price is below the minimum, false + * otherwise. + */ + private boolean isPriorityFeePriceBelowMinimum(final Transaction transaction) { + Wei priorityFeePerGas = + transaction.getEffectivePriorityFeePerGas(context.processableBlockHeader().getBaseFee()); + return priorityFeePerGas.lessThan(context.miningParameters().getMinPriorityFeePerGas()); + } + + /** + * No evaluation is performed post-processing. + * + * @param pendingTransaction The processed transaction. + * @param processingResult The result of the transaction processing. + * @return Always returns SELECTED. + */ + @Override + public TransactionSelectionResult evaluateTransactionPostProcessing( + final PendingTransaction pendingTransaction, + final TransactionSelectionResults blockTransactionResults, + final TransactionProcessingResult processingResult) { + return TransactionSelectionResult.SELECTED; + } +} diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java new file mode 100644 index 00000000000..72e68005595 --- /dev/null +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java @@ -0,0 +1,88 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * 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.ethereum.blockcreation; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.blockcreation.txselection.BlockSelectionContext; +import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.AbstractTransactionSelector; +import org.hyperledger.besu.ethereum.blockcreation.txselection.selectors.MinPriorityFeePerGasTransactionSelector; +import org.hyperledger.besu.ethereum.core.MiningParameters; +import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; +import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction; +import org.hyperledger.besu.plugin.data.TransactionSelectionResult; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class MinPriorityFeePerGasTransactionSelectorTest { + private AbstractTransactionSelector transactionSelector; + + private final int minPriorityFeeParameter = 7; + + @BeforeEach + public void initialize() { + MiningParameters miningParameters = + MiningParameters.newDefault().setMinPriorityFeePerGas(Wei.of(minPriorityFeeParameter)); + BlockSelectionContext context = + new BlockSelectionContext( + miningParameters, + null, + null, + mock(ProcessableBlockHeader.class), + null, + null, + null, + null); + transactionSelector = new MinPriorityFeePerGasTransactionSelector(context); + } + + @Test + public void shouldNotSelectWhen_PriorityFeePerGas_IsLessThan_MinPriorityFeePerGas() { + var transaction = mockTransactionWithPriorityFee(minPriorityFeeParameter - 1); + assertSelection(transaction, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN); + } + + @Test + public void shouldSelectWhen_PriorityFeePerGas_IsEqual_MinPriorityFeePerGas() { + var transaction = mockTransactionWithPriorityFee(minPriorityFeeParameter); + assertSelection(transaction, TransactionSelectionResult.SELECTED); + } + + @Test + public void shouldSelectWhen_PriorityFeePerGas_IsGreaterThan_MinPriorityFeePerGas() { + var transaction = mockTransactionWithPriorityFee(minPriorityFeeParameter + 1); + assertSelection(transaction, TransactionSelectionResult.SELECTED); + } + + private void assertSelection( + final PendingTransaction transaction, final TransactionSelectionResult expectedResult) { + var actualResult = transactionSelector.evaluateTransactionPreProcessing(transaction, null); + assertThat(actualResult).isEqualTo(expectedResult); + } + + private PendingTransaction mockTransactionWithPriorityFee(final int priorityFeePerGas) { + PendingTransaction mockTransaction = mock(PendingTransaction.class); + Transaction transaction = mock(Transaction.class); + when(mockTransaction.getTransaction()).thenReturn(transaction); + when(transaction.getEffectivePriorityFeePerGas(any())).thenReturn(Wei.of(priorityFeePerGas)); + return mockTransaction; + } +} diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/TransactionSelectionResult.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/TransactionSelectionResult.java index ffae842ca72..0cdaea997e2 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/TransactionSelectionResult.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/data/TransactionSelectionResult.java @@ -75,12 +75,19 @@ public String toString() { public static final TransactionSelectionResult CURRENT_TX_PRICE_BELOW_MIN = TransactionSelectionResult.invalidTransient("CURRENT_TX_PRICE_BELOW_MIN"); /** - * The transaction has not been selected since its data price is below the current network data + * The transaction has not been selected since its blob price is below the current network blob * price, but the selection should continue. */ public static final TransactionSelectionResult BLOB_PRICE_BELOW_CURRENT_MIN = TransactionSelectionResult.invalidTransient("BLOB_PRICE_BELOW_CURRENT_MIN"); + /** + * The transaction has not been selected since its priority fee is below the configured min + * priority fee per gas, but the selection should continue. + */ + public static final TransactionSelectionResult PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN = + TransactionSelectionResult.invalidTransient("PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN"); + private final Status status; private final Optional maybeInvalidReason; From 50aa9830b08f1b70f79b4aba0c5152f0dfe20dd0 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Wed, 25 Oct 2023 18:50:22 +1100 Subject: [PATCH 2/9] Change plugin known hash Signed-off-by: Gabriel-Trintinalia --- plugin-api/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index f79852f2011..8b52eabde78 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -69,7 +69,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'j6NRklFHlG35Pq/t6t/oJBrT8DbYOyruGq3cJNh4ENw=' + knownHash = 'zEQdO54rmbJoWoXk4YZUc8NVCg6e3W7mh0YKGeZCE1E=' } check.dependsOn('checkAPIChanges') From 54fc00615e2214615d12d1f9d4e2b1ad4fbe28d8 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Thu, 26 Oct 2023 11:27:27 +1100 Subject: [PATCH 3/9] update changelog Signed-off-by: Gabriel-Trintinalia --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 787ff1d137d..b0bb0489fce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,13 @@ # Changelog +## Next release ### Breaking Changes ### Deprecations ### Additions and Improvements +- New option `--min-priority-fee` that sets the minimum priority fee a transaction must meet to be selected for a block. [#6080](https://github.com/hyperledger/besu/pull/6080) [#6083](https://github.com/hyperledger/besu/pull/6083) +- Implement new `miner_setMinPriorityFee` and `miner_getMinPriorityFee` RPC methods [#6080](https://github.com/hyperledger/besu/pull/6080) ### Bug Fixes From 3c29d8a20c52a03123ebe8d3b27b1ec2e1932d6e Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Thu, 26 Oct 2023 13:43:54 +1100 Subject: [PATCH 4/9] Add test Signed-off-by: Gabriel-Trintinalia --- .../AbstractBlockTransactionSelectorTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java index 1ddcd264ea0..3dcfa4e89b1 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java @@ -737,6 +737,37 @@ public void transactionWithIncorrectNonceRemainsInPoolAndNotSelected() { TransactionInvalidReason.NONCE_TOO_HIGH.name()))); } + @Test + public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { + ProcessableBlockHeader blockHeader = createBlock(5_000_000, Wei.ONE); + miningParameters.setMinPriorityFeePerGas(Wei.of(7)); + final Transaction tx1 = createTransaction(1, Wei.of(8), 100_000); + ensureTransactionIsValid(tx1); + final Transaction tx2 = createTransaction(2, Wei.of(9), 100_000); + ensureTransactionIsValid(tx2); + // transaction tx3 should not be selected + final Transaction tx3 = createTransaction(3, Wei.of(7), 100_000); + ensureTransactionIsValid(tx3); + transactionPool.addRemoteTransactions(List.of(tx1, tx2, tx3)); + + final BlockTransactionSelector selector = + createBlockSelector( + transactionProcessor, + blockHeader, + Wei.ZERO, + AddressHelpers.ofValue(1), + Wei.ZERO, + MIN_OCCUPANCY_100_PERCENT); + + final TransactionSelectionResults results = selector.buildTransactionListForBlock(); + + assertThat(transactionPool.getTransactionByHash(tx3.getHash())).isPresent(); + assertThat(results.getSelectedTransactions()).containsOnly(tx1, tx2); + assertThat(results.getNotSelectedTransactions()) + .containsOnly( + entry(tx3, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN)); + } + protected BlockTransactionSelector createBlockSelector( final MainnetTransactionProcessor transactionProcessor, final ProcessableBlockHeader blockHeader, From f5f5d0a9e6a96baf1cb471d2d2888c0dc0507b1f Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Thu, 2 Nov 2023 09:57:57 +1100 Subject: [PATCH 5/9] Validate priority senders Signed-off-by: Gabriel-Trintinalia --- .../MinPriorityFeePerGasTransactionSelector.java | 15 ++++++++++----- ...nPriorityFeePerGasTransactionSelectorTest.java | 10 ++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/MinPriorityFeePerGasTransactionSelector.java b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/MinPriorityFeePerGasTransactionSelector.java index c142463e305..91085f4f020 100644 --- a/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/MinPriorityFeePerGasTransactionSelector.java +++ b/ethereum/blockcreation/src/main/java/org/hyperledger/besu/ethereum/blockcreation/txselection/selectors/MinPriorityFeePerGasTransactionSelector.java @@ -17,7 +17,6 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.blockcreation.txselection.BlockSelectionContext; import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults; -import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.transactions.PendingTransaction; import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; import org.hyperledger.besu.plugin.data.TransactionSelectionResult; @@ -47,7 +46,7 @@ public MinPriorityFeePerGasTransactionSelector(final BlockSelectionContext conte public TransactionSelectionResult evaluateTransactionPreProcessing( final PendingTransaction pendingTransaction, final TransactionSelectionResults transactionSelectionResults) { - if (isPriorityFeePriceBelowMinimum(pendingTransaction.getTransaction())) { + if (isPriorityFeePriceBelowMinimum(pendingTransaction)) { return TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN; } return TransactionSelectionResult.SELECTED; @@ -56,13 +55,19 @@ public TransactionSelectionResult evaluateTransactionPreProcessing( /** * Checks if the priority fee price is below the minimum. * - * @param transaction The transaction to check. + * @param pendingTransaction The transaction to check. * @return boolean. Returns true if the minimum priority fee price is below the minimum, false * otherwise. */ - private boolean isPriorityFeePriceBelowMinimum(final Transaction transaction) { + private boolean isPriorityFeePriceBelowMinimum(final PendingTransaction pendingTransaction) { + // Priority txs are exempt from this check + if (pendingTransaction.hasPriority()) { + return false; + } Wei priorityFeePerGas = - transaction.getEffectivePriorityFeePerGas(context.processableBlockHeader().getBaseFee()); + pendingTransaction + .getTransaction() + .getEffectivePriorityFeePerGas(context.processableBlockHeader().getBaseFee()); return priorityFeePerGas.lessThan(context.miningParameters().getMinPriorityFeePerGas()); } diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java index 72e68005595..c200c49d5da 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java @@ -72,6 +72,16 @@ public void shouldSelectWhen_PriorityFeePerGas_IsGreaterThan_MinPriorityFeePerGa assertSelection(transaction, TransactionSelectionResult.SELECTED); } + @Test + public void shouldSelectWhenPrioritySender() { + var prioritySenderTransaction = mockTransactionWithPriorityFee(minPriorityFeeParameter - 1); + assertSelection( + prioritySenderTransaction, + TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN); + when(prioritySenderTransaction.hasPriority()).thenReturn(true); + assertSelection(prioritySenderTransaction, TransactionSelectionResult.SELECTED); + } + private void assertSelection( final PendingTransaction transaction, final TransactionSelectionResult expectedResult) { var actualResult = transactionSelector.evaluateTransactionPreProcessing(transaction, null); From 608d9e7aabe96e93d879d0c21d402bc9db58aee4 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Thu, 2 Nov 2023 09:58:13 +1100 Subject: [PATCH 6/9] Add unit tests Signed-off-by: Gabriel-Trintinalia --- .../AbstractBlockTransactionSelectorTest.java | 13 +++--- ...FeeMarketBlockTransactionSelectorTest.java | 43 +++++++++++++++++++ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java index b6626c0ee3d..554de25ccf1 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java @@ -829,12 +829,10 @@ public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { miningParameters.setMinPriorityFeePerGas(Wei.of(7)); final Transaction tx1 = createTransaction(1, Wei.of(8), 100_000); ensureTransactionIsValid(tx1); - final Transaction tx2 = createTransaction(2, Wei.of(9), 100_000); + // transaction tx2 should not be selected + final Transaction tx2 = createTransaction(2, Wei.of(7), 100_000); ensureTransactionIsValid(tx2); - // transaction tx3 should not be selected - final Transaction tx3 = createTransaction(3, Wei.of(7), 100_000); - ensureTransactionIsValid(tx3); - transactionPool.addRemoteTransactions(List.of(tx1, tx2, tx3)); + transactionPool.addRemoteTransactions(List.of(tx1, tx2)); final BlockTransactionSelector selector = createBlockSelector( @@ -847,11 +845,10 @@ public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { final TransactionSelectionResults results = selector.buildTransactionListForBlock(); - assertThat(transactionPool.getTransactionByHash(tx3.getHash())).isPresent(); - assertThat(results.getSelectedTransactions()).containsOnly(tx1, tx2); + assertThat(results.getSelectedTransactions()).containsOnly(tx1); assertThat(results.getNotSelectedTransactions()) .containsOnly( - entry(tx3, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN)); + entry(tx2, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN)); } protected BlockTransactionSelector createBlockSelector( diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java index 57b89f8a1d7..35acb1ba315 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java @@ -215,4 +215,47 @@ public void transactionFromSameSenderWithMixedTypes() { .containsExactly(txFrontier1, txLondon1, txFrontier2, txLondon2); assertThat(results.getNotSelectedTransactions()).isEmpty(); } + + @Test + @Override + public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { + ProcessableBlockHeader blockHeader = createBlock(5_000_000, Wei.ONE); + miningParameters.setMinPriorityFeePerGas(Wei.of(7)); + + final Transaction tx1 = createEIP1559Transaction(1, Wei.of(8), Wei.of(8), 100_000); + ensureTransactionIsValid(tx1); + + // transaction tx2 should not be selected + final Transaction tx2 = createEIP1559Transaction(2, Wei.of(7), Wei.of(7), 100_000); + ensureTransactionIsValid(tx2); + + // transaction tx3 should be selected + final Transaction tx3 = createEIP1559Transaction(3, Wei.of(8), Wei.of(8), 100_000); + ensureTransactionIsValid(tx3); + + // transaction tx4 should be selected + final Transaction tx4 = createEIP1559Transaction(4, Wei.of(8), Wei.of(6), 100_000); + ensureTransactionIsValid(tx4); + + transactionPool.addRemoteTransactions(List.of(tx1, tx2, tx3, tx4)); + + assertThat(transactionPool.getPendingTransactions().size()).isEqualTo(4); + + final BlockTransactionSelector selector = + createBlockSelector( + transactionProcessor, + blockHeader, + Wei.ZERO, + AddressHelpers.ofValue(1), + Wei.ZERO, + MIN_OCCUPANCY_100_PERCENT); + + final TransactionSelectionResults results = selector.buildTransactionListForBlock(); + + assertThat(results.getSelectedTransactions()).containsOnly(tx1, tx3); + assertThat(results.getNotSelectedTransactions()) + .containsOnly( + entry(tx2, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN), + entry(tx4, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN)); + } } From c262403a20dcb20d90c28c0882ea51262f05d378 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Thu, 2 Nov 2023 09:58:19 +1100 Subject: [PATCH 7/9] Fix known hash Signed-off-by: Gabriel-Trintinalia --- plugin-api/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 75b433f4a63..beacad8710f 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -69,7 +69,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'ZXBvp7wuHQ8j4Gty2zg/gKdzgrOXSpehYukMuH98W/Y=' + knownHash = 'kyCYfllc1IcisRZIYuLxhC+0+POCzcMQPhE8F8mx1Ns=' } check.dependsOn('checkAPIChanges') From 7f0e8f9e3851f875d7475d0bae3990c780a8007b Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Thu, 2 Nov 2023 11:01:17 +1100 Subject: [PATCH 8/9] Fix comment Signed-off-by: Gabriel-Trintinalia --- .../LondonFeeMarketBlockTransactionSelectorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java index 35acb1ba315..739b4f56d7c 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java @@ -233,7 +233,7 @@ public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { final Transaction tx3 = createEIP1559Transaction(3, Wei.of(8), Wei.of(8), 100_000); ensureTransactionIsValid(tx3); - // transaction tx4 should be selected + // transaction tx4 should not be selected final Transaction tx4 = createEIP1559Transaction(4, Wei.of(8), Wei.of(6), 100_000); ensureTransactionIsValid(tx4); From 912e7cb9474e7470cb44e25640f9a778466ccc94 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Thu, 2 Nov 2023 20:42:07 +1100 Subject: [PATCH 9/9] Rename variable and tests Signed-off-by: Gabriel-Trintinalia --- .../AbstractBlockTransactionSelectorTest.java | 17 +++++----- ...FeeMarketBlockTransactionSelectorTest.java | 33 ++++++++++--------- ...orityFeePerGasTransactionSelectorTest.java | 13 ++++---- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java index 554de25ccf1..39a4f0673e8 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/AbstractBlockTransactionSelectorTest.java @@ -827,12 +827,12 @@ public void decreaseOfMinGasPriceAtRuntimeIncludeTxThatWasPreviouslyNotSelected( public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { ProcessableBlockHeader blockHeader = createBlock(5_000_000, Wei.ONE); miningParameters.setMinPriorityFeePerGas(Wei.of(7)); - final Transaction tx1 = createTransaction(1, Wei.of(8), 100_000); - ensureTransactionIsValid(tx1); - // transaction tx2 should not be selected - final Transaction tx2 = createTransaction(2, Wei.of(7), 100_000); - ensureTransactionIsValid(tx2); - transactionPool.addRemoteTransactions(List.of(tx1, tx2)); + final Transaction txSelected = createTransaction(1, Wei.of(8), 100_000); + ensureTransactionIsValid(txSelected); + // transaction txNotSelected should not be selected + final Transaction txNotSelected = createTransaction(2, Wei.of(7), 100_000); + ensureTransactionIsValid(txNotSelected); + transactionPool.addRemoteTransactions(List.of(txSelected, txNotSelected)); final BlockTransactionSelector selector = createBlockSelector( @@ -845,10 +845,11 @@ public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { final TransactionSelectionResults results = selector.buildTransactionListForBlock(); - assertThat(results.getSelectedTransactions()).containsOnly(tx1); + assertThat(results.getSelectedTransactions()).containsOnly(txSelected); assertThat(results.getNotSelectedTransactions()) .containsOnly( - entry(tx2, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN)); + entry( + txNotSelected, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN)); } protected BlockTransactionSelector createBlockSelector( diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java index 739b4f56d7c..1ef0fa8f2ff 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/LondonFeeMarketBlockTransactionSelectorTest.java @@ -222,22 +222,23 @@ public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { ProcessableBlockHeader blockHeader = createBlock(5_000_000, Wei.ONE); miningParameters.setMinPriorityFeePerGas(Wei.of(7)); - final Transaction tx1 = createEIP1559Transaction(1, Wei.of(8), Wei.of(8), 100_000); - ensureTransactionIsValid(tx1); + final Transaction txSelected1 = createEIP1559Transaction(1, Wei.of(8), Wei.of(8), 100_000); + ensureTransactionIsValid(txSelected1); - // transaction tx2 should not be selected - final Transaction tx2 = createEIP1559Transaction(2, Wei.of(7), Wei.of(7), 100_000); - ensureTransactionIsValid(tx2); + // transaction txNotSelected1 should not be selected + final Transaction txNotSelected1 = createEIP1559Transaction(2, Wei.of(7), Wei.of(7), 100_000); + ensureTransactionIsValid(txNotSelected1); - // transaction tx3 should be selected - final Transaction tx3 = createEIP1559Transaction(3, Wei.of(8), Wei.of(8), 100_000); - ensureTransactionIsValid(tx3); + // transaction txSelected2 should be selected + final Transaction txSelected2 = createEIP1559Transaction(3, Wei.of(8), Wei.of(8), 100_000); + ensureTransactionIsValid(txSelected2); - // transaction tx4 should not be selected - final Transaction tx4 = createEIP1559Transaction(4, Wei.of(8), Wei.of(6), 100_000); - ensureTransactionIsValid(tx4); + // transaction txNotSelected2 should not be selected + final Transaction txNotSelected2 = createEIP1559Transaction(4, Wei.of(8), Wei.of(6), 100_000); + ensureTransactionIsValid(txNotSelected2); - transactionPool.addRemoteTransactions(List.of(tx1, tx2, tx3, tx4)); + transactionPool.addRemoteTransactions( + List.of(txSelected1, txNotSelected1, txSelected2, txNotSelected2)); assertThat(transactionPool.getPendingTransactions().size()).isEqualTo(4); @@ -252,10 +253,12 @@ public void shouldNotSelectTransactionsWithPriorityFeeLessThanConfig() { final TransactionSelectionResults results = selector.buildTransactionListForBlock(); - assertThat(results.getSelectedTransactions()).containsOnly(tx1, tx3); + assertThat(results.getSelectedTransactions()).containsOnly(txSelected1, txSelected2); assertThat(results.getNotSelectedTransactions()) .containsOnly( - entry(tx2, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN), - entry(tx4, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN)); + entry( + txNotSelected1, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN), + entry( + txNotSelected2, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN)); } } diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java index c200c49d5da..a86dc73ee46 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/MinPriorityFeePerGasTransactionSelectorTest.java @@ -57,32 +57,33 @@ public void initialize() { @Test public void shouldNotSelectWhen_PriorityFeePerGas_IsLessThan_MinPriorityFeePerGas() { var transaction = mockTransactionWithPriorityFee(minPriorityFeeParameter - 1); - assertSelection(transaction, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN); + assertSelectionResult( + transaction, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN); } @Test public void shouldSelectWhen_PriorityFeePerGas_IsEqual_MinPriorityFeePerGas() { var transaction = mockTransactionWithPriorityFee(minPriorityFeeParameter); - assertSelection(transaction, TransactionSelectionResult.SELECTED); + assertSelectionResult(transaction, TransactionSelectionResult.SELECTED); } @Test public void shouldSelectWhen_PriorityFeePerGas_IsGreaterThan_MinPriorityFeePerGas() { var transaction = mockTransactionWithPriorityFee(minPriorityFeeParameter + 1); - assertSelection(transaction, TransactionSelectionResult.SELECTED); + assertSelectionResult(transaction, TransactionSelectionResult.SELECTED); } @Test public void shouldSelectWhenPrioritySender() { var prioritySenderTransaction = mockTransactionWithPriorityFee(minPriorityFeeParameter - 1); - assertSelection( + assertSelectionResult( prioritySenderTransaction, TransactionSelectionResult.PRIORITY_FEE_PER_GAS_BELOW_CURRENT_MIN); when(prioritySenderTransaction.hasPriority()).thenReturn(true); - assertSelection(prioritySenderTransaction, TransactionSelectionResult.SELECTED); + assertSelectionResult(prioritySenderTransaction, TransactionSelectionResult.SELECTED); } - private void assertSelection( + private void assertSelectionResult( final PendingTransaction transaction, final TransactionSelectionResult expectedResult) { var actualResult = transactionSelector.evaluateTransactionPreProcessing(transaction, null); assertThat(actualResult).isEqualTo(expectedResult);