-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add test to check that TX selection doesn't prioritize TXs from the same sender #6022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c474dea
Add bool TX pool flag to allow TX selection to skip finding all TXs f…
matthew1001 ee7a66f
Implement one approach to eliminating sender TX grouping. Note - this…
matthew1001 4199ec6
Merge main
matthew1001 3ae0747
Make the no-sdr-grouping flag experimental, remove code no longer nee…
matthew1001 20ad749
Update tests, tidy up empty lines
matthew1001 cc214ce
Fix tests to be inline with recent sender-priority changes
matthew1001 6600b49
Merge main
matthew1001 439a0ec
Address PR comments
matthew1001 4d0d375
Merge with main
matthew1001 540ef39
More unit test updates
matthew1001 3aefab8
Remove --Xtx-pool-disable-sender-grouping - the new legacy TX pool or…
matthew1001 f7cba5d
Fix test merge error
matthew1001 42f9fcb
Merge branch 'main' into no-sdr-grouping
matthew1001 2d5b16f
Merge branch 'main' into no-sdr-grouping
fab-10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,7 @@ | |
| public abstract class AbstractPendingTransactionsTestBase { | ||
|
|
||
| protected static final int MAX_TRANSACTIONS = 5; | ||
| protected static final int MAX_TRANSACTIONS_LARGE_POOL = 15; | ||
| private static final float LIMITED_TRANSACTIONS_BY_SENDER_PERCENTAGE = 0.8f; | ||
| protected static final Supplier<SignatureAlgorithm> SIGNATURE_ALGORITHM = | ||
| Suppliers.memoize(SignatureAlgorithmFactory::getInstance); | ||
|
|
@@ -92,9 +93,29 @@ public abstract class AbstractPendingTransactionsTestBase { | |
| .build(); | ||
| protected PendingTransactions senderLimitedTransactions = | ||
| getPendingTransactions(senderLimitedConfig, Optional.empty()); | ||
| protected AbstractPendingTransactionsSorter transactionsLarge = | ||
| getPendingTransactions( | ||
| ImmutableTransactionPoolConfiguration.builder() | ||
| .txPoolMaxSize(MAX_TRANSACTIONS_LARGE_POOL) | ||
| .txPoolLimitByAccountPercentage(Fraction.fromFloat(1.0f)) | ||
| .build(), | ||
| Optional.empty()); | ||
| protected AbstractPendingTransactionsSorter transactionsLargeNoSenderGrouping = | ||
| getPendingTransactions( | ||
| ImmutableTransactionPoolConfiguration.builder() | ||
| .txPoolMaxSize(MAX_TRANSACTIONS_LARGE_POOL) | ||
| .disableSenderTXGrouping(true) | ||
| .txPoolLimitByAccountPercentage(Fraction.fromFloat(1.0f)) | ||
| .build(), | ||
| Optional.empty()); | ||
|
|
||
| protected final Transaction transaction1 = createTransaction(2); | ||
| protected final Transaction transaction2 = createTransaction(1); | ||
| protected final Transaction transaction3 = createTransaction(3); | ||
|
|
||
| protected final Transaction transaction1Sdr2 = createTransactionSender2(1); | ||
| protected final Transaction transaction2Sdr2 = createTransactionSender2(2); | ||
| protected final Transaction transaction3Sdr2 = createTransactionSender2(3); | ||
|
|
||
| protected final PendingTransactionAddedListener listener = | ||
| mock(PendingTransactionAddedListener.class); | ||
|
|
@@ -309,19 +330,86 @@ public void shouldNotNotifyDroppedListenerWhenTransactionAddedToBlock() { | |
| } | ||
|
|
||
| @Test | ||
| public void selectTransactionsUntilSelectorRequestsNoMore() { | ||
| transactions.addRemoteTransaction(transaction1, Optional.empty()); | ||
| transactions.addRemoteTransaction(transaction2, Optional.empty()); | ||
| public void selectTransactionsInDefaultOrder() { | ||
| assertThat(transactionsLarge.addRemoteTransaction(transaction1, Optional.empty())) | ||
| .isEqualTo(ADDED); | ||
| assertThat(transactionsLarge.addRemoteTransaction(transaction2, Optional.empty())) | ||
| .isEqualTo(ADDED); | ||
| assertThat(transactionsLarge.addRemoteTransaction(transaction1Sdr2, Optional.empty())) | ||
| .isEqualTo(ADDED); | ||
| assertThat(transactionsLarge.addRemoteTransaction(transaction2Sdr2, Optional.empty())) | ||
| .isEqualTo(ADDED); | ||
| assertThat(transactionsLarge.addRemoteTransaction(transaction3Sdr2, Optional.empty())) | ||
| .isEqualTo(ADDED); | ||
| assertThat(transactionsLarge.addRemoteTransaction(transaction3, Optional.empty())) | ||
| .isEqualTo(ADDED); | ||
|
|
||
| final List<Transaction> parsedTransactions = Lists.newArrayList(); | ||
| transactions.selectTransactions( | ||
| transactionsLarge.selectTransactions( | ||
| pendingTx -> { | ||
| parsedTransactions.add(pendingTx.getTransaction()); | ||
| return TransactionSelectionResult.BLOCK_OCCUPANCY_ABOVE_THRESHOLD; | ||
|
|
||
| if (parsedTransactions.size() == 6) { | ||
| return TransactionSelectionResult.BLOCK_OCCUPANCY_ABOVE_THRESHOLD; | ||
| } | ||
| return SELECTED; | ||
| }); | ||
|
|
||
| assertThat(parsedTransactions.size()).isEqualTo(1); | ||
| assertThat(parsedTransactions.get(0)).isEqualTo(transaction2); | ||
| assertThat(parsedTransactions.size()).isEqualTo(6); | ||
|
|
||
| assertThat(parsedTransactions.get(0)).isEqualTo(transaction1Sdr2); | ||
| assertThat(parsedTransactions.get(1)).isEqualTo(transaction2Sdr2); | ||
| assertThat(parsedTransactions.get(2)).isEqualTo(transaction3Sdr2); | ||
| assertThat(parsedTransactions.get(3)) | ||
| .isEqualTo(transaction2); // Transaction 2 is actually the lowest nonce for this sender | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since the name of the tx is misleading with its nonce, you could consider to rename
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
| assertThat(parsedTransactions.get(4)) | ||
| .isEqualTo(transaction1); // Transaction 1 is the next nonce for the sender | ||
| assertThat(parsedTransactions.get(5)) | ||
| .isEqualTo(transaction3); // Transaction 3 is the next nonce for the sender | ||
| } | ||
|
|
||
| @Test | ||
| public void selectTransactionsInOrderNoGroupBySender() { | ||
| assertThat( | ||
| transactionsLargeNoSenderGrouping.addRemoteTransaction(transaction2, Optional.empty())) | ||
| .isEqualTo(ADDED); | ||
| assertThat( | ||
| transactionsLargeNoSenderGrouping.addRemoteTransaction( | ||
| transaction1Sdr2, Optional.empty())) | ||
| .isEqualTo(ADDED); | ||
| assertThat( | ||
| transactionsLargeNoSenderGrouping.addRemoteTransaction( | ||
| transaction2Sdr2, Optional.empty())) | ||
| .isEqualTo(ADDED); | ||
| assertThat( | ||
| transactionsLargeNoSenderGrouping.addRemoteTransaction(transaction1, Optional.empty())) | ||
| .isEqualTo(ADDED); | ||
| assertThat( | ||
| transactionsLargeNoSenderGrouping.addRemoteTransaction( | ||
| transaction3Sdr2, Optional.empty())) | ||
| .isEqualTo(ADDED); | ||
| assertThat( | ||
| transactionsLargeNoSenderGrouping.addRemoteTransaction(transaction3, Optional.empty())) | ||
| .isEqualTo(ADDED); | ||
|
|
||
| final List<Transaction> parsedTransactions = Lists.newArrayList(); | ||
| transactionsLargeNoSenderGrouping.selectTransactions( | ||
| pendingTx -> { | ||
| parsedTransactions.add(pendingTx.getTransaction()); | ||
|
|
||
| if (parsedTransactions.size() == 6) { | ||
| return TransactionSelectionResult.BLOCK_OCCUPANCY_ABOVE_THRESHOLD; | ||
| } | ||
| return SELECTED; | ||
| }); | ||
|
|
||
| assertThat(parsedTransactions.size()).isEqualTo(6); | ||
|
|
||
| // Check that by setting --tx-pool-disable-sender-grouping=true then sdr 1 hasn't monopolized | ||
| // the pool selection just because its transaction (transaction 3) is the first one to be parsed | ||
| // by the selector | ||
| assertThat(parsedTransactions.get(0)).isEqualTo(transaction1Sdr2); | ||
| assertThat(parsedTransactions.get(1)).isEqualTo(transaction2); | ||
|
matthew1001 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -613,9 +701,18 @@ protected Transaction createTransaction(final long transactionNumber) { | |
| return new TransactionTestFixture() | ||
| .value(Wei.of(transactionNumber)) | ||
| .nonce(transactionNumber) | ||
| .gasPrice(Wei.of(0)) | ||
| .createTransaction(KEYS1); | ||
| } | ||
|
|
||
| protected Transaction createTransactionSender2(final long transactionNumber) { | ||
| return new TransactionTestFixture() | ||
| .value(Wei.of(transactionNumber)) | ||
| .nonce(transactionNumber) | ||
| .gasPrice(Wei.of(0)) | ||
| .createTransaction(KEYS2); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldEvictMultipleOldTransactions() { | ||
| final int maxTransactionRetentionHours = 1; | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.