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(
|
async fn poll_signature_status(
|
||||||
self,
|
self,
|
||||||
signature: Signature,
|
signature: &Signature,
|
||||||
|
blockhash: &Hash,
|
||||||
last_valid_slot: Slot,
|
last_valid_slot: Slot,
|
||||||
commitment: CommitmentLevel,
|
commitment: CommitmentLevel,
|
||||||
) -> Option<transaction::Result<()>> {
|
) -> 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() {
|
while status.is_none() {
|
||||||
delay_for(Duration::from_millis(200)).await;
|
delay_for(Duration::from_millis(200)).await;
|
||||||
let bank = self.bank(commitment);
|
let bank = self.bank(commitment);
|
||||||
if bank.slot() > last_valid_slot {
|
if bank.slot() > last_valid_slot {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
status = bank.get_signature_status(&signature);
|
status = bank.get_signature_status_with_blockhash(signature, blockhash);
|
||||||
}
|
}
|
||||||
status
|
status
|
||||||
}
|
}
|
||||||
@ -193,13 +196,13 @@ impl Banks for BanksServer {
|
|||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.root_bank()
|
.root_bank()
|
||||||
.get_blockhash_last_valid_slot(&blockhash)
|
.get_blockhash_last_valid_slot(blockhash)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let signature = transaction.signatures.get(0).cloned().unwrap_or_default();
|
let signature = transaction.signatures.get(0).cloned().unwrap_or_default();
|
||||||
let info =
|
let info =
|
||||||
TransactionInfo::new(signature, serialize(&transaction).unwrap(), last_valid_slot);
|
TransactionInfo::new(signature, serialize(&transaction).unwrap(), last_valid_slot);
|
||||||
self.transaction_sender.send(info).unwrap();
|
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
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3466,6 +3466,17 @@ impl Bank {
|
|||||||
None
|
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<()>)> {
|
pub fn get_signature_status_slot(&self, signature: &Signature) -> Option<(Slot, Result<()>)> {
|
||||||
let rcache = self.src.status_cache.read().unwrap();
|
let rcache = self.src.status_cache.read().unwrap();
|
||||||
rcache.get_signature_slot(signature, &self.ancestors)
|
rcache.get_signature_slot(signature, &self.ancestors)
|
||||||
|
Reference in New Issue
Block a user