More descriptive event data
This commit is contained in:
24
src/event.rs
24
src/event.rs
@ -12,26 +12,30 @@
|
|||||||
/// Though processing power varies across nodes, the network gives priority to the
|
/// Though processing power varies across nodes, the network gives priority to the
|
||||||
/// fastest processor. Duration should therefore be estimated by assuming that the hash
|
/// 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.
|
/// was generated by the fastest processor at the time the entry was logged.
|
||||||
///
|
pub struct Event {
|
||||||
/// When 'data' is None, the event represents a simple "tick", and exists for the
|
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
|
/// 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
|
/// 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
|
/// the tick, each tick and be verified in parallel using the 'end_hash' of the preceding
|
||||||
/// tick to seed its hashing.
|
/// tick to seed its hashing.
|
||||||
pub struct Event {
|
pub enum EventData {
|
||||||
pub end_hash: u64,
|
Tick,
|
||||||
pub num_hashes: u64,
|
UserDataKey(u64),
|
||||||
pub data: Option<u64>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Event {
|
impl Event {
|
||||||
/// Creates an Event from the number of hashes 'num_hashes' since the previous event
|
/// Creates an Event from the number of hashes 'num_hashes' since the previous event
|
||||||
/// and that resulting 'end_hash'.
|
/// and that resulting 'end_hash'.
|
||||||
pub fn new(end_hash: u64, num_hashes: u64) -> Self {
|
pub fn new(num_hashes: u64, end_hash: u64) -> Self {
|
||||||
let data = None;
|
let data = EventData::Tick;
|
||||||
Event {
|
Event {
|
||||||
end_hash,
|
|
||||||
num_hashes,
|
num_hashes,
|
||||||
|
end_hash,
|
||||||
data,
|
data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,7 +55,7 @@ impl Event {
|
|||||||
hash.hash(&mut hasher);
|
hash.hash(&mut hasher);
|
||||||
hash = hasher.finish();
|
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.
|
/// Verifies self.end_hash is the result of hashing a 'start_hash' 'self.num_hashes' times.
|
||||||
///
|
///
|
||||||
|
Reference in New Issue
Block a user