@@ -25,10 +25,6 @@ use std::{
25
25
} ;
26
26
use tokio:: prelude:: Future ;
27
27
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
-
32
28
pub struct JsonRpcService {
33
29
thread_hdl : JoinHandle < ( ) > ,
34
30
@@ -45,6 +41,7 @@ struct RpcRequestMiddleware {
45
41
cluster_info : Arc < ClusterInfo > ,
46
42
trusted_validators : Option < HashSet < Pubkey > > ,
47
43
bank_forks : Arc < RwLock < BankForks > > ,
44
+ health_check_slot_distance : u64 ,
48
45
override_health_check : Arc < AtomicBool > ,
49
46
}
50
47
@@ -55,6 +52,7 @@ impl RpcRequestMiddleware {
55
52
cluster_info : Arc < ClusterInfo > ,
56
53
trusted_validators : Option < HashSet < Pubkey > > ,
57
54
bank_forks : Arc < RwLock < BankForks > > ,
55
+ health_check_slot_distance : u64 ,
58
56
override_health_check : Arc < AtomicBool > ,
59
57
) -> Self {
60
58
Self {
@@ -67,6 +65,7 @@ impl RpcRequestMiddleware {
67
65
cluster_info,
68
66
trusted_validators,
69
67
bank_forks,
68
+ health_check_slot_distance,
70
69
override_health_check,
71
70
}
72
71
}
@@ -171,12 +170,12 @@ impl RpcRequestMiddleware {
171
170
} ;
172
171
173
172
// 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
175
174
if latest_account_hash_slot > 0
176
175
&& latest_trusted_validator_account_hash_slot > 0
177
176
&& latest_account_hash_slot
178
177
> latest_trusted_validator_account_hash_slot
179
- . saturating_sub ( HEALTH_CHECK_SLOT_DISTANCE )
178
+ . saturating_sub ( self . health_check_slot_distance )
180
179
{
181
180
"ok"
182
181
} else {
@@ -300,6 +299,7 @@ impl JsonRpcService {
300
299
) -> Self {
301
300
info ! ( "rpc bound to {:?}" , rpc_addr) ;
302
301
info ! ( "rpc configuration: {:?}" , config) ;
302
+ let health_check_slot_distance = config. health_check_slot_distance ;
303
303
let request_processor = Arc :: new ( RwLock :: new ( JsonRpcRequestProcessor :: new (
304
304
config,
305
305
bank_forks. clone ( ) ,
@@ -327,6 +327,7 @@ impl JsonRpcService {
327
327
cluster_info. clone ( ) ,
328
328
trusted_validators,
329
329
bank_forks. clone ( ) ,
330
+ health_check_slot_distance,
330
331
override_health_check,
331
332
) ;
332
333
let server = ServerBuilder :: with_meta_extractor (
@@ -489,6 +490,7 @@ mod tests {
489
490
cluster_info. clone ( ) ,
490
491
None ,
491
492
bank_forks. clone ( ) ,
493
+ 42 ,
492
494
Arc :: new ( AtomicBool :: new ( false ) ) ,
493
495
) ;
494
496
let rrm_with_snapshot_config = RpcRequestMiddleware :: new (
@@ -502,6 +504,7 @@ mod tests {
502
504
cluster_info,
503
505
None ,
504
506
bank_forks,
507
+ 42 ,
505
508
Arc :: new ( AtomicBool :: new ( false ) ) ,
506
509
) ;
507
510
@@ -536,6 +539,7 @@ mod tests {
536
539
cluster_info,
537
540
None ,
538
541
create_bank_forks ( ) ,
542
+ 42 ,
539
543
Arc :: new ( AtomicBool :: new ( false ) ) ,
540
544
) ;
541
545
assert_eq ! ( rm. health_check( ) , "ok" ) ;
@@ -545,6 +549,8 @@ mod tests {
545
549
fn test_health_check_with_trusted_validators ( ) {
546
550
let cluster_info = Arc :: new ( ClusterInfo :: new_with_invalid_keypair ( ContactInfo :: default ( ) ) ) ;
547
551
552
+ let health_check_slot_distance = 123 ;
553
+
548
554
let override_health_check = Arc :: new ( AtomicBool :: new ( false ) ) ;
549
555
let trusted_validators = vec ! [ Pubkey :: new_rand( ) , Pubkey :: new_rand( ) , Pubkey :: new_rand( ) ] ;
550
556
let rm = RpcRequestMiddleware :: new (
@@ -553,6 +559,7 @@ mod tests {
553
559
cluster_info. clone ( ) ,
554
560
Some ( trusted_validators. clone ( ) . into_iter ( ) . collect ( ) ) ,
555
561
create_bank_forks ( ) ,
562
+ health_check_slot_distance,
556
563
override_health_check. clone ( ) ,
557
564
) ;
558
565
@@ -595,7 +602,7 @@ mod tests {
595
602
. insert (
596
603
CrdsValue :: new_unsigned ( CrdsData :: AccountsHashes ( SnapshotHash :: new (
597
604
trusted_validators[ 1 ] ,
598
- vec ! [ ( 1000 + HEALTH_CHECK_SLOT_DISTANCE - 1 , Hash :: default ( ) ) ] ,
605
+ vec ! [ ( 1000 + health_check_slot_distance - 1 , Hash :: default ( ) ) ] ,
599
606
) ) ) ,
600
607
1 ,
601
608
)
@@ -611,7 +618,7 @@ mod tests {
611
618
. insert (
612
619
CrdsValue :: new_unsigned ( CrdsData :: AccountsHashes ( SnapshotHash :: new (
613
620
trusted_validators[ 2 ] ,
614
- vec ! [ ( 1000 + HEALTH_CHECK_SLOT_DISTANCE , Hash :: default ( ) ) ] ,
621
+ vec ! [ ( 1000 + health_check_slot_distance , Hash :: default ( ) ) ] ,
615
622
) ) ) ,
616
623
1 ,
617
624
)
0 commit comments