diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index c4ed8ace9..1ae4f42a2 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -3050,14 +3050,6 @@ impl BeaconChain { // These fields are used for server-sent events. let state_root = new_head.beacon_state_root(); let head_slot = new_head.beacon_state.slot(); - let target_epoch_start_slot = new_head - .beacon_state - .current_epoch() - .start_slot(T::EthSpec::slots_per_epoch()); - let prev_target_epoch_start_slot = new_head - .beacon_state - .previous_epoch() - .start_slot(T::EthSpec::slots_per_epoch()); let head_proposer_index = new_head.beacon_block.message().proposer_index(); let proposer_graffiti = new_head .beacon_block @@ -3066,6 +3058,15 @@ impl BeaconChain { .graffiti() .as_utf8_lossy(); + // Find the dependent roots associated with this head before updating the snapshot. This + // is to ensure consistency when sending server sent events later in this method. + let dependent_root = new_head + .beacon_state + .proposer_shuffling_decision_root(self.genesis_block_root); + let prev_dependent_root = new_head + .beacon_state + .attester_shuffling_decision_root(self.genesis_block_root, RelativeEpoch::Current); + drop(lag_timer); // Update the snapshot that stores the head of the chain at the time it received the @@ -3210,12 +3211,8 @@ impl BeaconChain { // Register a server-sent event if necessary if let Some(event_handler) = self.event_handler.as_ref() { if event_handler.has_head_subscribers() { - if let Ok(Some(current_duty_dependent_root)) = - self.block_root_at_slot(target_epoch_start_slot - 1, WhenSlotSkipped::Prev) - { - if let Ok(Some(previous_duty_dependent_root)) = self - .block_root_at_slot(prev_target_epoch_start_slot - 1, WhenSlotSkipped::Prev) - { + match (dependent_root, prev_dependent_root) { + (Ok(current_duty_dependent_root), Ok(previous_duty_dependent_root)) => { event_handler.register(EventKind::Head(SseHead { slot: head_slot, block: beacon_block_root, @@ -3224,17 +3221,14 @@ impl BeaconChain { previous_duty_dependent_root, epoch_transition: is_epoch_transition, })); - } else { + } + (Err(e), _) | (_, Err(e)) => { warn!( self.log, - "Unable to find previous target root, cannot register head event" + "Unable to find dependent roots, cannot register head event"; + "error" => ?e ); } - } else { - warn!( - self.log, - "Unable to find current target root, cannot register head event" - ); } }