From 75d091bd3c26cea7d6dba0685942a69e76c662da Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Thu, 15 Feb 2018 10:57:32 -0700 Subject: [PATCH] More descriptive event data --- src/event.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/event.rs b/src/event.rs index 46a1388a7..a1a24d718 100644 --- a/src/event.rs +++ b/src/event.rs @@ -12,26 +12,30 @@ /// Though processing power varies across nodes, the network gives priority to the /// fastest processor. Duration should therefore be estimated by assuming that the hash /// was generated by the fastest processor at the time the entry was logged. -/// -/// When 'data' is None, the event represents a simple "tick", and exists for the +pub struct Event { + pub num_hashes: u64, + pub end_hash: u64, + pub data: EventData, +} + +/// When 'data' is Tick, the event represents a simple "tick", and exists for the /// sole purpose of improving the performance of event log verification. A tick can /// be generated in 'num_hashes' hashes and verified in 'num_hashes' hashes. By logging a hash alongside /// the tick, each tick and be verified in parallel using the 'end_hash' of the preceding /// tick to seed its hashing. -pub struct Event { - pub end_hash: u64, - pub num_hashes: u64, - pub data: Option, +pub enum EventData { + Tick, + UserDataKey(u64), } impl Event { /// Creates an Event from the number of hashes 'num_hashes' since the previous event /// and that resulting 'end_hash'. - pub fn new(end_hash: u64, num_hashes: u64) -> Self { - let data = None; + pub fn new(num_hashes: u64, end_hash: u64) -> Self { + let data = EventData::Tick; Event { - end_hash, num_hashes, + end_hash, data, } } @@ -51,7 +55,7 @@ impl Event { hash.hash(&mut hasher); hash = hasher.finish(); } - Self::new(hash, num_hashes) + Self::new(num_hashes, hash) } /// Verifies self.end_hash is the result of hashing a 'start_hash' 'self.num_hashes' times. ///