diff --git a/src/accountant.rs b/src/accountant.rs index a214aa419..d97e20673 100644 --- a/src/accountant.rs +++ b/src/accountant.rs @@ -69,9 +69,9 @@ impl Accountant { to: mint.pubkey(), tokens: mint.tokens, }; - let acc = Self::new_from_deposit(&deposit); - acc.register_entry_id(&mint.last_id()); - acc + let accountant = Self::new_from_deposit(&deposit); + accountant.register_entry_id(&mint.last_id()); + accountant } /// Return the last entry ID registered @@ -339,24 +339,26 @@ mod tests { fn test_accountant() { let alice = Mint::new(10_000); let bob_pubkey = KeyPair::new().pubkey(); - let acc = Accountant::new(&alice); - assert_eq!(acc.last_id(), alice.last_id()); + let accountant = Accountant::new(&alice); + assert_eq!(accountant.last_id(), alice.last_id()); - acc.transfer(1_000, &alice.keypair(), bob_pubkey, alice.last_id()) + accountant + .transfer(1_000, &alice.keypair(), bob_pubkey, alice.last_id()) .unwrap(); - assert_eq!(acc.get_balance(&bob_pubkey).unwrap(), 1_000); + assert_eq!(accountant.get_balance(&bob_pubkey).unwrap(), 1_000); - acc.transfer(500, &alice.keypair(), bob_pubkey, alice.last_id()) + accountant + .transfer(500, &alice.keypair(), bob_pubkey, alice.last_id()) .unwrap(); - assert_eq!(acc.get_balance(&bob_pubkey).unwrap(), 1_500); + assert_eq!(accountant.get_balance(&bob_pubkey).unwrap(), 1_500); } #[test] fn test_account_not_found() { let mint = Mint::new(1); - let acc = Accountant::new(&mint); + let accountant = Accountant::new(&mint); assert_eq!( - acc.transfer(1, &KeyPair::new(), mint.pubkey(), mint.last_id()), + accountant.transfer(1, &KeyPair::new(), mint.pubkey(), mint.last_id()), Err(AccountingError::AccountNotFound) ); } @@ -364,141 +366,156 @@ mod tests { #[test] fn test_invalid_transfer() { let alice = Mint::new(11_000); - let acc = Accountant::new(&alice); + let accountant = Accountant::new(&alice); let bob_pubkey = KeyPair::new().pubkey(); - acc.transfer(1_000, &alice.keypair(), bob_pubkey, alice.last_id()) + accountant + .transfer(1_000, &alice.keypair(), bob_pubkey, alice.last_id()) .unwrap(); assert_eq!( - acc.transfer(10_001, &alice.keypair(), bob_pubkey, alice.last_id()), + accountant.transfer(10_001, &alice.keypair(), bob_pubkey, alice.last_id()), Err(AccountingError::InsufficientFunds) ); let alice_pubkey = alice.keypair().pubkey(); - assert_eq!(acc.get_balance(&alice_pubkey).unwrap(), 10_000); - assert_eq!(acc.get_balance(&bob_pubkey).unwrap(), 1_000); + assert_eq!(accountant.get_balance(&alice_pubkey).unwrap(), 10_000); + assert_eq!(accountant.get_balance(&bob_pubkey).unwrap(), 1_000); } #[test] fn test_transfer_to_newb() { let alice = Mint::new(10_000); - let acc = Accountant::new(&alice); + let accountant = Accountant::new(&alice); let alice_keypair = alice.keypair(); let bob_pubkey = KeyPair::new().pubkey(); - acc.transfer(500, &alice_keypair, bob_pubkey, alice.last_id()) + accountant + .transfer(500, &alice_keypair, bob_pubkey, alice.last_id()) .unwrap(); - assert_eq!(acc.get_balance(&bob_pubkey).unwrap(), 500); + assert_eq!(accountant.get_balance(&bob_pubkey).unwrap(), 500); } #[test] fn test_transfer_on_date() { let alice = Mint::new(1); - let acc = Accountant::new(&alice); + let accountant = Accountant::new(&alice); let alice_keypair = alice.keypair(); let bob_pubkey = KeyPair::new().pubkey(); let dt = Utc::now(); - acc.transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.last_id()) + accountant + .transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.last_id()) .unwrap(); // Alice's balance will be zero because all funds are locked up. - assert_eq!(acc.get_balance(&alice.pubkey()), Some(0)); + assert_eq!(accountant.get_balance(&alice.pubkey()), Some(0)); // Bob's balance will be None because the funds have not been // sent. - assert_eq!(acc.get_balance(&bob_pubkey), None); + assert_eq!(accountant.get_balance(&bob_pubkey), None); // Now, acknowledge the time in the condition occurred and // that bob's funds are now available. - acc.process_verified_timestamp(alice.pubkey(), dt).unwrap(); - assert_eq!(acc.get_balance(&bob_pubkey), Some(1)); + accountant + .process_verified_timestamp(alice.pubkey(), dt) + .unwrap(); + assert_eq!(accountant.get_balance(&bob_pubkey), Some(1)); - acc.process_verified_timestamp(alice.pubkey(), dt).unwrap(); // <-- Attack! Attempt to process completed transaction. - assert_ne!(acc.get_balance(&bob_pubkey), Some(2)); + accountant + .process_verified_timestamp(alice.pubkey(), dt) + .unwrap(); // <-- Attack! Attempt to process completed transaction. + assert_ne!(accountant.get_balance(&bob_pubkey), Some(2)); } #[test] fn test_transfer_after_date() { let alice = Mint::new(1); - let acc = Accountant::new(&alice); + let accountant = Accountant::new(&alice); let alice_keypair = alice.keypair(); let bob_pubkey = KeyPair::new().pubkey(); let dt = Utc::now(); - acc.process_verified_timestamp(alice.pubkey(), dt).unwrap(); - - // It's now past now, so this transfer should be processed immediately. - acc.transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.last_id()) + accountant + .process_verified_timestamp(alice.pubkey(), dt) .unwrap(); - assert_eq!(acc.get_balance(&alice.pubkey()), Some(0)); - assert_eq!(acc.get_balance(&bob_pubkey), Some(1)); + // It's now past now, so this transfer should be processed immediately. + accountant + .transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.last_id()) + .unwrap(); + + assert_eq!(accountant.get_balance(&alice.pubkey()), Some(0)); + assert_eq!(accountant.get_balance(&bob_pubkey), Some(1)); } #[test] fn test_cancel_transfer() { let alice = Mint::new(1); - let acc = Accountant::new(&alice); + let accountant = Accountant::new(&alice); let alice_keypair = alice.keypair(); let bob_pubkey = KeyPair::new().pubkey(); let dt = Utc::now(); - let sig = acc.transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.last_id()) + let sig = accountant + .transfer_on_date(1, &alice_keypair, bob_pubkey, dt, alice.last_id()) .unwrap(); // Alice's balance will be zero because all funds are locked up. - assert_eq!(acc.get_balance(&alice.pubkey()), Some(0)); + assert_eq!(accountant.get_balance(&alice.pubkey()), Some(0)); // Bob's balance will be None because the funds have not been // sent. - assert_eq!(acc.get_balance(&bob_pubkey), None); + assert_eq!(accountant.get_balance(&bob_pubkey), None); // Now, cancel the trancaction. Alice gets her funds back, Bob never sees them. - acc.process_verified_sig(alice.pubkey(), sig).unwrap(); - assert_eq!(acc.get_balance(&alice.pubkey()), Some(1)); - assert_eq!(acc.get_balance(&bob_pubkey), None); + accountant + .process_verified_sig(alice.pubkey(), sig) + .unwrap(); + assert_eq!(accountant.get_balance(&alice.pubkey()), Some(1)); + assert_eq!(accountant.get_balance(&bob_pubkey), None); - acc.process_verified_sig(alice.pubkey(), sig).unwrap(); // <-- Attack! Attempt to cancel completed transaction. - assert_ne!(acc.get_balance(&alice.pubkey()), Some(2)); + accountant + .process_verified_sig(alice.pubkey(), sig) + .unwrap(); // <-- Attack! Attempt to cancel completed transaction. + assert_ne!(accountant.get_balance(&alice.pubkey()), Some(2)); } #[test] fn test_duplicate_event_signature() { let alice = Mint::new(1); - let acc = Accountant::new(&alice); + let accountant = Accountant::new(&alice); let sig = Signature::default(); - assert!(acc.reserve_signature_with_last_id(&sig, &alice.last_id())); - assert!(!acc.reserve_signature_with_last_id(&sig, &alice.last_id())); + assert!(accountant.reserve_signature_with_last_id(&sig, &alice.last_id())); + assert!(!accountant.reserve_signature_with_last_id(&sig, &alice.last_id())); } #[test] fn test_forget_signature() { let alice = Mint::new(1); - let acc = Accountant::new(&alice); + let accountant = Accountant::new(&alice); let sig = Signature::default(); - acc.reserve_signature_with_last_id(&sig, &alice.last_id()); - assert!(acc.forget_signature_with_last_id(&sig, &alice.last_id())); - assert!(!acc.forget_signature_with_last_id(&sig, &alice.last_id())); + accountant.reserve_signature_with_last_id(&sig, &alice.last_id()); + assert!(accountant.forget_signature_with_last_id(&sig, &alice.last_id())); + assert!(!accountant.forget_signature_with_last_id(&sig, &alice.last_id())); } #[test] fn test_max_entry_ids() { let alice = Mint::new(1); - let acc = Accountant::new(&alice); + let accountant = Accountant::new(&alice); let sig = Signature::default(); for i in 0..MAX_ENTRY_IDS { let last_id = hash(&serialize(&i).unwrap()); // Unique hash - acc.register_entry_id(&last_id); + accountant.register_entry_id(&last_id); } // Assert we're no longer able to use the oldest entry ID. - assert!(!acc.reserve_signature_with_last_id(&sig, &alice.last_id())); + assert!(!accountant.reserve_signature_with_last_id(&sig, &alice.last_id())); } #[test] fn test_debits_before_credits() { let mint = Mint::new(2); - let acc = Accountant::new(&mint); + let accountant = Accountant::new(&mint); let alice = KeyPair::new(); let tr0 = Transaction::new(&mint.keypair(), alice.pubkey(), 2, mint.last_id()); let tr1 = Transaction::new(&alice, mint.pubkey(), 1, mint.last_id()); let trs = vec![tr0, tr1]; - assert!(acc.process_verified_transactions(trs)[1].is_err()); + assert!(accountant.process_verified_transactions(trs)[1].is_err()); } } @@ -514,7 +531,7 @@ mod bench { #[bench] fn process_verified_event_bench(bencher: &mut Bencher) { let mint = Mint::new(100_000_000); - let acc = Accountant::new(&mint); + let accountant = Accountant::new(&mint); // Create transactions between unrelated parties. let transactions: Vec<_> = (0..4096) .into_par_iter() @@ -522,15 +539,15 @@ mod bench { // Seed the 'from' account. let rando0 = KeyPair::new(); let tr = Transaction::new(&mint.keypair(), rando0.pubkey(), 1_000, mint.last_id()); - acc.process_verified_transaction(&tr).unwrap(); + accountant.process_verified_transaction(&tr).unwrap(); // Seed the 'to' account and a cell for its signature. let last_id = hash(&serialize(&i).unwrap()); // Unique hash - acc.register_entry_id(&last_id); + accountant.register_entry_id(&last_id); let rando1 = KeyPair::new(); let tr = Transaction::new(&rando0, rando1.pubkey(), 1, last_id); - acc.process_verified_transaction(&tr).unwrap(); + accountant.process_verified_transaction(&tr).unwrap(); // Finally, return a transaction that's unique Transaction::new(&rando0, rando1.pubkey(), 1, last_id) @@ -538,12 +555,13 @@ mod bench { .collect(); bencher.iter(|| { // Since benchmarker runs this multiple times, we need to clear the signatures. - for sigs in acc.last_ids.read().unwrap().iter() { + for sigs in accountant.last_ids.read().unwrap().iter() { sigs.1.write().unwrap().clear(); } assert!( - acc.process_verified_transactions(transactions.clone()) + accountant + .process_verified_transactions(transactions.clone()) .iter() .all(|x| x.is_ok()) ); diff --git a/src/accounting_stage.rs b/src/accounting_stage.rs index ecf134527..746c44a09 100644 --- a/src/accounting_stage.rs +++ b/src/accounting_stage.rs @@ -13,21 +13,21 @@ use std::sync::{Arc, Mutex}; pub struct AccountingStage { pub output: Mutex>, entry_sender: Mutex>, - pub acc: Arc, + pub accountant: Arc, historian_input: Mutex>, historian: Mutex, } impl AccountingStage { /// Create a new Tpu that wraps the given Accountant. - pub fn new(acc: Accountant, start_hash: &Hash, ms_per_tick: Option) -> Self { + pub fn new(accountant: Accountant, start_hash: &Hash, ms_per_tick: Option) -> Self { let (historian_input, event_receiver) = channel(); let historian = Historian::new(event_receiver, start_hash, ms_per_tick); let (entry_sender, output) = channel(); AccountingStage { output: Mutex::new(output), entry_sender: Mutex::new(entry_sender), - acc: Arc::new(acc), + accountant: Arc::new(accountant), historian_input: Mutex::new(historian_input), historian: Mutex::new(historian), } @@ -36,14 +36,14 @@ impl AccountingStage { /// Process the transactions in parallel and then log the successful ones. pub fn process_events(&self, events: Vec) -> Result<()> { let historian = self.historian.lock().unwrap(); - let results = self.acc.process_verified_events(events); + let results = self.accountant.process_verified_events(events); let events = results.into_iter().filter_map(|x| x.ok()).collect(); let sender = self.historian_input.lock().unwrap(); sender.send(Signal::Events(events))?; // Wait for the historian to tag our Events with an ID and then register it. let entry = historian.output.lock().unwrap().recv()?; - self.acc.register_entry_id(&entry.id); + self.accountant.register_entry_id(&entry.id); self.entry_sender.lock().unwrap().send(entry)?; Ok(()) } @@ -65,8 +65,8 @@ mod tests { // differently if either the server doesn't signal the ledger to add an // Entry OR if the verifier tries to parallelize across multiple Entries. let mint = Mint::new(2); - let acc = Accountant::new(&mint); - let accounting_stage = AccountingStage::new(acc, &mint.last_id(), None); + let accountant = Accountant::new(&mint); + let accounting_stage = AccountingStage::new(accountant, &mint.last_id(), None); // Process a batch that includes a transaction that receives two tokens. let alice = KeyPair::new(); @@ -86,15 +86,16 @@ mod tests { // Assert the user holds one token, not two. If the server only output one // entry, then the second transaction will be rejected, because it drives // the account balance below zero before the credit is added. - let acc = Accountant::new(&mint); + let accountant = Accountant::new(&mint); for entry in entries { assert!( - acc.process_verified_events(entry.events) + accountant + .process_verified_events(entry.events) .into_iter() .all(|x| x.is_ok()) ); } - assert_eq!(acc.get_balance(&alice.pubkey()), Some(1)); + assert_eq!(accountant.get_balance(&alice.pubkey()), Some(1)); } } @@ -118,7 +119,7 @@ mod bench { #[bench] fn process_events_bench(_bencher: &mut Bencher) { let mint = Mint::new(100_000_000); - let acc = Accountant::new(&mint); + let accountant = Accountant::new(&mint); // Create transactions between unrelated parties. let txs = 100_000; let last_ids: Mutex> = Mutex::new(HashSet::new()); @@ -132,18 +133,18 @@ mod bench { let mut last_ids = last_ids.lock().unwrap(); if !last_ids.contains(&last_id) { last_ids.insert(last_id); - acc.register_entry_id(&last_id); + accountant.register_entry_id(&last_id); } } // Seed the 'from' account. let rando0 = KeyPair::new(); let tr = Transaction::new(&mint.keypair(), rando0.pubkey(), 1_000, last_id); - acc.process_verified_transaction(&tr).unwrap(); + accountant.process_verified_transaction(&tr).unwrap(); let rando1 = KeyPair::new(); let tr = Transaction::new(&rando0, rando1.pubkey(), 2, last_id); - acc.process_verified_transaction(&tr).unwrap(); + accountant.process_verified_transaction(&tr).unwrap(); // Finally, return a transaction that's unique Transaction::new(&rando0, rando1.pubkey(), 1, last_id) @@ -156,7 +157,7 @@ mod bench { .collect(); let (input, event_receiver) = channel(); - let accounting_stage = AccountingStage::new(acc, &mint.last_id(), None); + let accounting_stage = AccountingStage::new(accountant, &mint.last_id(), None); let now = Instant::now(); assert!(accounting_stage.process_events(events).is_ok()); diff --git a/src/bin/client-demo.rs b/src/bin/client-demo.rs index 013e02930..a1a5dee7d 100644 --- a/src/bin/client-demo.rs +++ b/src/bin/client-demo.rs @@ -87,10 +87,10 @@ fn main() { println!("Binding to {}", client_addr); let socket = UdpSocket::bind(&client_addr).unwrap(); socket.set_read_timeout(Some(Duration::new(5, 0))).unwrap(); - let mut acc = ThinClient::new(addr.parse().unwrap(), socket); + let mut accountant = ThinClient::new(addr.parse().unwrap(), socket); println!("Get last ID..."); - let last_id = acc.get_last_id().wait().unwrap(); + let last_id = accountant.get_last_id().wait().unwrap(); println!("Got last ID {:?}", last_id); println!("Creating keypairs..."); @@ -117,7 +117,7 @@ fn main() { nsps / 1_000_f64 ); - let initial_tx_count = acc.transaction_count(); + let initial_tx_count = accountant.transaction_count(); println!("initial count {}", initial_tx_count); println!("Transfering {} transactions in {} batches", txs, threads); @@ -129,16 +129,16 @@ fn main() { let mut client_addr: SocketAddr = client_addr.parse().unwrap(); client_addr.set_port(0); let socket = UdpSocket::bind(client_addr).unwrap(); - let acc = ThinClient::new(addr.parse().unwrap(), socket); + let accountant = ThinClient::new(addr.parse().unwrap(), socket); for tr in trs { - acc.transfer_signed(tr.clone()).unwrap(); + accountant.transfer_signed(tr.clone()).unwrap(); } }); println!("Waiting for transactions to complete...",); let mut tx_count; for _ in 0..10 { - tx_count = acc.transaction_count(); + tx_count = accountant.transaction_count(); duration = now.elapsed(); let txs = tx_count - initial_tx_count; println!("Transactions processed {}", txs); diff --git a/src/bin/testnode.rs b/src/bin/testnode.rs index bea72d561..bb0a81743 100644 --- a/src/bin/testnode.rs +++ b/src/bin/testnode.rs @@ -94,28 +94,28 @@ fn main() { eprintln!("creating accountant..."); - let acc = Accountant::new_from_deposit(&deposit.unwrap()); - acc.register_entry_id(&entry0.id); - acc.register_entry_id(&entry1.id); + let accountant = Accountant::new_from_deposit(&deposit.unwrap()); + accountant.register_entry_id(&entry0.id); + accountant.register_entry_id(&entry1.id); eprintln!("processing entries..."); let mut last_id = entry1.id; for entry in entries { last_id = entry.id; - let results = acc.process_verified_events(entry.events); + let results = accountant.process_verified_events(entry.events); for result in results { if let Err(e) = result { eprintln!("failed to process event {:?}", e); exit(1); } } - acc.register_entry_id(&last_id); + accountant.register_entry_id(&last_id); } eprintln!("creating networking stack..."); - let accounting_stage = AccountingStage::new(acc, &last_id, Some(1000)); + let accounting_stage = AccountingStage::new(accountant, &last_id, Some(1000)); let exit = Arc::new(AtomicBool::new(false)); let tpu = Arc::new(Tpu::new(accounting_stage)); let serve_sock = UdpSocket::bind(&serve_addr).unwrap(); diff --git a/src/thin_client.rs b/src/thin_client.rs index ad6ac2ace..4db2056c1 100644 --- a/src/thin_client.rs +++ b/src/thin_client.rs @@ -179,24 +179,26 @@ mod tests { ); let alice = Mint::new(10_000); - let acc = Accountant::new(&alice); + let accountant = Accountant::new(&alice); let bob_pubkey = KeyPair::new().pubkey(); let exit = Arc::new(AtomicBool::new(false)); - let accounting_stage = AccountingStage::new(acc, &alice.last_id(), Some(30)); - let acc = Arc::new(Tpu::new(accounting_stage)); - let threads = Tpu::serve(&acc, d, serve, skinny, gossip, exit.clone(), sink()).unwrap(); + let accounting_stage = AccountingStage::new(accountant, &alice.last_id(), Some(30)); + let accountant = Arc::new(Tpu::new(accounting_stage)); + let threads = + Tpu::serve(&accountant, d, serve, skinny, gossip, exit.clone(), sink()).unwrap(); sleep(Duration::from_millis(300)); let socket = UdpSocket::bind("0.0.0.0:0").unwrap(); - let mut acc = ThinClient::new(addr, socket); - let last_id = acc.get_last_id().wait().unwrap(); - let _sig = acc.transfer(500, &alice.keypair(), bob_pubkey, &last_id) + let mut accountant = ThinClient::new(addr, socket); + let last_id = accountant.get_last_id().wait().unwrap(); + let _sig = accountant + .transfer(500, &alice.keypair(), bob_pubkey, &last_id) .unwrap(); let mut balance; let now = Instant::now(); loop { - balance = acc.get_balance(&bob_pubkey); + balance = accountant.get_balance(&bob_pubkey); if balance.is_ok() { break; } @@ -215,10 +217,10 @@ mod tests { fn test_bad_sig() { let (leader_data, leader_gossip, _, leader_serve, leader_skinny) = tpu::test_node(); let alice = Mint::new(10_000); - let acc = Accountant::new(&alice); + let accountant = Accountant::new(&alice); let bob_pubkey = KeyPair::new().pubkey(); let exit = Arc::new(AtomicBool::new(false)); - let accounting_stage = AccountingStage::new(acc, &alice.last_id(), Some(30)); + let accounting_stage = AccountingStage::new(accountant, &alice.last_id(), Some(30)); let tpu = Arc::new(Tpu::new(accounting_stage)); let serve_addr = leader_serve.local_addr().unwrap(); let threads = Tpu::serve( @@ -286,14 +288,14 @@ mod tests { let exit = Arc::new(AtomicBool::new(false)); let leader_acc = { - let acc = Accountant::new(&alice); - let accounting_stage = AccountingStage::new(acc, &alice.last_id(), Some(30)); + let accountant = Accountant::new(&alice); + let accounting_stage = AccountingStage::new(accountant, &alice.last_id(), Some(30)); Arc::new(Tpu::new(accounting_stage)) }; let replicant_acc = { - let acc = Accountant::new(&alice); - let accounting_stage = AccountingStage::new(acc, &alice.last_id(), Some(30)); + let accountant = Accountant::new(&alice); + let accounting_stage = AccountingStage::new(accountant, &alice.last_id(), Some(30)); Arc::new(Tpu::new(accounting_stage)) }; @@ -358,14 +360,15 @@ mod tests { let socket = UdpSocket::bind("0.0.0.0:0").unwrap(); socket.set_read_timeout(Some(Duration::new(1, 0))).unwrap(); - let mut acc = ThinClient::new(leader.0.serve_addr, socket); + let mut accountant = ThinClient::new(leader.0.serve_addr, socket); info!("getting leader last_id"); - let last_id = acc.get_last_id().wait().unwrap(); + let last_id = accountant.get_last_id().wait().unwrap(); info!("executing leader transer"); - let _sig = acc.transfer(500, &alice.keypair(), bob_pubkey, &last_id) + let _sig = accountant + .transfer(500, &alice.keypair(), bob_pubkey, &last_id) .unwrap(); info!("getting leader balance"); - acc.get_balance(&bob_pubkey).unwrap() + accountant.get_balance(&bob_pubkey).unwrap() }; assert_eq!(leader_balance, 500); //verify replicant has the same balance @@ -374,9 +377,9 @@ mod tests { let socket = UdpSocket::bind("0.0.0.0:0").unwrap(); socket.set_read_timeout(Some(Duration::new(1, 0))).unwrap(); - let mut acc = ThinClient::new(replicant.0.serve_addr, socket); + let mut accountant = ThinClient::new(replicant.0.serve_addr, socket); info!("getting replicant balance"); - if let Ok(bal) = acc.get_balance(&bob_pubkey) { + if let Ok(bal) = accountant.get_balance(&bob_pubkey) { replicant_balance = bal; } info!("replicant balance {}", replicant_balance); diff --git a/src/thin_client_service.rs b/src/thin_client_service.rs index 6c87608e0..df46b15b1 100644 --- a/src/thin_client_service.rs +++ b/src/thin_client_service.rs @@ -14,18 +14,18 @@ use transaction::Transaction; pub struct ThinClientService { //pub output: Mutex>, //response_sender: Mutex>, - pub acc: Arc, + accountant: Arc, entry_info_subscribers: Mutex>, } impl ThinClientService { /// Create a new Tpu that wraps the given Accountant. - pub fn new(acc: Arc) -> Self { + pub fn new(accountant: Arc) -> Self { //let (response_sender, output) = channel(); ThinClientService { //output: Mutex::new(output), //response_sender: Mutex::new(response_sender), - acc, + accountant, entry_info_subscribers: Mutex::new(vec![]), } } @@ -38,7 +38,7 @@ impl ThinClientService { ) -> Option<(Response, SocketAddr)> { match msg { Request::GetBalance { key } => { - let val = self.acc.get_balance(&key); + let val = self.accountant.get_balance(&key); let rsp = (Response::Balance { key, val }, rsp_addr); info!("Response::Balance {:?}", rsp); Some(rsp) diff --git a/src/tpu.rs b/src/tpu.rs index 950bafc4e..502c90cd5 100644 --- a/src/tpu.rs +++ b/src/tpu.rs @@ -39,7 +39,7 @@ type SharedTpu = Arc; impl Tpu { /// Create a new Tpu that wraps the given Accountant. pub fn new(accounting_stage: AccountingStage) -> Self { - let thin_client_service = ThinClientService::new(accounting_stage.acc.clone()); + let thin_client_service = ThinClientService::new(accounting_stage.accountant.clone()); Tpu { accounting_stage, thin_client_service, @@ -48,7 +48,7 @@ impl Tpu { fn update_entry(obj: &Tpu, writer: &Mutex, entry: &Entry) { trace!("update_entry entry"); - obj.accounting_stage.acc.register_entry_id(&entry.id); + obj.accounting_stage.accountant.register_entry_id(&entry.id); writeln!( writer.lock().unwrap(), "{}", @@ -153,12 +153,12 @@ impl Tpu { } fn thin_client_service( - acc: Arc, + accountant: Arc, exit: Arc, socket: UdpSocket, ) -> JoinHandle<()> { spawn(move || loop { - let _ = Self::process_thin_client_requests(&acc, &socket); + let _ = Self::process_thin_client_requests(&accountant, &socket); if exit.load(Ordering::Relaxed) { info!("sync_service exiting"); break; @@ -378,10 +378,10 @@ impl Tpu { for msgs in &blobs { let blob = msgs.read().unwrap(); let entries: Vec = deserialize(&blob.data()[..blob.meta.size]).unwrap(); - let acc = &obj.accounting_stage.acc; + let accountant = &obj.accounting_stage.accountant; for entry in entries { - acc.register_entry_id(&entry.id); - for result in acc.process_verified_events(entry.events) { + accountant.register_entry_id(&entry.id); + for result in accountant.process_verified_events(entry.events) { result?; } } @@ -463,8 +463,11 @@ impl Tpu { Mutex::new(writer), ); - let t_skinny = - Self::thin_client_service(obj.accounting_stage.acc.clone(), exit.clone(), skinny); + let t_skinny = Self::thin_client_service( + obj.accounting_stage.accountant.clone(), + exit.clone(), + skinny, + ); let tpu = obj.clone(); let t_server = spawn(move || loop { @@ -787,8 +790,8 @@ mod tests { let starting_balance = 10_000; let alice = Mint::new(starting_balance); - let acc = Accountant::new(&alice); - let accounting_stage = AccountingStage::new(acc, &alice.last_id(), Some(30)); + let accountant = Accountant::new(&alice); + let accounting_stage = AccountingStage::new(accountant, &alice.last_id(), Some(30)); let tpu = Arc::new(Tpu::new(accounting_stage)); let replicate_addr = target1_data.replicate_addr; let threads = Tpu::replicate( @@ -814,11 +817,11 @@ mod tests { w.set_index(i).unwrap(); w.set_id(leader_id).unwrap(); - let acc = &tpu.accounting_stage.acc; + let accountant = &tpu.accounting_stage.accountant; let tr0 = Event::new_timestamp(&bob_keypair, Utc::now()); let entry0 = entry::create_entry(&cur_hash, i, vec![tr0]); - acc.register_entry_id(&cur_hash); + accountant.register_entry_id(&cur_hash); cur_hash = hash(&cur_hash); let tr1 = Transaction::new( @@ -827,11 +830,11 @@ mod tests { transfer_amount, cur_hash, ); - acc.register_entry_id(&cur_hash); + accountant.register_entry_id(&cur_hash); cur_hash = hash(&cur_hash); let entry1 = entry::create_entry(&cur_hash, i + num_blobs, vec![Event::Transaction(tr1)]); - acc.register_entry_id(&cur_hash); + accountant.register_entry_id(&cur_hash); cur_hash = hash(&cur_hash); alice_ref_balance -= transfer_amount; @@ -856,11 +859,11 @@ mod tests { msgs.push(msg); } - let acc = &tpu.accounting_stage.acc; - let alice_balance = acc.get_balance(&alice.keypair().pubkey()).unwrap(); + let accountant = &tpu.accounting_stage.accountant; + let alice_balance = accountant.get_balance(&alice.keypair().pubkey()).unwrap(); assert_eq!(alice_balance, alice_ref_balance); - let bob_balance = acc.get_balance(&bob_keypair.pubkey()).unwrap(); + let bob_balance = accountant.get_balance(&bob_keypair.pubkey()).unwrap(); assert_eq!(bob_balance, starting_balance - alice_ref_balance); exit.store(true, Ordering::Relaxed);