From 7777bdbdad167b75da0f1ba9eeaab4b37f5c182d Mon Sep 17 00:00:00 2001 From: Ayelet Zilber Date: Mon, 23 Sep 2024 14:58:55 +0300 Subject: [PATCH] refactor(mempool): change align to account state func input to account state --- crates/mempool/src/mempool.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/mempool/src/mempool.rs b/crates/mempool/src/mempool.rs index b82937213..01b68e13c 100644 --- a/crates/mempool/src/mempool.rs +++ b/crates/mempool/src/mempool.rs @@ -78,9 +78,9 @@ impl Mempool { /// TODO: check Account nonce and balance. pub fn add_tx(&mut self, input: MempoolInput) -> MempoolResult<()> { self.validate_input(&input)?; - let MempoolInput { tx, account: AccountState { sender_address, nonce } } = input; + let MempoolInput { tx, account: account_state } = input; self.tx_pool.insert(tx)?; - self.align_to_account_state(sender_address, nonce); + self.align_to_account_state(account_state); Ok(()) } @@ -96,7 +96,8 @@ impl Mempool { ) -> MempoolResult<()> { for (&address, nonce) in &state_changes { let next_nonce = nonce.try_increment().map_err(|_| MempoolError::FeltOutOfRange)?; - self.align_to_account_state(address, next_nonce); + let account_state = AccountState { sender_address: address, nonce: next_nonce }; + self.align_to_account_state(account_state); } // Rewind nonces of addresses that were not included in block. @@ -166,9 +167,8 @@ impl Mempool { Ok(()) } - // TODO: Consider creating an abstraction for the (address, nonce) tuple that is passed - // throughout the code. - fn align_to_account_state(&mut self, address: ContractAddress, nonce: Nonce) { + fn align_to_account_state(&mut self, account_state: AccountState) { + let AccountState { sender_address: address, nonce } = account_state; // Maybe remove out-of-date transactions. // Note: != is equivalent to > in `add_tx`, as lower nonces are rejected in validation. if self.tx_queue.get_nonce(address).is_some_and(|queued_nonce| queued_nonce != nonce) {