diff --git a/src/accountant_stub.rs b/src/accountant_stub.rs index 9c7c410497..e23c1c3851 100644 --- a/src/accountant_stub.rs +++ b/src/accountant_stub.rs @@ -117,14 +117,28 @@ impl AccountantStub { self.socket .send_to(&data, &self.addr) .expect("buffer error"); - let resp = self.recv_response().expect("recv response"); - self.process_response(resp); + let mut done = false; + while !done { + let resp = self.recv_response().expect("recv response"); + if let &Response::LastId { .. } = &resp { + done = true; + } + self.process_response(resp); + } ok(self.last_id.unwrap_or(Hash::default())) } /// Return the number of transactions the server processed since creating /// this stub instance. - pub fn transaction_count(&self) -> u64 { + pub fn transaction_count(&mut self) -> u64 { + self.socket.set_nonblocking(true).expect("set nonblocking"); + loop { + match self.recv_response() { + Err(_) => break, + Ok(resp) => self.process_response(resp), + } + } + self.socket.set_nonblocking(false).expect("set blocking"); self.num_events } } diff --git a/src/bin/client-demo.rs b/src/bin/client-demo.rs index 831d2521b5..57bf01b297 100644 --- a/src/bin/client-demo.rs +++ b/src/bin/client-demo.rs @@ -77,6 +77,7 @@ fn main() { exit(1); } + println!("Parsing stdin..."); let demo: MintDemo = serde_json::from_reader(stdin()).unwrap_or_else(|e| { eprintln!("failed to parse json: {}", e); exit(1); @@ -84,9 +85,11 @@ fn main() { let socket = UdpSocket::bind(&send_addr).unwrap(); let mut acc = AccountantStub::new(&addr, socket); - println!("Get last id"); + + println!("Get last ID..."); let last_id = acc.get_last_id().wait().unwrap(); + println!("Creating keypairs..."); let txs = demo.users.len() / 2; let keypairs: Vec<_> = demo.users .into_par_iter() @@ -127,7 +130,6 @@ fn main() { }); let mut tx_count = acc.transaction_count(); - println!("tx count {}", tx_count); let mut prev_tx_count = tx_count + 1; println!("Waiting for the server to go idle...",); @@ -142,5 +144,5 @@ fn main() { let duration = now.elapsed(); let ns = duration.as_secs() * 1_000_000_000 + u64::from(duration.subsec_nanos()); let tps = (txs * 1_000_000_000) as f64 / ns as f64; - println!("Done. If no packets dropped, {} tps", tps); + println!("Done. {} tps", tps); } diff --git a/src/bin/testnode.rs b/src/bin/testnode.rs index 4c34a3a27e..8b6da2c1c8 100644 --- a/src/bin/testnode.rs +++ b/src/bin/testnode.rs @@ -72,7 +72,7 @@ fn main() { // The first item in the ledger is required to be an entry with zero num_hashes, // which implies its id can be used as the ledger's seed. - entries.next().unwrap(); + let entry0 = entries.next().unwrap(); // The second item in the ledger is a special transaction where the to and from // fields are the same. That entry should be treated as a deposit, not a @@ -85,11 +85,14 @@ fn main() { }; let acc = Accountant::new_from_deposit(&deposit.unwrap()); + acc.register_entry_id(&entry0.id); + acc.register_entry_id(&entry1.id); let mut last_id = entry1.id; for entry in entries { last_id = entry.id; acc.process_verified_events(entry.events).unwrap(); + acc.register_entry_id(&last_id); } let historian = Historian::new(&last_id, Some(1000));