Skip to content
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

dev(pool): trait object safe BestTransactions #10478

Merged
merged 3 commits into from
Aug 26, 2024

Conversation

greged93
Copy link
Contributor

@greged93 greged93 commented Aug 23, 2024

  • Split the BestTransactions in two traits in order to make the BestTransactions trait object safe.
  • Add a test for a BestTransactionsFilter trait object that verifies that the predicates only keeps transactions with even nonces.

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense, but the test should actually use the trait function

Comment on lines +622 to +620
// Create a filter that only returns transactions with even nonces
let filter =
BestTransactionFilter::new(best, |tx: &Arc<ValidPoolTransaction<MockTransaction>>| {
tx.nonce() % 2 == 0
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should use the trait function on best

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the trait function filter? I can't use it because of the Sized requirement

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see, then this won't be very useful because we usually operate on Box<dyn and won't be much different from the previous impl right? so what does this change actually achieve?

@mattsse mattsse added the A-tx-pool Related to the transaction mempool label Aug 24, 2024
@@ -162,6 +164,8 @@ impl<T: TransactionOrdering> crate::traits::BestTransactions for BestTransaction
}
}

impl<T: TransactionOrdering> crate::traits::BestTransactionsFilter for BestTransactions<T> {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we try replacing this with a blanket impl

filter for T where T: BestTransaction

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes a lot of sense and seems possible, will add

Comment on lines +622 to +620
// Create a filter that only returns transactions with even nonces
let filter =
BestTransactionFilter::new(best, |tx: &Arc<ValidPoolTransaction<MockTransaction>>| {
tx.nonce() % 2 == 0
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see, then this won't be very useful because we usually operate on Box<dyn and won't be much different from the previous impl right? so what does this change actually achieve?

@greged93
Copy link
Contributor Author

The idea was to make this work for a Box<dyn> by splitting the trait into 2, so making BestTransactions trait object safe and placing filter in an extension trait. From there we can give access to BestTransactionFilter by making the new function public.

This builds towards #10437, making it then possible to filter the transactions returned by best_transactions_with_attributes which return a Box<dyn BestTransaction>. For this, we can make a trait (e.g. TransactionFilter with single function is_valid(tx)) which would then be used in order to filter the transactions (i.e. BestTransactionsFilter::new(best_transactions, |tx| tx_filter.is_valid(tx))).

Let me know if this makes sense or if you would rather change something.

@mattsse
Copy link
Collaborator

mattsse commented Aug 26, 2024

gotcha, now I understood.

is this possible

#10478 (comment)

if not this is complete

@greged93 greged93 force-pushed the dev/best-transactions-filter branch from 572836e to 82b3f50 Compare August 26, 2024 10:50
@mattsse mattsse added this pull request to the merge queue Aug 26, 2024
Merged via the queue into paradigmxyz:main with commit 1ac5336 Aug 26, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tx-pool Related to the transaction mempool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants