diff --git a/src/entry.rs b/src/entry.rs index ac2228510c..47f4952ee1 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -218,9 +218,9 @@ fn next_hash(start_hash: &Hash, num_hashes: u64, transactions: &[Transaction]) - } if transactions.is_empty() { - poh.tick().id + poh.tick().hash } else { - poh.record(Transaction::hash(transactions)).id + poh.record(Transaction::hash(transactions)).hash } } diff --git a/src/poh.rs b/src/poh.rs index 1b47208799..8f9b7ab03b 100644 --- a/src/poh.rs +++ b/src/poh.rs @@ -1,9 +1,9 @@ -//! The `Poh` module provides an object for generating a Proof of History. +//! The `Poh` module provhashes an object for generating a Proof of History. //! It records Hashes items on behalf of its users. use solana_sdk::hash::{hash, hashv, Hash}; pub struct Poh { - pub id: Hash, + pub hash: Hash, num_hashes: u64, pub tick_height: u64, } @@ -12,26 +12,26 @@ pub struct Poh { pub struct PohEntry { pub tick_height: u64, pub num_hashes: u64, - pub id: Hash, + pub hash: Hash, pub mixin: Option, } impl Poh { - pub fn new(id: Hash, tick_height: u64) -> Self { + pub fn new(hash: Hash, tick_height: u64) -> Self { Poh { num_hashes: 0, - id, + hash, tick_height, } } pub fn hash(&mut self) { - self.id = hash(&self.id.as_ref()); + self.hash = hash(&self.hash.as_ref()); self.num_hashes += 1; } pub fn record(&mut self, mixin: Hash) -> PohEntry { - self.id = hashv(&[&self.id.as_ref(), &mixin.as_ref()]); + self.hash = hashv(&[&self.hash.as_ref(), &mixin.as_ref()]); let num_hashes = self.num_hashes + 1; self.num_hashes = 0; @@ -39,13 +39,13 @@ impl Poh { PohEntry { tick_height: self.tick_height, num_hashes, - id: self.id, + hash: self.hash, mixin: Some(mixin), } } // emissions of Ticks (i.e. PohEntries without a mixin) allows - // validators to parallelize the work of catching up + // valhashators to parallelize the work of catching up pub fn tick(&mut self) -> PohEntry { self.hash(); @@ -56,27 +56,27 @@ impl Poh { PohEntry { tick_height: self.tick_height, num_hashes, - id: self.id, + hash: self.hash, mixin: None, } } } #[cfg(test)] -pub fn verify(initial: Hash, entries: &[PohEntry]) -> bool { - let mut id = initial; +pub fn verify(initial_hash: Hash, entries: &[PohEntry]) -> bool { + let mut current_hash = initial_hash; for entry in entries { assert!(entry.num_hashes != 0); for _ in 1..entry.num_hashes { - id = hash(&id.as_ref()); + current_hash = hash(¤t_hash.as_ref()); } - id = match entry.mixin { - Some(mixin) => hashv(&[&id.as_ref(), &mixin.as_ref()]), - None => hash(&id.as_ref()), + current_hash = match entry.mixin { + Some(mixin) => hashv(&[¤t_hash.as_ref(), &mixin.as_ref()]), + None => hash(¤t_hash.as_ref()), }; - if id != entry.id { + if current_hash != entry.hash { return false; } } @@ -111,7 +111,7 @@ mod tests { &[PohEntry { tick_height: 0, num_hashes: 1, - id: one, + hash: one, mixin: None, }], ), @@ -123,7 +123,7 @@ mod tests { &[PohEntry { tick_height: 0, num_hashes: 2, - id: two, + hash: two, mixin: None, }] ), @@ -136,7 +136,7 @@ mod tests { &[PohEntry { tick_height: 0, num_hashes: 1, - id: one_with_zero, + hash: one_with_zero, mixin: Some(zero), }] ), @@ -148,7 +148,7 @@ mod tests { &[PohEntry { tick_height: 0, num_hashes: 1, - id: zero, + hash: zero, mixin: None }] ), @@ -162,13 +162,13 @@ mod tests { PohEntry { tick_height: 0, num_hashes: 1, - id: one_with_zero, + hash: one_with_zero, mixin: Some(zero), }, PohEntry { tick_height: 0, num_hashes: 1, - id: hash(&one_with_zero.as_ref()), + hash: hash(&one_with_zero.as_ref()), mixin: None }, ] @@ -185,7 +185,7 @@ mod tests { &[PohEntry { tick_height: 0, num_hashes: 0, - id: Hash::default(), + hash: Hash::default(), mixin: None, }], ); diff --git a/src/poh_recorder.rs b/src/poh_recorder.rs index 48474acc5d..13893804e0 100644 --- a/src/poh_recorder.rs +++ b/src/poh_recorder.rs @@ -56,7 +56,7 @@ impl PohRecorder { let mut cache = vec![]; info!( "reset poh from: {},{} to: {},{}", - self.poh.id, self.poh.tick_height, last_id, tick_height, + self.poh.hash, self.poh.tick_height, last_id, tick_height, ); std::mem::swap(&mut cache, &mut self.tick_cache); self.poh = Poh::new(last_id, tick_height); @@ -158,17 +158,17 @@ impl PohRecorder { .working_bank .as_ref() .ok_or(Error::PohRecorderError(PohRecorderError::MaxHeightReached))?; - let entry = self.poh.record(mixin); + let poh_entry = self.poh.record(mixin); assert!(!txs.is_empty(), "Entries without transactions are used to track real-time passing in the ledger and can only be generated with PohRecorder::tick function"); let recorded_entry = Entry { - num_hashes: entry.num_hashes, - hash: entry.id, + num_hashes: poh_entry.num_hashes, + hash: poh_entry.hash, transactions: txs, }; trace!("sending entry {}", recorded_entry.is_tick()); working_bank .sender - .send(vec![(recorded_entry, entry.tick_height)])?; + .send(vec![(recorded_entry, poh_entry.tick_height)])?; Ok(()) } @@ -178,7 +178,7 @@ impl PohRecorder { ( Entry { num_hashes: tick.num_hashes, - hash: tick.id, + hash: tick.hash, transactions: vec![], }, tick.tick_height,