More descriptive event data
This commit is contained in:
parent
d21ad9357c
commit
75d091bd3c
24
src/event.rs
24
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<u64>,
|
||||
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.
|
||||
///
|
||||
|
|
Loading…
Reference in New Issue