Hacky fork choice changes

This commit is contained in:
Eitan Seri- Levi
2026-02-12 23:58:42 -08:00
parent 7d0d438fd4
commit dc143d9709
5 changed files with 95 additions and 5 deletions

View File

@@ -10,6 +10,7 @@ use superstruct::superstruct;
use types::{
AttestationShufflingId, ChainSpec, Checkpoint, Epoch, EthSpec, ExecutionBlockHash, Hash256,
Slot,
consts::gloas::{PAYLOAD_STATUS_FULL, PAYLOAD_STATUS_PENDING, PayloadStatus},
};
// Define a "legacy" implementation of `Option<usize>` which uses four bytes for encoding the union
@@ -109,6 +110,13 @@ pub struct ProtoNode {
pub unrealized_justified_checkpoint: Option<Checkpoint>,
#[ssz(with = "four_byte_option_checkpoint")]
pub unrealized_finalized_checkpoint: Option<Checkpoint>,
/// The payload status of this block (Gloas).
///
/// - `PAYLOAD_STATUS_PENDING` (0): The payload has not yet been received.
/// - `PAYLOAD_STATUS_EMPTY` (1): The slot has passed without a payload (pre-Gloas blocks
/// or empty Gloas slots).
/// - `PAYLOAD_STATUS_FULL` (2): A valid execution payload has been received.
pub payload_status: PayloadStatus,
}
#[derive(PartialEq, Debug, Encode, Decode, Serialize, Deserialize, Copy, Clone)]
@@ -332,6 +340,7 @@ impl ProtoArray {
execution_status: block.execution_status,
unrealized_justified_checkpoint: block.unrealized_justified_checkpoint,
unrealized_finalized_checkpoint: block.unrealized_finalized_checkpoint,
payload_status: block.payload_status,
};
// If the parent has an invalid execution status, return an error before adding the block to
@@ -369,6 +378,32 @@ impl ProtoArray {
Ok(())
}
/// Register that an execution payload has been received and validated for `block_root`.
///
/// Updates the node's `payload_status` from `PENDING` to `FULL`.
///
/// Returns an error if the block is unknown to fork choice.
pub fn on_execution_payload(
&mut self,
block_root: Hash256,
) -> Result<(), Error> {
let index = self
.indices
.get(&block_root)
.copied()
.ok_or(Error::NodeUnknown(block_root))?;
let node = self
.nodes
.get_mut(index)
.ok_or(Error::InvalidNodeIndex(index))?;
if node.payload_status == PAYLOAD_STATUS_PENDING {
node.payload_status = PAYLOAD_STATUS_FULL;
}
Ok(())
}
/// Updates the `block_root` and all ancestors to have validated execution payloads.
///
/// Returns an error if: