diff --git a/src/entry.rs b/src/entry.rs index 127326260f..5737ee494b 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -32,9 +32,6 @@ pub type EntryReceiver = Receiver>; #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub struct Entry { - /// The the previous Entry ID. - pub prev_id: Hash, - /// tick height of the ledger, not including any tick implied by this Entry pub tick_height: u64, @@ -61,7 +58,6 @@ impl Entry { let entry = { if num_hashes == 0 && transactions.is_empty() { Entry { - prev_id: *prev_id, tick_height, num_hashes: 0, id: *prev_id, @@ -72,7 +68,6 @@ impl Entry { // next_hash will generate the next hash and set num_hashes == 1 let id = next_hash(prev_id, 1, &transactions); Entry { - prev_id: *prev_id, tick_height, num_hashes: 1, id, @@ -84,7 +79,6 @@ impl Entry { // and transactions = empty let id = next_hash(prev_id, num_hashes, &transactions); Entry { - prev_id: *prev_id, tick_height, num_hashes, id, @@ -122,9 +116,9 @@ impl Entry { pub fn serialized_size(transactions: &[Transaction]) -> u64 { let txs_size = serialized_size(transactions).unwrap(); - // tick_height+num_hashes + id+prev_id + txs + // tick_height+num_hashes + id + txs - (2 * size_of::() + 2 * size_of::()) as u64 + txs_size + (2 * size_of::() + size_of::()) as u64 + txs_size } pub fn num_will_fit(transactions: &[Transaction]) -> usize { @@ -180,21 +174,15 @@ impl Entry { /// since the previous transaction and that resulting `id`. #[cfg(test)] - pub fn new_tick(prev_id: &Hash, tick_height: u64, num_hashes: u64, id: &Hash) -> Self { + pub fn new_tick(tick_height: u64, num_hashes: u64, id: &Hash) -> Self { Entry { - prev_id: *prev_id, tick_height, - num_hashes, id: *id, transactions: vec![], } } - pub fn verify_self(&self) -> bool { - self.id == next_hash(&self.prev_id, self.num_hashes, &self.transactions) - } - /// Verifies self.id is the result of hashing a `start_hash` `self.num_hashes` times. /// If the transaction is not a Tick, then hash that as well. pub fn verify(&self, start_hash: &Hash) -> bool { @@ -260,7 +248,6 @@ pub fn reconstruct_entries_from_blobs(blobs: Vec) -> Result<(Vec) -> Entry { assert!(num_hashes > 0 || transactions.is_empty()); Entry { - prev_id: *prev_id, tick_height: 0, num_hashes, id: next_hash(prev_id, num_hashes, &transactions), @@ -283,10 +270,9 @@ mod tests { fn test_entry_verify() { let zero = Hash::default(); let one = hash(&zero.as_ref()); - assert!(Entry::new_tick(&zero, 0, 0, &zero).verify(&zero)); // base case, never used - assert!(!Entry::new_tick(&zero, 1, 0, &zero).verify(&one)); // base case, bad + assert!(Entry::new_tick(0, 0, &zero).verify(&zero)); // base case, never used + assert!(!Entry::new_tick(1, 0, &zero).verify(&one)); // base case, bad assert!(next_entry(&zero, 1, vec![]).verify(&zero)); // inductive step - assert!(next_entry(&zero, 1, vec![]).verify_self()); // also inductive step assert!(!next_entry(&zero, 1, vec![]).verify(&one)); // inductive step, bad } diff --git a/src/ledger.rs b/src/ledger.rs index 2d20a27eaa..b37b808fec 100644 --- a/src/ledger.rs +++ b/src/ledger.rs @@ -457,7 +457,6 @@ pub trait Block { impl Block for [Entry] { fn verify(&self, start_hash: &Hash) -> bool { let genesis = [Entry { - prev_id: *start_hash, tick_height: 0, num_hashes: 0, id: *start_hash, @@ -737,8 +736,8 @@ mod tests { let zero = Hash::default(); let one = hash(&zero.as_ref()); assert!(vec![][..].verify(&zero)); // base case - assert!(vec![Entry::new_tick(&zero, 0, 0, &zero)][..].verify(&zero)); // singleton case 1 - assert!(!vec![Entry::new_tick(&zero, 0, 0, &zero)][..].verify(&one)); // singleton case 2, bad + assert!(vec![Entry::new_tick(0, 0, &zero)][..].verify(&zero)); // singleton case 1 + assert!(!vec![Entry::new_tick(0, 0, &zero)][..].verify(&one)); // singleton case 2, bad assert!(vec![next_entry(&zero, 0, vec![]); 2][..].verify(&zero)); // inductive step let mut bad_ticks = vec![next_entry(&zero, 0, vec![]); 2]; @@ -808,7 +807,6 @@ mod tests { let tx_small_size = serialized_size(&tx_small).unwrap() as usize; let tx_large_size = serialized_size(&tx_large).unwrap() as usize; let entry_size = serialized_size(&Entry { - prev_id: Hash::default(), tick_height: 0, num_hashes: 0, id: Hash::default(), diff --git a/src/poh.rs b/src/poh.rs index 58d73b767a..26d9b4decf 100644 --- a/src/poh.rs +++ b/src/poh.rs @@ -3,7 +3,6 @@ use solana_sdk::hash::{hash, hashv, Hash}; pub struct Poh { - prev_id: Hash, id: Hash, num_hashes: u64, pub tick_height: u64, @@ -11,7 +10,6 @@ pub struct Poh { #[derive(Debug)] pub struct PohEntry { - pub prev_id: Hash, pub tick_height: u64, pub num_hashes: u64, pub id: Hash, @@ -19,11 +17,10 @@ pub struct PohEntry { } impl Poh { - pub fn new(prev_id: Hash, tick_height: u64) -> Self { + pub fn new(id: Hash, tick_height: u64) -> Self { Poh { - prev_id, num_hashes: 0, - id: prev_id, + id, tick_height, } } @@ -36,14 +33,10 @@ impl Poh { pub fn record(&mut self, mixin: Hash) -> PohEntry { self.id = hashv(&[&self.id.as_ref(), &mixin.as_ref()]); - let prev_id = self.prev_id; - self.prev_id = self.id; - let num_hashes = self.num_hashes + 1; self.num_hashes = 0; PohEntry { - prev_id, tick_height: self.tick_height, num_hashes, id: self.id, @@ -59,14 +52,10 @@ impl Poh { let num_hashes = self.num_hashes; self.num_hashes = 0; - let prev_id = self.prev_id; - self.prev_id = self.id; - let tick_height = self.tick_height; self.tick_height += 1; PohEntry { - prev_id, tick_height, num_hashes, id: self.id, @@ -77,20 +66,19 @@ impl Poh { #[cfg(test)] pub fn verify(initial: Hash, entries: &[PohEntry]) -> bool { - let mut prev_id = initial; + let mut id = initial; for entry in entries { assert!(entry.num_hashes != 0); - assert!(prev_id == entry.prev_id); for _ in 1..entry.num_hashes { - prev_id = hash(&prev_id.as_ref()); + id = hash(&id.as_ref()); } - prev_id = match entry.mixin { - Some(mixin) => hashv(&[&prev_id.as_ref(), &mixin.as_ref()]), - None => hash(&prev_id.as_ref()), + id = match entry.mixin { + Some(mixin) => hashv(&[&id.as_ref(), &mixin.as_ref()]), + None => hash(&id.as_ref()), }; - if prev_id != entry.id { + if id != entry.id { return false; } } @@ -109,7 +97,6 @@ mod tests { poh::verify( Hash::default(), &[PohEntry { - prev_id: Hash::default(), tick_height: 0, num_hashes: 0, id: Hash::default(), diff --git a/src/poh_recorder.rs b/src/poh_recorder.rs index b948cd942f..cb0636f805 100644 --- a/src/poh_recorder.rs +++ b/src/poh_recorder.rs @@ -89,7 +89,6 @@ impl PohRecorder { let entry = 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 entry = Entry { - prev_id: entry.prev_id, tick_height: entry.tick_height, num_hashes: entry.num_hashes, id: entry.id, @@ -102,7 +101,6 @@ impl PohRecorder { fn register_and_send_tick(&self, poh: &mut Poh) -> Result<()> { let tick = poh.tick(); let tick = Entry { - prev_id: tick.prev_id, tick_height: tick.tick_height, num_hashes: tick.num_hashes, id: tick.id,