Rename UserDataKey to Discovery
From the perspective of the log, when some data's hash is added, that data is "discovered" by the historian. Another event might be a "claim" that some signed data belongs to the owner of a public key.
This commit is contained in:
parent
afb830c91f
commit
29a607427d
|
@ -37,7 +37,7 @@ use std::sync::mpsc::SendError;
|
|||
|
||||
fn create_log(hist: &Historian) -> Result<(), SendError<Event>> {
|
||||
sleep(Duration::from_millis(15));
|
||||
hist.sender.send(Event::UserDataKey(Sha256Hash::default()))?;
|
||||
hist.sender.send(Event::Discovery(Sha256Hash::default()))?;
|
||||
sleep(Duration::from_millis(10));
|
||||
Ok(())
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ Running the program should produce a log similar to:
|
|||
|
||||
```rust
|
||||
Entry { num_hashes: 0, end_hash: [0, ...], event: Tick }
|
||||
Entry { num_hashes: 2, end_hash: [67, ...], event: UserDataKey(3735928559) }
|
||||
Entry { num_hashes: 2, end_hash: [67, ...], event: Discovery(3735928559) }
|
||||
Entry { num_hashes: 3, end_hash: [123, ...], event: Tick }
|
||||
```
|
||||
|
||||
|
|
|
@ -4,10 +4,10 @@ msc {
|
|||
logger=>historian [ label = "e0 = Entry{hash: h0, n: 0, event: Tick}" ] ;
|
||||
logger=>logger [ label = "h1 = hash(h0)" ] ;
|
||||
logger=>logger [ label = "h2 = hash(h1)" ] ;
|
||||
client=>historian [ label = "UserData(d0)" ] ;
|
||||
historian=>logger [ label = "UserData(d0)" ] ;
|
||||
client=>historian [ label = "Discovery(d0)" ] ;
|
||||
historian=>logger [ label = "Discovery(d0)" ] ;
|
||||
logger=>logger [ label = "h3 = hash(h2 + d0)" ] ;
|
||||
logger=>historian [ label = "e1 = Entry{hash: hash(h3), n: 2, event: UserData(d0)}" ] ;
|
||||
logger=>historian [ label = "e1 = Entry{hash: hash(h3), n: 2, event: Discovery(d0)}" ] ;
|
||||
logger=>logger [ label = "h4 = hash(h3)" ] ;
|
||||
logger=>logger [ label = "h5 = hash(h4)" ] ;
|
||||
logger=>logger [ label = "h6 = hash(h5)" ] ;
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::sync::mpsc::SendError;
|
|||
|
||||
fn create_log(hist: &Historian) -> Result<(), SendError<Event>> {
|
||||
sleep(Duration::from_millis(15));
|
||||
hist.sender.send(Event::UserDataKey(Sha256Hash::default()))?;
|
||||
hist.sender.send(Event::Discovery(Sha256Hash::default()))?;
|
||||
sleep(Duration::from_millis(10));
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ fn log_event(
|
|||
end_hash: &mut Sha256Hash,
|
||||
event: Event,
|
||||
) -> Result<(), (Entry, ExitReason)> {
|
||||
if let Event::UserDataKey(key) = event {
|
||||
if let Event::Discovery(key) = event {
|
||||
*end_hash = extend_and_hash(end_hash, &key);
|
||||
}
|
||||
let entry = Entry {
|
||||
|
@ -139,7 +139,7 @@ mod tests {
|
|||
|
||||
hist.sender.send(Event::Tick).unwrap();
|
||||
sleep(Duration::new(0, 1_000_000));
|
||||
hist.sender.send(Event::UserDataKey(zero)).unwrap();
|
||||
hist.sender.send(Event::Discovery(zero)).unwrap();
|
||||
sleep(Duration::new(0, 1_000_000));
|
||||
hist.sender.send(Event::Tick).unwrap();
|
||||
|
||||
|
@ -173,7 +173,7 @@ mod tests {
|
|||
let zero = Sha256Hash::default();
|
||||
let hist = Historian::new(&zero, Some(20));
|
||||
sleep(Duration::from_millis(30));
|
||||
hist.sender.send(Event::UserDataKey(zero)).unwrap();
|
||||
hist.sender.send(Event::Discovery(zero)).unwrap();
|
||||
sleep(Duration::from_millis(15));
|
||||
drop(hist.sender);
|
||||
assert_eq!(
|
||||
|
|
14
src/log.rs
14
src/log.rs
|
@ -32,7 +32,7 @@ pub struct Entry {
|
|||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||
pub enum Event {
|
||||
Tick,
|
||||
UserDataKey(Sha256Hash),
|
||||
Discovery(Sha256Hash),
|
||||
}
|
||||
|
||||
impl Entry {
|
||||
|
@ -47,7 +47,7 @@ impl Entry {
|
|||
}
|
||||
|
||||
/// Verifies self.end_hash is the result of hashing a 'start_hash' 'self.num_hashes' times.
|
||||
/// If the event is a UserDataKey, then hash that as well.
|
||||
/// If the event is not a Tick, then hash that as well.
|
||||
pub fn verify(self: &Self, start_hash: &Sha256Hash) -> bool {
|
||||
self.end_hash == next_hash(start_hash, self.num_hashes, &self.event)
|
||||
}
|
||||
|
@ -72,8 +72,8 @@ pub fn next_hash(start_hash: &Sha256Hash, num_hashes: u64, event: &Event) -> Sha
|
|||
for _ in 0..num_hashes {
|
||||
end_hash = hash(&end_hash);
|
||||
}
|
||||
if let Event::UserDataKey(key) = *event {
|
||||
return extend_and_hash(&end_hash, &key);
|
||||
if let Event::Discovery(data) = *event {
|
||||
return extend_and_hash(&end_hash, &data);
|
||||
}
|
||||
end_hash
|
||||
}
|
||||
|
@ -169,9 +169,9 @@ mod tests {
|
|||
let zero = Sha256Hash::default();
|
||||
let one = hash(&zero);
|
||||
|
||||
// First, verify UserData events
|
||||
// First, verify Discovery events
|
||||
let mut end_hash = zero;
|
||||
let events = [Event::UserDataKey(zero), Event::UserDataKey(one)];
|
||||
let events = [Event::Discovery(zero), Event::Discovery(one)];
|
||||
let mut entries: Vec<Entry> = events
|
||||
.iter()
|
||||
.map(|event| {
|
||||
|
@ -182,7 +182,7 @@ mod tests {
|
|||
.collect();
|
||||
assert!(verify_slice(&entries, &zero)); // inductive step
|
||||
|
||||
// Next, swap only two UserData events and ensure verification fails.
|
||||
// Next, swap two Discovery events and ensure verification fails.
|
||||
let event0 = entries[0].event.clone();
|
||||
let event1 = entries[1].event.clone();
|
||||
entries[0].event = event1;
|
||||
|
|
Loading…
Reference in New Issue