Skip to content

Commit

Permalink
Only prepare execution payload if there is a registered validator pro…
Browse files Browse the repository at this point in the history
…posing in the next slot.

Add AlwaysPrepareExecutionPayload feature to prepare execution in advance for each slot.
  • Loading branch information
povi committed Jun 25, 2024
1 parent 7c12074 commit 5e65b52
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions features/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static FEATURES: [AtomicBool; Feature::CARDINALITY] = [FALSE; Feature::CARDINALI
)]
pub enum Feature {
AlwaysPrepackAttestations,
AlwaysPrepareExecutionPayload,
CacheTargetStates,
DebugEth1,
DebugP2p,
Expand Down
12 changes: 11 additions & 1 deletion operation_pools/src/attestation_agg_pool/manager.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::ops::RangeBounds;
use std::sync::Arc;

use anyhow::{Context, Error, Result};
Expand All @@ -15,7 +16,7 @@ use types::{
config::Config,
phase0::{
containers::{Attestation, AttestationData},
primitives::{Epoch, ValidatorIndex, H256},
primitives::{Epoch, Slot, ValidatorIndex, H256},
},
preset::Preset,
};
Expand Down Expand Up @@ -133,6 +134,15 @@ impl<P: Preset, W: Wait> Manager<P, W> {
});
}

pub async fn has_registered_validators_proposing_in_slots(
&self,
range: impl RangeBounds<Slot> + Send,
) -> bool {
self.pool
.has_registered_validators_proposing_in_slots(range)
.await
}

pub fn pack_proposable_attestations(&self) {
self.spawn_detached(PackProposableAttestationsTask {
pool: self.pool.clone_arc(),
Expand Down
7 changes: 7 additions & 0 deletions validator/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@ impl<P: Preset, W: Wait + Sync> Validator<P, W> {
}
},
ValidatorMessage::PrepareExecutionPayload(slot, safe_execution_payload_hash, finalized_execution_payload_hash) => {
let should_prepare_execution_payload = Feature::AlwaysPrepareExecutionPayload.is_enabled()
|| self.attestation_agg_pool.has_registered_validators_proposing_in_slots(slot..=slot).await;

if !should_prepare_execution_payload {
return Ok(());
}

let slot_head = self.safe_slot_head(slot).await;

if let Some(slot_head) = slot_head {
Expand Down

0 comments on commit 5e65b52

Please sign in to comment.