Skip to content

Commit 7a0a25a

Browse files
committed
Merge remote-tracking branch 'origin/unstable' into add-electra-fulu-sim-test-support
2 parents 0d292b0 + 70f8ab9 commit 7a0a25a

File tree

48 files changed

+859
-432
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+859
-432
lines changed

Cargo.lock

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ use operation_pool::{
9292
};
9393
use parking_lot::{Mutex, RwLock, RwLockWriteGuard};
9494
use proto_array::{DoNotReOrg, ProposerHeadError};
95+
use rand::RngCore;
9596
use safe_arith::SafeArith;
9697
use slasher::Slasher;
9798
use slot_clock::SlotClock;
@@ -491,6 +492,8 @@ pub struct BeaconChain<T: BeaconChainTypes> {
491492
pub data_availability_checker: Arc<DataAvailabilityChecker<T>>,
492493
/// The KZG trusted setup used by this chain.
493494
pub kzg: Arc<Kzg>,
495+
/// RNG instance used by the chain. Currently used for shuffling column sidecars in block publishing.
496+
pub rng: Arc<Mutex<Box<dyn RngCore + Send>>>,
494497
}
495498

496499
pub enum BeaconBlockResponseWrapper<E: EthSpec> {
@@ -4004,7 +4007,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
40044007
&mut state,
40054008
)
40064009
.unwrap_or_else(|e| {
4007-
error!("error caching light_client data {:?}", e);
4010+
debug!("error caching light_client data {:?}", e);
40084011
});
40094012
}
40104013

@@ -7132,6 +7135,31 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
71327135
}
71337136
}
71347137
}
7138+
7139+
/// Retrieves block roots (in ascending slot order) within some slot range from fork choice.
7140+
pub fn block_roots_from_fork_choice(&self, start_slot: u64, count: u64) -> Vec<Hash256> {
7141+
let head_block_root = self.canonical_head.cached_head().head_block_root();
7142+
let fork_choice_read_lock = self.canonical_head.fork_choice_read_lock();
7143+
let block_roots_iter = fork_choice_read_lock
7144+
.proto_array()
7145+
.iter_block_roots(&head_block_root);
7146+
let end_slot = start_slot.saturating_add(count);
7147+
let mut roots = vec![];
7148+
7149+
for (root, slot) in block_roots_iter {
7150+
if slot < end_slot && slot >= start_slot {
7151+
roots.push(root);
7152+
}
7153+
if slot < start_slot {
7154+
break;
7155+
}
7156+
}
7157+
7158+
drop(fork_choice_read_lock);
7159+
// return in ascending slot order
7160+
roots.reverse();
7161+
roots
7162+
}
71357163
}
71367164

71377165
impl<T: BeaconChainTypes> Drop for BeaconChain<T> {

beacon_node/beacon_chain/src/builder.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use logging::crit;
3030
use operation_pool::{OperationPool, PersistedOperationPool};
3131
use parking_lot::{Mutex, RwLock};
3232
use proto_array::{DisallowedReOrgOffsets, ReOrgThreshold};
33+
use rand::RngCore;
3334
use rayon::prelude::*;
3435
use slasher::Slasher;
3536
use slot_clock::{SlotClock, TestingSlotClock};
@@ -105,6 +106,7 @@ pub struct BeaconChainBuilder<T: BeaconChainTypes> {
105106
task_executor: Option<TaskExecutor>,
106107
validator_monitor_config: Option<ValidatorMonitorConfig>,
107108
import_all_data_columns: bool,
109+
rng: Option<Box<dyn RngCore + Send>>,
108110
}
109111

110112
impl<TSlotClock, TEth1Backend, E, THotStore, TColdStore>
@@ -145,6 +147,7 @@ where
145147
task_executor: None,
146148
validator_monitor_config: None,
147149
import_all_data_columns: false,
150+
rng: None,
148151
}
149152
}
150153

@@ -691,6 +694,14 @@ where
691694
self
692695
}
693696

