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

Commit 4dd6591

Browse files
authored
Added --health-check-slot-distance (#10324) (#10331)
automerge
1 parent 1632178 commit 4dd6591

File tree

3 files changed

+52
-18
lines changed

3 files changed

+52
-18
lines changed

core/src/rpc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub struct JsonRpcConfig {
6464
pub enable_rpc_transaction_history: bool,
6565
pub identity_pubkey: Pubkey,
6666
pub faucet_addr: Option<SocketAddr>,
67+
pub health_check_slot_distance: u64,
6768
}
6869

6970
#[derive(Clone)]

core/src/rpc_service.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ use std::{
2525
};
2626
use tokio::prelude::Future;
2727

28-
// If trusted validators are specified, consider this validator healthy if its latest account hash
29-
// is no further behind than this distance from the latest trusted validator account hash
30-
const HEALTH_CHECK_SLOT_DISTANCE: u64 = 150;
31-
3228
pub struct JsonRpcService {
3329
thread_hdl: JoinHandle<()>,
3430

@@ -45,6 +41,7 @@ struct RpcRequestMiddleware {
4541
cluster_info: Arc<ClusterInfo>,
4642
trusted_validators: Option<HashSet<Pubkey>>,
4743
bank_forks: Arc<RwLock<BankForks>>,
44+
health_check_slot_distance: u64,
4845
override_health_check: Arc<AtomicBool>,
4946
}
5047

@@ -55,6 +52,7 @@ impl RpcRequestMiddleware {
5552
cluster_info: Arc<ClusterInfo>,
5653
trusted_validators: Option<HashSet<Pubkey>>,
5754
bank_forks: Arc<RwLock<BankForks>>,
55+
health_check_slot_distance: u64,
5856
override_health_check: Arc<AtomicBool>,
5957
) -> Self {
6058
Self {
@@ -67,6 +65,7 @@ impl RpcRequestMiddleware {
6765
cluster_info,
6866
trusted_validators,
6967
bank_forks,
68+
health_check_slot_distance,
7069
override_health_check,
7170
}
7271
}
@@ -171,12 +170,12 @@ impl RpcRequestMiddleware {
171170
};
172171

173172
// This validator is considered healthy if its latest account hash slot is within
174-
// `HEALTH_CHECK_SLOT_DISTANCE` of the latest trusted validator's account hash slot
173+
// `health_check_slot_distance` of the latest trusted validator's account hash slot
175174
if latest_account_hash_slot > 0
176175
&& latest_trusted_validator_account_hash_slot > 0
177176
&& latest_account_hash_slot
178177
> latest_trusted_validator_account_hash_slot
179-
.saturating_sub(HEALTH_CHECK_SLOT_DISTANCE)
178+
.saturating_sub(self.health_check_slot_distance)
180179
{
181180
"ok"
182181
} else {
@@ -300,6 +299,7 @@ impl JsonRpcService {
300299
) -> Self {
301300
info!("rpc bound to {:?}", rpc_addr);
302301
info!("rpc configuration: {:?}", config);
302+
let health_check_slot_distance = config.health_check_slot_distance;
303303
let request_processor = Arc::new(RwLock::new(JsonRpcRequestProcessor::new(
304304
config,
305305
bank_forks.clone(),
@@ -327,6 +327,7 @@ impl JsonRpcService {
327327
cluster_info.clone(),
328328
trusted_validators,
329329
bank_forks.clone(),
330+
health_check_slot_distance,
330331
override_health_check,
331332
);
332333
let server = ServerBuilder::with_meta_extractor(
@@ -489,6 +490,7 @@ mod tests {
489490
cluster_info.clone(),
490491
None,
491492
bank_forks.clone(),
493+
42,
492494
Arc::new(AtomicBool::new(false)),
493495
);
494496
let rrm_with_snapshot_config = RpcRequestMiddleware::new(
@@ -502,6 +504,7 @@ mod tests {
502504
cluster_info,
503505
None,
504506
bank_forks,
507+
42,
505508
Arc::new(AtomicBool::new(false)),
506509
);
507510

@@ -536,6 +539,7 @@ mod tests {
536539
cluster_info,
537540
None,
538541
create_bank_forks(),
542+
42,
539543
Arc::new(AtomicBool::new(false)),
540544
);
541545
assert_eq!(rm.health_check(), "ok");
@@ -545,6 +549,8 @@ mod tests {
545549
fn test_health_check_with_trusted_validators() {
546550
let cluster_info = Arc::new(ClusterInfo::new_with_invalid_keypair(ContactInfo::default()));
547551

552+
let health_check_slot_distance = 123;
553+
548554
let override_health_check = Arc::new(AtomicBool::new(false));
549555
let trusted_validators = vec![Pubkey::new_rand(), Pubkey::new_rand(), Pubkey::new_rand()];
550556
let rm = RpcRequestMiddleware::new(
@@ -553,6 +559,7 @@ mod tests {
553559
cluster_info.clone(),
554560
Some(trusted_validators.clone().into_iter().collect()),
555561
create_bank_forks(),
562+
health_check_slot_distance,
556563
override_health_check.clone(),
557564
);
558565

@@ -595,7 +602,7 @@ mod tests {
595602
.insert(
596603
CrdsValue::new_unsigned(CrdsData::AccountsHashes(SnapshotHash::new(
597604
trusted_validators[1],
598-
vec![(1000 + HEALTH_CHECK_SLOT_DISTANCE - 1, Hash::default())],
605+
vec![(1000 + health_check_slot_distance - 1, Hash::default())],
599606
))),
600607
1,
601608
)
@@ -611,7 +618,7 @@ mod tests {
611618
.insert(
612619
CrdsValue::new_unsigned(CrdsData::AccountsHashes(SnapshotHash::new(
613620
trusted_validators[2],
614-
vec![(1000 + HEALTH_CHECK_SLOT_DISTANCE, Hash::default())],
621+
vec![(1000 + health_check_slot_distance, Hash::default())],
615622
))),
616623
1,
617624
)

validator/src/main.rs

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -516,16 +516,18 @@ pub fn main() {
516516
.takes_value(true)
517517
.validator(is_pubkey_or_keypair)
518518
.requires("identity")
519-
.help("Validator vote account public key. If unspecified voting will be disabled. \
520-
The authorized voter for the account must either be the --identity keypair \
521-
or with the --authorized-voter argument")
519+
.help("Validator vote account public key. \
520+
If unspecified voting will be disabled. \
521+
The authorized voter for the account must either be the \
522+
--identity keypair or with the --authorized-voter argument")
522523
)
523524
.arg(
524525
Arg::with_name("init_complete_file")
525526
.long("init-complete-file")
526527
.value_name("FILE")
527528
.takes_value(true)
528-
.help("Create this file, if it doesn't already exist, once node initialization is complete"),
529+
.help("Create this file if it doesn't already exist \
530+
once node initialization is complete"),
529531
)
530532
.arg(
531533
Arg::with_name("ledger_path")
@@ -550,7 +552,8 @@ pub fn main() {
550552
.long("no-snapshot-fetch")
551553
.takes_value(false)
552554
.requires("entrypoint")
553-
.help("Do not attempt to fetch a snapshot from the cluster, start from a local snapshot if present"),
555+
.help("Do not attempt to fetch a snapshot from the cluster, \
556+
start from a local snapshot if present"),
554557
)
555558
.arg(
556559
Arg::with_name("no_genesis_fetch")
@@ -599,19 +602,35 @@ pub fn main() {
599602
Arg::with_name("enable_rpc_exit")
600603
.long("enable-rpc-exit")
601604
.takes_value(false)
602-
.help("Enable the JSON RPC 'validatorExit' API. Only enable in a debug environment"),
605+
.help("Enable the JSON RPC 'validatorExit' API. \
606+
Only enable in a debug environment"),
603607
)
604608
.arg(
605609
Arg::with_name("enable_rpc_set_log_filter")
606610
.long("enable-rpc-set-log-filter")
607611
.takes_value(false)
608-
.help("Enable the JSON RPC 'setLogFilter' API. Only enable in a debug environment"),
612+
.help("Enable the JSON RPC 'setLogFilter' API. \
613+
Only enable in a debug environment"),
609614
)
610615
.arg(
611616
Arg::with_name("enable_rpc_transaction_history")
612617
.long("enable-rpc-transaction-history")
613618
.takes_value(false)
614-
.help("Enable historical transaction info over JSON RPC, including the 'getConfirmedBlock' API. This will cause an increase in disk usage and IOPS"),
619+
.help("Enable historical transaction info over JSON RPC, \
620+
including the 'getConfirmedBlock' API. \
621+
This will cause an increase in disk usage and IOPS"),
622+
)
623+
.arg(
624+
Arg::with_name("health_check_slot_distance")
625+
.long("health-check-slot-distance")
626+
.value_name("SLOT_DISTANCE")
627+
.takes_value(true)
628+
.default_value("150")
629+
.help("If --trusted-validators are specified, report this validator healthy \
630+
if its latest account hash is no further behind than this number of \
631+
slots from the latest trusted validator account hash. \
632+
If no --trusted-validators are specified, the validator will always \
633+
report itself to be healthy")
615634
)
616635
.arg(
617636
Arg::with_name("rpc_faucet_addr")
@@ -651,7 +670,8 @@ pub fn main() {
651670
.takes_value(true)
652671
.conflicts_with("entrypoint")
653672
.validator(solana_net_utils::is_host)
654-
.help("IP address for the node to advertise in gossip when --entrypoint is not provided [default: 127.0.0.1]"),
673+
.help("IP address for the node to advertise in gossip when \
674+
--entrypoint is not provided [default: 127.0.0.1]"),
655675
)
656676
.arg(
657677
Arg::with_name("dynamic_port_range")
@@ -668,7 +688,8 @@ pub fn main() {
668688
.value_name("SNAPSHOT_INTERVAL_SLOTS")
669689
.takes_value(true)
670690
.default_value("100")
671-
.help("Number of slots between generating snapshots, 0 to disable snapshots"),
691+
.help("Number of slots between generating snapshots, \
692+
0 to disable snapshots"),
672693
)
673694
.arg(
674695
Arg::with_name("accounts_hash_interval_slots")
@@ -874,6 +895,11 @@ pub fn main() {
874895
faucet_addr: matches.value_of("rpc_faucet_addr").map(|address| {
875896
solana_net_utils::parse_host_port(address).expect("failed to parse faucet address")
876897
}),
898+
health_check_slot_distance: value_t_or_exit!(
899+
matches,
900+
"health_check_slot_distance",
901+
u64
902+
),
877903
},
878904
rpc_ports: value_t!(matches, "rpc_port", u16)
879905
.ok()

0 commit comments

Comments
 (0)