Skip to content

Commit 091e292

Browse files
authored
Return eth1_data early post transition (#7248)
N/A Return state.eth1_data() early if we have passed the transition period post electra. Even if we don't return early, the function would still return state.eth1_data() based on the current conditions. However, doing this explicitly here to match the spec. This covers setting the right eth1_data in our block. The other thing we need to ensure is that the deposits returned by the eth1_chain is empty post transition. The only way we get non-empty deposits post the transition is if `state.eth1_deposit_index` in the below code is less than `min(deposit_requests_start_index, state.eth1_data().deposit_count)`. https://github.com/sigp/lighthouse/blob/0850bcfb89d1048030c1aced795f3d43d91abeb0/beacon_node/beacon_chain/src/eth1_chain.rs#L543-L579 This can never happen because state.eth1_deposit_index will be equal to state.eth1_data.deposit count and cannot exceed the value. @michaelsproul @ethDreamer please double check the logic for deposits being empty post transition. Following the logic in the spec makes my head hurt.
1 parent d511ca0 commit 091e292

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

beacon_node/beacon_chain/src/eth1_chain.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,12 @@ pub struct DummyEth1ChainBackend<E: EthSpec>(PhantomData<E>);
369369
impl<E: EthSpec> Eth1ChainBackend<E> for DummyEth1ChainBackend<E> {
370370
/// Produce some deterministic junk based upon the current epoch.
371371
fn eth1_data(&self, state: &BeaconState<E>, _spec: &ChainSpec) -> Result<Eth1Data, Error> {
372+
// [New in Electra:EIP6110]
373+
if let Ok(deposit_requests_start_index) = state.deposit_requests_start_index() {
374+
if state.eth1_deposit_index() == deposit_requests_start_index {
375+
return Ok(state.eth1_data().clone());
376+
}
377+
}
372378
let current_epoch = state.current_epoch();
373379
let slots_per_voting_period = E::slots_per_eth1_voting_period() as u64;
374380
let current_voting_period: u64 = current_epoch.as_u64() / slots_per_voting_period;
@@ -467,6 +473,12 @@ impl<E: EthSpec> CachingEth1Backend<E> {
467473

468474
impl<E: EthSpec> Eth1ChainBackend<E> for CachingEth1Backend<E> {
469475
fn eth1_data(&self, state: &BeaconState<E>, spec: &ChainSpec) -> Result<Eth1Data, Error> {
476+
// [New in Electra:EIP6110]
477+
if let Ok(deposit_requests_start_index) = state.deposit_requests_start_index() {
478+
if state.eth1_deposit_index() == deposit_requests_start_index {
479+
return Ok(state.eth1_data().clone());
480+
}
481+
}
470482
let period = E::SlotsPerEth1VotingPeriod::to_u64();
471483
let voting_period_start_slot = (state.slot() / period) * period;
472484
let voting_period_start_seconds = slot_start_seconds(

0 commit comments

Comments
 (0)