Don't log crits for missing EE before Bellatrix (#3150)

## Issue Addressed

NA

## Proposed Changes

Fixes an issue introduced in #3088 which was causing unnecessary `crit` logs on networks without Bellatrix enabled.

## Additional Info

NA
This commit is contained in:
Paul Hauner 2022-04-11 23:14:47 +00:00
parent fff4dd6311
commit c8edeaff29
2 changed files with 41 additions and 21 deletions

View File

@ -3715,13 +3715,22 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
} }
pub fn prepare_beacon_proposer_blocking(&self) -> Result<(), Error> { 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 let execution_layer = self
.execution_layer .execution_layer
.as_ref() .as_ref()
.ok_or(Error::ExecutionLayerMissing)?; .ok_or(Error::ExecutionLayerMissing)?;
execution_layer execution_layer
.block_on_generic(|_| self.prepare_beacon_proposer_async()) .block_on_generic(|_| self.prepare_beacon_proposer_async(current_slot))
.map_err(Error::PrepareProposerBlockingFailed)? .map_err(Error::PrepareProposerBlockingFailed)?
} }
@ -3737,17 +3746,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// 1. We're in the tail-end of the slot (as defined by PAYLOAD_PREPARATION_LOOKAHEAD_FACTOR) /// 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 /// 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). /// the next slot and the block at the current slot is already known).
pub async fn prepare_beacon_proposer_async(&self) -> Result<(), Error> { pub async fn prepare_beacon_proposer_async(&self, current_slot: Slot) -> Result<(), Error> {
let current_slot = self.slot()?;
let prepare_slot = current_slot + 1; let prepare_slot = current_slot + 1;
let prepare_epoch = prepare_slot.epoch(T::EthSpec::slots_per_epoch()); 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. // There's no need to run the proposer preparation routine before the bellatrix fork.
if self if self.slot_is_prior_to_bellatrix(prepare_slot) {
.spec
.bellatrix_fork_epoch
.map_or(true, |bellatrix| prepare_epoch < bellatrix)
{
return Ok(()); return Ok(());
} }
@ -3947,6 +3951,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
&self, &self,
current_slot: Slot, current_slot: Slot,
) -> Result<(), Error> { ) -> 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 let execution_layer = self
.execution_layer .execution_layer
.as_ref() .as_ref()
@ -3972,9 +3983,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// The reason for a fcU message in the slot prior to the Bellatrix fork is in case the // 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 // terminal difficulty has already been reached and a payload preparation message needs to
// be issued. // be issued.
if self.spec.bellatrix_fork_epoch.map_or(true, |bellatrix| { if self.slot_is_prior_to_bellatrix(next_slot) {
next_slot.epoch(T::EthSpec::slots_per_epoch()) < bellatrix
}) {
return Ok(()); return Ok(());
} }
@ -4068,10 +4077,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
return Ok(()); return Ok(());
}; };
let forkchoice_updated_response = self let forkchoice_updated_response = execution_layer
.execution_layer
.as_ref()
.ok_or(Error::ExecutionLayerMissing)?
.notify_forkchoice_updated(head_hash, finalized_hash, current_slot, head_block_root) .notify_forkchoice_updated(head_hash, finalized_hash, current_slot, head_block_root)
.await .await
.map_err(Error::ExecutionForkChoiceUpdateFailed); .map_err(Error::ExecutionForkChoiceUpdateFailed);
@ -4159,6 +4165,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
} }
} }
/// 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 /// Returns the status of the current head block, regarding the validity of the execution
/// payload. /// payload.
pub fn head_safety_status(&self) -> Result<HeadSafetyStatus, BeaconChainError> { pub fn head_safety_status(&self) -> Result<HeadSafetyStatus, BeaconChainError> {

View File

@ -50,12 +50,19 @@ async fn proposer_prep_service<T: BeaconChainTypes>(
let inner_chain = chain.clone(); let inner_chain = chain.clone();
executor.spawn( executor.spawn(
async move { async move {
if let Err(e) = inner_chain.prepare_beacon_proposer_async().await { if let Ok(current_slot) = inner_chain.slot() {
error!( if let Err(e) = inner_chain
inner_chain.log, .prepare_beacon_proposer_async(current_slot)
"Proposer prepare routine failed"; .await
"error" => ?e {
); error!(
inner_chain.log,
"Proposer prepare routine failed";
"error" => ?e
);
}
} else {
debug!(inner_chain.log, "No slot for proposer prepare routine");
} }
}, },
"proposer_prep_update", "proposer_prep_update",