From 6b228df3df7df55417ecac931e939926ce434bee Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Thu, 28 Feb 2019 12:59:26 -0800 Subject: [PATCH] Remove last_entry_id/next_blob_index from TvuRotationInfo --- src/blocktree_processor.rs | 18 +----------------- src/fullnode.rs | 13 ++++--------- src/replay_stage.rs | 27 +++++++-------------------- src/tvu.rs | 10 +++------- tests/tvu.rs | 2 -- 5 files changed, 15 insertions(+), 55 deletions(-) diff --git a/src/blocktree_processor.rs b/src/blocktree_processor.rs index b813feaf08..2186ef7ba3 100644 --- a/src/blocktree_processor.rs +++ b/src/blocktree_processor.rs @@ -6,7 +6,6 @@ use rayon::prelude::*; use solana_metrics::counter::Counter; use solana_runtime::bank::{Bank, BankError, Result}; use solana_sdk::genesis_block::GenesisBlock; -use solana_sdk::hash::Hash; use solana_sdk::timing::duration_as_ms; use solana_sdk::timing::MAX_ENTRY_IDS; use std::sync::Arc; @@ -101,8 +100,6 @@ fn process_block(bank: &Bank, entries: &[Entry]) -> Result<()> { pub struct BankForksInfo { pub bank_id: u64, pub entry_height: u64, - pub last_entry_id: Hash, - pub next_blob_index: u64, } pub fn process_blocktree( @@ -195,8 +192,6 @@ pub fn process_blocktree( let bfi = BankForksInfo { bank_id: slot, entry_height: starting_entry_height, - last_entry_id: starting_bank.last_id(), - next_blob_index: 0, }; fork_info.push((starting_bank, bfi)); continue; @@ -211,8 +206,6 @@ pub fn process_blocktree( let bfi = BankForksInfo { bank_id: slot, entry_height, - last_entry_id: bank.last_id(), - next_blob_index: meta.consumed, }; fork_info.push((bank, bfi)); continue; @@ -253,6 +246,7 @@ mod tests { use crate::blocktree::tests::entries_to_blobs; use crate::entry::{create_ticks, next_entry, Entry}; use solana_sdk::genesis_block::GenesisBlock; + use solana_sdk::hash::Hash; use solana_sdk::signature::{Keypair, KeypairUtil}; use solana_sdk::system_transaction::SystemTransaction; @@ -298,8 +292,6 @@ mod tests { let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot) .expect("Expected to successfully open database ledger"); - let expected_last_entry_id = last_id; - // Write slot 1 // slot 1, points at slot 0. Missing one tick { @@ -326,8 +318,6 @@ mod tests { BankForksInfo { bank_id: 1, // never finished first slot entry_height: ticks_per_slot, - last_entry_id: expected_last_entry_id, - next_blob_index: 0, } ); } @@ -385,8 +375,6 @@ mod tests { BankForksInfo { bank_id: 3, // Fork 1's head is slot 3 entry_height: ticks_per_slot * 4, - last_entry_id: last_fork1_entry_id, - next_blob_index: ticks_per_slot, // this fork is done, but we need to look for children in replay } ); assert_eq!( @@ -394,8 +382,6 @@ mod tests { BankForksInfo { bank_id: 4, // Fork 2's head is slot 4 entry_height: ticks_per_slot * 3, - last_entry_id: last_fork2_entry_id, - next_blob_index: ticks_per_slot, // this fork is done, but we need to look for children in replay } ); @@ -499,8 +485,6 @@ mod tests { BankForksInfo { bank_id: 1, entry_height, - last_entry_id: entries.last().unwrap().id, - next_blob_index: entries.len() as u64, } ); diff --git a/src/fullnode.rs b/src/fullnode.rs index ccdc701771..4c665fc262 100644 --- a/src/fullnode.rs +++ b/src/fullnode.rs @@ -131,14 +131,10 @@ impl Fullnode { let bank_info = &bank_forks_info[0]; let bank = bank_forks[bank_info.bank_id].clone(); - info!( - "starting PoH... {} {}", - bank.tick_height(), - bank_info.last_entry_id - ); + info!("starting PoH... {} {}", bank.tick_height(), bank.last_id(),); let poh_recorder = Arc::new(Mutex::new(PohRecorder::new( bank.tick_height(), - bank_info.last_entry_id, + bank.last_id(), ))); let poh_service = PohService::new(poh_recorder.clone(), &config.tick_config, exit.clone()); @@ -270,11 +266,10 @@ impl Fullnode { fn rotate(&mut self, rotation_info: TvuRotationInfo) -> FullnodeReturnType { trace!( - "{:?}: rotate for slot={} to leader={:?} using last_entry_id={:?}", + "{:?}: rotate for slot={} to leader={:?}", self.id, rotation_info.slot, rotation_info.leader_id, - rotation_info.last_entry_id, ); let was_leader = leader_schedule_utils::slot_leader(&rotation_info.bank) == self.id; @@ -351,7 +346,7 @@ impl Fullnode { //instead of here self.poh_recorder.lock().unwrap().reset( rotation_info.bank.tick_height(), - rotation_info.last_entry_id, + rotation_info.bank.last_id(), ); let slot = rotation_info.slot; let transition = self.rotate(rotation_info); diff --git a/src/replay_stage.rs b/src/replay_stage.rs index 6368b00c0c..2db0f51ee6 100644 --- a/src/replay_stage.rs +++ b/src/replay_stage.rs @@ -185,20 +185,11 @@ impl ReplayStage { let subscriptions_ = subscriptions.clone(); // Gather up all the metadata about the current state of the ledger - let (mut bank, tick_height, mut last_entry_id, mut current_blob_index) = { - let bank = bank_forks.read().unwrap()[bank_forks_info[0].bank_id].clone(); - let tick_height = bank.tick_height(); - ( - bank, - tick_height, - bank_forks_info[0].last_entry_id, - bank_forks_info[0].next_blob_index, - ) - }; - assert_eq!(bank.last_id(), last_entry_id); // TODO: remove last_entry_id, this assert proves it's unnecessary + let mut bank = bank_forks.read().unwrap()[bank_forks_info[0].bank_id].clone(); // Update Tpu and other fullnode components with the current bank let (mut current_slot, mut current_leader_id, mut max_tick_height_for_slot) = { + let tick_height = bank.tick_height(); let slot = (tick_height + 1) / bank.ticks_per_slot(); let first_tick_in_slot = slot * bank.ticks_per_slot(); @@ -208,13 +199,9 @@ impl ReplayStage { let old_bank = bank.clone(); // If the next slot is going to be a new slot and we're the leader for that slot, // make a new working bank, set it as the working bank. - if tick_height + 1 == first_tick_in_slot { - if leader_id == my_id { - bank = Self::create_and_set_working_bank(slot, &bank_forks, &old_bank); - } - current_blob_index = 0; + if tick_height + 1 == first_tick_in_slot && leader_id == my_id { + bank = Self::create_and_set_working_bank(slot, &bank_forks, &old_bank); } - assert_eq!(current_blob_index, 0); // TODO: remove next_blob_index, this assert proves it's unnecessary // Send a rotation notification back to Fullnode to initialize the TPU to the right // state. After this point, the bank.tick_height() is live, which it means it can @@ -222,7 +209,6 @@ impl ReplayStage { to_leader_sender .send(TvuRotationInfo { bank: bank.clone(), - last_entry_id, slot, leader_id, }) @@ -233,6 +219,8 @@ impl ReplayStage { (Some(slot), leader_id, max_tick_height_for_slot) }; + let mut last_entry_id = bank.last_id(); + let mut current_blob_index = 0; // Start the replay stage loop let bank_forks = bank_forks.clone(); @@ -388,7 +376,6 @@ impl ReplayStage { to_leader_sender .send(TvuRotationInfo { bank: bank.clone(), - last_entry_id, slot: next_slot, leader_id, }) @@ -508,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_forks_info[0].last_entry_id; + let last_entry_id = bank.last_id(); let blocktree = Arc::new(blocktree); let (replay_stage, _slot_full_receiver, ledger_writer_recv) = ReplayStage::new( diff --git a/src/tvu.rs b/src/tvu.rs index 82ef5effb2..de13c86b86 100644 --- a/src/tvu.rs +++ b/src/tvu.rs @@ -24,7 +24,6 @@ use crate::rpc_subscriptions::RpcSubscriptions; use crate::service::Service; use crate::storage_stage::{StorageStage, StorageState}; use solana_runtime::bank::Bank; -use solana_sdk::hash::Hash; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::{Keypair, KeypairUtil}; use std::net::UdpSocket; @@ -34,10 +33,9 @@ use std::sync::{Arc, RwLock}; use std::thread; pub struct TvuRotationInfo { - pub bank: Arc, // Bank to use - pub last_entry_id: Hash, // last_entry_id of that bank - pub slot: u64, // slot height to initiate a rotation - pub leader_id: Pubkey, // leader upon rotation + pub bank: Arc, // Bank to use + pub slot: u64, // slot height to initiate a rotation + pub leader_id: Pubkey, // leader upon rotation } pub type TvuRotationSender = Sender; pub type TvuRotationReceiver = Receiver; @@ -218,8 +216,6 @@ pub mod tests { let bank_forks_info = vec![BankForksInfo { bank_id: 0, entry_height: 0, - last_entry_id: bank_forks.working_bank().last_id(), - next_blob_index: 0, }]; //start cluster_info1 diff --git a/tests/tvu.rs b/tests/tvu.rs index 421cd200bb..633dd71237 100644 --- a/tests/tvu.rs +++ b/tests/tvu.rs @@ -91,8 +91,6 @@ fn test_replay() { let bank_forks_info = vec![BankForksInfo { bank_id: 0, entry_height: 0, - last_entry_id: cur_hash, - next_blob_index: 0, }]; let bank = bank_forks.working_bank();