Skip to content

Commit

Permalink
feat(mempool): implement remove from nonce for account transaction index
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadNassar1 committed Jul 11, 2024
1 parent 7ff6fc1 commit 2b907ba
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions crates/mempool/src/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,24 @@ impl AccountTransactionIndex {
fn get(&self, address: ContractAddress, nonce: Nonce) -> Option<&TransactionReference> {
self.0.get(&address)?.get(&nonce)
}

fn _remove_from_nonce(
&mut self,
address: ContractAddress,
nonce: Nonce,
) -> Vec<TransactionReference> {
if let Some(btree_map) = self.0.get_mut(&address) {
let nonces_to_remove: Vec<_> = btree_map.range(..=nonce).map(|(&n, _)| n).collect();
let txs: Vec<_> = nonces_to_remove.iter().filter_map(|n| btree_map.remove(n)).collect();

// Remove the entry from the HashMap if the BTreeMap is empty
if btree_map.is_empty() {
self.0.remove(&address);
}

txs
} else {
Vec::new()
}
}
}

0 comments on commit 2b907ba

Please sign in to comment.