Add Bank::get_signature_status_with_blockhash() (#13167)
Get the signature status in O(1) time, instead of O(n) where n is the number of blockhashes in the StatusCache.
This commit is contained in:
@ -109,18 +109,21 @@ impl BanksServer {
|
||||
|
||||
async fn poll_signature_status(
|
||||
self,
|
||||
signature: Signature,
|
||||
signature: &Signature,
|
||||
blockhash: &Hash,
|
||||
last_valid_slot: Slot,
|
||||
commitment: CommitmentLevel,
|
||||
) -> Option<transaction::Result<()>> {
|
||||
let mut status = self.bank(commitment).get_signature_status(&signature);
|
||||
let mut status = self
|
||||
.bank(commitment)
|
||||
.get_signature_status_with_blockhash(signature, blockhash);
|
||||
while status.is_none() {
|
||||
delay_for(Duration::from_millis(200)).await;
|
||||
let bank = self.bank(commitment);
|
||||
if bank.slot() > last_valid_slot {
|
||||
break;
|
||||
}
|
||||
status = bank.get_signature_status(&signature);
|
||||
status = bank.get_signature_status_with_blockhash(signature, blockhash);
|
||||
}
|
||||
status
|
||||
}
|
||||
@ -193,13 +196,13 @@ impl Banks for BanksServer {
|
||||
.read()
|
||||
.unwrap()
|
||||
.root_bank()
|
||||
.get_blockhash_last_valid_slot(&blockhash)
|
||||
.get_blockhash_last_valid_slot(blockhash)
|
||||
.unwrap();
|
||||
let signature = transaction.signatures.get(0).cloned().unwrap_or_default();
|
||||
let info =
|
||||
TransactionInfo::new(signature, serialize(&transaction).unwrap(), last_valid_slot);
|
||||
self.transaction_sender.send(info).unwrap();
|
||||
self.poll_signature_status(signature, last_valid_slot, commitment)
|
||||
self.poll_signature_status(&signature, blockhash, last_valid_slot, commitment)
|
||||
.await
|
||||
}
|
||||
|
||||
|
@ -3466,6 +3466,17 @@ impl Bank {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn get_signature_status_with_blockhash(
|
||||
&self,
|
||||
signature: &Signature,
|
||||
blockhash: &Hash,
|
||||
) -> Option<Result<()>> {
|
||||
let rcache = self.src.status_cache.read().unwrap();
|
||||
rcache
|
||||
.get_signature_status(signature, blockhash, &self.ancestors)
|
||||
.map(|v| v.1)
|
||||
}
|
||||
|
||||
pub fn get_signature_status_slot(&self, signature: &Signature) -> Option<(Slot, Result<()>)> {
|
||||
let rcache = self.src.status_cache.read().unwrap();
|
||||
rcache.get_signature_slot(signature, &self.ancestors)
|
||||
|
Reference in New Issue
Block a user