Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions fork_choice_control/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,10 @@ where
self.store_snapshot().is_payload_verified(block_root)
}

pub fn is_payload_present_timely(&self, block_root: H256) -> bool {
self.store_snapshot().is_payload_present_timely(block_root)
}

pub fn blocks_by_root(
&self,
block_roots: impl IntoIterator<Item = H256> + Send,
Expand Down
42 changes: 32 additions & 10 deletions fork_choice_store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ pub struct Store<P: Preset, S: Storage<P>> {
// - Obtaining active balances from the justified state requires it to be in the right epoch.
checkpoint_states: HashMap<Checkpoint, Arc<BeaconState<P>>>,
payloads: HashSet<H256>,
timely_payloads: HashSet<H256>,
// This field is used to track which PTC members have cast a valid vote for a given block root.
payload_vote: HashMap<H256, BitVector<P::PtcSize>>,
payload_timeliness_vote: HashMap<H256, BitVector<P::PtcSize>>,
Expand Down Expand Up @@ -358,6 +359,7 @@ impl<P: Preset, S: Storage<P>> Store<P, S> {
seen_gossip_aggregators: BTreeMap::new(),
checkpoint_states: HashMap::unit(checkpoint, anchor_state),
payloads: HashSet::new(),
timely_payloads: HashSet::new(),
payload_vote: HashMap::new(),
payload_timeliness_vote: HashMap::new(),
payload_data_availability_vote: HashMap::new(),
Expand Down Expand Up @@ -894,7 +896,8 @@ impl<P: Preset, S: Storage<P>> Store<P, S> {
let proposer_root = self.proposer_boost_root;

if proposer_root.is_zero()
|| (self.is_payload_timely(block_root) && self.is_payload_data_available(block_root))
|| (self.is_payload_voted_timely(block_root)
&& self.is_payload_data_available(block_root))
{
return true;
}
Expand All @@ -921,6 +924,12 @@ impl<P: Preset, S: Storage<P>> Store<P, S> {
self.payloads.contains(&block_root)
}

// > Return whether the execution payload envelope for the beacon block with
// > root ``root`` was seen before the ``PAYLOAD_DUE_BPS`` deadline.
pub fn is_payload_present_timely(&self, block_root: H256) -> bool {
self.timely_payloads.contains(&block_root)
}

#[must_use]
pub fn payload_vote(&self, block_root: H256) -> Option<&BitVector<P::PtcSize>> {
self.payload_vote.get(&block_root)
Expand All @@ -941,7 +950,7 @@ impl<P: Preset, S: Storage<P>> Store<P, S> {

// > Return whether the execution payload for the beacon block with root ``root``
// > was voted as present by the PTC, and was locally determined to be available.
fn is_payload_timely(&self, block_root: H256) -> bool {
fn is_payload_voted_timely(&self, block_root: H256) -> bool {
let Some(payload_timeliness_vote) = self.payload_timeliness_vote.get(&block_root) else {
return false;
};
Expand Down Expand Up @@ -3833,14 +3842,7 @@ impl<P: Preset, S: Storage<P>> Store<P, S> {
// Apply proposer boost to first block in case of equivocation.
// See <https://github.com/ethereum/consensus-specs/pull/3352>.
let is_before_attesting_interval = if self.phase() >= Phase::Gloas {
let ticks_per_slot = u64::try_from(TickKind::ticks_per_slot::<P>(
&self.chain_config,
self.slot(),
))?;
let tick_index: u64 = self.tick.kind as u64;

(tick_index + 1) * BASIS_POINTS
<= self.chain_config.attestation_due_bps_gloas * ticks_per_slot
self.is_before_due_bps_deadline(self.chain_config.attestation_due_bps_gloas)
} else {
self.tick.is_before_attesting_interval()
};
Expand Down Expand Up @@ -4147,6 +4149,10 @@ impl<P: Preset, S: Storage<P>> Store<P, S> {

self.payloads.insert(beacon_block_root);

if self.is_before_due_bps_deadline(self.chain_config.payload_due_bps) {
self.timely_payloads.insert(beacon_block_root);
}

self.accepted_execution_payload_envelopes
.insert((slot, beacon_block_root, builder_index));

Expand Down Expand Up @@ -4666,6 +4672,8 @@ impl<P: Preset, S: Storage<P>> Store<P, S> {
.prune_finalized(finalized_slot);
self.payloads
.retain(|block_root| self.unfinalized_locations.contains_key(block_root));
self.timely_payloads
.retain(|block_root| self.unfinalized_locations.contains_key(block_root));
self.accepted_blob_sidecars
.retain(|(slot, _, _), _| finalized_slot <= *slot);
self.accepted_data_column_sidecars
Expand Down Expand Up @@ -5215,6 +5223,20 @@ impl<P: Preset, S: Storage<P>> Store<P, S> {
archived
}

// Return whether the current tick is before the deadline defined by `due_bps`
// basis points into the slot.
fn is_before_due_bps_deadline(&self, due_bps: u64) -> bool {
let ticks_per_slot = u64::try_from(TickKind::ticks_per_slot::<P>(
&self.chain_config,
self.slot(),
))
.expect("number of ticks per slot should fit in u64");
let tick_index = self.tick.kind as u64;

(tick_index.saturating_add(1)).saturating_mul(BASIS_POINTS)
<= due_bps.saturating_mul(ticks_per_slot)
}

const fn start_of_epoch(epoch: Epoch) -> Slot {
misc::compute_start_slot_at_epoch::<P>(epoch)
}
Expand Down
3 changes: 3 additions & 0 deletions types/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ pub struct Config {
pub contribution_due_bps_gloas: u64,
#[serde(with = "serde_utils::string_or_native")]
pub payload_attestation_due_bps: u64,
#[serde(with = "serde_utils::string_or_native")]
pub payload_due_bps: u64,

// Validator cycle
#[serde(with = "serde_utils::string_or_native")]
Expand Down Expand Up @@ -283,6 +285,7 @@ impl Default for Config {
sync_message_due_bps_gloas: 2500,
contribution_due_bps_gloas: 5000,
payload_attestation_due_bps: 7500,
payload_due_bps: 7500,

// Validator cycle
churn_limit_quotient: nonzero!(1_u64 << 16),
Expand Down
5 changes: 1 addition & 4 deletions validator/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2251,10 +2251,7 @@ impl<P: Preset, W: Wait + Sync> Validator<P, W> {
return Ok(own_payload_attestations);
}

let payload_present = self
.controller
.execution_payload_envelope_by_root(beacon_block_root)?
.is_some();
let payload_present = self.controller.is_payload_present_timely(beacon_block_root);

let blob_data_available = self
.controller
Expand Down
Loading