From e993d511e3ac30e94a2afa5d3074d0d0f6423747 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Fri, 1 Mar 2019 08:26:47 -0800 Subject: [PATCH] Rename last_entry_id variables to last_entry_hash --- src/blocktree_processor.rs | 44 +++++++++++++++++++------------------- src/fullnode.rs | 10 ++++----- src/poh_recorder.rs | 4 ++-- src/replay_stage.rs | 22 +++++++++---------- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/blocktree_processor.rs b/src/blocktree_processor.rs index 2186ef7ba3..e888cb9a29 100644 --- a/src/blocktree_processor.rs +++ b/src/blocktree_processor.rs @@ -115,13 +115,13 @@ pub fn process_blocktree( let slot = 0; let bank = Arc::new(Bank::new_with_paths(&genesis_block, account_paths)); let entry_height = 0; - let last_entry_id = bank.last_id(); - vec![(slot, bank, entry_height, last_entry_id)] + let last_entry_hash = bank.last_id(); + vec![(slot, bank, entry_height, last_entry_hash)] }; let mut fork_info = vec![]; while !pending_slots.is_empty() { - let (slot, starting_bank, starting_entry_height, mut last_entry_id) = + let (slot, starting_bank, starting_entry_height, mut last_entry_hash) = pending_slots.pop().unwrap(); let bank = Arc::new(Bank::new_from_parent_and_id( @@ -155,17 +155,17 @@ pub fn process_blocktree( return Err(BankError::LedgerVerificationFailed); } let entry0 = &entries[0]; - if !(entry0.is_tick() && entry0.verify(&last_entry_id)) { + if !(entry0.is_tick() && entry0.verify(&last_entry_hash)) { warn!("Ledger proof of history failed at entry0"); return Err(BankError::LedgerVerificationFailed); } - last_entry_id = entry0.id; + last_entry_hash = entry0.id; entry_height += 1; entries = entries.drain(1..).collect(); } if !entries.is_empty() { - if !entries.verify(&last_entry_id) { + if !entries.verify(&last_entry_hash) { warn!("Ledger proof of history failed at entry: {}", entry_height); return Err(BankError::LedgerVerificationFailed); } @@ -175,7 +175,7 @@ pub fn process_blocktree( BankError::LedgerVerificationFailed })?; - last_entry_id = entries.last().unwrap().id; + last_entry_hash = entries.last().unwrap().id; entry_height += entries.len() as u64; } @@ -220,7 +220,7 @@ pub fn process_blocktree( )); trace!("Add child bank for slot={}", next_slot); // bank_forks.insert(*next_slot, child_bank); - (*next_slot, child_bank, entry_height, last_entry_id) + (*next_slot, child_bank, entry_height, last_entry_hash) })); // reverse sort by slot, so the next slot to be processed can be pop()ed @@ -255,15 +255,15 @@ mod tests { ticks_per_slot: u64, slot: u64, parent_slot: u64, - last_entry_id: Hash, + last_entry_hash: Hash, ) -> Hash { - let entries = create_ticks(ticks_per_slot, last_entry_id); - let last_entry_id = entries.last().unwrap().id; + let entries = create_ticks(ticks_per_slot, last_entry_hash); + let last_entry_hash = entries.last().unwrap().id; let blobs = entries_to_blobs(&entries, slot, parent_slot); blocktree.insert_data_blobs(blobs.iter()).unwrap(); - last_entry_id + last_entry_hash } #[test] @@ -332,7 +332,7 @@ mod tests { // Create a new ledger with slot 0 full of ticks let (ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block); debug!("ledger_path: {:?}", ledger_path); - let mut last_entry_id = last_id; + let mut last_entry_hash = last_id; /* Build a blocktree in the ledger with the following fork structure: @@ -353,11 +353,11 @@ mod tests { // Fork 1, ending at slot 3 let last_slot1_entry_id = - fill_blocktree_slot_with_ticks(&blocktree, ticks_per_slot, 1, 0, last_entry_id); - last_entry_id = + fill_blocktree_slot_with_ticks(&blocktree, ticks_per_slot, 1, 0, last_entry_hash); + last_entry_hash = fill_blocktree_slot_with_ticks(&blocktree, ticks_per_slot, 2, 1, last_slot1_entry_id); let last_fork1_entry_id = - fill_blocktree_slot_with_ticks(&blocktree, ticks_per_slot, 3, 2, last_entry_id); + fill_blocktree_slot_with_ticks(&blocktree, ticks_per_slot, 3, 2, last_entry_hash); // Fork 2, ending at slot 4 let last_fork2_entry_id = @@ -451,26 +451,26 @@ mod tests { debug!("ledger_path: {:?}", ledger_path); let mut entries = vec![]; - let mut last_entry_id = last_id; + let mut last_entry_hash = last_id; for _ in 0..3 { // 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(&last_entry_id, 1, vec![tx]); - last_entry_id = entry.id; + let entry = Entry::new(&last_entry_hash, 1, vec![tx]); + last_entry_hash = entry.id; entries.push(entry); // Add a second Transaction that will produce a // 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(&last_entry_id, 1, vec![tx]); - last_entry_id = entry.id; + let entry = Entry::new(&last_entry_hash, 1, vec![tx]); + last_entry_hash = entry.id; entries.push(entry); } // Fill up the rest of slot 1 with ticks - entries.extend(create_ticks(genesis_block.ticks_per_slot, last_entry_id)); + entries.extend(create_ticks(genesis_block.ticks_per_slot, last_entry_hash)); let blocktree = Blocktree::open(&ledger_path).expect("Expected to successfully open database ledger"); diff --git a/src/fullnode.rs b/src/fullnode.rs index 4c665fc262..df2afb0479 100644 --- a/src/fullnode.rs +++ b/src/fullnode.rs @@ -449,8 +449,8 @@ pub fn make_active_set_entries( // 1) Assume the active_keypair node has no tokens staked let transfer_tx = SystemTransaction::new_account(&token_source, active_keypair.pubkey(), stake, *last_id, 0); - let mut last_entry_id = *last_id; - let transfer_entry = next_entry_mut(&mut last_entry_id, 1, vec![transfer_tx]); + let mut last_entry_hash = *last_id; + let transfer_entry = next_entry_mut(&mut last_entry_hash, 1, vec![transfer_tx]); // 2) Create and register a vote account for active_keypair let voting_keypair = VotingKeypair::new_local(active_keypair); @@ -458,15 +458,15 @@ pub fn make_active_set_entries( let new_vote_account_tx = VoteTransaction::fund_staking_account(active_keypair, vote_account_id, *last_id, 1, 1); - let new_vote_account_entry = next_entry_mut(&mut last_entry_id, 1, vec![new_vote_account_tx]); + let new_vote_account_entry = next_entry_mut(&mut last_entry_hash, 1, vec![new_vote_account_tx]); // 3) Create vote entry let vote_tx = VoteTransaction::new_vote(&voting_keypair, slot_height_to_vote_on, *last_id, 0); - let vote_entry = next_entry_mut(&mut last_entry_id, 1, vec![vote_tx]); + let vote_entry = next_entry_mut(&mut last_entry_hash, 1, vec![vote_tx]); // 4) Create `num_ending_ticks` empty ticks let mut entries = vec![transfer_entry, new_vote_account_entry, vote_entry]; - let empty_ticks = create_ticks(num_ending_ticks, last_entry_id); + let empty_ticks = create_ticks(num_ending_ticks, last_entry_hash); entries.extend(empty_ticks); (entries, voting_keypair) diff --git a/src/poh_recorder.rs b/src/poh_recorder.rs index 36615c8e11..1410e2ec06 100644 --- a/src/poh_recorder.rs +++ b/src/poh_recorder.rs @@ -144,8 +144,8 @@ impl PohRecorder { /// A recorder to synchronize PoH with the following data structures /// * bank - the LastId's queue is updated on `tick` and `record` events /// * sender - the Entry channel that outputs to the ledger - pub fn new(tick_height: u64, last_entry_id: Hash) -> Self { - let poh = Poh::new(last_entry_id, tick_height); + pub fn new(tick_height: u64, last_entry_hash: Hash) -> Self { + let poh = Poh::new(last_entry_hash, tick_height); PohRecorder { poh, tick_cache: vec![], diff --git a/src/replay_stage.rs b/src/replay_stage.rs index 2db0f51ee6..66c09c3f58 100644 --- a/src/replay_stage.rs +++ b/src/replay_stage.rs @@ -62,7 +62,7 @@ impl ReplayStage { voting_keypair: &Option>, forward_entry_sender: &EntrySender, current_blob_index: &mut u64, - last_entry_id: &mut Hash, + last_entry_hash: &mut Hash, subscriptions: &Arc, ) -> Result<()> { // Coalesce all the available entries into a single vote @@ -76,7 +76,7 @@ impl ReplayStage { let mut num_entries_to_write = entries.len(); let now = Instant::now(); - if !entries.as_slice().verify(last_entry_id) { + if !entries.as_slice().verify(last_entry_hash) { inc_new_counter_info!("replicate_stage-verify-fail", entries.len()); return Err(Error::BlobError(BlobError::VerificationFailed)); } @@ -135,7 +135,7 @@ impl ReplayStage { // If leader rotation happened, only write the entries up to leader rotation. entries.truncate(num_entries_to_write); - *last_entry_id = entries + *last_entry_hash = entries .last() .expect("Entries cannot be empty at this point") .id; @@ -219,7 +219,7 @@ impl ReplayStage { (Some(slot), leader_id, max_tick_height_for_slot) }; - let mut last_entry_id = bank.last_id(); + let mut last_entry_hash = bank.last_id(); let mut current_blob_index = 0; // Start the replay stage loop @@ -302,7 +302,7 @@ impl ReplayStage { &voting_keypair, &forward_entry_sender, &mut current_blob_index, - &mut last_entry_id, + &mut last_entry_hash, &subscriptions_, ) { error!("{} process_entries failed: {:?}", my_id, e); @@ -338,7 +338,7 @@ impl ReplayStage { let last_entry = blocktree .get_slot_entries(slot, meta.last_index, Some(1)) .unwrap(); - last_entry_id = last_entry[0].id; + last_entry_hash = last_entry[0].id; } let old_bank = bank.clone(); @@ -495,7 +495,7 @@ mod test { let (bank_forks, bank_forks_info, blocktree, l_receiver) = new_banks_from_blocktree(&my_ledger_path, None); let bank = bank_forks.working_bank(); - let last_entry_id = bank.last_id(); + let last_entry_hash = bank.last_id(); let blocktree = Arc::new(blocktree); let (replay_stage, _slot_full_receiver, ledger_writer_recv) = ReplayStage::new( @@ -516,7 +516,7 @@ mod test { cluster_info_me.write().unwrap().push_vote(vote); info!("Send ReplayStage an entry, should see it on the ledger writer receiver"); - let next_tick = create_ticks(1, last_entry_id); + let next_tick = create_ticks(1, last_entry_hash); blocktree.write_entries(1, 0, 0, next_tick.clone()).unwrap(); let received_tick = ledger_writer_recv @@ -541,7 +541,7 @@ mod test { // Set up the cluster info let cluster_info_me = Arc::new(RwLock::new(ClusterInfo::new(my_node.info.clone()))); let (forward_entry_sender, _forward_entry_receiver) = channel(); - let mut last_entry_id = Hash::default(); + let mut last_entry_hash = Hash::default(); let mut current_blob_index = 0; let mut last_id = Hash::default(); let mut entries = Vec::new(); @@ -560,7 +560,7 @@ mod test { &voting_keypair, &forward_entry_sender, &mut current_blob_index, - &mut last_entry_id, + &mut last_entry_hash, &Arc::new(RpcSubscriptions::default()), ); @@ -583,7 +583,7 @@ mod test { &voting_keypair, &forward_entry_sender, &mut current_blob_index, - &mut last_entry_id, + &mut last_entry_hash, &Arc::new(RpcSubscriptions::default()), );