Skip to content

Commit

Permalink
feat(mempool): remove addresses of reverted transactions from queue i…
Browse files Browse the repository at this point in the history
…n commit block method
  • Loading branch information
MohammadNassar1 committed Jul 23, 2024
1 parent c67cc0a commit addf42e
Showing 1 changed file with 12 additions and 2 deletions.
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.iter() {
let next_nonce = nonce.try_increment().map_err(|_| MempoolError::FeltOutOfRange)?;
// Dequeue transactions from the queue in the following cases:
// 1. Remove a transaction from queue with nonce lower and eq than those committed to
Expand All @@ -100,7 +100,17 @@ impl Mempool {
// TODO: remove the transactions from the tx_pool.
}
// TODO: update the tx_queue with the new state changes.
todo!()

// Iterate over the mempool state and remove any addresses from the transaction queue
// that do not appear in state_changes, as they were not included in the block.
for address in self.mempool_state.keys() {
if !state_changes.contains_key(address) {
self.tx_queue.remove(*address);
}
}
self.mempool_state.clear();

Ok(())
}

fn insert_tx(&mut self, input: MempoolInput) -> MempoolResult<()> {
Expand Down

0 comments on commit addf42e

Please sign in to comment.