diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index b1d67e5d9e..2c2b36c37b 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -3715,13 +3715,22 @@ impl BeaconChain { } pub fn prepare_beacon_proposer_blocking(&self) -> Result<(), Error> { + let current_slot = self.slot()?; + + // Avoids raising an error before Bellatrix. + // + // See `Self::prepare_beacon_proposer_async` for more detail. + if self.slot_is_prior_to_bellatrix(current_slot + 1) { + return Ok(()); + } + let execution_layer = self .execution_layer .as_ref() .ok_or(Error::ExecutionLayerMissing)?; execution_layer - .block_on_generic(|_| self.prepare_beacon_proposer_async()) + .block_on_generic(|_| self.prepare_beacon_proposer_async(current_slot)) .map_err(Error::PrepareProposerBlockingFailed)? } @@ -3737,17 +3746,12 @@ impl BeaconChain { /// 1. We're in the tail-end of the slot (as defined by PAYLOAD_PREPARATION_LOOKAHEAD_FACTOR) /// 2. The head block is one slot (or less) behind the prepare slot (e.g., we're preparing for /// the next slot and the block at the current slot is already known). - pub async fn prepare_beacon_proposer_async(&self) -> Result<(), Error> { - let current_slot = self.slot()?; + pub async fn prepare_beacon_proposer_async(&self, current_slot: Slot) -> Result<(), Error> { let prepare_slot = current_slot + 1; let prepare_epoch = prepare_slot.epoch(T::EthSpec::slots_per_epoch()); // There's no need to run the proposer preparation routine before the bellatrix fork. - if self - .spec - .bellatrix_fork_epoch - .map_or(true, |bellatrix| prepare_epoch < bellatrix) - { + if self.slot_is_prior_to_bellatrix(prepare_slot) { return Ok(()); } @@ -3947,6 +3951,13 @@ impl BeaconChain { &self, current_slot: Slot, ) -> Result<(), Error> { + // Avoids raising an error before Bellatrix. + // + // See `Self::update_execution_engine_forkchoice_async` for more detail. + if self.slot_is_prior_to_bellatrix(current_slot + 1) { + return Ok(()); + } + let execution_layer = self .execution_layer .as_ref() @@ -3972,9 +3983,7 @@ impl BeaconChain { // The reason for a fcU message in the slot prior to the Bellatrix fork is in case the // terminal difficulty has already been reached and a payload preparation message needs to // be issued. - if self.spec.bellatrix_fork_epoch.map_or(true, |bellatrix| { - next_slot.epoch(T::EthSpec::slots_per_epoch()) < bellatrix - }) { + if self.slot_is_prior_to_bellatrix(next_slot) { return Ok(()); } @@ -4068,10 +4077,7 @@ impl BeaconChain { return Ok(()); }; - let forkchoice_updated_response = self - .execution_layer - .as_ref() - .ok_or(Error::ExecutionLayerMissing)? + let forkchoice_updated_response = execution_layer .notify_forkchoice_updated(head_hash, finalized_hash, current_slot, head_block_root) .await .map_err(Error::ExecutionForkChoiceUpdateFailed); @@ -4159,6 +4165,13 @@ impl BeaconChain { } } + /// Returns `true` if the given slot is prior to the `bellatrix_fork_epoch`. + fn slot_is_prior_to_bellatrix(&self, slot: Slot) -> bool { + self.spec.bellatrix_fork_epoch.map_or(true, |bellatrix| { + slot.epoch(T::EthSpec::slots_per_epoch()) < bellatrix + }) + } + /// Returns the status of the current head block, regarding the validity of the execution /// payload. pub fn head_safety_status(&self) -> Result { diff --git a/beacon_node/beacon_chain/src/proposer_prep_service.rs b/beacon_node/beacon_chain/src/proposer_prep_service.rs index 59977f02c8..18abbc8c5b 100644 --- a/beacon_node/beacon_chain/src/proposer_prep_service.rs +++ b/beacon_node/beacon_chain/src/proposer_prep_service.rs @@ -50,12 +50,19 @@ async fn proposer_prep_service( let inner_chain = chain.clone(); executor.spawn( async move { - if let Err(e) = inner_chain.prepare_beacon_proposer_async().await { - error!( - inner_chain.log, - "Proposer prepare routine failed"; - "error" => ?e - ); + if let Ok(current_slot) = inner_chain.slot() { + if let Err(e) = inner_chain + .prepare_beacon_proposer_async(current_slot) + .await + { + error!( + inner_chain.log, + "Proposer prepare routine failed"; + "error" => ?e + ); + } + } else { + debug!(inner_chain.log, "No slot for proposer prepare routine"); } }, "proposer_prep_update",