697+
/// Sets the `rng` field.
698+
///
699+
/// Currently used for shuffling column sidecars in block publishing.
700+
pub fn rng(mut self, rng: Box<dyn RngCore + Send>) -> Self {
701+
self.rng = Some(rng);
702+
self
703+
}
704+
694705
/// Consumes `self`, returning a `BeaconChain` if all required parameters have been supplied.
695706
///
696707
/// An error will be returned at runtime if all required parameters have not been configured.
@@ -716,6 +727,7 @@ where
716727
.genesis_state_root
717728
.ok_or("Cannot build without a genesis state root")?;
718729
let validator_monitor_config = self.validator_monitor_config.unwrap_or_default();
730+
let rng = self.rng.ok_or("Cannot build without an RNG")?;
719731
let beacon_proposer_cache: Arc<Mutex<BeaconProposerCache>> = <_>::default();
720732

721733
let mut validator_monitor =
@@ -979,6 +991,7 @@ where
979991
.map_err(|e| format!("Error initializing DataAvailabilityChecker: {:?}", e))?,
980992
),
981993
kzg: self.kzg.clone(),
994+
rng: Arc::new(Mutex::new(rng)),
982995
};
983996

984997
let head = beacon_chain.head_snapshot();
@@ -1184,6 +1197,8 @@ mod test {
11841197
use genesis::{
11851198
generate_deterministic_keypairs, interop_genesis_state, DEFAULT_ETH1_BLOCK_HASH,
11861199
};
1200+
use rand::rngs::StdRng;
1201+
use rand::SeedableRng;
11871202
use ssz::Encode;
11881203
use std::time::Duration;
11891204
use store::config::StoreConfig;
@@ -1230,6 +1245,7 @@ mod test {
12301245
.testing_slot_clock(Duration::from_secs(1))
12311246
.expect("should configure testing slot clock")
12321247
.shutdown_sender(shutdown_tx)
1248+
.rng(Box::new(StdRng::seed_from_u64(42)))
12331249
.build()
12341250
.expect("should build");
12351251

beacon_node/beacon_chain/src/eth1_chain.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,12 @@ pub struct DummyEth1ChainBackend<E: EthSpec>(PhantomData<E>);
362362
impl<E: EthSpec> Eth1ChainBackend<E> for DummyEth1ChainBackend<E> {
363363
/// Produce some deterministic junk based upon the current epoch.
364364
fn eth1_data(&self, state: &BeaconState<E>, _spec: &ChainSpec) -> Result<Eth1Data, Error> {
365+
// [New in Electra:EIP6110]
366+
if let Ok(deposit_requests_start_index) = state.deposit_requests_start_index() {
367+
if state.eth1_deposit_index() == deposit_requests_start_index {
368+
return Ok(state.eth1_data().clone());
369+
}
370+
}
365371
let current_epoch = state.current_epoch();
366372
let slots_per_voting_period = E::slots_per_eth1_voting_period() as u64;
367373
let current_voting_period: u64 = current_epoch.as_u64() / slots_per_voting_period;
@@ -456,6 +462,12 @@ impl<E: EthSpec> CachingEth1Backend<E> {
456462

457463
impl<E: EthSpec> Eth1ChainBackend<E> for CachingEth1Backend<E> {
458464
fn eth1_data(&self, state: &BeaconState<E>, spec: &ChainSpec) -> Result<Eth1Data, Error> {
465+
// [New in Electra:EIP6110]
466+
if let Ok(deposit_requests_start_index) = state.deposit_requests_start_index() {
467+
if state.eth1_deposit_index() == deposit_requests_start_index {
468+
return Ok(state.eth1_data().clone());
469+
}
470+
}
459471
let period = E::SlotsPerEth1VotingPeriod::to_u64();
460472
let voting_period_start_slot = (state.slot() / period) * period;
461473
let voting_period_start_seconds = slot_start_seconds(

beacon_node/beacon_chain/src/test_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ use kzg::{Kzg, TrustedSetup};
3838
use logging::create_test_tracing_subscriber;
3939
use merkle_proof::MerkleTree;
4040
use operation_pool::ReceivedPreCapella;
41-
use parking_lot::Mutex;
42-
use parking_lot::RwLockWriteGuard;
41+
use parking_lot::{Mutex, RwLockWriteGuard};
4342
use rand::rngs::StdRng;
4443
use rand::Rng;
4544
use rand::SeedableRng;
@@ -588,7 +587,8 @@ where
588587
.chain_config(chain_config)
589588
.import_all_data_columns(self.import_all_data_columns)
590589
.event_handler(Some(ServerSentEventHandler::new_with_capacity(5)))
591-
.validator_monitor_config(validator_monitor_config);
590+
.validator_monitor_config(validator_monitor_config)
591+
.rng(Box::new(StdRng::seed_from_u64(42)));
592592

593593
builder = if let Some(mutator) = self.initial_mutator {
594594
mutator(builder)

beacon_node/beacon_chain/tests/store_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use beacon_chain::{
1616
};
1717
use logging::create_test_tracing_subscriber;
1818
use maplit::hashset;
19+
use rand::rngs::StdRng;
1920
use rand::Rng;
2021
use slot_clock::{SlotClock, TestingSlotClock};
2122
use state_processing::{state_advance::complete_state_advance, BlockReplayer};
@@ -2373,6 +2374,7 @@ async fn weak_subjectivity_sync_test(slots: Vec<Slot>, checkpoint_slot: Slot) {
23732374
.chain_config(ChainConfig::default())
23742375
.event_handler(Some(ServerSentEventHandler::new_with_capacity(1)))
23752376
.execution_layer(Some(mock.el))
2377+
.rng(Box::new(StdRng::seed_from_u64(42)))
23762378
.build()
23772379
.expect("should build");
23782380

beacon_node/client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ logging = { workspace = true }
3131
metrics = { workspace = true }
3232
monitoring_api = { workspace = true }
3333
network = { workspace = true }
34+
rand = { workspace = true }
3435
sensitive_url = { workspace = true }
3536
serde = { workspace = true }
3637
serde_json = { workspace = true }

beacon_node/client/src/builder.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ use genesis::{interop_genesis_state, Eth1GenesisService, DEFAULT_ETH1_BLOCK_HASH
3333
use lighthouse_network::{prometheus_client::registry::Registry, NetworkGlobals};
3434
use monitoring_api::{MonitoringHttpClient, ProcessType};
3535
use network::{NetworkConfig, NetworkSenders, NetworkService};
36+
use rand::rngs::{OsRng, StdRng};
37+
use rand::SeedableRng;
3638
use slasher::Slasher;
3739
use slasher_service::SlasherService;
3840
use std::net::TcpListener;
@@ -210,7 +212,10 @@ where
210212
.event_handler(event_handler)
211213
.execution_layer(execution_layer)
212214
.import_all_data_columns(config.network.subscribe_all_data_column_subnets)
213-
.validator_monitor_config(config.validator_monitor.clone());
215+
.validator_monitor_config(config.validator_monitor.clone())
216+
.rng(Box::new(
217+
StdRng::from_rng(OsRng).map_err(|e| format!("Failed to create RNG: {:?}", e))?,
218+
));
214219

215220
let builder = if let Some(slasher) = self.slasher.clone() {
216221
builder.slasher(slasher)

beacon_node/execution_layer/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ pub enum BlockProposalContents<E: EthSpec, Payload: AbstractExecPayload<E>> {
210210
/// `None` for blinded `PayloadAndBlobs`.
211211
blobs_and_proofs: Option<(BlobsList<E>, KzgProofs<E>)>,
212212
// TODO(electra): this should probably be a separate variant/superstruct
213+
// See: https://github.com/sigp/lighthouse/issues/6981
213214
requests: Option<ExecutionRequests<E>>,
214215
},
215216
}

beacon_node/http_api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ metrics = { workspace = true }
2828
network = { workspace = true }
2929
operation_pool = { workspace = true }
3030
parking_lot = { workspace = true }
31+
proto_array = { workspace = true }
3132
rand = { workspace = true }
3233
safe_arith = { workspace = true }
3334
sensitive_url = { workspace = true }

0 commit comments

Comments
 (0)