Skip to content
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ use operation_pool::{
};
use parking_lot::{Mutex, RwLock, RwLockWriteGuard};
use proto_array::{DoNotReOrg, ProposerHeadError};
use rand::RngCore;
use safe_arith::SafeArith;
use slasher::Slasher;
use slot_clock::SlotClock;
Expand Down Expand Up @@ -494,6 +495,8 @@ pub struct BeaconChain<T: BeaconChainTypes> {
pub data_availability_checker: Arc<DataAvailabilityChecker<T>>,
/// The KZG trusted setup used by this chain.
pub kzg: Arc<Kzg>,
/// RNG instance used by the chain. Currently used for shuffling column sidecars in block publishing.
pub rng: Arc<Mutex<Box<dyn RngCore + Send>>>,
}

pub enum BeaconBlockResponseWrapper<E: EthSpec> {
Expand Down
14 changes: 14 additions & 0 deletions beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use logging::crit;
use operation_pool::{OperationPool, PersistedOperationPool};
use parking_lot::{Mutex, RwLock};
use proto_array::{DisallowedReOrgOffsets, ReOrgThreshold};
use rand::RngCore;
use slasher::Slasher;
use slot_clock::{SlotClock, TestingSlotClock};
use state_processing::{per_slot_processing, AllCaches};
Expand Down Expand Up @@ -106,6 +107,7 @@ pub struct BeaconChainBuilder<T: BeaconChainTypes> {
task_executor: Option<TaskExecutor>,
validator_monitor_config: Option<ValidatorMonitorConfig>,
import_all_data_columns: bool,
rng: Option<Box<dyn RngCore + Send>>,
}

impl<TSlotClock, TEth1Backend, E, THotStore, TColdStore>
Expand Down Expand Up @@ -147,6 +149,7 @@ where
task_executor: None,
validator_monitor_config: None,
import_all_data_columns: false,
rng: None,
}
}

Expand Down Expand Up @@ -699,6 +702,14 @@ where
self
}

/// Sets the `rng` field.
///
/// Currently used for shuffling column sidecars in block publishing.
pub fn rng(mut self, rng: Box<dyn RngCore + Send>) -> Self {
self.rng = Some(rng);
self
}

/// Consumes `self`, returning a `BeaconChain` if all required parameters have been supplied.
///
/// An error will be returned at runtime if all required parameters have not been configured.
Expand All @@ -724,6 +735,7 @@ where
.genesis_state_root
.ok_or("Cannot build without a genesis state root")?;
let validator_monitor_config = self.validator_monitor_config.unwrap_or_default();
let rng = self.rng.ok_or("Cannot build without an RNG")?;
let head_tracker = Arc::new(self.head_tracker.unwrap_or_default());
let beacon_proposer_cache: Arc<Mutex<BeaconProposerCache>> = <_>::default();

Expand Down Expand Up @@ -980,6 +992,7 @@ where
.map_err(|e| format!("Error initializing DataAvailabilityChecker: {:?}", e))?,
),
kzg: self.kzg.clone(),
rng: Arc::new(Mutex::new(rng)),
};

