Skip to content

Commit

Permalink
feat(sequencer): implement basic app side mempool with nonce ordering (
Browse files Browse the repository at this point in the history
…#1000)

## Summary
implement a basic app side mempool with nonce ordering. 

the mempool works as follows:
- when a tx passes `check_tx`, it's inserted into the mempool. if a tx
fails `check_tx` it's removed from the mempool (if it was in it already)
- during `prepare_proposal`, txs passed in from cometbft are ignored,
and txs are popped from the app's mempool instead.
- after a block is finalized, any included txs are removed from the
mempool, and the priorities of the txs remaining are updated.
- txs in the mempool are ordered by nonce, specifically the differential
between the tx nonce and the current account nonce. the lower the
differential, the higher the priority. for example, a tx with nonce 7
sent from an account with nonce 7 is a higher priority than a tx with
nonce 1 sent from an account with nonce 0.

question (maybe for a follow up): there is no reason for a non-validator
node to have the app-side mempool, as it doesn't gossip. should we make
a config flag to enable/disable it?

## Background
- cometbft mempool is too opaque, doesn't know about app-specific
ordering, should only be used for tx gossip
- will help with the sequencer api (can return pending nonce for an
account)
- can use for fee-based ordering or tx expiry time in the future

## Changes
- implementation of a basic nonce-ordered mempool
- update `App` to use this mempool (see summary for how it works)
- updated `App` to have separate functions for executing txs in prepare
vs process proposal, as the functionality of the two was diverging too
much
- update the `mempool` service to also use the mempool in `check_tx`

## Testing
unit tests

## Related Issues

closes #856
  • Loading branch information
noot authored May 4, 2024
1 parent 3654816 commit c3a3021
Show file tree
Hide file tree
Showing 11 changed files with 703 additions and 125 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/astria-core/src/protocol/transaction/v1alpha1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ impl SignedTransaction {
pub fn unsigned_transaction(&self) -> &UnsignedTransaction {
&self.transaction
}

#[must_use]
pub fn nonce(&self) -> u32 {
self.transaction.params.nonce
}
}

#[derive(Clone, Debug)]
Expand Down
1 change: 1 addition & 0 deletions crates/astria-sequencer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ telemetry = { package = "astria-telemetry", path = "../astria-telemetry", featur
anyhow = "1"
borsh = { version = "1", features = ["derive"] }
matchit = "0.7.2"
priority-queue = "2.0.2"
tower = "0.4"
tower-abci = "0.12.0"
tower-actor = "0.1.0"
Expand Down
Loading

0 comments on commit c3a3021

Please sign in to comment.