Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Use blockstore opt slot vs. local latest opt slot
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Czabaniuk committed Oct 11, 2023
1 parent 0373940 commit 784126f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
6 changes: 3 additions & 3 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,17 +381,17 @@ impl JsonRpcRequestProcessor {
Self {
config: JsonRpcConfig::default(),
snapshot_config: None,
bank_forks: Arc::clone(&bank_forks),
bank_forks,
block_commitment_cache: Arc::new(RwLock::new(BlockCommitmentCache::new(
HashMap::new(),
0,
CommitmentSlots::new_from_slot(slot),
))),
blockstore,
blockstore: Arc::clone(&blockstore),
validator_exit: create_validator_exit(exit.clone()),
health: Arc::new(RpcHealth::new(
Arc::clone(&optimistically_confirmed_bank),
bank_forks,
blockstore,
0,
exit,
startup_verification_complete,
Expand Down
44 changes: 29 additions & 15 deletions rpc/src/rpc_health.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
crate::optimistically_confirmed_bank_tracker::OptimisticallyConfirmedBank,
solana_runtime::bank_forks::BankForks,
solana_ledger::blockstore::Blockstore,
solana_sdk::clock::Slot,
std::sync::{
atomic::{AtomicBool, Ordering},
Expand All @@ -17,7 +17,7 @@ pub enum RpcHealthStatus {

pub struct RpcHealth {
optimistically_confirmed_bank: Arc<RwLock<OptimisticallyConfirmedBank>>,
bank_forks: Arc<RwLock<BankForks>>,
blockstore: Arc<Blockstore>,
health_check_slot_distance: u64,
override_health_check: Arc<AtomicBool>,
startup_verification_complete: Arc<AtomicBool>,
Expand All @@ -28,14 +28,14 @@ pub struct RpcHealth {
impl RpcHealth {
pub fn new(
optimistically_confirmed_bank: Arc<RwLock<OptimisticallyConfirmedBank>>,
bank_forks: Arc<RwLock<BankForks>>,
blockstore: Arc<Blockstore>,
health_check_slot_distance: u64,
override_health_check: Arc<AtomicBool>,
startup_verification_complete: Arc<AtomicBool>,
) -> Self {
Self {
optimistically_confirmed_bank,
bank_forks,
blockstore,
health_check_slot_distance,
override_health_check,
startup_verification_complete,
Expand All @@ -60,28 +60,42 @@ impl RpcHealth {
}

// A node participating in gossip will observe cluster optimistically
// confirmed slots even if the node is behind. On the other hand, the
// root from BankForks is node's latest finalized slot.
// TODO: this isn't quite an apples to apples comparison ...
let cluster_optimistically_confirmed_slot = self
// confirmed slots even if the node is behind. Optimistically confirmed
// slots are marked in the Blockstore, even if the node itself is not
// caught up with the tip of the cluster.
let my_latest_optimistically_confirmed_slot = self
.optimistically_confirmed_bank
.read()
.unwrap()
.bank
.slot();
let my_latest_root_slot = self.bank_forks.read().unwrap().root();

if my_latest_root_slot
> cluster_optimistically_confirmed_slot.saturating_sub(self.health_check_slot_distance)
let mut optimistic_slot_infos = match self.blockstore.get_latest_optimistic_slots(1) {
Ok(infos) => infos,
Err(err) => {
warn!("health check: blockstore error: {err}");
return RpcHealthStatus::Unknown;
}
};
let Some((cluster_latest_optimistically_confirmed_slot, _, _)) =
optimistic_slot_infos.pop()
else {
warn!("health check: blockstore does not contain any optimistically confirmed slots");
return RpcHealthStatus::Unknown;
};

if my_latest_optimistically_confirmed_slot
> cluster_latest_optimistically_confirmed_slot
.saturating_sub(self.health_check_slot_distance)
{
RpcHealthStatus::Ok
} else {
let num_slots =
cluster_optimistically_confirmed_slot.saturating_sub(my_latest_root_slot);
let num_slots = cluster_latest_optimistically_confirmed_slot
.saturating_sub(my_latest_optimistically_confirmed_slot);
warn!(
"health check: behind by {num_slots} \
slots: me={my_latest_root_slot}, \
latest cluster={cluster_optimistically_confirmed_slot}",
slots: me={my_latest_optimistically_confirmed_slot}, \
latest cluster={cluster_latest_optimistically_confirmed_slot}",
);
RpcHealthStatus::Behind { num_slots }
}
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/rpc_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ impl JsonRpcService {

let health = Arc::new(RpcHealth::new(
Arc::clone(&optimistically_confirmed_bank),
Arc::clone(&bank_forks),
Arc::clone(&blockstore),
config.health_check_slot_distance,
override_health_check,
startup_verification_complete,
Expand Down

0 comments on commit 784126f

Please sign in to comment.