@@ -67,7 +67,7 @@ fn get_weight(bucket: u64, alpha: u64) -> u64 {
67
67
/// Note: This function is most accurate when `base` is small e.g. < ~25.
68
68
#[ inline]
69
69
#[ allow( clippy:: arithmetic_side_effects) ]
70
- pub fn gossip_interpolate_weight ( base : u64 , base_squared : u64 , alpha : u64 ) -> u64 {
70
+ fn gossip_interpolate_weight ( base : u64 , base_squared : u64 , alpha : u64 ) -> u64 {
71
71
let scale = lpf:: SCALE . get ( ) ;
72
72
let t = alpha. saturating_sub ( ALPHA_MIN ) ;
73
73
debug_assert ! ( t <= scale, "interpolation t={} > SCALE={}" , t, scale) ;
@@ -94,10 +94,8 @@ impl PushActiveSet {
94
94
}
95
95
}
96
96
97
- pub ( crate ) fn new_dynamic ( ) -> Self {
98
- Self :: new ( WeightingMode :: from ( WeightingConfigTyped :: Dynamic {
99
- tc : TimeConstant :: Default ,
100
- } ) )
97
+ pub ( crate ) fn new_static ( ) -> Self {
98
+ Self :: new ( WeightingMode :: Static )
101
99
}
102
100
103
101
pub ( crate ) fn apply_cfg ( & mut self , cfg : & WeightingConfig ) {
@@ -365,6 +363,12 @@ mod tests {
365
363
366
364
const MAX_STAKE : u64 = ( 1 << 20 ) * LAMPORTS_PER_SOL ;
367
365
366
+ fn push_active_set_new_dynamic ( ) -> PushActiveSet {
367
+ PushActiveSet :: new ( WeightingMode :: from ( WeightingConfigTyped :: Dynamic {
368
+ tc : TimeConstant :: Default ,
369
+ } ) )
370
+ }
371
+
368
372
// Helper to generate a stake map given unstaked count
369
373
fn make_stakes (
370
374
nodes : & [ Pubkey ] ,
@@ -473,7 +477,7 @@ mod tests {
473
477
let stakes = repeat_with ( || rng. gen_range ( 1 ..MAX_STAKE ) ) ;
474
478
let mut stakes: HashMap < _ , _ > = nodes. iter ( ) . copied ( ) . zip ( stakes) . collect ( ) ;
475
479
stakes. insert ( pubkey, rng. gen_range ( 1 ..MAX_STAKE ) ) ;
476
- let mut active_set = PushActiveSet :: new_dynamic ( ) ;
480
+ let mut active_set = push_active_set_new_dynamic ( ) ;
477
481
assert ! ( active_set. entries. iter( ) . all( |entry| entry. 0 . is_empty( ) ) ) ;
478
482
active_set. rotate ( & mut rng, 5 , CLUSTER_SIZE , & nodes, & stakes, & pubkey) ;
479
483
assert ! ( active_set. entries. iter( ) . all( |entry| entry. 0 . len( ) == 5 ) ) ;
@@ -593,7 +597,7 @@ mod tests {
593
597
#[ test]
594
598
fn test_alpha_converges_to_expected_target ( ) {
595
599
const CLUSTER_SIZE : usize = 415 ;
596
- const TOLERANCE_MILLI : u64 = 10_000 ; // ±1% of alpha
600
+ const TOLERANCE_MILLI : u64 = lpf :: SCALE . get ( ) / 100 ; // ±1% of alpha
597
601
598
602
let mut rng = ChaChaRng :: from_seed ( [ 77u8 ; 32 ] ) ;
599
603
let mut nodes: Vec < Pubkey > = repeat_with ( Pubkey :: new_unique) . take ( CLUSTER_SIZE ) . collect ( ) ;
@@ -606,7 +610,7 @@ mod tests {
606
610
let stakes = make_stakes ( & nodes, num_unstaked, & mut rng) ;
607
611
let my_pubkey = nodes. pop ( ) . unwrap ( ) ;
608
612
609
- let mut active_set = PushActiveSet :: new_dynamic ( ) ;
613
+ let mut active_set = push_active_set_new_dynamic ( ) ;
610
614
611
615
// Simulate repeated calls to `rotate()` (as would happen every 7.5s)
612
616
// 8 calls (60s) should be enough to converge to the expected target alpha.
@@ -645,13 +649,13 @@ mod tests {
645
649
#[ test]
646
650
fn test_alpha_converges_up_and_down ( ) {
647
651
const CLUSTER_SIZE : usize = 415 ;
648
- const TOLERANCE_MILLI : u64 = 10_000 ; // ±1% of alpha
652
+ const TOLERANCE_MILLI : u64 = lpf :: SCALE . get ( ) / 100 ; // ±1% of alpha
649
653
const ROTATE_CALLS : usize = 8 ;
650
654
651
655
let mut rng = ChaChaRng :: from_seed ( [ 99u8 ; 32 ] ) ;
652
656
let mut nodes: Vec < Pubkey > = repeat_with ( Pubkey :: new_unique) . take ( CLUSTER_SIZE ) . collect ( ) ;
653
657
654
- let mut active_set = PushActiveSet :: new_dynamic ( ) ;
658
+ let mut active_set = push_active_set_new_dynamic ( ) ;
655
659
656
660
// 0% unstaked → alpha_target = 1,000,000
657
661
let num_unstaked = 0 ;
@@ -790,7 +794,7 @@ mod tests {
790
794
#[ test]
791
795
fn test_apply_cfg_dynamic_to_static ( ) {
792
796
// Dynamic -> Static: Mode switch
793
- let mut active_set = PushActiveSet :: new_dynamic ( ) ;
797
+ let mut active_set = push_active_set_new_dynamic ( ) ;
794
798
assert ! ( matches!( active_set. mode, WeightingMode :: Dynamic { .. } ) ) ;
795
799
796
800
active_set. apply_cfg ( & WeightingConfig :: new_for_test ( WEIGHTING_MODE_STATIC , 0 ) ) ;
@@ -826,7 +830,7 @@ mod tests {
826
830
#[ test]
827
831
fn test_apply_cfg_dynamic_to_dynamic_same_tc ( ) {
828
832
// Dynamic -> Dynamic (same tc): No change
829
- let mut active_set = PushActiveSet :: new_dynamic ( ) ;
833
+ let mut active_set = push_active_set_new_dynamic ( ) ;
830
834
let original_mode = active_set. mode ;
831
835
832
836
let config = WeightingConfig :: new_for_test ( WEIGHTING_MODE_DYNAMIC , 0 ) ;
@@ -839,7 +843,7 @@ mod tests {
839
843
#[ test]
840
844
fn test_apply_cfg_dynamic_to_dynamic_different_tc ( ) {
841
845
// Dynamic -> Dynamic (different tc): Update filter parameters
842
- let mut active_set = PushActiveSet :: new_dynamic ( ) ;
846
+ let mut active_set = push_active_set_new_dynamic ( ) ;
843
847
844
848
// Change to a different tc value
845
849
let new_tc_ms = 45_000 ;
0 commit comments