Use BlockCommitmentCache for RPC slots (#11103)

* Add BankForks::highest_descendant(slot)

* Update debug messages

* Update core/src/rpc.rs

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>

* cargo fmt

* Remove highest_descendant

* Fix test

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
This commit is contained in:
Greg Fitzgerald
2020-07-17 16:22:27 -06:00
committed by GitHub
parent a255b0fc86
commit 815b0f31b4
2 changed files with 45 additions and 19 deletions

View File

@ -1,4 +1,4 @@
use solana_sdk::clock::Slot;
use solana_sdk::{clock::Slot, commitment_config::CommitmentLevel};
use solana_vote_program::vote_state::MAX_LOCKOUT_HISTORY;
use std::collections::HashMap;
@ -103,6 +103,22 @@ impl BlockCommitmentCache {
self.commitment_slots
}
pub fn highest_gossip_confirmed_slot(&self) -> Slot {
// TODO: see solana_core::RpcSubscriptions:
//self.last_checked_slots.get(&CommitmentLevel::SingleGossip).unwrap_or(&0)
self.highest_confirmed_slot
}
pub fn slot_with_commitment(&self, commitment_level: CommitmentLevel) -> Slot {
match commitment_level {
CommitmentLevel::Recent => self.slot(),
CommitmentLevel::Root => self.root(),
CommitmentLevel::Single => self.highest_confirmed_slot(),
CommitmentLevel::SingleGossip => self.highest_gossip_confirmed_slot(),
CommitmentLevel::Max => self.highest_confirmed_root(),
}
}
fn highest_slot_with_confirmation_count(&self, confirmation_count: usize) -> Slot {
assert!(confirmation_count > 0 && confirmation_count <= MAX_LOCKOUT_HISTORY);
for slot in (self.root()..self.slot()).rev() {