Merged
Conversation
SuperFluffy
reviewed
May 22, 2024
| } | ||
| } | ||
|
|
||
| fn priority(&self, current_account_nonce: u32) -> anyhow::Result<TransactionPriority> { |
Contributor
There was a problem hiding this comment.
What if this returned an Option<TransactionPriority> instead?
Contributor
Author
There was a problem hiding this comment.
Not sure if there's much of a win there. We'd just need to convert the None case to an Err in Mempool::insert unless we wanted to change its return type too?
noot
reviewed
May 24, 2024
noot
reviewed
May 24, 2024
noot
reviewed
May 24, 2024
noot
reviewed
May 24, 2024
noot
reviewed
May 24, 2024
noot
approved these changes
May 24, 2024
Contributor
noot
left a comment
There was a problem hiding this comment.
nice, this looks good to me!
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The mempool was refactored to reduce the visibility, count and scope of acquired lock guards, and to be implemented in terms of a single collection rather than two which needed synchronized.
Background
The mempool has been implemented to be functionally correct, but can benefit from a refactor to improve safety, performance and complexity (by avoiding synchronizing two collections).
NOTE: This PR is based on top of #1073. Only the final two commits comprise the new work in this PR.
Changes
BasicMempoolto only holding a single collection, there seemed little point to retaining it, so theMempoolnow just holds the naked priority queue.DoublePriorityQueueto aPriorityQueuesince we don't need the extra functionality, and the latter is slightly more performant.&selfrather than&mut self.RwLockis no longer locked and unlocked in a tight loop in theinsert_allandremove_allmethodsTransactionPriorityhas been updated to only hold the nonce diff. There was a subtle bug in the previous impl since the derivedPartialEqandEqdidn't correspond to the hand-rolled impls ofPartialOrdandOrd. This has been fixed and further tests added.SignedTransactionis internally held in anArcnow and passed in anArcwhen executing by the app to reduce the number of clones. We could potentially look to extend this across more of the sequencer code for the same reason (not in this PR)update_mempool_after_finalizationwas implemented, so that the mempool no longer has to expose a lock guard. I think it's generally much safer to not expose the lock or a guard on the lock in a non-private API. As well as moving the implementation inside mempool, I added a temporary in-mem cache of current account nonces, since it seems that there could be many txs all under the same account. As already noted, this method could be problematic due to holding the mempool lock for an extended duration, so this might reduce the risk.Testing
Unit tests extended/added.
Related Issues
Closes #1083.