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

feat(mempool): remove addresses of reverted transactions from queue in commit block method #508

Closed
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
14 changes: 12 additions & 2 deletions crates/mempool/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Mempool {
&mut self,
state_changes: HashMap<ContractAddress, AccountState>,
) -> MempoolResult<()> {
for (address, AccountState { nonce }) in state_changes {
for (&address, AccountState { nonce }) in &state_changes {
let next_nonce = nonce.try_increment().map_err(|_| MempoolError::FeltOutOfRange)?;

// Align the queue with the committed nonces.
Expand All @@ -96,13 +96,23 @@ impl Mempool {
}

if self.tx_queue.get_nonce(address).is_none() {
if let Some(tx) = self.tx_pool.get_by_address_and_nonce(address, nonce) {
if let Some(tx) = self.tx_pool.get_by_address_and_nonce(address, next_nonce) {
self.tx_queue.insert(*tx);
}
}

self.tx_pool.remove_up_to_nonce(address, next_nonce);
}

// Rewind nonces of addresses that were not included in block.
let addresses_not_included_in_block =
self.mempool_state.keys().filter(|&key| !state_changes.contains_key(key));
for address in addresses_not_included_in_block {
self.tx_queue.remove(*address);
}

self.mempool_state.clear();

Ok(())
}

Expand Down
Loading