Skip to content

Commit

Permalink
Remove some blocking methods
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Jun 28, 2022
1 parent 5be6374 commit 1bcf234
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 35 deletions.
26 changes: 3 additions & 23 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3659,26 +3659,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.canonical_head.read().fork_choice.contains_block(root)
}

pub fn prepare_beacon_proposer_blocking(self: &Arc<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(current_slot))
.map_err(Error::PrepareProposerBlockingFailed)?
}

/// Determines the beacon proposer for the next slot. If that proposer is registered in the
/// `execution_layer`, provide the `execution_layer` with the necessary information to produce
/// `PayloadAttributes` for future calls to fork choice.
Expand All @@ -3691,7 +3671,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// 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(
pub async fn prepare_beacon_proposer(
self: &Arc<Self>,
current_slot: Slot,
) -> Result<(), Error> {
Expand Down Expand Up @@ -3897,14 +3877,14 @@ impl<T: BeaconChainTypes> BeaconChain<T> {

// Use the blocking method here so that we don't form a queue of these functions when
// routinely calling them.
self.update_execution_engine_forkchoice_async(current_slot, forkchoice_update_params)
self.update_execution_engine_forkchoice(current_slot, forkchoice_update_params)
.await?;
}

Ok(())
}

pub async fn update_execution_engine_forkchoice_async(
pub async fn update_execution_engine_forkchoice(
self: &Arc<Self>,
current_slot: Slot,
params: ForkchoiceUpdateParameters,
Expand Down
4 changes: 1 addition & 3 deletions beacon_node/beacon_chain/src/proposer_prep_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ async fn proposer_prep_service<T: BeaconChainTypes>(
executor.spawn(
async move {
if let Ok(current_slot) = inner_chain.slot() {
if let Err(e) = inner_chain
.prepare_beacon_proposer_async(current_slot)
.await
if let Err(e) = inner_chain.prepare_beacon_proposer(current_slot).await
{
error!(
inner_chain.log,
Expand Down
9 changes: 3 additions & 6 deletions beacon_node/beacon_chain/src/recompute_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,16 +517,13 @@ fn spawn_execution_layer_updates<T: BeaconChainTypes>(
async move {
// Avoids raising an error before Bellatrix.
//
// See `Self::prepare_beacon_proposer_async` for more detail.
// See `Self::prepare_beacon_proposer` for more detail.
if chain.slot_is_prior_to_bellatrix(current_slot + 1) {
return;
}

if let Err(e) = chain
.update_execution_engine_forkchoice_async(
current_slot,
forkchoice_update_params,
)
.update_execution_engine_forkchoice(current_slot, forkchoice_update_params)
.await
{
crit!(
Expand All @@ -544,7 +541,7 @@ fn spawn_execution_layer_updates<T: BeaconChainTypes>(
//
// This seems OK. It's not a significant waste of EL<>CL bandwidth or resources, as far as I
// know.
if let Err(e) = chain.prepare_beacon_proposer_async(current_slot).await {
if let Err(e) = chain.prepare_beacon_proposer(current_slot).await {
crit!(
chain.log,
"Failed to prepare proposers after fork choice";
Expand Down
7 changes: 4 additions & 3 deletions beacon_node/beacon_chain/tests/payload_invalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,8 @@ async fn payload_preparation() {

rig.harness
.chain
.prepare_beacon_proposer_blocking()
.prepare_beacon_proposer(rig.harness.chain.slot().unwrap())
.await
.unwrap();

let payload_attributes = PayloadAttributes {
Expand Down Expand Up @@ -1116,7 +1117,7 @@ async fn payload_preparation_before_transition_block() {

rig.harness
.chain
.prepare_beacon_proposer_async(current_slot)
.prepare_beacon_proposer(current_slot)
.await
.unwrap();
let forkchoice_update_params = rig
Expand All @@ -1129,7 +1130,7 @@ async fn payload_preparation_before_transition_block() {
.unwrap();
rig.harness
.chain
.update_execution_engine_forkchoice_async(current_slot, forkchoice_update_params)
.update_execution_engine_forkchoice(current_slot, forkchoice_update_params)
.await
.unwrap();

Expand Down

0 comments on commit 1bcf234

Please sign in to comment.