Skip to content

Commit 1c58bc0

Browse files
committed
Add setup for account control
1 parent 6ba787a commit 1c58bc0

File tree

12 files changed

+175
-48
lines changed

12 files changed

+175
-48
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gossip/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ serde-big-array = { workspace = true }
5252
serde_bytes = { workspace = true }
5353
serde_derive = { workspace = true }
5454
siphasher = { workspace = true }
55+
solana-account = { workspace = true }
5556
solana-bloom = { workspace = true }
5657
solana-clap-utils = { workspace = true }
5758
solana-client = { workspace = true }

gossip/src/cluster_info.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use {
6868
solana_pubkey::Pubkey,
6969
solana_quic_definitions::QUIC_PORT_OFFSET,
7070
solana_rayon_threadlimit::get_thread_count,
71-
solana_runtime::bank_forks::BankForks,
71+
solana_runtime::{bank::Bank, bank_forks::BankForks},
7272
solana_sanitize::Sanitize,
7373
solana_signature::Signature,
7474
solana_signer::Signer,
@@ -223,6 +223,7 @@ impl ClusterInfo {
223223
stakes: &HashMap<Pubkey, u64>,
224224
gossip_validators: Option<&HashSet<Pubkey>>,
225225
sender: &impl ChannelSend<PacketBatch>,
226+
maybe_bank_ref: Option<&Bank>,
226227
) {
227228
let shred_version = self.my_contact_info.read().unwrap().shred_version();
228229
let self_keypair: Arc<Keypair> = self.keypair().clone();
@@ -235,6 +236,7 @@ impl ClusterInfo {
235236
&self.ping_cache,
236237
&mut pings,
237238
&self.socket_addr_space,
239+
maybe_bank_ref,
238240
);
239241
let pings = pings
240242
.into_iter()
@@ -1436,7 +1438,7 @@ impl ClusterInfo {
14361438
.thread_name(|i| format!("solRunGossip{i:02}"))
14371439
.build()
14381440
.unwrap();
1439-
let mut epoch_specs = bank_forks.map(EpochSpecs::from);
1441+
let mut epoch_specs = bank_forks.clone().map(EpochSpecs::from);
14401442
Builder::new()
14411443
.name("solGossip".to_string())
14421444
.spawn(move || {
@@ -1493,12 +1495,18 @@ impl ClusterInfo {
14931495
//TODO: possibly tune this parameter
14941496
//we saw a deadlock passing an self.read().unwrap().timeout into sleep
14951497
if start - last_push > REFRESH_PUSH_ACTIVE_SET_INTERVAL_MS {
1498+
let maybe_bank = bank_forks
1499+
.as_ref()
1500+
.and_then(|bf| bf.read().ok())
1501+
.map(|forks| forks.root_bank());
1502+
let maybe_bank_ref = maybe_bank.as_deref();
14961503
self.refresh_my_gossip_contact_info();
14971504
self.refresh_push_active_set(
14981505
&recycler,
14991506
&stakes,
15001507
gossip_validators.as_ref(),
15011508
&sender,
1509+
maybe_bank_ref,
15021510
);
15031511
last_push = timestamp();
15041512
}
@@ -3086,6 +3094,7 @@ mod tests {
30863094
&cluster_info.ping_cache,
30873095
&mut Vec::new(), // pings
30883096
&SocketAddrSpace::Unspecified,
3097+
None,
30893098
);
30903099
let mut reqs = cluster_info.generate_new_gossip_requests(
30913100
&thread_pool,
@@ -3227,6 +3236,7 @@ mod tests {
32273236
&cluster_info.ping_cache,
32283237
&mut Vec::new(), // pings
32293238
&SocketAddrSpace::Unspecified,
3239+
None,
32303240
);
32313241
//check that all types of gossip messages are signed correctly
32323242
cluster_info.flush_push_queue();

gossip/src/crds_gossip.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use {
2727
solana_keypair::Keypair,
2828
solana_ledger::shred::Shred,
2929
solana_pubkey::Pubkey,
30+
solana_runtime::bank::Bank,
3031
solana_signer::Signer,
3132
solana_streamer::socket::SocketAddrSpace,
3233
solana_time_utils::timestamp,
@@ -186,6 +187,7 @@ impl CrdsGossip {
186187
ping_cache: &Mutex<PingCache>,
187188
pings: &mut Vec<(SocketAddr, Ping)>,
188189
socket_addr_space: &SocketAddrSpace,
190+
maybe_bank_ref: Option<&Bank>,
189191
) {
190192
self.push.refresh_push_active_set(
191193
&self.crds,
@@ -196,6 +198,7 @@ impl CrdsGossip {
196198
ping_cache,
197199
pings,
198200
socket_addr_space,
201+
maybe_bank_ref,
199202
)
200203
}
201204

@@ -445,6 +448,7 @@ mod test {
445448
&ping_cache,
446449
&mut Vec::new(), // pings
447450
&SocketAddrSpace::Unspecified,
451+
None,
448452
);
449453
let now = timestamp();
450454
//incorrect dest

gossip/src/crds_gossip_push.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use {
2525
itertools::Itertools,
2626
solana_keypair::Keypair,
2727
solana_pubkey::Pubkey,
28+
solana_runtime::bank::Bank,
2829
solana_signer::Signer,
2930
solana_streamer::socket::SocketAddrSpace,
3031
solana_time_utils::timestamp,
@@ -250,6 +251,7 @@ impl CrdsGossipPush {
250251
ping_cache: &Mutex<PingCache>,
251252
pings: &mut Vec<(SocketAddr, Ping)>,
252253
socket_addr_space: &SocketAddrSpace,
254+
maybe_bank_ref: Option<&Bank>,
253255
) {
254256
let mut rng = rand::thread_rng();
255257
// Active and valid gossip nodes with matching shred-version.
@@ -287,6 +289,7 @@ impl CrdsGossipPush {
287289
cluster_size,
288290
&nodes,
289291
stakes,
292+
maybe_bank_ref,
290293
)
291294
}
292295
}
@@ -447,6 +450,7 @@ mod tests {
447450
&ping_cache,
448451
&mut Vec::new(), // pings
449452
&SocketAddrSpace::Unspecified,
453+
None,
450454
);
451455

452456
let new_msg = CrdsValue::new_unsigned(CrdsData::from(ContactInfo::new_localhost(
@@ -514,6 +518,7 @@ mod tests {
514518
&ping_cache,
515519
&mut Vec::new(),
516520
&SocketAddrSpace::Unspecified,
521+
None,
517522
);
518523

519524
// push 3's contact info to 1 and 2 and 3
@@ -557,6 +562,7 @@ mod tests {
557562
&ping_cache,
558563
&mut Vec::new(), // pings
559564
&SocketAddrSpace::Unspecified,
565+
None,
560566
);
561567

562568
let new_msg = CrdsValue::new_unsigned(CrdsData::from(ContactInfo::new_localhost(
@@ -605,6 +611,7 @@ mod tests {
605611
&ping_cache,
606612
&mut Vec::new(), // pings
607613
&SocketAddrSpace::Unspecified,
614+
None,
608615
);
609616

610617
let mut ci = ContactInfo::new_localhost(&solana_pubkey::new_rand(), 0);

gossip/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ mod protocol;
4141
mod push_active_set;
4242
mod received_cache;
4343
pub mod restart_crds_values;
44+
pub mod stake_weighting_config;
4445
pub mod weighted_shuffle;
4546

4647
#[macro_use]

gossip/src/low_pass_filter.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,28 @@
99
//! K = W_C / (1 + W_C), where Wc = 2π * Fc * Fs
1010
//! Fc = 1 / TC (cutoff frequency)
1111
//! Fs = 1 / refresh interval
12-
use crate::cluster_info::REFRESH_PUSH_ACTIVE_SET_INTERVAL_MS;
12+
use std::num::NonZeroU64;
1313

1414
// Fixed point scale for K and `alpha` calculation
15-
pub const SCALE: u64 = 1_000;
16-
// 30_000ms convergence time
17-
const TC_MS: u64 = 30_000;
18-
// 7500ms refresh interval
19-
const FS_MS: u64 = REFRESH_PUSH_ACTIVE_SET_INTERVAL_MS;
15+
pub const SCALE: NonZeroU64 = NonZeroU64::new(1000).unwrap();
2016
// 2 * pi * SCALE
2117
const TWO_PI_SCALED: u64 = 6_283;
22-
const W_C_SCALED: u64 = (TWO_PI_SCALED * FS_MS) / TC_MS;
23-
const K: u64 = (W_C_SCALED * 1_000 + (SCALE / 2)) / (SCALE + W_C_SCALED);
18+
19+
/// Computes the filter constant `K` for a given sample period and
20+
/// time‑constant, both in **milliseconds**.
21+
///
22+
/// K = Wc / (1 + Wc) where Wc = 2π · Fs / Tc
23+
///
24+
/// Returns `K` scaled by `SCALE` (0–1000).
25+
pub fn compute_k(fs_ms: u64, tc_ms: u64) -> u64 {
26+
if tc_ms == 0 {
27+
return 0;
28+
} // disabled / passthrough
29+
let scale = SCALE.get();
30+
let wc_scaled = (TWO_PI_SCALED * fs_ms) / tc_ms;
31+
// round to nearest integer
32+
((wc_scaled * scale + scale / 2) / (scale + wc_scaled)).min(scale)
33+
}
2434

2535
/// Updates alpha with a first-order low-pass filter.
2636
/// ### Convergence Characteristics (w/ K = 0.611):
@@ -32,21 +42,23 @@ const K: u64 = (W_C_SCALED * 1_000 + (SCALE / 2)) / (SCALE + W_C_SCALED);
3242
/// - ~98% after 4
3343
/// - ~99% after 5
3444
///
35-
/// Note: Each update is 7500ms apart.
45+
/// Note: Each update is `fs_ms` apart. `fs_ms` is 7500ms for push_active_set.
3646
///
3747
/// If future code changes make `alpha_target` jump larger, we must retune
3848
/// `TC`/`K` or use a higher‑order filter to avoid lag/overshoot.
3949
/// Returns `alpha_new = K * target + (1 - K) * prev`, rounded and clamped.
40-
pub fn filter_alpha(prev: u64, target: u64, min: u64, max: u64) -> u64 {
41-
let updated = (K * target + (SCALE - K) * prev) / SCALE;
42-
updated.clamp(min, max)
50+
pub fn filter_alpha(prev: u64, target: u64, k: u64, min: u64, max: u64) -> u64 {
51+
let scale = SCALE.get();
52+
let next = (k * target + (scale - k) * prev) / scale;
53+
next.clamp(min, max)
4354
}
4455

4556
/// Approximates `base^alpha` rounded to nearest integer using
4657
/// integer-only linear interpolation between `base^1` and `base^2`.
4758
#[inline]
4859
pub fn interpolate(base: u64, t: u64) -> u64 {
49-
debug_assert!(t <= SCALE, "interpolation t={} > SCALE={}", t, SCALE);
60+
let scale = SCALE.get();
61+
debug_assert!(t <= scale, "interpolation t={} > SCALE={}", t, scale);
5062
let base_squared = base.saturating_mul(base);
51-
((base * (SCALE - t) + base_squared * t) + SCALE / 2) / SCALE
63+
((base * (scale - t) + base_squared * t) + scale / 2) / scale
5264
}

0 commit comments

Comments
 (0)