From e387fa2be2ea87dd93fd43f7f8c946c705dc0ecd Mon Sep 17 00:00:00 2001 From: Elin Date: Wed, 13 Nov 2024 14:29:46 +0200 Subject: [PATCH] chore(mempool): move a check in `commit_block` into a util (#2016) This is a prep. refactor for small diffs. in nonce abstraction feature. --- crates/starknet_mempool/src/mempool.rs | 29 ++++++++++++++------------ 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/crates/starknet_mempool/src/mempool.rs b/crates/starknet_mempool/src/mempool.rs index 60f46826c7..8a5d5e0e4b 100644 --- a/crates/starknet_mempool/src/mempool.rs +++ b/crates/starknet_mempool/src/mempool.rs @@ -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); } @@ -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 };