Use cluster confirmations in rpc and pubsub (#9138)
* Add runtime methods to simply get status and slot * Add helper function to get slot confirmation_count from BlockCommitmentCache * Return cluster confirmations in getSignatureStatus * Remove use of invalid get_signature_confirmation_status * Remove unused methods * Update pubsub to use cluster confirmations * Fix test_check_signature_subscribe failure * Refactor confirmations to read commitment cache only once * Review comments * Use bank, root from BlockCommitmentCache * Update docs * Add metric for block-commitment aggregations Co-authored-by: Justin Starry <justin@solana.com>
This commit is contained in:
@@ -103,29 +103,20 @@ impl<T: Serialize + Clone> StatusCache<T> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn get_signature_status_slow(
|
||||
pub fn get_signature_slot(
|
||||
&self,
|
||||
sig: &Signature,
|
||||
signature: &Signature,
|
||||
ancestors: &HashMap<Slot, usize>,
|
||||
) -> Option<SignatureConfirmationStatus<T>> {
|
||||
trace!("get_signature_status_slow");
|
||||
) -> Option<(Slot, T)> {
|
||||
let mut keys = vec![];
|
||||
let mut val: Vec<_> = self.cache.iter().map(|(k, _)| *k).collect();
|
||||
keys.append(&mut val);
|
||||
|
||||
for blockhash in keys.iter() {
|
||||
trace!("get_signature_status_slow: trying {}", blockhash);
|
||||
if let Some((forkid, res)) = self.get_signature_status(sig, blockhash, ancestors) {
|
||||
trace!("get_signature_status_slow: got {}", forkid);
|
||||
let confirmations = ancestors
|
||||
.get(&forkid)
|
||||
.copied()
|
||||
.unwrap_or_else(|| ancestors.len());
|
||||
return Some(SignatureConfirmationStatus {
|
||||
slot: forkid,
|
||||
confirmations,
|
||||
status: res,
|
||||
});
|
||||
trace!("get_signature_slot: trying {}", blockhash);
|
||||
let status = self.get_signature_status(signature, blockhash, ancestors);
|
||||
if status.is_some() {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
None
|
||||
@@ -265,10 +256,7 @@ mod tests {
|
||||
status_cache.get_signature_status(&sig, &blockhash, &HashMap::new()),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
status_cache.get_signature_status_slow(&sig, &HashMap::new()),
|
||||
None
|
||||
);
|
||||
assert_eq!(status_cache.get_signature_slot(&sig, &HashMap::new()), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -283,12 +271,8 @@ mod tests {
|
||||
Some((0, ()))
|
||||
);
|
||||
assert_eq!(
|
||||
status_cache.get_signature_status_slow(&sig, &ancestors),
|
||||
Some(SignatureConfirmationStatus {
|
||||
slot: 0,
|
||||
confirmations: 1,
|
||||
status: ()
|
||||
})
|
||||
status_cache.get_signature_slot(&sig, &ancestors),
|
||||
Some((0, ()))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -303,10 +287,7 @@ mod tests {
|
||||
status_cache.get_signature_status(&sig, &blockhash, &ancestors),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
status_cache.get_signature_status_slow(&sig, &ancestors),
|
||||
None
|
||||
);
|
||||
assert_eq!(status_cache.get_signature_slot(&sig, &ancestors), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -323,24 +304,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_sig_with_root_ancestor_fork_max_len() {
|
||||
let sig = Signature::default();
|
||||
let mut status_cache = BankStatusCache::default();
|
||||
let blockhash = hash(Hash::default().as_ref());
|
||||
let ancestors = vec![(2, 2)].into_iter().collect();
|
||||
status_cache.insert(&blockhash, &sig, 0, ());
|
||||
status_cache.add_root(0);
|
||||
assert_eq!(
|
||||
status_cache.get_signature_status_slow(&sig, &ancestors),
|
||||
Some(SignatureConfirmationStatus {
|
||||
slot: 0,
|
||||
confirmations: ancestors.len(),
|
||||
status: ()
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_insert_picks_latest_blockhash_fork() {
|
||||
let sig = Signature::default();
|
||||
@@ -371,10 +334,6 @@ mod tests {
|
||||
status_cache.get_signature_status(&sig, &blockhash, &ancestors),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
status_cache.get_signature_status_slow(&sig, &ancestors),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Reference in New Issue
Block a user