Fix names that are exact or effects depending on the list

This commit is contained in:
teor 2021-10-07 13:39:58 +10:00 committed by Deirdre Connolly
parent e470ed00e6
commit b6a60c6c17
4 changed files with 19 additions and 21 deletions

View File

@ -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<Request> 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) => {

View File

@ -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<MempoolError> {
/// This matches transactions based on each rejection list's matching rule.
pub fn rejection_error(&self, txid: &UnminedTxId) -> Option<MempoolError> {
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<UnminedTxId>,
) -> impl Iterator<Item = UnminedTxId> + '_ {
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())
}

View File

@ -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();
}

View File

@ -115,19 +115,17 @@ fn mempool_storage_basic_for_network(network: Network) -> Result<()> {
let all_ids: HashSet<UnminedTxId> = 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<UnminedTxId> = storage
.rejected_transactions_exact(all_ids)
.into_iter()
.collect();
let rejected_response: HashSet<UnminedTxId> =
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(())
}