Make proposer_index mandatory in on_block

This commit is contained in:
Michael Sproul
2026-03-26 11:07:38 +11:00
parent f1b261f336
commit d58df3a656
4 changed files with 13 additions and 6 deletions

View File

@@ -61,6 +61,7 @@ pub enum Error {
block_root: Hash256,
},
NoViableChildren,
OnBlockRequiresProposerIndex,
}
impl From<ArithError> for Error {

View File

@@ -280,7 +280,7 @@ impl ForkChoiceTestDefinition {
unrealized_finalized_checkpoint: None,
execution_payload_parent_hash,
execution_payload_block_hash,
proposer_index: None,
proposer_index: Some(0),
};
fork_choice
.process_block::<MainnetEthSpec>(

View File

@@ -551,6 +551,12 @@ impl ProtoArray {
return Ok(());
}
// We do not allow `proposer_index=None` for calls to `on_block`, it is only non-optional
// for backwards-compatibility with pre-Gloas V17 proto nodes.
let Some(proposer_index) = block.proposer_index else {
return Err(Error::OnBlockRequiresProposerIndex);
};
let node_index = self.nodes.len();
let parent_index = block
@@ -658,7 +664,7 @@ impl ProtoArray {
BitVector::default()
},
payload_received: is_genesis,
proposer_index: block.proposer_index.unwrap_or(0),
proposer_index,
// Spec: `record_block_timeliness` + `get_forkchoice_store`.
// Anchor gets [True, True]. Others computed from time_into_slot.
block_timeliness_attestation_threshold: is_genesis

View File

@@ -492,7 +492,7 @@ impl ProtoArrayForkChoice {
unrealized_finalized_checkpoint: Some(finalized_checkpoint),
execution_payload_parent_hash,
execution_payload_block_hash,
proposer_index: None,
proposer_index: Some(0),
};
proto_array
@@ -1338,7 +1338,7 @@ mod test_compute_deltas {
unrealized_finalized_checkpoint: Some(genesis_checkpoint),
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
proposer_index: None,
proposer_index: Some(0),
},
genesis_slot + 1,
genesis_checkpoint,
@@ -1368,7 +1368,7 @@ mod test_compute_deltas {
unrealized_finalized_checkpoint: None,
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
proposer_index: None,
proposer_index: Some(0),
},
genesis_slot + 1,
genesis_checkpoint,
@@ -1505,7 +1505,7 @@ mod test_compute_deltas {
unrealized_finalized_checkpoint: Some(genesis_checkpoint),
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
proposer_index: None,
proposer_index: Some(0),
},
Slot::from(block.slot),
genesis_checkpoint,