Skip to content

Commit

Permalink
chore(mempool): move a check in commit_block into a util (#2016)
Browse files Browse the repository at this point in the history
This is a prep. refactor for small diffs. in nonce abstraction feature.
  • Loading branch information
elintul authored Nov 13, 2024
1 parent 0a50fd8 commit e387fa2
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions crates/starknet_mempool/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,7 @@ impl Mempool {

// Align mempool data to committed nonces.
for (&address, &next_nonce) in &address_to_nonce {
// FIXME: Remove after first POC.
// If commit_block wants to decrease the stored account nonce this can mean one of two
// things:
// 1. this is a reorg, which should be handled by a dedicated TBD mechanism and not
// inside commit_block
// 2. the stored nonce originated from add_tx, so should be treated as tentative due
// to possible races with the gateway; these types of nonces should be tagged somehow
// so that commit_block can override them. Regardless, in the first POC this cannot
// happen because the GW nonces are always 1.
if let Some(&stored_nonce) = self.account_nonces.get(&address) {
assert!(stored_nonce <= next_nonce, "NOT SUPPORTED YET {address:?} {next_nonce:?}.")
}

self.validate_committed_nonce(address, next_nonce);
let account_state = AccountState { address, nonce: next_nonce };
self.align_to_account_state(account_state);
}
Expand Down Expand Up @@ -217,6 +205,21 @@ impl Mempool {
Ok(())
}

fn validate_committed_nonce(&self, address: ContractAddress, next_nonce: Nonce) {
// FIXME: Remove after first POC.
// If commit_block wants to decrease the stored account nonce this can mean one of two
// things:
// 1. this is a reorg, which should be handled by a dedicated TBD mechanism and not inside
// commit_block
// 2. the stored nonce originated from add_tx, so should be treated as tentative due
// to possible races with the gateway; these types of nonces should be tagged somehow
// so that commit_block can override them. Regardless, in the first POC this cannot
// happen because the GW nonces are always 1.
if let Some(&stored_nonce) = self.account_nonces.get(&address) {
assert!(stored_nonce <= next_nonce, "NOT SUPPORTED YET {address:?} {next_nonce:?}.")
}
}

fn enqueue_next_eligible_txs(&mut self, txs: &[TransactionReference]) -> MempoolResult<()> {
for tx in txs {
let current_account_state = AccountState { address: tx.address, nonce: tx.nonce };
Expand Down

0 comments on commit e387fa2

Please sign in to comment.