Skip to content

Commit 28b94cb

Browse files
committed
Tidy, add comments
1 parent b24a3ea commit 28b94cb

3 files changed

Lines changed: 35 additions & 11 deletions

File tree

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
11181118
.beacon_state
11191119
.proposer_shuffling_decision_root(head.beacon_block_root)?;
11201120

1121+
// The `random` value is used whilst producing an `ExecutionPayload` atop the head.
11211122
let current_epoch = head.beacon_state.current_epoch();
11221123
let random = *head.beacon_state.get_randao_mix(current_epoch)?;
11231124

@@ -3700,12 +3701,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
37003701
);
37013702
}
37023703

3703-
// This performing this call immediately after
3704+
// Performing this call immediately after
37043705
// `update_execution_engine_forkchoice_blocking` might result in two calls to fork
3705-
// choice, one *without* payload attributes and then a second *with* payload
3706-
// attributes.
3706+
// choice updated, one *without* payload attributes and then a second *with*
3707+
// payload attributes.
37073708
//
3708-
// This seems OK, it's not a significant waste of EL<>CL bandwidth or resources, as
3709+
// This seems OK. It's not a significant waste of EL<>CL bandwidth or resources, as
37093710
// far as I know.
37103711
if let Err(e) = self.prepare_beacon_proposer_blocking() {
37113712
crit!(
@@ -3751,7 +3752,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
37513752

37523753
// Nothing to do if there are no proposers registered with the EL, exit early to avoid
37533754
// wasting cycles.
3754-
if !execution_layer.has_proposers().await {
3755+
if !execution_layer.has_any_proposer_preparation_data().await {
37553756
return Ok(());
37563757
}
37573758

beacon_node/beacon_chain/src/proposer_prep_service.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
use crate::{BeaconChain, BeaconChainTypes};
2-
use slog::error;
2+
use slog::{debug, error};
33
use slot_clock::SlotClock;
44
use std::sync::Arc;
55
use task_executor::TaskExecutor;
66
use tokio::time::sleep;
77

8+
/// At 12s slot times, the means that the payload preparation routine will run 4s before the start
9+
/// of each slot (`12 / 3 = 4`).
810
pub const PAYLOAD_PREPARATION_LOOKAHEAD_FACTOR: u32 = 3;
911

12+
/// Spawns a routine which ensures the EL is provided advance notice of any block producers.
13+
///
14+
/// This routine will run once per slot, at `slot_duration / PAYLOAD_PREPARATION_LOOKAHEAD_FACTOR`
15+
/// before the start of each slot.
16+
///
17+
/// The service will not be started if there is no `execution_layer` on the `chain`.
1018
pub fn start_proposer_prep_service<T: BeaconChainTypes>(
1119
executor: &TaskExecutor,
1220
chain: Arc<BeaconChain<T>>,
@@ -20,6 +28,7 @@ pub fn start_proposer_prep_service<T: BeaconChainTypes>(
2028
}
2129
}
2230

31+
/// Loop indefinitely, calling `BeaconChain::prepare_beacon_proposer_async` at an interval.
2332
async fn proposer_prep_service<T: BeaconChainTypes>(chain: Arc<BeaconChain<T>>) {
2433
let slot_duration = chain.slot_clock.slot_duration();
2534

@@ -30,6 +39,11 @@ async fn proposer_prep_service<T: BeaconChainTypes>(chain: Arc<BeaconChain<T>>)
3039
- chain.slot_clock.slot_duration() / PAYLOAD_PREPARATION_LOOKAHEAD_FACTOR;
3140
sleep(duration + additional_delay).await;
3241

42+
debug!(
43+
chain.log,
44+
"Proposer prepare routine firing";
45+
);
46+
3347
if let Err(e) = chain.prepare_beacon_proposer_async().await {
3448
error!(
3549
chain.log,

beacon_node/execution_layer/src/lib.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,15 +335,15 @@ impl ExecutionLayer {
335335
self.block_on_generic(|_| async move {
336336
self.update_proposer_preparation(update_epoch, preparation_data)
337337
.await
338-
})?
338+
})
339339
}
340340

341341
/// Updates the proposer preparation data provided by validators
342342
async fn update_proposer_preparation(
343343
&self,
344344
update_epoch: Epoch,
345345
preparation_data: &[ProposerPreparationData],
346-
) -> Result<(), Error> {
346+
) {
347347
let mut proposer_preparation_data = self.proposer_preparation_data().await;
348348
for preparation_entry in preparation_data {
349349
proposer_preparation_data.insert(
@@ -354,8 +354,6 @@ impl ExecutionLayer {
354354
},
355355
);
356356
}
357-
358-
Ok(())
359357
}
360358

361359
/// Removes expired entries from cached proposer preparations
@@ -371,10 +369,14 @@ impl ExecutionLayer {
371369
Ok(())
372370
}
373371

374-
pub async fn has_proposers(&self) -> bool {
372+
/// Returns `true` if there have been any validators registered via
373+
/// `Self::update_proposer_preparation`.
374+
pub async fn has_any_proposer_preparation_data(&self) -> bool {
375375
!self.proposer_preparation_data().await.is_empty()
376376
}
377377

378+
/// Returns `true` if the `proposer_index` has registered as a local validator via
379+
/// `Self::update_proposer_preparation`.
378380
pub async fn has_proposer_preparation_data(&self, proposer_index: u64) -> bool {
379381
self.proposer_preparation_data()
380382
.await
@@ -523,6 +525,10 @@ impl ExecutionLayer {
523525
)
524526
}
525527

528+
/// Register that the given `validator_index` is going to produce a block at `slot`.
529+
///
530+
/// The block will be build atop `head_block_root` and the EL will need to prepare an
531+
/// `ExecutionPayload` as defined by the given `payload_attributes`.
526532
pub async fn insert_proposer(
527533
&self,
528534
slot: Slot,
@@ -548,6 +554,9 @@ impl ExecutionLayer {
548554
.is_some()
549555
}
550556

557+
/// If there has been a proposer registered via `Self::insert_proposer` with a matching `slot`
558+
/// `head_block_root`, then return the appropriate `PayloadAttributes` for inclusion in
559+
/// `forkchoiceUpdated` calls.
551560
pub async fn payload_attributes(
552561
&self,
553562
current_slot: Slot,

0 commit comments

Comments
 (0)