feat(sequencer): various updates to mempool PR#1349
Conversation
| let mut all = self.all.write().await; | ||
| let mut pending = self.pending.write().await; | ||
| let mut parked = self.parked.write().await; | ||
| let (mut pending, mut parked) = join!(self.pending.write(), self.parked.write()); |
There was a problem hiding this comment.
Is there a possibility of deadlock here? I'm thinking if two threads calls this (or one of the other holding joins) at the same time, what happens if one thread gets the pending lock and the other the parked lock and then they just both squat on the locks? I tried reading into the join! macro more but it didn't seem to say what would happen
There was a problem hiding this comment.
Good call - it could indeed deadlock! I'll revert these join! calls.
| drop(parked); | ||
| for ttx in to_promote { | ||
| if let Err(error) = pending.add(ttx, current_account_nonce) { | ||
| error!( |
There was a problem hiding this comment.
Out of curiosity, where to these error logs go? Like do we track them anywhere?
| let tx1_replacement = mock_tx(1, &signing_key, "test"); | ||
| assert_eq!( | ||
| mempool | ||
| .insert(tx1_replacement.clone(), 0) | ||
| .await | ||
| .unwrap_err(), | ||
| InsertionError::AlreadyPresent, |
There was a problem hiding this comment.
To preserve the original assert intent:
| let tx1_replacement = mock_tx(1, &signing_key, "test"); | |
| assert_eq!( | |
| mempool | |
| .insert(tx1_replacement.clone(), 0) | |
| .await | |
| .unwrap_err(), | |
| InsertionError::AlreadyPresent, | |
| let tx1_replacement = mock_tx(1, &signing_key, "test_0"); | |
| assert_eq!( | |
| mempool | |
| .insert(tx1_replacement.clone(), 0) | |
| .await | |
| .unwrap_err(), | |
| InsertionError::NonceTaken, |
|
This LGTM! Going to merge in to make the discussed changes to the current nonce checks and promotion logic |
Summary
This is effectively an update to the existing PR #1323.
Background
While reviewing #1323, it seemed more expedient to open a PR against it rather than adding many GH comments (this was discussed with @Lilyjjo).
As always, there are more changes here than I initially expected. The main thrust of the changes was to try and use the type system to avoid certain classes of errors, and to make things a little more canonical where possible.
Changes
PendingTransactionsForAccount,PendingTransactions,ParkedTransactionsForAccountandParkedTransactions. For the ones dealing with a single account, much of their logic is common, so a traitTransactionsForAccountwas introduced to express that shared logic. For the ones dealing with collection of accounts' txs, a struct was introduced:TransactionsContainergeneric over the type of the account-specific containerT: TransactionsForAccount. This allowed for the shared logic to be expressed on the generic impl, with methods which are only relevant to pending being added to only that specialization, and similarly for the parked impl.Mempool::allandTransactionContainer::all)RwLocksTesting
Example of running
cargo bench -qp astria-sequenceron my Ryzen 7900X