Use newer blockhash for recent_confirmed_blockhash api (#3995)
Oldest blockhash is sometimes too old and does not allow for transactions to go through.
This commit is contained in:
parent
15aa07f2a0
commit
aa0b67c93c
|
@ -25,6 +25,7 @@ use solana_sdk::system_transaction;
|
|||
use solana_sdk::timing::{duration_as_ms, duration_as_us, MAX_RECENT_BLOCKHASHES};
|
||||
use solana_sdk::transaction::{Result, Transaction, TransactionError};
|
||||
use solana_vote_api::vote_state::{self, Vote};
|
||||
use std::cmp;
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::time::Instant;
|
||||
|
@ -409,12 +410,17 @@ impl Bank {
|
|||
pub fn last_blockhash(&self) -> Hash {
|
||||
self.blockhash_queue.read().unwrap().last_hash()
|
||||
}
|
||||
/// Return the root bank's blockhash
|
||||
|
||||
/// Return a confirmed blockhash with NUM_BLOCKHASH_CONFIRMATIONS
|
||||
pub fn confirmed_last_blockhash(&self) -> Hash {
|
||||
if let Some(bank) = self.parents().last() {
|
||||
bank.last_blockhash()
|
||||
} else {
|
||||
const NUM_BLOCKHASH_CONFIRMATIONS: usize = 3;
|
||||
|
||||
let parents = self.parents();
|
||||
if parents.is_empty() {
|
||||
self.last_blockhash()
|
||||
} else {
|
||||
let index = cmp::min(NUM_BLOCKHASH_CONFIRMATIONS, parents.len() - 1);
|
||||
parents[index].last_blockhash()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue