Add mempool::Storage::remove()

Resolves #2738
This commit is contained in:
Deirdre Connolly 2021-09-09 22:29:57 -04:00
parent eff4f8720c
commit c03d1c156b
2 changed files with 10 additions and 13 deletions

View File

@ -1,7 +1,4 @@
use std::{
collections::{HashMap, HashSet, VecDeque},
hash::Hash,
};
use std::collections::{HashMap, HashSet, VecDeque};
use zebra_chain::{
block,
@ -106,12 +103,12 @@ impl Storage {
// `retain()` removes it and returns `Some(UnminedTx)`. If it's not
// present and nothing changes, returns `None`.
return match self.verified.binary_search_by_key(txid, |&tx| tx.id.hash()) {
Ok(tx) => {
self.verified.retain(|x| &x.id != txid);
Some(tx)
return match self.verified.clone().iter().find(|tx| &tx.id == txid) {
Some(tx) => {
self.verified.retain(|tx| &tx.id != txid);
Some(tx.clone())
}
Err(e) => None,
None => None,
};
}

View File

@ -16,16 +16,16 @@ fn mempool_storage_crud_mainnet() {
let mut storage: Storage = Default::default();
// Get transactions from the first 10 blocks of the Zcash blockchain
let (total_transactions, unmined_transactions) = unmined_transactions_in_blocks(10, network);
let (_, unmined_transactions) = unmined_transactions_in_blocks(10, network);
// Get one (1) unmined transaction
let unmined_tx = unmined_transactions[0];
let unmined_tx = &unmined_transactions[0];
// Insert unmined tx into the mempool.
storage.insert(unmined_tx);
let _ = storage.insert(unmined_tx.clone());
// Check that it is in the mempool, and not rejected.
assert!(storage.contains(&unmined_tx.id));
assert!(storage.clone().contains(&unmined_tx.id));
// Remove tx
let _ = storage.remove(&unmined_tx.id);