let head = beacon_chain.head_snapshot();
Expand Down Expand Up @@ -1188,6 +1201,7 @@ mod test {
.testing_slot_clock(Duration::from_secs(1))
.expect("should configure testing slot clock")
.shutdown_sender(shutdown_tx)
.rng(Box::new(StdRng::seed_from_u64(42)))
.build()
.expect("should build");

Expand Down
6 changes: 3 additions & 3 deletions beacon_node/beacon_chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ use kzg::{Kzg, TrustedSetup};
use logging::create_test_tracing_subscriber;
use merkle_proof::MerkleTree;
use operation_pool::ReceivedPreCapella;
use parking_lot::Mutex;
use parking_lot::RwLockWriteGuard;
use parking_lot::{Mutex, RwLockWriteGuard};
use rand::rngs::StdRng;
use rand::Rng;
use rand::SeedableRng;
Expand Down Expand Up @@ -588,7 +587,8 @@ where
.chain_config(chain_config)
.import_all_data_columns(self.import_all_data_columns)
.event_handler(Some(ServerSentEventHandler::new_with_capacity(5)))
.validator_monitor_config(validator_monitor_config);
.validator_monitor_config(validator_monitor_config)
.rng(Box::new(StdRng::seed_from_u64(42)));

builder = if let Some(mutator) = self.initial_mutator {
mutator(builder)
Expand Down
2 changes: 2 additions & 0 deletions beacon_node/beacon_chain/tests/store_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use beacon_chain::{
};
use logging::create_test_tracing_subscriber;
use maplit::hashset;
use rand::rngs::StdRng;
use rand::Rng;
use slot_clock::{SlotClock, TestingSlotClock};
use state_processing::{state_advance::complete_state_advance, BlockReplayer};
Expand Down Expand Up @@ -2398,6 +2399,7 @@ async fn weak_subjectivity_sync_test(slots: Vec<Slot>, checkpoint_slot: Slot) {
.chain_config(ChainConfig::default())
.event_handler(Some(ServerSentEventHandler::new_with_capacity(1)))
.execution_layer(Some(mock.el))
.rng(Box::new(StdRng::seed_from_u64(42)))
.build()
.expect("should build");

Expand Down
1 change: 1 addition & 0 deletions beacon_node/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ logging = { workspace = true }
metrics = { workspace = true }
monitoring_api = { workspace = true }
network = { workspace = true }
rand = { workspace = true }
sensitive_url = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
7 changes: 6 additions & 1 deletion beacon_node/client/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ use genesis::{interop_genesis_state, Eth1GenesisService, DEFAULT_ETH1_BLOCK_HASH
use lighthouse_network::{prometheus_client::registry::Registry, NetworkGlobals};
use monitoring_api::{MonitoringHttpClient, ProcessType};
use network::{NetworkConfig, NetworkSenders, NetworkService};
use rand::rngs::{OsRng, StdRng};
use rand::SeedableRng;
use slasher::Slasher;
use slasher_service::SlasherService;
use std::net::TcpListener;
Expand Down Expand Up @@ -210,7 +212,10 @@ where
.event_handler(event_handler)
.execution_layer(execution_layer)
.import_all_data_columns(config.network.subscribe_all_data_column_subnets)
.validator_monitor_config(config.validator_monitor.clone());
.validator_monitor_config(config.validator_monitor.clone())
.rng(Box::new(
StdRng::from_rng(OsRng).map_err(|e| format!("Failed to create RNG: {:?}", e))?,
));

let builder = if let Some(slasher) = self.slasher.clone() {
builder.slasher(slasher)
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/http_api/src/publish_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ fn publish_column_sidecars<T: BeaconChainTypes>(
.len()
.saturating_sub(malicious_withhold_count);
// Randomize columns before dropping the last malicious_withhold_count items
data_column_sidecars.shuffle(&mut rand::thread_rng());
data_column_sidecars.shuffle(&mut **chain.rng.lock());
data_column_sidecars.truncate(columns_to_keep);
}
let pubsub_messages = data_column_sidecars
Expand Down
3 changes: 3 additions & 0 deletions beacon_node/network/src/subnet_service/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use beacon_chain::{
};
use genesis::{generate_deterministic_keypairs, interop_genesis_state, DEFAULT_ETH1_BLOCK_HASH};
use lighthouse_network::NetworkConfig;
use rand::rngs::StdRng;
use rand::SeedableRng;
use slot_clock::{SlotClock, SystemTimeSlotClock};
use std::sync::{Arc, LazyLock};
use std::time::{Duration, SystemTime};
Expand Down Expand Up @@ -76,6 +78,7 @@ impl TestBeaconChain {
Duration::from_millis(SLOT_DURATION_MILLIS),
))
.shutdown_sender(shutdown_tx)
.rng(Box::new(StdRng::seed_from_u64(42)))
.build()
.expect("should build"),
);
Expand Down
Loading