Skip to content

Commit

Permalink
feat(mempool): implement remove from nonce for account transaction in…
Browse files Browse the repository at this point in the history
…dex (#443)
  • Loading branch information
MohammadNassar1 authored Jul 23, 2024
1 parent 088ce7f commit bd34515
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions crates/mempool/src/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,25 @@ impl AccountTransactionIndex {
fn get(&self, address: ContractAddress, nonce: Nonce) -> Option<&TransactionReference> {
self.0.get(&address)?.get(&nonce)
}

fn _remove_up_to_nonce(
&mut self,
address: ContractAddress,
nonce: Nonce,
) -> Vec<TransactionReference> {
let Some(account_txs) = self.0.get_mut(&address) else {
return Vec::default();
};

// Split the transactions at the given nonce.
let txs_with_higher_or_equal_nonce = account_txs.split_off(&nonce);
let txs_with_lower_nonce = std::mem::replace(account_txs, txs_with_higher_or_equal_nonce);

if account_txs.is_empty() {
self.0.remove(&address);
}

// Collect and return the transactions with lower nonces.
txs_with_lower_nonce.into_values().collect()
}
}

0 comments on commit bd34515

Please sign in to comment.