Remove Entry::tick_height field
This commit is contained in:
parent
9848de6cda
commit
8d38c2f800
|
@ -433,7 +433,7 @@ mod tests {
|
|||
|
||||
// Start off the ledger with the psuedo-tick linked to the genesis block
|
||||
// (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;
|
||||
entries.push(tick);
|
||||
|
||||
|
@ -444,7 +444,7 @@ mod tests {
|
|||
let mut e = next_entries(&hash, 0, txs);
|
||||
entries.append(&mut e);
|
||||
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;
|
||||
last_id = hash;
|
||||
entries.push(tick);
|
||||
|
@ -532,7 +532,7 @@ mod tests {
|
|||
|
||||
// Start off the ledger with the psuedo-tick linked to the genesis block
|
||||
// (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;
|
||||
entries.push(tick);
|
||||
|
||||
|
@ -540,7 +540,7 @@ mod tests {
|
|||
// Transfer one token from the mint to a random account
|
||||
let keypair = Keypair::new();
|
||||
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;
|
||||
entries.push(entry);
|
||||
|
||||
|
@ -548,12 +548,12 @@ mod tests {
|
|||
// ProgramError<0, ResultWithNegativeTokens> error when processed
|
||||
let keypair2 = Keypair::new();
|
||||
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;
|
||||
entries.push(entry);
|
||||
|
||||
if (i + 1) % tick_interval == 0 {
|
||||
let tick = Entry::new(&hash, 0, 1, vec![]);
|
||||
let tick = Entry::new(&hash, 1, vec![]);
|
||||
hash = tick.id;
|
||||
last_id = hash;
|
||||
entries.push(tick);
|
||||
|
|
|
@ -405,9 +405,7 @@ mod test {
|
|||
);
|
||||
|
||||
let ticks = create_ticks(max_tick_height - start_tick_height, Hash::default());
|
||||
for (i, mut tick) in ticks.into_iter().enumerate() {
|
||||
// Simulate the tick heights generated in poh.rs
|
||||
tick.tick_height = start_tick_height + i as u64 + 1;
|
||||
for (_, tick) in ticks.into_iter().enumerate() {
|
||||
entry_sender
|
||||
.send(vec![tick])
|
||||
.expect("Expect successful send to broadcast service");
|
||||
|
|
40
src/entry.rs
40
src/entry.rs
|
@ -41,9 +41,6 @@ pub type EntryReceiver = Receiver<Vec<Entry>>;
|
|||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||
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.
|
||||
pub num_hashes: u64,
|
||||
|
||||
|
@ -58,16 +55,10 @@ pub struct Entry {
|
|||
|
||||
impl Entry {
|
||||
/// Creates the next Entry `num_hashes` after `start_hash`.
|
||||
pub fn new(
|
||||
prev_id: &Hash,
|
||||
tick_height: u64,
|
||||
num_hashes: u64,
|
||||
transactions: Vec<Transaction>,
|
||||
) -> Self {
|
||||
pub fn new(prev_id: &Hash, num_hashes: u64, transactions: Vec<Transaction>) -> Self {
|
||||
let entry = {
|
||||
if num_hashes == 0 && transactions.is_empty() {
|
||||
Entry {
|
||||
tick_height,
|
||||
num_hashes: 0,
|
||||
id: *prev_id,
|
||||
transactions,
|
||||
|
@ -77,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 {
|
||||
tick_height,
|
||||
num_hashes: 1,
|
||||
id,
|
||||
transactions,
|
||||
|
@ -88,7 +78,6 @@ impl Entry {
|
|||
// and transactions = empty
|
||||
let id = next_hash(prev_id, num_hashes, &transactions);
|
||||
Entry {
|
||||
tick_height,
|
||||
num_hashes,
|
||||
id,
|
||||
transactions,
|
||||
|
@ -129,9 +118,8 @@ impl Entry {
|
|||
.iter()
|
||||
.map(|tx| tx.serialized_size().unwrap())
|
||||
.sum();
|
||||
// tick_height+num_hashes + id + txs
|
||||
|
||||
(3 * size_of::<u64>() + size_of::<Hash>()) as u64 + txs_size
|
||||
// num_hashes + id + txs
|
||||
(2 * size_of::<u64>() + size_of::<Hash>()) as u64 + txs_size
|
||||
}
|
||||
|
||||
pub fn num_will_fit(transactions: &[Transaction]) -> usize {
|
||||
|
@ -176,7 +164,7 @@ impl Entry {
|
|||
num_hashes: &mut u64,
|
||||
transactions: Vec<Transaction>,
|
||||
) -> Self {
|
||||
let entry = Self::new(start_hash, 0, *num_hashes, transactions);
|
||||
let entry = Self::new(start_hash, *num_hashes, transactions);
|
||||
*start_hash = entry.id;
|
||||
*num_hashes = 0;
|
||||
assert!(serialized_size(&entry).unwrap() <= BLOB_DATA_SIZE as u64);
|
||||
|
@ -187,9 +175,8 @@ impl Entry {
|
|||
/// since the previous transaction and that resulting `id`.
|
||||
|
||||
#[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 {
|
||||
tick_height,
|
||||
num_hashes,
|
||||
id: *id,
|
||||
transactions: vec![],
|
||||
|
@ -271,7 +258,6 @@ pub trait EntrySlice {
|
|||
impl EntrySlice for [Entry] {
|
||||
fn verify(&self, start_hash: &Hash) -> bool {
|
||||
let genesis = [Entry {
|
||||
tick_height: 0,
|
||||
num_hashes: 0,
|
||||
id: *start_hash,
|
||||
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 {
|
||||
let entry = Entry::new(&start, 0, num_hashes, transactions);
|
||||
let entry = Entry::new(&start, num_hashes, transactions);
|
||||
*start = entry.id;
|
||||
entry
|
||||
}
|
||||
|
@ -476,7 +462,6 @@ pub fn make_consecutive_blobs(
|
|||
pub fn next_entry(prev_id: &Hash, num_hashes: u64, transactions: Vec<Transaction>) -> Entry {
|
||||
assert!(num_hashes > 0 || transactions.is_empty());
|
||||
Entry {
|
||||
tick_height: 0,
|
||||
num_hashes,
|
||||
id: next_hash(prev_id, num_hashes, &transactions),
|
||||
transactions,
|
||||
|
@ -497,8 +482,8 @@ mod tests {
|
|||
fn test_entry_verify() {
|
||||
let zero = Hash::default();
|
||||
let one = hash(&zero.as_ref());
|
||||
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!(Entry::new_tick(0, &zero).verify(&zero)); // base case, never used
|
||||
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(&one)); // inductive step, bad
|
||||
}
|
||||
|
@ -511,7 +496,7 @@ mod tests {
|
|||
let keypair = Keypair::new();
|
||||
let tx0 = SystemTransaction::new_account(&keypair, keypair.pubkey(), 0, 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));
|
||||
|
||||
// Next, swap two transactions and ensure verification fails.
|
||||
|
@ -535,7 +520,7 @@ mod tests {
|
|||
);
|
||||
let tx1 =
|
||||
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));
|
||||
|
||||
// Next, swap two witness transactions and ensure verification fails.
|
||||
|
@ -595,8 +580,8 @@ mod tests {
|
|||
let zero = Hash::default();
|
||||
let one = hash(&zero.as_ref());
|
||||
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, 0, &zero)][..].verify(&one)); // singleton case 2, bad
|
||||
assert!(vec![Entry::new_tick(0, &zero)][..].verify(&zero)); // singleton case 1
|
||||
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
|
||||
|
||||
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_large_size = tx_large.serialized_size().unwrap() as usize;
|
||||
let entry_size = serialized_size(&Entry {
|
||||
tick_height: 0,
|
||||
num_hashes: 0,
|
||||
id: Hash::default(),
|
||||
transactions: vec![],
|
||||
|
|
|
@ -206,7 +206,7 @@ mod test {
|
|||
.emit_block_event(previous_slot, &leader_id, tick_height - 1, last_id)
|
||||
.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;
|
||||
previous_slot = curr_slot;
|
||||
entry_stream
|
||||
|
|
|
@ -148,15 +148,15 @@ mod test {
|
|||
let mut last_id = Hash::default();
|
||||
let mut entries = Vec::new();
|
||||
let mut expected_entries = Vec::new();
|
||||
for x in 0..6 {
|
||||
let entry = Entry::new(&mut last_id, x, 1, vec![]); //just ticks
|
||||
for _ in 0..6 {
|
||||
let entry = Entry::new(&mut last_id, 1, vec![]); //just ticks
|
||||
last_id = entry.id;
|
||||
expected_entries.push(entry.clone());
|
||||
entries.push(entry);
|
||||
}
|
||||
let keypair = Keypair::new();
|
||||
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());
|
||||
entries.insert(ticks_per_slot as usize, entry);
|
||||
|
||||
|
|
|
@ -94,7 +94,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 {
|
||||
tick_height: entry.tick_height,
|
||||
num_hashes: entry.num_hashes,
|
||||
id: entry.id,
|
||||
transactions: txs,
|
||||
|
@ -111,7 +110,6 @@ impl PohRecorder {
|
|||
) -> Result<()> {
|
||||
let tick = poh.tick();
|
||||
let tick = Entry {
|
||||
tick_height: tick.tick_height,
|
||||
num_hashes: tick.num_hashes,
|
||||
id: tick.id,
|
||||
transactions: vec![],
|
||||
|
@ -146,16 +144,13 @@ mod tests {
|
|||
.record(h1, vec![tx.clone()], &entry_sender)
|
||||
.unwrap();
|
||||
//get some events
|
||||
let e = entry_receiver.recv().unwrap();
|
||||
assert_eq!(e[0].tick_height, 0); // super weird case, but ok!
|
||||
let _e = entry_receiver.recv().unwrap();
|
||||
|
||||
poh_recorder.tick(&bank, &entry_sender).unwrap();
|
||||
let e = entry_receiver.recv().unwrap();
|
||||
assert_eq!(e[0].tick_height, 1);
|
||||
let _e = entry_receiver.recv().unwrap();
|
||||
|
||||
poh_recorder.tick(&bank, &entry_sender).unwrap();
|
||||
let e = entry_receiver.recv().unwrap();
|
||||
assert_eq!(e[0].tick_height, 2);
|
||||
let _e = entry_receiver.recv().unwrap();
|
||||
|
||||
// max tick height reached
|
||||
assert!(poh_recorder.tick(&bank, &entry_sender).is_err());
|
||||
|
|
|
@ -793,7 +793,7 @@ mod test {
|
|||
|
||||
entries.clear();
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -628,7 +628,7 @@ mod tests {
|
|||
let keypair = Keypair::new();
|
||||
let vote_tx = VoteTransaction::new_vote(&keypair, 123456, Hash::default(), 1);
|
||||
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();
|
||||
|
||||
for _ in 0..5 {
|
||||
|
|
Loading…
Reference in New Issue