implement scoring mechanisms and plumbing

This commit is contained in:
hopinheimer
2026-02-24 17:40:11 -05:00
parent 3e3ccba1a6
commit d5c5077a31
26 changed files with 1573 additions and 413 deletions

View File

@@ -35,6 +35,8 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: get_root(0),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that the head is 2
@@ -73,6 +75,8 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: get_root(0),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that the head is still 2
@@ -101,7 +105,8 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_root(1),
target_epoch: Epoch::new(2),
attestation_slot: Slot::new(2),
payload_present: false,
});
// Ensure that the head is now 1, because 1 has a vote.
@@ -143,7 +148,8 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 1,
block_root: get_root(2),
target_epoch: Epoch::new(2),
attestation_slot: Slot::new(2),
payload_present: false,
});
// Ensure that the head is 2 since 1 and 2 both have a vote
@@ -196,6 +202,8 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: get_root(0),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that the head is still 2
@@ -245,7 +253,8 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_root(3),
target_epoch: Epoch::new(3),
attestation_slot: Slot::new(3),
payload_present: false,
});
// Ensure that the head is still 2
@@ -347,7 +356,8 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 1,
block_root: get_root(1),
target_epoch: Epoch::new(3),
attestation_slot: Slot::new(3),
payload_present: false,
});
// Ensure that the head has switched back to 1
@@ -399,6 +409,9 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
root: get_root(0),
},
operations: ops,
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
spec: None,
}
}
@@ -437,6 +450,8 @@ pub fn get_execution_status_test_definition_02() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: get_root(0),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that the head is 2
@@ -475,6 +490,8 @@ pub fn get_execution_status_test_definition_02() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: get_root(0),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that the head is still 2
@@ -503,7 +520,8 @@ pub fn get_execution_status_test_definition_02() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_root(1),
target_epoch: Epoch::new(2),
attestation_slot: Slot::new(2),
payload_present: false,
});
// Ensure that the head is now 1, because 1 has a vote.
@@ -545,7 +563,8 @@ pub fn get_execution_status_test_definition_02() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 1,
block_root: get_root(2),
target_epoch: Epoch::new(2),
attestation_slot: Slot::new(2),
payload_present: false,
});
// Ensure that the head is 2 since 1 and 2 both have a vote
@@ -598,6 +617,8 @@ pub fn get_execution_status_test_definition_02() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: get_root(0),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that the head is still 2
@@ -647,7 +668,8 @@ pub fn get_execution_status_test_definition_02() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_root(3),
target_epoch: Epoch::new(3),
attestation_slot: Slot::new(3),
payload_present: false,
});
// Move validator #1 vote from 2 to 3
@@ -660,7 +682,8 @@ pub fn get_execution_status_test_definition_02() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 1,
block_root: get_root(3),
target_epoch: Epoch::new(3),
attestation_slot: Slot::new(3),
payload_present: false,
});
// Ensure that the head is now 3.
@@ -763,6 +786,9 @@ pub fn get_execution_status_test_definition_02() -> ForkChoiceTestDefinition {
root: get_root(0),
},
operations: ops,
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
spec: None,
}
}
@@ -801,6 +827,8 @@ pub fn get_execution_status_test_definition_03() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: get_root(0),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that the head is 2
@@ -839,6 +867,8 @@ pub fn get_execution_status_test_definition_03() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: get_root(0),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that the head is still 2
@@ -867,7 +897,8 @@ pub fn get_execution_status_test_definition_03() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_root(1),
target_epoch: Epoch::new(2),
attestation_slot: Slot::new(2),
payload_present: false,
});
// Ensure that the head is now 1, because 1 has a vote.
@@ -909,7 +940,8 @@ pub fn get_execution_status_test_definition_03() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 1,
block_root: get_root(1),
target_epoch: Epoch::new(2),
attestation_slot: Slot::new(2),
payload_present: false,
});
// Ensure that the head is 1.
@@ -962,6 +994,8 @@ pub fn get_execution_status_test_definition_03() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: get_root(0),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that the head is now 3, applying a proposer boost to 3 as well.
@@ -1065,6 +1099,9 @@ pub fn get_execution_status_test_definition_03() -> ForkChoiceTestDefinition {
root: get_root(0),
},
operations: ops,
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
spec: None,
}
}

