Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(mempool): change align to account state func input to accoun… #969

Open
wants to merge 1 commit into
base: ayelet/mempool/account-state-refactor/remove-account-nonce
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/mempool/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand All @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
Loading