mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 05:44:44 +00:00
Hacky fork choice changes
This commit is contained in:
@@ -89,6 +89,7 @@ impl ForkChoiceTestDefinition {
|
||||
junk_shuffling_id.clone(),
|
||||
junk_shuffling_id,
|
||||
ExecutionStatus::Optimistic(ExecutionBlockHash::zero()),
|
||||
types::consts::gloas::PAYLOAD_STATUS_FULL,
|
||||
)
|
||||
.expect("should create fork choice struct");
|
||||
let equivocating_indices = BTreeSet::new();
|
||||
@@ -211,6 +212,8 @@ impl ForkChoiceTestDefinition {
|
||||
),
|
||||
unrealized_justified_checkpoint: None,
|
||||
unrealized_finalized_checkpoint: None,
|
||||
// Test blocks default to FULL payload status.
|
||||
payload_status: types::consts::gloas::PAYLOAD_STATUS_FULL,
|
||||
};
|
||||
fork_choice
|
||||
.process_block::<MainnetEthSpec>(
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -17,7 +17,7 @@ use std::{
|
||||
};
|
||||
use types::{
|
||||
AttestationShufflingId, ChainSpec, Checkpoint, Epoch, EthSpec, ExecutionBlockHash, Hash256,
|
||||
Slot,
|
||||
Slot, consts::gloas::PayloadStatus,
|
||||
};
|
||||
|
||||
pub const DEFAULT_PRUNE_THRESHOLD: usize = 256;
|
||||
@@ -159,6 +159,8 @@ pub struct Block {
|
||||
pub execution_status: ExecutionStatus,
|
||||
pub unrealized_justified_checkpoint: Option<Checkpoint>,
|
||||
pub unrealized_finalized_checkpoint: Option<Checkpoint>,
|
||||
/// The payload status for this block (Gloas fork choice).
|
||||
pub payload_status: PayloadStatus,
|
||||
}
|
||||
|
||||
impl Block {
|
||||
@@ -422,6 +424,7 @@ impl ProtoArrayForkChoice {
|
||||
current_epoch_shuffling_id: AttestationShufflingId,
|
||||
next_epoch_shuffling_id: AttestationShufflingId,
|
||||
execution_status: ExecutionStatus,
|
||||
payload_status: PayloadStatus,
|
||||
) -> Result<Self, String> {
|
||||
let mut proto_array = ProtoArray {
|
||||
prune_threshold: DEFAULT_PRUNE_THRESHOLD,
|
||||
@@ -445,6 +448,7 @@ impl ProtoArrayForkChoice {
|
||||
execution_status,
|
||||
unrealized_justified_checkpoint: Some(justified_checkpoint),
|
||||
unrealized_finalized_checkpoint: Some(finalized_checkpoint),
|
||||
payload_status,
|
||||
};
|
||||
|
||||
proto_array
|
||||
@@ -484,6 +488,18 @@ impl ProtoArrayForkChoice {
|
||||
.map_err(|e| format!("Failed to process invalid payload: {:?}", e))
|
||||
}
|
||||
|
||||
/// Register that a valid execution payload envelope has been received for `block_root`.
|
||||
///
|
||||
/// See `ProtoArray::on_execution_payload` for documentation.
|
||||
pub fn on_execution_payload(
|
||||
&mut self,
|
||||
block_root: Hash256,
|
||||
) -> Result<(), String> {
|
||||
self.proto_array
|
||||
.on_execution_payload(block_root)
|
||||
.map_err(|e| format!("on_execution_payload error: {:?}", e))
|
||||
}
|
||||
|
||||
pub fn process_attestation(
|
||||
&mut self,
|
||||
validator_index: usize,
|
||||
@@ -873,6 +889,7 @@ impl ProtoArrayForkChoice {
|
||||
execution_status: block.execution_status,
|
||||
unrealized_justified_checkpoint: block.unrealized_justified_checkpoint,
|
||||
unrealized_finalized_checkpoint: block.unrealized_finalized_checkpoint,
|
||||
payload_status: block.payload_status,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1136,6 +1153,7 @@ mod test_compute_deltas {
|
||||
junk_shuffling_id.clone(),
|
||||
junk_shuffling_id.clone(),
|
||||
execution_status,
|
||||
types::consts::gloas::PAYLOAD_STATUS_FULL,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1155,6 +1173,7 @@ mod test_compute_deltas {
|
||||
execution_status,
|
||||
unrealized_justified_checkpoint: Some(genesis_checkpoint),
|
||||
unrealized_finalized_checkpoint: Some(genesis_checkpoint),
|
||||
payload_status: types::consts::gloas::PAYLOAD_STATUS_FULL,
|
||||
},
|
||||
genesis_slot + 1,
|
||||
genesis_checkpoint,
|
||||
@@ -1180,6 +1199,7 @@ mod test_compute_deltas {
|
||||
execution_status,
|
||||
unrealized_justified_checkpoint: None,
|
||||
unrealized_finalized_checkpoint: None,
|
||||
payload_status: types::consts::gloas::PAYLOAD_STATUS_FULL,
|
||||
},
|
||||
genesis_slot + 1,
|
||||
genesis_checkpoint,
|
||||
@@ -1280,6 +1300,7 @@ mod test_compute_deltas {
|
||||
junk_shuffling_id.clone(),
|
||||
junk_shuffling_id.clone(),
|
||||
execution_status,
|
||||
types::consts::gloas::PAYLOAD_STATUS_FULL,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1308,6 +1329,7 @@ mod test_compute_deltas {
|
||||
execution_status,
|
||||
unrealized_justified_checkpoint: Some(genesis_checkpoint),
|
||||
unrealized_finalized_checkpoint: Some(genesis_checkpoint),
|
||||
payload_status: types::consts::gloas::PAYLOAD_STATUS_FULL,
|
||||
},
|
||||
Slot::from(block.slot),
|
||||
genesis_checkpoint,
|
||||
|
||||
Reference in New Issue
Block a user