Startup log can reference IDs without itself
This commit is contained in:
@ -117,14 +117,28 @@ impl AccountantStub {
|
|||||||
self.socket
|
self.socket
|
||||||
.send_to(&data, &self.addr)
|
.send_to(&data, &self.addr)
|
||||||
.expect("buffer error");
|
.expect("buffer error");
|
||||||
|
let mut done = false;
|
||||||
|
while !done {
|
||||||
let resp = self.recv_response().expect("recv response");
|
let resp = self.recv_response().expect("recv response");
|
||||||
|
if let &Response::LastId { .. } = &resp {
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
self.process_response(resp);
|
self.process_response(resp);
|
||||||
|
}
|
||||||
ok(self.last_id.unwrap_or(Hash::default()))
|
ok(self.last_id.unwrap_or(Hash::default()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the number of transactions the server processed since creating
|
/// Return the number of transactions the server processed since creating
|
||||||
/// this stub instance.
|
/// 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
|
self.num_events
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,7 @@ fn main() {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("Parsing stdin...");
|
||||||
let demo: MintDemo = serde_json::from_reader(stdin()).unwrap_or_else(|e| {
|
let demo: MintDemo = serde_json::from_reader(stdin()).unwrap_or_else(|e| {
|
||||||
eprintln!("failed to parse json: {}", e);
|
eprintln!("failed to parse json: {}", e);
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -84,9 +85,11 @@ fn main() {
|
|||||||
|
|
||||||
let socket = UdpSocket::bind(&send_addr).unwrap();
|
let socket = UdpSocket::bind(&send_addr).unwrap();
|
||||||
let mut acc = AccountantStub::new(&addr, socket);
|
let mut acc = AccountantStub::new(&addr, socket);
|
||||||
println!("Get last id");
|
|
||||||
|
println!("Get last ID...");
|
||||||
let last_id = acc.get_last_id().wait().unwrap();
|
let last_id = acc.get_last_id().wait().unwrap();
|
||||||
|
|
||||||
|
println!("Creating keypairs...");
|
||||||
let txs = demo.users.len() / 2;
|
let txs = demo.users.len() / 2;
|
||||||
let keypairs: Vec<_> = demo.users
|
let keypairs: Vec<_> = demo.users
|
||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
@ -127,7 +130,6 @@ fn main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let mut tx_count = acc.transaction_count();
|
let mut tx_count = acc.transaction_count();
|
||||||
println!("tx count {}", tx_count);
|
|
||||||
let mut prev_tx_count = tx_count + 1;
|
let mut prev_tx_count = tx_count + 1;
|
||||||
|
|
||||||
println!("Waiting for the server to go idle...",);
|
println!("Waiting for the server to go idle...",);
|
||||||
@ -142,5 +144,5 @@ fn main() {
|
|||||||
let duration = now.elapsed();
|
let duration = now.elapsed();
|
||||||
let ns = duration.as_secs() * 1_000_000_000 + u64::from(duration.subsec_nanos());
|
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;
|
let tps = (txs * 1_000_000_000) as f64 / ns as f64;
|
||||||
println!("Done. If no packets dropped, {} tps", tps);
|
println!("Done. {} tps", tps);
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ fn main() {
|
|||||||
|
|
||||||
// The first item in the ledger is required to be an entry with zero num_hashes,
|
// 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.
|
// 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
|
// 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
|
// 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());
|
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;
|
let mut last_id = entry1.id;
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
last_id = entry.id;
|
last_id = entry.id;
|
||||||
acc.process_verified_events(entry.events).unwrap();
|
acc.process_verified_events(entry.events).unwrap();
|
||||||
|
acc.register_entry_id(&last_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
let historian = Historian::new(&last_id, Some(1000));
|
let historian = Historian::new(&last_id, Some(1000));
|
||||||
|
Reference in New Issue
Block a user