From b6a60c6c17d95e157b39a83d8e1fb4aa0b2fe22b Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 7 Oct 2021 13:39:58 +1000 Subject: [PATCH] Fix names that are exact or effects depending on the list --- zebrad/src/components/mempool.rs | 4 ++-- zebrad/src/components/mempool/storage.rs | 24 +++++++++---------- .../components/mempool/storage/tests/prop.rs | 2 +- .../mempool/storage/tests/vectors.rs | 10 ++++---- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/zebrad/src/components/mempool.rs b/zebrad/src/components/mempool.rs index e7d6fb3cc..86f8d44de 100644 --- a/zebrad/src/components/mempool.rs +++ b/zebrad/src/components/mempool.rs @@ -184,7 +184,7 @@ impl Mempool { if storage.contains_transaction_exact(&txid) { return Err(MempoolError::InMempool); } - if let Some(error) = storage.rejection_error_exact(&txid) { + if let Some(error) = storage.rejection_error(&txid) { return Err(error); } Ok(()) @@ -266,7 +266,7 @@ impl Service for Mempool { async move { Ok(Response::Transactions(res)) }.boxed() } Request::RejectedTransactionIds(ids) => { - let res = storage.rejected_transactions_exact(ids).collect(); + let res = storage.rejected_transactions(ids).collect(); async move { Ok(Response::RejectedTransactionIds(res)) }.boxed() } Request::Queue(gossiped_txs) => { diff --git a/zebrad/src/components/mempool/storage.rs b/zebrad/src/components/mempool/storage.rs index 1a5aac6ea..65c7273cf 100644 --- a/zebrad/src/components/mempool/storage.rs +++ b/zebrad/src/components/mempool/storage.rs @@ -78,7 +78,7 @@ impl Storage { let tx_id = tx.id; // First, check if we have a cached rejection for this transaction. - if let Some(error) = self.rejection_error_exact(&tx.id) { + if let Some(error) = self.rejection_error(&tx.id) { return Err(error); } @@ -214,11 +214,11 @@ impl Storage { self.rejected_exact.len() + self.rejected_same_effects.len() } - /// Returns `true` if a [`UnminedTx`] exactly matching an [`UnminedTxId`] is in - /// the mempool rejected list. + /// Returns `true` if a [`UnminedTx`] matching an [`UnminedTxId`] is in + /// any mempool rejected list. /// - /// This matches the exact transaction, with identical blockchain effects, signatures, and proofs. - pub fn rejection_error_exact(&self, txid: &UnminedTxId) -> Option { + /// This matches transactions based on each rejection list's matching rule. + pub fn rejection_error(&self, txid: &UnminedTxId) -> Option { if let Some(exact_error) = self.rejected_exact.get(txid) { return Some(exact_error.clone().into()); } @@ -230,23 +230,23 @@ impl Storage { None } - /// Returns the set of [`UnminedTxId`]s exactly matching ids in the rejected list. + /// Returns the set of [`UnminedTxId`]s matching `tx_ids` in the rejected list. /// - /// This matches the exact transaction, with identical blockchain effects, signatures, and proofs. - pub fn rejected_transactions_exact( + /// This matches transactions based on each rejection list's matching rule. + pub fn rejected_transactions( &self, tx_ids: HashSet, ) -> impl Iterator + '_ { tx_ids .into_iter() - .filter(move |txid| self.contains_rejected_exact(txid)) + .filter(move |txid| self.contains_rejected(txid)) } - /// Returns `true` if a [`UnminedTx`] exactly matching the supplied [`UnminedTxId`] is in + /// Returns `true` if a [`UnminedTx`] matching the supplied [`UnminedTxId`] is in /// the mempool rejected list. /// - /// This matches the exact transaction, with identical blockchain effects, signatures, and proofs. - pub fn contains_rejected_exact(&self, txid: &UnminedTxId) -> bool { + /// This matches transactions based on each rejection list's matching rule. + pub fn contains_rejected(&self, txid: &UnminedTxId) -> bool { self.rejected_exact.contains_key(txid) || self.rejected_same_effects.contains_key(&txid.mined_id()) } diff --git a/zebrad/src/components/mempool/storage/tests/prop.rs b/zebrad/src/components/mempool/storage/tests/prop.rs index afeaf508a..bcaf3f17d 100644 --- a/zebrad/src/components/mempool/storage/tests/prop.rs +++ b/zebrad/src/components/mempool/storage/tests/prop.rs @@ -45,7 +45,7 @@ proptest! { Err(MempoolError::StorageEffects(SameEffectsRejectionError::SpendConflict)) ); - assert!(storage.contains_rejected_exact(&id_to_reject)); + assert!(storage.contains_rejected(&id_to_reject)); storage.clear(); } diff --git a/zebrad/src/components/mempool/storage/tests/vectors.rs b/zebrad/src/components/mempool/storage/tests/vectors.rs index ea33b1ffa..3a38cece9 100644 --- a/zebrad/src/components/mempool/storage/tests/vectors.rs +++ b/zebrad/src/components/mempool/storage/tests/vectors.rs @@ -115,19 +115,17 @@ fn mempool_storage_basic_for_network(network: Network) -> Result<()> { let all_ids: HashSet = unmined_transactions.iter().map(|tx| tx.id).collect(); // Convert response to a `HashSet`, because the order of the response doesn't matter. - let rejected_response: HashSet = storage - .rejected_transactions_exact(all_ids) - .into_iter() - .collect(); + let rejected_response: HashSet = + storage.rejected_transactions(all_ids).into_iter().collect(); let rejected_ids = expected_to_be_rejected.iter().map(|tx| tx.id).collect(); assert_eq!(rejected_response, rejected_ids); // Make sure the first id stored is now rejected - assert!(storage.contains_rejected_exact(&expected_to_be_rejected[0].id)); + assert!(storage.contains_rejected(&expected_to_be_rejected[0].id)); // Make sure the last id stored is not rejected - assert!(!storage.contains_rejected_exact(&expected_in_mempool[0].id)); + assert!(!storage.contains_rejected(&expected_in_mempool[0].id)); Ok(()) }