mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-22 07:18:25 +00:00
addressing comments
This commit is contained in:
@@ -16,6 +16,7 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(0),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add a block with a hash of 2.
|
||||
@@ -55,6 +56,7 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add a block with a hash of 1 that comes off the genesis block (this is a fork compared
|
||||
@@ -95,6 +97,7 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add a vote to block 1
|
||||
@@ -124,6 +127,7 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(1),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
ops.push(Operation::AssertWeight {
|
||||
@@ -166,6 +170,7 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
ops.push(Operation::AssertWeight {
|
||||
@@ -222,6 +227,7 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
ops.push(Operation::AssertWeight {
|
||||
@@ -272,6 +278,7 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
ops.push(Operation::AssertWeight {
|
||||
@@ -321,6 +328,7 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Invalidation of 3 should have removed upstream weight.
|
||||
@@ -374,6 +382,7 @@ pub fn get_execution_status_test_definition_01() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances,
|
||||
expected_head: get_root(1),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
ops.push(Operation::AssertWeight {
|
||||
@@ -427,6 +436,7 @@ pub fn get_execution_status_test_definition_02() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(0),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add a block with a hash of 2.
|
||||
@@ -466,6 +476,7 @@ pub fn get_execution_status_test_definition_02() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add a block with a hash of 1 that comes off the genesis block (this is a fork compared
|
||||
@@ -506,6 +517,7 @@ pub fn get_execution_status_test_definition_02() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add a vote to block 1
|
||||
@@ -535,6 +547,7 @@ pub fn get_execution_status_test_definition_02() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(1),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
ops.push(Operation::AssertWeight {
|
||||
@@ -577,6 +590,7 @@ pub fn get_execution_status_test_definition_02() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
ops.push(Operation::AssertWeight {
|
||||
@@ -633,6 +647,7 @@ pub fn get_execution_status_test_definition_02() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
ops.push(Operation::AssertWeight {
|
||||
@@ -696,6 +711,7 @@ pub fn get_execution_status_test_definition_02() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(3),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
ops.push(Operation::AssertWeight {
|
||||
@@ -745,6 +761,7 @@ pub fn get_execution_status_test_definition_02() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances,
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Invalidation of 3 should have removed upstream weight.
|
||||
@@ -800,6 +817,7 @@ pub fn get_execution_status_test_definition_03() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(0),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add a block with a hash of 2.
|
||||
@@ -839,6 +857,7 @@ pub fn get_execution_status_test_definition_03() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add a block with a hash of 1 that comes off the genesis block (this is a fork compared
|
||||
@@ -879,6 +898,7 @@ pub fn get_execution_status_test_definition_03() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add a vote to block 1
|
||||
@@ -908,6 +928,7 @@ pub fn get_execution_status_test_definition_03() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(1),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
ops.push(Operation::AssertWeight {
|
||||
@@ -950,6 +971,7 @@ pub fn get_execution_status_test_definition_03() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(1),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
ops.push(Operation::AssertWeight {
|
||||
|
||||
@@ -10,6 +10,7 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(0),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Build the following tree (stick? lol).
|
||||
@@ -63,6 +64,7 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(3),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Ensure that with justified epoch 1 we find 3
|
||||
@@ -83,6 +85,7 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(3),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Ensure that with justified epoch 2 we find 3
|
||||
@@ -99,6 +102,7 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(1),
|
||||
justified_state_balances: balances,
|
||||
expected_head: get_root(3),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// END OF TESTS
|
||||
@@ -123,6 +127,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(0),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Build the following tree.
|
||||
@@ -269,6 +274,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(10),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
// Same as above, but with justified epoch 2.
|
||||
ops.push(Operation::FindHead {
|
||||
@@ -279,6 +285,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(10),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
// Same as above, but with justified epoch 3.
|
||||
//
|
||||
@@ -293,6 +300,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(10),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add a vote to 1.
|
||||
@@ -332,6 +340,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(9),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
// Save as above but justified epoch 2.
|
||||
ops.push(Operation::FindHead {
|
||||
@@ -342,6 +351,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(9),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
// Save as above but justified epoch 3.
|
||||
//
|
||||
@@ -356,6 +366,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(9),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add a vote to 2.
|
||||
@@ -395,6 +406,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(10),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
// Same as above but justified epoch 2.
|
||||
ops.push(Operation::FindHead {
|
||||
@@ -405,6 +417,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(10),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
// Same as above but justified epoch 3.
|
||||
//
|
||||
@@ -419,6 +432,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(10),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Ensure that if we start at 1 we find 9 (just: 0, fin: 0).
|
||||
@@ -442,6 +456,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(9),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
// Same as above but justified epoch 2.
|
||||
ops.push(Operation::FindHead {
|
||||
@@ -452,6 +467,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(9),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
// Same as above but justified epoch 3.
|
||||
//
|
||||
@@ -466,6 +482,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(9),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Ensure that if we start at 2 we find 10 (just: 0, fin: 0).
|
||||
@@ -486,6 +503,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(10),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
// Same as above but justified epoch 2.
|
||||
ops.push(Operation::FindHead {
|
||||
@@ -496,6 +514,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(10),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
// Same as above but justified epoch 3.
|
||||
//
|
||||
@@ -510,6 +529,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances,
|
||||
expected_head: get_root(10),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// END OF TESTS
|
||||
|
||||
@@ -71,6 +71,7 @@ pub fn get_gloas_chain_following_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: vec![1],
|
||||
expected_head: get_root(3),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
ops.push(Operation::SetPayloadTiebreak {
|
||||
@@ -83,6 +84,7 @@ pub fn get_gloas_chain_following_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: vec![1],
|
||||
expected_head: get_root(4),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
ForkChoiceTestDefinition {
|
||||
@@ -130,6 +132,7 @@ pub fn get_gloas_payload_probe_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: vec![1, 1],
|
||||
expected_head: get_root(1),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
ops.push(Operation::AssertPayloadWeights {
|
||||
block_root: get_root(1),
|
||||
@@ -154,6 +157,7 @@ pub fn get_gloas_payload_probe_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: vec![1, 1],
|
||||
expected_head: get_root(1),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
ops.push(Operation::AssertPayloadWeights {
|
||||
block_root: get_root(1),
|
||||
@@ -187,6 +191,7 @@ pub fn get_gloas_payload_probe_test_definition() -> ForkChoiceTestDefinition {
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: vec![1, 1, 1],
|
||||
expected_head: get_root(5),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
ops.push(Operation::AssertPayloadWeights {
|
||||
block_root: get_root(5),
|
||||
@@ -261,6 +266,7 @@ pub fn get_gloas_find_head_vote_transition_test_definition() -> ForkChoiceTestDe
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: vec![1],
|
||||
expected_head: get_root(3),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Validator 0 votes Empty branch -> head flips to 4.
|
||||
@@ -276,6 +282,7 @@ pub fn get_gloas_find_head_vote_transition_test_definition() -> ForkChoiceTestDe
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: vec![1],
|
||||
expected_head: get_root(4),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Latest-message update back to Full branch -> head returns to 3.
|
||||
@@ -291,6 +298,7 @@ pub fn get_gloas_find_head_vote_transition_test_definition() -> ForkChoiceTestDe
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: vec![1],
|
||||
expected_head: get_root(3),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
ops.push(Operation::AssertPayloadWeights {
|
||||
block_root: get_root(3),
|
||||
@@ -362,6 +370,7 @@ pub fn get_gloas_weight_priority_over_payload_preference_test_definition()
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: vec![1],
|
||||
expected_head: get_root(3),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add two Empty votes to make the Empty branch strictly heavier.
|
||||
@@ -384,6 +393,7 @@ pub fn get_gloas_weight_priority_over_payload_preference_test_definition()
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: vec![1, 1],
|
||||
expected_head: get_root(4),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
ForkChoiceTestDefinition {
|
||||
@@ -452,6 +462,143 @@ pub fn get_gloas_parent_empty_when_child_points_to_grandparent_test_definition()
|
||||
}
|
||||
}
|
||||
|
||||
/// Test interleaving of blocks, regular attestations, and late-arriving PTC votes.
|
||||
///
|
||||
/// Exercises the spec's `get_weight` rule: FULL/EMPTY virtual nodes at `current_slot - 1`
|
||||
/// have weight 0, so payload preference is determined solely by the tiebreaker.
|
||||
///
|
||||
/// genesis → block 1 (Full) → block 3
|
||||
/// → block 2 (Empty) → block 4
|
||||
///
|
||||
/// Timeline:
|
||||
/// 1. Blocks 1 (Full) and 2 (Empty) arrive at slot 1
|
||||
/// 2. Regular attestations arrive (equal weight per branch)
|
||||
/// 3. Child blocks 3 and 4 arrive at slot 2
|
||||
/// 4. PTC votes arrive for genesis (2 Full), making genesis prefer Full by weight
|
||||
/// 5. At current_slot=1 (genesis is current-1), PTC weights are ignored → tiebreaker decides
|
||||
/// 6. At current_slot=100 (genesis is old), PTC weights apply → Full branch wins
|
||||
pub fn get_gloas_interleaved_attestations_test_definition() -> ForkChoiceTestDefinition {
|
||||
let mut ops = vec![];
|
||||
|
||||
// Step 1: Two competing blocks at slot 1.
|
||||
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)),
|
||||
});
|
||||
|
||||
// Step 2: Regular attestations arrive, one per branch (equal CL weight).
|
||||
ops.push(Operation::ProcessAttestation {
|
||||
validator_index: 0,
|
||||
block_root: get_root(1),
|
||||
attestation_slot: Slot::new(1),
|
||||
});
|
||||
ops.push(Operation::ProcessAttestation {
|
||||
validator_index: 1,
|
||||
block_root: get_root(2),
|
||||
attestation_slot: Slot::new(1),
|
||||
});
|
||||
|
||||
// Step 3: Child blocks at slot 2.
|
||||
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)),
|
||||
});
|
||||
|
||||
// Step 4: PTC votes arrive for genesis, 2 Full votes from fresh validators.
|
||||
// Vals 0 and 1 can't be reused because they already have votes at slot 1.
|
||||
// Vals 2 and 3 target genesis; CL weight on genesis doesn't affect branch comparison.
|
||||
ops.push(Operation::ProcessPayloadAttestation {
|
||||
validator_index: 2,
|
||||
block_root: get_root(0),
|
||||
attestation_slot: Slot::new(1),
|
||||
payload_present: true,
|
||||
blob_data_available: false,
|
||||
});
|
||||
ops.push(Operation::ProcessPayloadAttestation {
|
||||
validator_index: 3,
|
||||
block_root: get_root(0),
|
||||
attestation_slot: Slot::new(1),
|
||||
payload_present: true,
|
||||
blob_data_available: false,
|
||||
});
|
||||
|
||||
// Set tiebreaker to Empty on genesis.
|
||||
ops.push(Operation::SetPayloadTiebreak {
|
||||
block_root: get_root(0),
|
||||
is_timely: false,
|
||||
is_data_available: false,
|
||||
});
|
||||
|
||||
// Step 5: At current_slot=1, genesis (slot 0) is at current_slot-1.
|
||||
// Per spec, FULL/EMPTY weights are zeroed → tiebreaker decides.
|
||||
// Tiebreaker is Empty → Empty branch (block 4) wins.
|
||||
ops.push(Operation::FindHead {
|
||||
justified_checkpoint: get_checkpoint(0),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: vec![1, 1, 1, 1],
|
||||
expected_head: get_root(4),
|
||||
current_slot: Slot::new(1),
|
||||
});
|
||||
|
||||
// Step 6: At current_slot=100, genesis (slot 0) is no longer at current_slot-1.
|
||||
// FULL/EMPTY weights now apply. Genesis has Full > Empty → prefers Full.
|
||||
// Full branch (block 3) wins despite Empty tiebreaker.
|
||||
ops.push(Operation::FindHead {
|
||||
justified_checkpoint: get_checkpoint(0),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: vec![1, 1, 1, 1],
|
||||
expected_head: get_root(3),
|
||||
current_slot: Slot::new(100),
|
||||
});
|
||||
|
||||
// Verify the PTC weights are recorded on genesis.
|
||||
// full = 2 (PTC votes) + 1 (back-propagated from Full child block 1) = 3
|
||||
// empty = 0 (PTC votes) + 1 (back-propagated from Empty child block 2) = 1
|
||||
ops.push(Operation::AssertPayloadWeights {
|
||||
block_root: get_root(0),
|
||||
expected_full_weight: 3,
|
||||
expected_empty_weight: 1,
|
||||
});
|
||||
|
||||
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::*;
|
||||
@@ -485,4 +632,10 @@ mod tests {
|
||||
let test = get_gloas_parent_empty_when_child_points_to_grandparent_test_definition();
|
||||
test.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn interleaved_attestations() {
|
||||
let test = get_gloas_interleaved_attestations_test_definition();
|
||||
test.run();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: Hash256::zero(),
|
||||
current_slot: Slot::new(0),
|
||||
},
|
||||
// Add block 2
|
||||
//
|
||||
@@ -55,6 +56,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
},
|
||||
// Add block 1
|
||||
//
|
||||
@@ -92,6 +94,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
},
|
||||
// Add block 3
|
||||
//
|
||||
@@ -133,6 +136,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
},
|
||||
// Add block 4
|
||||
//
|
||||
@@ -174,6 +178,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(4),
|
||||
current_slot: Slot::new(0),
|
||||
},
|
||||
// Add block 5 with a justified epoch of 2
|
||||
//
|
||||
@@ -216,6 +221,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(5),
|
||||
current_slot: Slot::new(0),
|
||||
},
|
||||
// Ensure there is no error when starting from a block that has the
|
||||
// wrong justified epoch.
|
||||
@@ -242,6 +248,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(5),
|
||||
current_slot: Slot::new(0),
|
||||
},
|
||||
// Set the justified epoch to 2 and the start block to 5 and ensure 5 is the head.
|
||||
//
|
||||
@@ -260,6 +267,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(5),
|
||||
current_slot: Slot::new(0),
|
||||
},
|
||||
// Add block 6
|
||||
//
|
||||
@@ -303,6 +311,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances,
|
||||
expected_head: get_root(6),
|
||||
current_slot: Slot::new(0),
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(0),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add a block with a hash of 2.
|
||||
@@ -55,6 +56,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add a block with a hash of 1 that comes off the genesis block (this is a fork compared
|
||||
@@ -95,6 +97,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add a vote to block 1
|
||||
@@ -124,6 +127,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(1),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add a vote to block 2
|
||||
@@ -153,6 +157,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add block 3.
|
||||
@@ -196,6 +201,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Move validator #0 vote from 1 to 3
|
||||
@@ -229,6 +235,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(2),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Move validator #1 vote from 2 to 1 (this is an equivocation, but fork choice doesn't
|
||||
@@ -263,6 +270,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(3),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add block 4.
|
||||
@@ -310,6 +318,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(4),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add block 5, which has a justified epoch of 2.
|
||||
@@ -361,6 +370,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(4),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add block 6, which has a justified epoch of 0.
|
||||
@@ -505,6 +515,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(6),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Change fork-choice justified epoch to 1, and the start block to 5 and ensure that 9 is
|
||||
@@ -538,6 +549,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(9),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Change fork-choice justified epoch to 1, and the start block to 5 and ensure that 9 is
|
||||
@@ -616,6 +628,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(9),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Introduce 2 more validators into the system
|
||||
@@ -677,6 +690,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(10),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Set the balances of the last two validators to zero
|
||||
@@ -702,6 +716,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(9),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Set the balances of the last two validators back to 1
|
||||
@@ -727,6 +742,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(10),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Remove the last two validators
|
||||
@@ -753,6 +769,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(9),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Ensure that pruning below the prune threshold does not prune.
|
||||
@@ -774,6 +791,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(9),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Ensure that pruning above the prune threshold does prune.
|
||||
@@ -812,6 +830,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_root(9),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
// Add block 11
|
||||
@@ -863,6 +882,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
},
|
||||
justified_state_balances: balances,
|
||||
expected_head: get_root(11),
|
||||
current_slot: Slot::new(0),
|
||||
});
|
||||
|
||||
ForkChoiceTestDefinition {
|
||||
|
||||
Reference in New Issue
Block a user