Skip to content

Commit

Permalink
Start adding payload prep delay
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Mar 1, 2022
1 parent 0f72e34 commit f1e6056
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ const EARLY_ATTESTER_CACHE_HISTORIC_SLOTS: u64 = 4;
pub const INVALID_JUSTIFIED_PAYLOAD_SHUTDOWN_REASON: &str =
"Justified block has an invalid execution payload.";

const PAYLOAD_PREPARATION_LOOKAHEAD_FACTOR: u32 = 3;

/// Defines the behaviour when a block/block-root for a skipped slot is requested.
pub enum WhenSlotSkipped {
/// If the slot is a skip slot, return `None`.
Expand Down Expand Up @@ -3710,6 +3712,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.clone()
.ok_or(Error::ExecutionLayerMissing)?;

if !execution_layer.has_proposers().await {
// Nothing to do if there are no proposers registered with the EL.
return Ok(());
}

let head = self.head_info()?;
let head_epoch = head.slot.epoch(T::EthSpec::slots_per_epoch());
let prepare_slot = self.slot()? + 1;
Expand Down Expand Up @@ -3769,8 +3776,25 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.log,
"Prepared beacon proposer";
"already_known" => already_known,
"prepare_slot" => prepare_slot,
"validator" => proposer.index,
);

if let Some(duration) = self.slot_clock.duration_to_slot(prepare_slot) {
if duration
<= self.slot_clock.slot_duration()
/ PAYLOAD_PREPARATION_LOOKAHEAD_FACTOR
{
// TODO(paul): update fork choice.
}
} else {
warn!(
self.log,
"Delayed proposer preparation";
"prepare_slot" => prepare_slot,
"validator" => proposer.index,
);
}
}
} else {
debug!(
Expand Down
4 changes: 4 additions & 0 deletions beacon_node/execution_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ impl ExecutionLayer {
Ok(())
}

pub async fn has_proposers(&self) -> bool {
!self.proposer_preparation_data().await.is_empty()
}

pub async fn has_proposer_preparation_data(&self, proposer_index: u64) -> bool {
self.proposer_preparation_data()
.await
Expand Down

0 comments on commit f1e6056

Please sign in to comment.