From 957fb0667cfa24ca62f700e3f4a817a4e863b603 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Fri, 9 Mar 2018 06:55:08 -0700 Subject: [PATCH] Deterministic historian/accountant hashes When in tick-less mode, no longer continuously hash on the background thread. That mode is just used for testing and genesis log generation, and those extra hashes are just noise. Note that without the extra hashes, with lose the duration between events. Effectively, we distinguish proof-of-order from proof-of-time. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/historian.rs | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6676830bd0..a38d95457e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -355,7 +355,7 @@ dependencies = [ [[package]] name = "silk" -version = "0.3.2" +version = "0.3.3" dependencies = [ "bincode 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index f5d6b216df..58819fa2fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "silk" description = "A silky smooth implementation of the Loom architecture" -version = "0.3.2" +version = "0.3.3" documentation = "https://docs.rs/silk" homepage = "http://loomprotocol.com/" repository = "https://github.com/loomprotocol/silk" diff --git a/src/historian.rs b/src/historian.rs index 83e5b7bae5..6b6e02e934 100644 --- a/src/historian.rs +++ b/src/historian.rs @@ -48,8 +48,10 @@ impl Historian { if let Err(err) = logger.process_events(now, ms_per_tick) { return err; } - logger.last_id = hash(&logger.last_id); - logger.num_hashes += 1; + if ms_per_tick.is_some() { + logger.last_id = hash(&logger.last_id); + logger.num_hashes += 1; + } } }) } @@ -86,6 +88,10 @@ mod tests { let entry1 = hist.receiver.recv().unwrap(); let entry2 = hist.receiver.recv().unwrap(); + assert_eq!(entry0.num_hashes, 0); + assert_eq!(entry1.num_hashes, 0); + assert_eq!(entry2.num_hashes, 0); + drop(hist.sender); assert_eq!( hist.thread_hdl.join().unwrap(),