Remove Entry::tick_height field

This commit is contained in:
Michael Vines 2019-02-19 22:18:57 -08:00
parent 9848de6cda
commit 8d38c2f800
8 changed files with 28 additions and 51 deletions

View File

@ -433,7 +433,7 @@ mod tests {
// Start off the ledger with the psuedo-tick linked to the genesis block // Start off the ledger with the psuedo-tick linked to the genesis block
// (see entry0 in `process_ledger`) // (see entry0 in `process_ledger`)
let tick = Entry::new(&genesis_block.last_id(), 0, 1, vec![]); let tick = Entry::new(&genesis_block.last_id(), 1, vec![]);
let mut hash = tick.id; let mut hash = tick.id;
entries.push(tick); entries.push(tick);
@ -444,7 +444,7 @@ mod tests {
let mut e = next_entries(&hash, 0, txs); let mut e = next_entries(&hash, 0, txs);
entries.append(&mut e); entries.append(&mut e);
hash = entries.last().unwrap().id; hash = entries.last().unwrap().id;
let tick = Entry::new(&hash, 0, num_hashes, vec![]); let tick = Entry::new(&hash, num_hashes, vec![]);
hash = tick.id; hash = tick.id;
last_id = hash; last_id = hash;
entries.push(tick); entries.push(tick);
@ -532,7 +532,7 @@ mod tests {
// Start off the ledger with the psuedo-tick linked to the genesis block // Start off the ledger with the psuedo-tick linked to the genesis block
// (see entry0 in `process_ledger`) // (see entry0 in `process_ledger`)
let tick = Entry::new(&genesis_block.last_id(), 0, 1, vec![]); let tick = Entry::new(&genesis_block.last_id(), 1, vec![]);
let mut hash = tick.id; let mut hash = tick.id;
entries.push(tick); entries.push(tick);
@ -540,7 +540,7 @@ mod tests {
// Transfer one token from the mint to a random account // Transfer one token from the mint to a random account
let keypair = Keypair::new(); let keypair = Keypair::new();
let tx = SystemTransaction::new_account(mint_keypair, keypair.pubkey(), 1, last_id, 0); let tx = SystemTransaction::new_account(mint_keypair, keypair.pubkey(), 1, last_id, 0);
let entry = Entry::new(&hash, 0, 1, vec![tx]); let entry = Entry::new(&hash, 1, vec![tx]);
hash = entry.id; hash = entry.id;
entries.push(entry); entries.push(entry);
@ -548,12 +548,12 @@ mod tests {
// ProgramError<0, ResultWithNegativeTokens> error when processed // ProgramError<0, ResultWithNegativeTokens> error when processed
let keypair2 = Keypair::new(); let keypair2 = Keypair::new();
let tx = SystemTransaction::new_account(&keypair, keypair2.pubkey(), 42, last_id, 0); let tx = SystemTransaction::new_account(&keypair, keypair2.pubkey(), 42, last_id, 0);
let entry = Entry::new(&hash, 0, 1, vec![tx]); let entry = Entry::new(&hash, 1, vec![tx]);
hash = entry.id; hash = entry.id;
entries.push(entry); entries.push(entry);
if (i + 1) % tick_interval == 0 { if (i + 1) % tick_interval == 0 {
let tick = Entry::new(&hash, 0, 1, vec![]); let tick = Entry::new(&hash, 1, vec![]);
hash = tick.id; hash = tick.id;
last_id = hash; last_id = hash;
entries.push(tick); entries.push(tick);

View File

@ -405,9 +405,7 @@ mod test {
); );
let ticks = create_ticks(max_tick_height - start_tick_height, Hash::default()); let ticks = create_ticks(max_tick_height - start_tick_height, Hash::default());
for (i, mut tick) in ticks.into_iter().enumerate() { for (_, tick) in ticks.into_iter().enumerate() {
// Simulate the tick heights generated in poh.rs
tick.tick_height = start_tick_height + i as u64 + 1;
entry_sender entry_sender
.send(vec![tick]) .send(vec![tick])
.expect("Expect successful send to broadcast service"); .expect("Expect successful send to broadcast service");

View File

@ -41,9 +41,6 @@ pub type EntryReceiver = Receiver<Vec<Entry>>;
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct Entry { pub struct Entry {
/// tick height of the ledger, not including any tick implied by this Entry
pub tick_height: u64,
/// The number of hashes since the previous Entry ID. /// The number of hashes since the previous Entry ID.
pub num_hashes: u64, pub num_hashes: u64,
@ -58,16 +55,10 @@ pub struct Entry {
impl Entry { impl Entry {
/// Creates the next Entry `num_hashes` after `start_hash`. /// Creates the next Entry `num_hashes` after `start_hash`.
pub fn new( pub fn new(prev_id: &Hash, num_hashes: u64, transactions: Vec<Transaction>) -> Self {
prev_id: &Hash,
tick_height: u64,
num_hashes: u64,
transactions: Vec<Transaction>,
) -> Self {
let entry = { let entry = {
if num_hashes == 0 && transactions.is_empty() { if num_hashes == 0 && transactions.is_empty() {
Entry { Entry {
tick_height,
num_hashes: 0, num_hashes: 0,
id: *prev_id, id: *prev_id,
transactions, transactions,
@ -77,7 +68,6 @@ impl Entry {
// next_hash will generate the next hash and set num_hashes == 1 // next_hash will generate the next hash and set num_hashes == 1
let id = next_hash(prev_id, 1, &transactions); let id = next_hash(prev_id, 1, &transactions);
Entry { Entry {
tick_height,
num_hashes: 1, num_hashes: 1,
id, id,
transactions, transactions,
@ -88,7 +78,6 @@ impl Entry {
// and transactions = empty // and transactions = empty
let id = next_hash(prev_id, num_hashes, &transactions); let id = next_hash(prev_id, num_hashes, &transactions);
Entry { Entry {
tick_height,
num_hashes, num_hashes,
id, id,
transactions, transactions,
@ -129,9 +118,8 @@ impl Entry {
.iter() .iter()
.map(|tx| tx.serialized_size().unwrap()) .map(|tx| tx.serialized_size().unwrap())
.sum(); .sum();
// tick_height+num_hashes + id + txs // num_hashes + id + txs
(2 * size_of::<u64>() + size_of::<Hash>()) as u64 + txs_size
(3 * size_of::<u64>() + size_of::<Hash>()) as u64 + txs_size
} }
pub fn num_will_fit(transactions: &[Transaction]) -> usize { pub fn num_will_fit(transactions: &[Transaction]) -> usize {
@ -176,7 +164,7 @@ impl Entry {
num_hashes: &mut u64, num_hashes: &mut u64,
transactions: Vec<Transaction>, transactions: Vec<Transaction>,
) -> Self { ) -> Self {
let entry = Self::new(start_hash, 0, *num_hashes, transactions); let entry = Self::new(start_hash, *num_hashes, transactions);
*start_hash = entry.id; *start_hash = entry.id;
*num_hashes = 0; *num_hashes = 0;
assert!(serialized_size(&entry).unwrap() <= BLOB_DATA_SIZE as u64); assert!(serialized_size(&entry).unwrap() <= BLOB_DATA_SIZE as u64);
@ -187,9 +175,8 @@ impl Entry {
/// since the previous transaction and that resulting `id`. /// since the previous transaction and that resulting `id`.
#[cfg(test)] #[cfg(test)]
pub fn new_tick(tick_height: u64, num_hashes: u64, id: &Hash) -> Self { pub fn new_tick(num_hashes: u64, id: &Hash) -> Self {
Entry { Entry {
tick_height,
num_hashes, num_hashes,
id: *id, id: *id,
transactions: vec![], transactions: vec![],
@ -271,7 +258,6 @@ pub trait EntrySlice {
impl EntrySlice for [Entry] { impl EntrySlice for [Entry] {
fn verify(&self, start_hash: &Hash) -> bool { fn verify(&self, start_hash: &Hash) -> bool {
let genesis = [Entry { let genesis = [Entry {
tick_height: 0,
num_hashes: 0, num_hashes: 0,
id: *start_hash, id: *start_hash,
transactions: vec![], transactions: vec![],
@ -312,7 +298,7 @@ impl EntrySlice for [Entry] {
} }
pub fn next_entry_mut(start: &mut Hash, num_hashes: u64, transactions: Vec<Transaction>) -> Entry { pub fn next_entry_mut(start: &mut Hash, num_hashes: u64, transactions: Vec<Transaction>) -> Entry {
let entry = Entry::new(&start, 0, num_hashes, transactions); let entry = Entry::new(&start, num_hashes, transactions);
*start = entry.id; *start = entry.id;
entry entry
} }
@ -476,7 +462,6 @@ pub fn make_consecutive_blobs(
pub fn next_entry(prev_id: &Hash, num_hashes: u64, transactions: Vec<Transaction>) -> Entry { pub fn next_entry(prev_id: &Hash, num_hashes: u64, transactions: Vec<Transaction>) -> Entry {
assert!(num_hashes > 0 || transactions.is_empty()); assert!(num_hashes > 0 || transactions.is_empty());
Entry { Entry {
tick_height: 0,
num_hashes, num_hashes,
id: next_hash(prev_id, num_hashes, &transactions), id: next_hash(prev_id, num_hashes, &transactions),
transactions, transactions,
@ -497,8 +482,8 @@ mod tests {
fn test_entry_verify() { fn test_entry_verify() {
let zero = Hash::default(); let zero = Hash::default();
let one = hash(&zero.as_ref()); let one = hash(&zero.as_ref());
assert!(Entry::new_tick(0, 0, &zero).verify(&zero)); // base case, never used assert!(Entry::new_tick(0, &zero).verify(&zero)); // base case, never used
assert!(!Entry::new_tick(1, 0, &zero).verify(&one)); // base case, bad assert!(!Entry::new_tick(0, &zero).verify(&one)); // base case, bad
assert!(next_entry(&zero, 1, vec![]).verify(&zero)); // inductive step assert!(next_entry(&zero, 1, vec![]).verify(&zero)); // inductive step
assert!(!next_entry(&zero, 1, vec![]).verify(&one)); // inductive step, bad assert!(!next_entry(&zero, 1, vec![]).verify(&one)); // inductive step, bad
} }
@ -511,7 +496,7 @@ mod tests {
let keypair = Keypair::new(); let keypair = Keypair::new();
let tx0 = SystemTransaction::new_account(&keypair, keypair.pubkey(), 0, zero, 0); let tx0 = SystemTransaction::new_account(&keypair, keypair.pubkey(), 0, zero, 0);
let tx1 = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, zero, 0); let tx1 = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, zero, 0);
let mut e0 = Entry::new(&zero, 0, 0, vec![tx0.clone(), tx1.clone()]); let mut e0 = Entry::new(&zero, 0, vec![tx0.clone(), tx1.clone()]);
assert!(e0.verify(&zero)); assert!(e0.verify(&zero));
// Next, swap two transactions and ensure verification fails. // Next, swap two transactions and ensure verification fails.
@ -535,7 +520,7 @@ mod tests {
); );
let tx1 = let tx1 =
BudgetTransaction::new_signature(&keypair, keypair.pubkey(), keypair.pubkey(), zero); BudgetTransaction::new_signature(&keypair, keypair.pubkey(), keypair.pubkey(), zero);
let mut e0 = Entry::new(&zero, 0, 0, vec![tx0.clone(), tx1.clone()]); let mut e0 = Entry::new(&zero, 0, vec![tx0.clone(), tx1.clone()]);
assert!(e0.verify(&zero)); assert!(e0.verify(&zero));
// Next, swap two witness transactions and ensure verification fails. // Next, swap two witness transactions and ensure verification fails.
@ -595,8 +580,8 @@ mod tests {
let zero = Hash::default(); let zero = Hash::default();
let one = hash(&zero.as_ref()); let one = hash(&zero.as_ref());
assert!(vec![][..].verify(&zero)); // base case assert!(vec![][..].verify(&zero)); // base case
assert!(vec![Entry::new_tick(0, 0, &zero)][..].verify(&zero)); // singleton case 1 assert!(vec![Entry::new_tick(0, &zero)][..].verify(&zero)); // singleton case 1
assert!(!vec![Entry::new_tick(0, 0, &zero)][..].verify(&one)); // singleton case 2, bad assert!(!vec![Entry::new_tick(0, &zero)][..].verify(&one)); // singleton case 2, bad
assert!(vec![next_entry(&zero, 0, vec![]); 2][..].verify(&zero)); // inductive step assert!(vec![next_entry(&zero, 0, vec![]); 2][..].verify(&zero)); // inductive step
let mut bad_ticks = vec![next_entry(&zero, 0, vec![]); 2]; let mut bad_ticks = vec![next_entry(&zero, 0, vec![]); 2];
@ -663,7 +648,6 @@ mod tests {
let tx_small_size = tx_small.serialized_size().unwrap() as usize; let tx_small_size = tx_small.serialized_size().unwrap() as usize;
let tx_large_size = tx_large.serialized_size().unwrap() as usize; let tx_large_size = tx_large.serialized_size().unwrap() as usize;
let entry_size = serialized_size(&Entry { let entry_size = serialized_size(&Entry {
tick_height: 0,
num_hashes: 0, num_hashes: 0,
id: Hash::default(), id: Hash::default(),
transactions: vec![], transactions: vec![],

View File

@ -206,7 +206,7 @@ mod test {
.emit_block_event(previous_slot, &leader_id, tick_height - 1, last_id) .emit_block_event(previous_slot, &leader_id, tick_height - 1, last_id)
.unwrap(); .unwrap();
} }
let entry = Entry::new(&mut last_id, tick_height, 1, vec![]); // just ticks let entry = Entry::new(&mut last_id, 1, vec![]); // just ticks
last_id = entry.id; last_id = entry.id;
previous_slot = curr_slot; previous_slot = curr_slot;
entry_stream entry_stream

View File

@ -148,15 +148,15 @@ mod test {
let mut last_id = Hash::default(); let mut last_id = Hash::default();
let mut entries = Vec::new(); let mut entries = Vec::new();
let mut expected_entries = Vec::new(); let mut expected_entries = Vec::new();
for x in 0..6 { for _ in 0..6 {
let entry = Entry::new(&mut last_id, x, 1, vec![]); //just ticks let entry = Entry::new(&mut last_id, 1, vec![]); //just ticks
last_id = entry.id; last_id = entry.id;
expected_entries.push(entry.clone()); expected_entries.push(entry.clone());
entries.push(entry); entries.push(entry);
} }
let keypair = Keypair::new(); let keypair = Keypair::new();
let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, Hash::default(), 0); let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, Hash::default(), 0);
let entry = Entry::new(&mut last_id, ticks_per_slot - 1, 1, vec![tx]); let entry = Entry::new(&mut last_id, 1, vec![tx]);
expected_entries.insert(ticks_per_slot as usize, entry.clone()); expected_entries.insert(ticks_per_slot as usize, entry.clone());
entries.insert(ticks_per_slot as usize, entry); entries.insert(ticks_per_slot as usize, entry);

View File

@ -94,7 +94,6 @@ impl PohRecorder {
let entry = poh.record(mixin); 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"); 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 { let entry = Entry {
tick_height: entry.tick_height,
num_hashes: entry.num_hashes, num_hashes: entry.num_hashes,
id: entry.id, id: entry.id,
transactions: txs, transactions: txs,
@ -111,7 +110,6 @@ impl PohRecorder {
) -> Result<()> { ) -> Result<()> {
let tick = poh.tick(); let tick = poh.tick();
let tick = Entry { let tick = Entry {
tick_height: tick.tick_height,
num_hashes: tick.num_hashes, num_hashes: tick.num_hashes,
id: tick.id, id: tick.id,
transactions: vec![], transactions: vec![],
@ -146,16 +144,13 @@ mod tests {
.record(h1, vec![tx.clone()], &entry_sender) .record(h1, vec![tx.clone()], &entry_sender)
.unwrap(); .unwrap();
//get some events //get some events
let e = entry_receiver.recv().unwrap(); let _e = entry_receiver.recv().unwrap();
assert_eq!(e[0].tick_height, 0); // super weird case, but ok!
poh_recorder.tick(&bank, &entry_sender).unwrap(); poh_recorder.tick(&bank, &entry_sender).unwrap();
let e = entry_receiver.recv().unwrap(); let _e = entry_receiver.recv().unwrap();
assert_eq!(e[0].tick_height, 1);
poh_recorder.tick(&bank, &entry_sender).unwrap(); poh_recorder.tick(&bank, &entry_sender).unwrap();
let e = entry_receiver.recv().unwrap(); let _e = entry_receiver.recv().unwrap();
assert_eq!(e[0].tick_height, 2);
// max tick height reached // max tick height reached
assert!(poh_recorder.tick(&bank, &entry_sender).is_err()); assert!(poh_recorder.tick(&bank, &entry_sender).is_err());

View File

@ -793,7 +793,7 @@ mod test {
entries.clear(); entries.clear();
for _ in 0..5 { for _ in 0..5 {
let entry = Entry::new(&mut Hash::default(), 0, 1, vec![]); //just broken entries let entry = Entry::new(&mut Hash::default(), 1, vec![]); //just broken entries
entries.push(entry); entries.push(entry);
} }

View File

@ -628,7 +628,7 @@ mod tests {
let keypair = Keypair::new(); let keypair = Keypair::new();
let vote_tx = VoteTransaction::new_vote(&keypair, 123456, Hash::default(), 1); let vote_tx = VoteTransaction::new_vote(&keypair, 123456, Hash::default(), 1);
vote_txs.push(vote_tx); vote_txs.push(vote_tx);
let vote_entries = vec![Entry::new(&Hash::default(), 0, 1, vote_txs)]; let vote_entries = vec![Entry::new(&Hash::default(), 1, vote_txs)];
storage_entry_sender.send(vote_entries).unwrap(); storage_entry_sender.send(vote_entries).unwrap();
for _ in 0..5 { for _ in 0..5 {