From 22e77c9485af4c9c5f9146a1223812397f1ed8eb Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Fri, 21 Sep 2018 10:50:07 -0600 Subject: [PATCH] Add a way of getting transaction errors out of the bank --- src/bank.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/bank.rs b/src/bank.rs index 16892a8660..8f2cee162e 100644 --- a/src/bank.rs +++ b/src/bank.rs @@ -17,7 +17,7 @@ use mint::Mint; use payment_plan::Payment; use signature::{Keypair, Pubkey, Signature}; use std; -use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; +use std::collections::{BTreeMap, HashMap, VecDeque}; use std::result; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::RwLock; @@ -125,7 +125,7 @@ pub struct Bank { /// Mapping of hashes to signature sets along with timestamp. The bank uses this data to /// reject transactions with signatures its seen before - last_ids_sigs: RwLock, u64)>>, + last_ids_sigs: RwLock>, u64)>>, /// The number of transactions the bank has processed without error since the /// start of the ledger. @@ -202,11 +202,14 @@ impl Bank { } /// Store the given signature. The bank will reject any transaction with the same signature. - fn reserve_signature(signatures: &mut HashSet, signature: &Signature) -> Result<()> { - if let Some(signature) = signatures.get(signature) { + fn reserve_signature( + signatures: &mut HashMap>, + signature: &Signature, + ) -> Result<()> { + if let Some(_result) = signatures.get(signature) { return Err(BankError::DuplicateSignature(*signature)); } - signatures.insert(*signature); + signatures.insert(*signature, Ok(())); Ok(()) } @@ -262,7 +265,7 @@ impl Bank { let id = last_ids.pop_front().unwrap(); last_ids_sigs.remove(&id); } - last_ids_sigs.insert(*last_id, (HashSet::new(), timestamp())); + last_ids_sigs.insert(*last_id, (HashMap::new(), timestamp())); last_ids.push_back(*last_id); } @@ -673,7 +676,7 @@ impl Bank { .read() .expect("'last_ids_sigs' read lock"); for (_hash, signatures) in last_ids_sigs.iter() { - if signatures.0.contains(signature) { + if signatures.0.contains_key(signature) { return true; } }