Update get recent blockhashes to return confirmed blockhashes only

This commit is contained in:
Sagar Dhawan 2019-04-12 12:03:02 -07:00 committed by Grimes
parent 1dac4c33b8
commit 1db80d79fc
3 changed files with 18 additions and 10 deletions

View File

@ -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);
}
}

View File

@ -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");
})

View File

@ -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) {