Skip to content

Commit 3ca64a7

Browse files
committed
address comments and make default setting static for PushActiveSet
1 parent 60dc858 commit 3ca64a7

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

gossip/src/crds_gossip_push.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub struct CrdsGossipPush {
7474
impl Default for CrdsGossipPush {
7575
fn default() -> Self {
7676
Self {
77-
active_set: RwLock::new(PushActiveSet::new_dynamic()),
77+
active_set: RwLock::new(PushActiveSet::new_static()),
7878
crds_cursor: Mutex::default(),
7979
received_cache: Mutex::new(ReceivedCache::new(2 * CRDS_UNIQUE_PUBKEY_CAPACITY)),
8080
push_fanout: CRDS_GOSSIP_PUSH_FANOUT,

gossip/src/push_active_set.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn get_weight(bucket: u64, alpha: u64) -> u64 {
6767
/// Note: This function is most accurate when `base` is small e.g. < ~25.
6868
#[inline]
6969
#[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 {
7171
let scale = lpf::SCALE.get();
7272
let t = alpha.saturating_sub(ALPHA_MIN);
7373
debug_assert!(t <= scale, "interpolation t={} > SCALE={}", t, scale);
@@ -94,10 +94,8 @@ impl PushActiveSet {
9494
}
9595
}
9696

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)
10199
}
102100

103101
pub(crate) fn apply_cfg(&mut self, cfg: &WeightingConfig) {
@@ -365,6 +363,12 @@ mod tests {
365363

366364
const MAX_STAKE: u64 = (1 << 20) * LAMPORTS_PER_SOL;
367365

366+
fn push_active_set_new_dynamic() -> PushActiveSet {
367+
PushActiveSet::new(WeightingMode::from(WeightingConfigTyped::Dynamic {
368+
tc: TimeConstant::Default,
369+
}))
370+
}
371+
368372
// Helper to generate a stake map given unstaked count
369373
fn make_stakes(
370374
nodes: &[Pubkey],
@@ -473,7 +477,7 @@ mod tests {
473477
let stakes = repeat_with(|| rng.gen_range(1..MAX_STAKE));
474478
let mut stakes: HashMap<_, _> = nodes.iter().copied().zip(stakes).collect();
475479
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();
477481
assert!(active_set.entries.iter().all(|entry| entry.0.is_empty()));
478482
active_set.rotate(&mut rng, 5, CLUSTER_SIZE, &nodes, &stakes, &pubkey);
479483
assert!(active_set.entries.iter().all(|entry| entry.0.len() == 5));
@@ -593,7 +597,7 @@ mod tests {
593597
#[test]
594598
fn test_alpha_converges_to_expected_target() {
595599
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
597601

598602
let mut rng = ChaChaRng::from_seed([77u8; 32]);
599603
let mut nodes: Vec<Pubkey> = repeat_with(Pubkey::new_unique).take(CLUSTER_SIZE).collect();
@@ -606,7 +610,7 @@ mod tests {
606610
let stakes = make_stakes(&nodes, num_unstaked, &mut rng);
607611
let my_pubkey = nodes.pop().unwrap();
608612

609-
let mut active_set = PushActiveSet::new_dynamic();
613+
let mut active_set = push_active_set_new_dynamic();
610614

611615
// Simulate repeated calls to `rotate()` (as would happen every 7.5s)
612616
// 8 calls (60s) should be enough to converge to the expected target alpha.
@@ -645,13 +649,13 @@ mod tests {
645649
#[test]
646650
fn test_alpha_converges_up_and_down() {
647651
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
649653
const ROTATE_CALLS: usize = 8;
650654

651655
let mut rng = ChaChaRng::from_seed([99u8; 32]);
652656
let mut nodes: Vec<Pubkey> = repeat_with(Pubkey::new_unique).take(CLUSTER_SIZE).collect();
653657

654-
let mut active_set = PushActiveSet::new_dynamic();
658+
let mut active_set = push_active_set_new_dynamic();
655659

656660
// 0% unstaked → alpha_target = 1,000,000
657661
let num_unstaked = 0;
@@ -790,7 +794,7 @@ mod tests {
790794
#[test]
791795
fn test_apply_cfg_dynamic_to_static() {
792796
// Dynamic -> Static: Mode switch
793-
let mut active_set = PushActiveSet::new_dynamic();
797+
let mut active_set = push_active_set_new_dynamic();
794798
assert!(matches!(active_set.mode, WeightingMode::Dynamic { .. }));
795799

796800
active_set.apply_cfg(&WeightingConfig::new_for_test(WEIGHTING_MODE_STATIC, 0));
@@ -826,7 +830,7 @@ mod tests {
826830
#[test]
827831
fn test_apply_cfg_dynamic_to_dynamic_same_tc() {
828832
// Dynamic -> Dynamic (same tc): No change
829-
let mut active_set = PushActiveSet::new_dynamic();
833+
let mut active_set = push_active_set_new_dynamic();
830834
let original_mode = active_set.mode;
831835

832836
let config = WeightingConfig::new_for_test(WEIGHTING_MODE_DYNAMIC, 0);
@@ -839,7 +843,7 @@ mod tests {
839843
#[test]
840844
fn test_apply_cfg_dynamic_to_dynamic_different_tc() {
841845
// 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();
843847

844848
// Change to a different tc value
845849
let new_tc_ms = 45_000;

gossip/src/stake_weighting_config.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use {serde::Deserialize, solana_account::ReadableAccount, solana_runtime::bank::Bank};
1+
use {
2+
serde::{Deserialize, Serialize},
3+
solana_account::ReadableAccount,
4+
solana_runtime::bank::Bank,
5+
};
26

37
#[derive(Debug, Clone, Copy, PartialEq)]
48
pub enum TimeConstant {
@@ -47,7 +51,7 @@ impl From<&WeightingConfig> for WeightingConfigTyped {
4751

4852
impl WeightingConfig {
4953
#[cfg(test)]
50-
pub fn new_for_test(weighting_mode: u8, tc_ms: u64) -> Self {
54+
pub(crate) fn new_for_test(weighting_mode: u8, tc_ms: u64) -> Self {
5155
Self {
5256
_version: 0,
5357
_authority: [0; 32],

low-pass-filter/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ publish = false
1212
path = "src/lib.rs"
1313

1414
[features]
15-
default = []
1615
agave-unstable-api = []
1716

1817
[dependencies]

0 commit comments

Comments
 (0)