Skip to content

Commit 17baf80

Browse files
committed
only export symbols when agave-unstable-api set
1 parent b11599e commit 17baf80

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

gossip/src/push_active_set.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#[cfg(feature = "agave-unstable-api")]
2+
use crate::{
3+
cluster_info::REFRESH_PUSH_ACTIVE_SET_INTERVAL_MS, stake_weighting_config::TimeConstant,
4+
};
5+
#[cfg(feature = "agave-unstable-api")]
26
use solana_low_pass_filter::api as lpf;
37
use {
4-
crate::{
5-
cluster_info::REFRESH_PUSH_ACTIVE_SET_INTERVAL_MS,
6-
stake_weighting_config::{TimeConstant, WeightingConfig},
7-
weighted_shuffle::WeightedShuffle,
8-
},
8+
crate::{stake_weighting_config::WeightingConfig, weighted_shuffle::WeightedShuffle},
99
indexmap::IndexMap,
1010
rand::Rng,
1111
solana_bloom::bloom::{Bloom, ConcurrentBloom},
@@ -15,9 +15,14 @@ use {
1515
};
1616

1717
const NUM_PUSH_ACTIVE_SET_ENTRIES: usize = 25;
18+
19+
#[cfg(feature = "agave-unstable-api")]
1820
const ALPHA_MIN: u64 = lpf::SCALE.get();
21+
#[cfg(feature = "agave-unstable-api")]
1922
const ALPHA_MAX: u64 = 2 * lpf::SCALE.get();
23+
#[cfg(feature = "agave-unstable-api")]
2024
const DEFAULT_ALPHA: u64 = ALPHA_MAX;
25+
#[cfg(feature = "agave-unstable-api")]
2126
// Low pass filter convergence time (ms)
2227
const DEFAULT_TC_MS: u64 = 30_000;
2328

@@ -26,6 +31,7 @@ pub enum WeightingMode {
2631
// alpha = 2.0 -> Quadratic
2732
Static,
2833
// alpha in [1.0, 2.0], smoothed over time, scaled up by 1,000,000 to avoid floating-point math
34+
#[cfg(feature = "agave-unstable-api")]
2935
Dynamic {
3036
alpha: u64, // current alpha (fixed-point, 1,000,000–2,000,000)
3137
filter_k: u64, // default: 611,000
@@ -37,6 +43,7 @@ impl From<&WeightingConfig> for WeightingMode {
3743
fn from(cfg: &WeightingConfig) -> Self {
3844
match cfg {
3945
WeightingConfig::Static => WeightingMode::Static,
46+
#[cfg(feature = "agave-unstable-api")]
4047
WeightingConfig::Dynamic { tc } => {
4148
let tc_ms = match tc {
4249
TimeConstant::Value(tc_ms) => *tc_ms,
@@ -49,10 +56,16 @@ impl From<&WeightingConfig> for WeightingMode {
4956
tc_ms,
5057
}
5158
}
59+
#[cfg(not(feature = "agave-unstable-api"))]
60+
WeightingConfig::Dynamic { .. } => {
61+
// When the feature is not enabled, fall back to Static mode
62+
WeightingMode::Static
63+
}
5264
}
5365
}
5466
}
5567

68+
#[cfg(feature = "agave-unstable-api")]
5669
#[inline]
5770
fn get_weight(bucket: u64, alpha: u64) -> u64 {
5871
debug_assert!((ALPHA_MIN..=ALPHA_MIN + lpf::SCALE.get()).contains(&alpha));
@@ -99,6 +112,7 @@ impl PushActiveSet {
99112
self.mode = WeightingMode::Static;
100113
}
101114
}
115+
#[cfg(feature = "agave-unstable-api")]
102116
WeightingConfig::Dynamic { tc } => {
103117
let new_tc_ms = match tc {
104118
TimeConstant::Value(tc_ms) => *tc_ms,
@@ -138,6 +152,12 @@ impl PushActiveSet {
138152
}
139153
}
140154
}
155+
#[cfg(not(feature = "agave-unstable-api"))]
156+
WeightingConfig::Dynamic { .. } => {
157+
// When the feature is not enabled, Dynamic config is treated as Static
158+
// This ensures the code compiles but users don't get the dynamic behavior
159+
info!("Dynamic weighting config ignored - requires 'agave-unstable-api' feature");
160+
}
141161
}
142162
}
143163
}
@@ -193,6 +213,7 @@ impl PushActiveSet {
193213
// Gossip nodes to be sampled for each push active set.
194214
nodes: &[Pubkey],
195215
stakes: &HashMap<Pubkey, u64>,
216+
#[cfg_attr(not(feature = "agave-unstable-api"), allow(unused_variables))]
196217
self_pubkey: &Pubkey,
197218
) {
198219
if nodes.is_empty() {
@@ -234,6 +255,7 @@ impl PushActiveSet {
234255
entry.rotate(rng, size, num_bloom_filter_items, nodes, &weights);
235256
}
236257
}
258+
#[cfg(feature = "agave-unstable-api")]
237259
WeightingMode::Dynamic {
238260
ref mut alpha,
239261
filter_k,
@@ -281,28 +303,6 @@ impl PushActiveSet {
281303
}
282304
}
283305

284-
#[cfg(not(feature = "agave-unstable-api"))]
285-
mod lpf {
286-
pub const SCALE: std::num::NonZeroU64 = std::num::NonZeroU64::new(1000000).unwrap();
287-
pub struct FilterConfig {
288-
pub output_range: std::ops::Range<u64>,
289-
#[allow(dead_code)]
290-
pub k: u64,
291-
}
292-
pub fn compute_k(_: u64, _: u64) -> u64 {
293-
0
294-
}
295-
pub fn filter_alpha(alpha: u64, _: u64, filter_config: FilterConfig) -> u64 {
296-
alpha.clamp(
297-
filter_config.output_range.start,
298-
filter_config.output_range.end,
299-
)
300-
}
301-
pub fn interpolate(_: u64, _: u64) -> u64 {
302-
0
303-
}
304-
}
305-
306306
impl PushActiveSetEntry {
307307
const BLOOM_FALSE_RATE: f64 = 0.1;
308308
const BLOOM_MAX_BITS: usize = 1024 * 8 * 4;

low-pass-filter/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
[package]
22
name = "solana-low-pass-filter"
3-
version = "3.0.0"
4-
edition = "2021"
3+
description = "Low Pass Filter for Gossip Peer Weighting"
4+
version = { workspace = true }
5+
repository = { workspace = true }
6+
homepage = { workspace = true }
7+
license = { workspace = true }
8+
edition = { workspace = true }
9+
publish = false
510

611
[features]
712
default = []

low-pass-filter/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(not(feature = "agave-unstable-api"), allow(dead_code))]
1+
#![cfg(feature = "agave-unstable-api")]
22
//! Fixed-point IIR filter for smoothing `alpha` updates.
33
//!
44
//! This is equivalent to a discrete-time Butterworth filter of order 1
@@ -11,7 +11,6 @@
1111
//! K = W_C / (1 + W_C), where Wc = 2π * Fs / Tc
1212
//! Fc = 1 / TC (cutoff frequency)
1313
//! Fs = 1 / refresh interval
14-
#[cfg(feature = "agave-unstable-api")]
1514
pub mod api {
1615
use std::num::NonZeroU64;
1716

0 commit comments

Comments
 (0)