View File

@@ -27,6 +27,8 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
parent_root: get_root(0),
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(2),
@@ -34,6 +36,8 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
parent_root: get_root(1),
justified_checkpoint: get_checkpoint(1),
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(3),
@@ -41,6 +45,8 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
parent_root: get_root(2),
justified_checkpoint: get_checkpoint(2),
finalized_checkpoint: get_checkpoint(1),
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that with justified epoch 0 we find 3
@@ -101,6 +107,9 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
operations: ops,
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
spec: None,
}
}
@@ -137,6 +146,8 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
parent_root: get_root(0),
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(2),
@@ -147,6 +158,8 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
root: get_root(1),
},
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(3),
@@ -157,6 +170,8 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
root: get_root(1),
},
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(4),
@@ -167,6 +182,8 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
root: get_root(1),
},
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(5),
@@ -177,6 +194,8 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
root: get_root(3),
},
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Right branch
@@ -186,6 +205,8 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
parent_root: get_root(0),
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(2),
@@ -193,6 +214,8 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
parent_root: get_root(2),
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(3),
@@ -200,6 +223,8 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
parent_root: get_root(4),
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(4),
@@ -210,6 +235,8 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
root: get_root(2),
},
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(5),
@@ -220,6 +247,8 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
root: get_root(4),
},
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that if we start at 0 we find 10 (just: 0, fin: 0).
@@ -282,7 +311,8 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_root(1),
target_epoch: Epoch::new(0),
attestation_slot: Slot::new(0),
payload_present: false,
});
// Ensure that if we start at 0 we find 9 (just: 0, fin: 0).
@@ -345,7 +375,8 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 1,
block_root: get_root(2),
target_epoch: Epoch::new(0),
attestation_slot: Slot::new(0),
payload_present: false,
});
// Ensure that if we start at 0 we find 10 (just: 0, fin: 0).
@@ -489,6 +520,9 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
operations: ops,
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
spec: None,
}
}

View File

