From 1db80d79fcfcf5a9e59a4c30a8e80d256f7180d4 Mon Sep 17 00:00:00 2001 From: Sagar Dhawan Date: Fri, 12 Apr 2019 12:03:02 -0700 Subject: [PATCH] Update get recent blockhashes to return confirmed blockhashes only --- core/src/replay_stage.rs | 12 ++++++------ core/src/rpc.rs | 8 ++++---- runtime/src/bank.rs | 8 ++++++++ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 2f076ce691..221e3f4033 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -299,12 +299,13 @@ impl ReplayStage { ) where T: 'static + KeypairUtil + Send + Sync, { + if let Some(new_root) = locktower.record_vote(bank.slot()) { + bank_forks.write().unwrap().set_root(new_root); + blocktree.set_root(new_root); + Self::handle_new_root(&bank_forks, progress); + } + locktower.update_epoch(&bank); if let Some(ref voting_keypair) = voting_keypair { - if let Some(new_root) = locktower.record_vote(bank.slot()) { - bank_forks.write().unwrap().set_root(new_root); - blocktree.set_root(new_root); - Self::handle_new_root(&bank_forks, progress); - } // Send our last few votes along with the new one let vote_ix = vote_instruction::vote(vote_account_pubkey, locktower.recent_votes()); let vote_tx = Transaction::new_signed_instructions( @@ -312,7 +313,6 @@ impl ReplayStage { vec![vote_ix], bank.last_blockhash(), ); - locktower.update_epoch(&bank); cluster_info.write().unwrap().push_vote(vote_tx); } } diff --git a/core/src/rpc.rs b/core/src/rpc.rs index fdec366254..309ac141a9 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -74,7 +74,7 @@ impl JsonRpcRequestProcessor { } fn get_recent_blockhash(&self) -> String { - let id = self.bank().last_blockhash(); + let id = self.bank().get_confirmed_blockhash(); bs58::encode(id).into_string() } @@ -329,7 +329,7 @@ impl RpcSol for RpcSolImpl { .read() .unwrap() .bank() - .last_blockhash(); + .get_confirmed_blockhash(); let transaction = request_airdrop_transaction(&drone_addr, &pubkey, lamports, blockhash) .map_err(|err| { info!("request_airdrop_transaction failed: {:?}", err); @@ -450,7 +450,7 @@ mod tests { let bank = bank_forks.read().unwrap().working_bank(); let exit = Arc::new(AtomicBool::new(false)); - let blockhash = bank.last_blockhash(); + let blockhash = bank.get_confirmed_blockhash(); let tx = system_transaction::transfer(&alice, pubkey, 20, blockhash, 0); bank.process_transaction(&tx).expect("process transaction"); @@ -493,7 +493,7 @@ mod tests { &exit, ); thread::spawn(move || { - let blockhash = bank.last_blockhash(); + let blockhash = bank.get_confirmed_blockhash(); let tx = system_transaction::transfer(&alice, &bob_pubkey, 20, blockhash, 0); bank.process_transaction(&tx).expect("process transaction"); }) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index fc74bff911..99e46d49ef 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -382,6 +382,14 @@ impl Bank { pub fn last_blockhash(&self) -> Hash { self.blockhash_queue.read().unwrap().last_hash() } + /// Return the root bank's blockhash + pub fn get_confirmed_blockhash(&self) -> Hash { + if let Some(bank) = self.parents().last() { + bank.last_blockhash() + } else { + self.last_blockhash() + } + } /// Forget all signatures. Useful for benchmarking. pub fn clear_signatures(&self) {