@@ -0,0 +1,222 @@
use super::*;
fn gloas_spec() -> ChainSpec {
let mut spec = MainnetEthSpec::default_spec();
spec.proposer_score_boost = Some(50);
spec.gloas_fork_epoch = Some(Epoch::new(0));
spec
}
pub fn get_gloas_chain_following_test_definition() -> ForkChoiceTestDefinition {
let mut ops = vec![];
// Build two branches off genesis where one child extends parent's payload chain (Full)
// and the other does not (Empty).
ops.push(Operation::ProcessBlock {
slot: Slot::new(1),
root: get_root(1),
parent_root: get_root(0),
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: Some(get_hash(0)),
execution_payload_block_hash: Some(get_hash(1)),
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(1),
root: get_root(2),
parent_root: get_root(0),
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: Some(get_hash(99)),
execution_payload_block_hash: Some(get_hash(2)),
});
// Extend both branches to verify that head selection follows the selected chain.
ops.push(Operation::ProcessBlock {
slot: Slot::new(2),
root: get_root(3),
parent_root: get_root(1),
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: Some(get_hash(1)),
execution_payload_block_hash: Some(get_hash(3)),
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(2),
root: get_root(4),
parent_root: get_root(2),
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: Some(get_hash(100)),
execution_payload_block_hash: Some(get_hash(4)),
});
ops.push(Operation::AssertParentPayloadStatus {
block_root: get_root(1),
expected_status: PayloadStatus::Full,
});
ops.push(Operation::AssertParentPayloadStatus {
block_root: get_root(2),
expected_status: PayloadStatus::Empty,
});
// With equal full/empty parent weights, tiebreak decides which chain to follow.
ops.push(Operation::SetPayloadTiebreak {
block_root: get_root(0),
is_timely: true,
is_data_available: true,
});
ops.push(Operation::FindHead {
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: vec![1],
expected_head: get_root(3),
});
ops.push(Operation::SetPayloadTiebreak {
block_root: get_root(0),
is_timely: false,
is_data_available: false,
});
ops.push(Operation::FindHead {
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: vec![1],
expected_head: get_root(4),
});
ForkChoiceTestDefinition {
finalized_block_slot: Slot::new(0),
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
operations: ops,
execution_payload_parent_hash: Some(get_hash(42)),
execution_payload_block_hash: Some(get_hash(0)),
spec: Some(gloas_spec()),
}
}
pub fn get_gloas_payload_probe_test_definition() -> ForkChoiceTestDefinition {
let mut ops = vec![];
ops.push(Operation::ProcessBlock {
slot: Slot::new(1),
root: get_root(1),
parent_root: get_root(0),
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: Some(get_hash(0)),
execution_payload_block_hash: Some(get_hash(1)),
});
// One Full and one Empty vote for the same head block: tie should probe as Full.
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_root(1),
attestation_slot: Slot::new(2),
payload_present: true,
});
ops.push(Operation::ProcessAttestation {
validator_index: 1,
block_root: get_root(1),
attestation_slot: Slot::new(2),
payload_present: false,
});
ops.push(Operation::FindHead {
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: vec![1, 1],
expected_head: get_root(1),
});
ops.push(Operation::AssertPayloadWeights {
block_root: get_root(1),
expected_full_weight: 1,
expected_empty_weight: 1,
});
ops.push(Operation::AssertHeadPayloadStatus {
head_root: get_root(1),
expected_status: PayloadStatus::Full,
});
// Flip validator 0 to Empty; probe should now report Empty.
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_root(1),
attestation_slot: Slot::new(3),
payload_present: false,
});
ops.push(Operation::FindHead {
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: vec![1, 1],
expected_head: get_root(1),
});
ops.push(Operation::AssertPayloadWeights {
block_root: get_root(1),
expected_full_weight: 0,
expected_empty_weight: 2,
});
ops.push(Operation::AssertHeadPayloadStatus {
head_root: get_root(1),
expected_status: PayloadStatus::Empty,
});
// Same-slot attestation to a new head candidate should be Pending (no payload bucket change).
ops.push(Operation::ProcessBlock {
slot: Slot::new(3),
root: get_root(5),
parent_root: get_root(1),
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
execution_payload_parent_hash: Some(get_hash(1)),
execution_payload_block_hash: Some(get_hash(5)),
});
ops.push(Operation::ProcessAttestation {
validator_index: 2,
block_root: get_root(5),
attestation_slot: Slot::new(3),
payload_present: true,
});
ops.push(Operation::FindHead {
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: vec![1, 1, 1],
expected_head: get_root(5),
});
ops.push(Operation::AssertPayloadWeights {
block_root: get_root(5),
expected_full_weight: 0,
expected_empty_weight: 0,
});
ops.push(Operation::AssertHeadPayloadStatus {
head_root: get_root(5),
expected_status: PayloadStatus::Full,
});
ForkChoiceTestDefinition {
finalized_block_slot: Slot::new(0),
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
operations: ops,
execution_payload_parent_hash: Some(get_hash(42)),
execution_payload_block_hash: Some(get_hash(0)),
spec: Some(gloas_spec()),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn chain_following() {
let test = get_gloas_chain_following_test_definition();
test.run();
}
#[test]
fn payload_probe() {
let test = get_gloas_payload_probe_test_definition();
test.run();
}
}

View File

@@ -36,6 +36,8 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: Hash256::zero(),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
},
// Ensure the head is 2
//
@@ -71,6 +73,8 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: Hash256::zero(),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
},
// Ensure the head is still 2
//
@@ -108,6 +112,8 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: Hash256::zero(),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
},
// Ensure 2 is still the head
//
@@ -147,6 +153,8 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: Hash256::zero(),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
},
// Ensure the head is 4.
//
@@ -185,6 +193,8 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: Hash256::zero(),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
},
// Ensure the head is now 5 whilst the justified epoch is 0.
//
@@ -271,6 +281,8 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: Hash256::zero(),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
},
// Ensure 6 is the head
//
@@ -305,6 +317,9 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
root: Hash256::zero(),
},
operations,
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
spec: None,
}
}

View File

@@ -35,6 +35,8 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: get_root(0),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that the head is 2
@@ -73,6 +75,8 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: get_root(0),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that the head is still 2
@@ -101,7 +105,8 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_root(1),
target_epoch: Epoch::new(2),
attestation_slot: Slot::new(2),
payload_present: false,
});
// Ensure that the head is now 1, because 1 has a vote.
@@ -130,7 +135,8 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 1,
block_root: get_root(2),
target_epoch: Epoch::new(2),
attestation_slot: Slot::new(2),
payload_present: false,
});
// Ensure that the head is 2 since 1 and 2 both have a vote
@@ -170,6 +176,8 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: get_root(0),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that the head is still 2
@@ -202,7 +210,8 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_root(3),
target_epoch: Epoch::new(3),
attestation_slot: Slot::new(3),
payload_present: false,
});
// Ensure that the head is still 2
@@ -236,7 +245,8 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 1,
block_root: get_root(1),
target_epoch: Epoch::new(3),
attestation_slot: Slot::new(3),
payload_present: false,
});
// Ensure that the head is now 3
@@ -280,6 +290,8 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: get_root(0),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that the head is now 4
@@ -327,9 +339,11 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(2),
root: get_root(1),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that 5 is filtered out and the head stays at 4.
// Ensure that 5 becomes the head.
//
// 0
// / \
@@ -337,9 +351,9 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// |
// 3
// |
// 4 <- head
// 4
// /
// 5
// head-> 5
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
@@ -350,7 +364,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
root: get_root(0),
},
justified_state_balances: balances.clone(),
expected_head: get_root(4),
expected_head: get_root(5),
});
// Add block 6, which has a justified epoch of 0.
@@ -376,6 +390,8 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(1),
root: get_root(0),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Move both votes to 5.
@@ -392,12 +408,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_root(5),
target_epoch: Epoch::new(4),
attestation_slot: Slot::new(4),
payload_present: false,
});
ops.push(Operation::ProcessAttestation {
validator_index: 1,
block_root: get_root(5),
target_epoch: Epoch::new(4),
attestation_slot: Slot::new(4),
payload_present: false,
});
// Add blocks 7, 8 and 9. Adding these blocks helps test the `best_descendant`
@@ -430,6 +448,8 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(2),
root: get_root(5),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(0),
@@ -443,6 +463,8 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(2),
root: get_root(5),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(0),
@@ -456,10 +478,12 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(2),
root: get_root(5),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure that 6 is the head, even though 5 has all the votes. This is testing to ensure
// that 5 is filtered out due to a differing justified epoch.
// Ensure that 9 is the head. The branch rooted at 5 remains viable and its best descendant
// is selected.
//
// 0
// / \
@@ -469,13 +493,13 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// |
// 4
// / \
// 5 6 <- head
// 5 6
// |
// 7
// |
// 8
// /
// 9
// head-> 9
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
@@ -486,7 +510,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
root: get_root(0),
},
justified_state_balances: balances.clone(),
expected_head: get_root(6),
expected_head: get_root(9),
});
// Change fork-choice justified epoch to 1, and the start block to 5 and ensure that 9 is
@@ -545,12 +569,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_root(9),
target_epoch: Epoch::new(5),
attestation_slot: Slot::new(5),
payload_present: false,
});
ops.push(Operation::ProcessAttestation {
validator_index: 1,
block_root: get_root(9),
target_epoch: Epoch::new(5),
attestation_slot: Slot::new(5),
payload_present: false,
});
// Add block 10
@@ -582,6 +608,8 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(2),
root: get_root(5),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Double-check the head is still 9 (no diagram this time)
@@ -621,12 +649,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::ProcessAttestation {
validator_index: 2,
block_root: get_root(10),
target_epoch: Epoch::new(5),
attestation_slot: Slot::new(5),
payload_present: false,
});
ops.push(Operation::ProcessAttestation {
validator_index: 3,
block_root: get_root(10),
target_epoch: Epoch::new(5),
attestation_slot: Slot::new(5),
payload_present: false,
});
// Check the head is now 10.
@@ -817,6 +847,8 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
epoch: Epoch::new(2),
root: get_root(5),
},
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
});
// Ensure the head is now 11
@@ -854,6 +886,9 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
root: get_root(0),
},
operations: ops,
execution_payload_parent_hash: None,
execution_payload_block_hash: None,
spec: None,
}
}