mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-22 06:14:38 +00:00
v1.1.6 Fork Choice changes (#2822)
## Issue Addressed Resolves: https://github.com/sigp/lighthouse/issues/2741 Includes: https://github.com/sigp/lighthouse/pull/2853 so that we can get ssz static tests passing here on v1.1.6. If we want to merge that first, we can make this diff slightly smaller ## Proposed Changes - Changes the `justified_epoch` and `finalized_epoch` in the `ProtoArrayNode` each to an `Option<Checkpoint>`. The `Option` is necessary only for the migration, so not ideal. But does allow us to add a default logic to `None` on these fields during the database migration. - Adds a database migration from a legacy fork choice struct to the new one, search for all necessary block roots in fork choice by iterating through blocks in the db. - updates related to https://github.com/ethereum/consensus-specs/pull/2727 - We will have to update the persisted forkchoice to make sure the justified checkpoint stored is correct according to the updated fork choice logic. This boils down to setting the forkchoice store's justified checkpoint to the justified checkpoint of the block that advanced the finalized checkpoint to the current one. - AFAICT there's no migration steps necessary for the update to allow applying attestations from prior blocks, but would appreciate confirmation on that - I updated the consensus spec tests to v1.1.6 here, but they will fail until we also implement the proposer score boost updates. I confirmed that the previously failing scenario `new_finalized_slot_is_justified_checkpoint_ancestor` will now pass after the boost updates, but haven't confirmed _all_ tests will pass because I just quickly stubbed out the proposer boost test scenario formatting. - This PR now also includes proposer boosting https://github.com/ethereum/consensus-specs/pull/2730 ## Additional Info I realized checking justified and finalized roots in fork choice makes it more likely that we trigger this bug: https://github.com/ethereum/consensus-specs/pull/2727 It's possible the combination of justified checkpoint and finalized checkpoint in the forkchoice store is different from in any block in fork choice. So when trying to startup our store's justified checkpoint seems invalid to the rest of fork choice (but it should be valid). When this happens we get an `InvalidBestNode` error and fail to start up. So I'm including that bugfix in this branch. Todo: - [x] Fix fork choice tests - [x] Self review - [x] Add fix for https://github.com/ethereum/consensus-specs/pull/2727 - [x] Rebase onto Kintusgi - [x] Fix `num_active_validators` calculation as @michaelsproul pointed out - [x] Clean up db migrations Co-authored-by: realbigsean <seananderson33@gmail.com>
This commit is contained in:
@@ -6,9 +6,8 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
|
||||
|
||||
// Ensure that the head starts at the finalized block.
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(0),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: get_checkpoint(0),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(0),
|
||||
});
|
||||
@@ -26,22 +25,22 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
|
||||
slot: Slot::new(1),
|
||||
root: get_hash(1),
|
||||
parent_root: get_hash(0),
|
||||
justified_epoch: Epoch::new(0),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: get_checkpoint(0),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
});
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(2),
|
||||
root: get_hash(2),
|
||||
parent_root: get_hash(1),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: get_checkpoint(1),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
});
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(3),
|
||||
root: get_hash(3),
|
||||
parent_root: get_hash(2),
|
||||
justified_epoch: Epoch::new(2),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: get_checkpoint(2),
|
||||
finalized_checkpoint: get_checkpoint(1),
|
||||
});
|
||||
|
||||
// Ensure that with justified epoch 0 we find 3
|
||||
@@ -54,9 +53,8 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 3 <- head
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(0),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: get_checkpoint(0),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(3),
|
||||
});
|
||||
@@ -71,9 +69,8 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 3 <- head
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: get_hash(2),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: get_checkpoint(1),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(2),
|
||||
});
|
||||
@@ -88,9 +85,8 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 3 <- start + head
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(3),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: get_checkpoint(2),
|
||||
finalized_checkpoint: get_checkpoint(1),
|
||||
justified_state_balances: balances,
|
||||
expected_head: get_hash(3),
|
||||
});
|
||||
@@ -98,9 +94,8 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
|
||||
// END OF TESTS
|
||||
ForkChoiceTestDefinition {
|
||||
finalized_block_slot: Slot::new(0),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
finalized_root: get_hash(0),
|
||||
justified_checkpoint: get_checkpoint(0),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
operations: ops,
|
||||
}
|
||||
}
|
||||
@@ -111,9 +106,8 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
|
||||
// Ensure that the head starts at the finalized block.
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: get_checkpoint(0),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(0),
|
||||
});
|
||||
@@ -137,36 +131,48 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
slot: Slot::new(1),
|
||||
root: get_hash(1),
|
||||
parent_root: get_hash(0),
|
||||
justified_epoch: Epoch::new(0),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: get_checkpoint(0),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
});
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(2),
|
||||
root: get_hash(3),
|
||||
parent_root: get_hash(1),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(1),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
});
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(3),
|
||||
root: get_hash(5),
|
||||
parent_root: get_hash(3),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(1),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
});
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(4),
|
||||
root: get_hash(7),
|
||||
parent_root: get_hash(5),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(1),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
});
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(4),
|
||||
slot: Slot::new(5),
|
||||
root: get_hash(9),
|
||||
parent_root: get_hash(7),
|
||||
justified_epoch: Epoch::new(2),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(3),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
});
|
||||
|
||||
// Right branch
|
||||
@@ -174,36 +180,42 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
slot: Slot::new(1),
|
||||
root: get_hash(2),
|
||||
parent_root: get_hash(0),
|
||||
justified_epoch: Epoch::new(0),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: get_checkpoint(0),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
});
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(2),
|
||||
root: get_hash(4),
|
||||
parent_root: get_hash(2),
|
||||
justified_epoch: Epoch::new(0),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: get_checkpoint(0),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
});
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(3),
|
||||
root: get_hash(6),
|
||||
parent_root: get_hash(4),
|
||||
justified_epoch: Epoch::new(0),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: get_checkpoint(0),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
});
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(4),
|
||||
root: get_hash(8),
|
||||
parent_root: get_hash(6),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(2),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
});
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(4),
|
||||
slot: Slot::new(5),
|
||||
root: get_hash(10),
|
||||
parent_root: get_hash(8),
|
||||
justified_epoch: Epoch::new(2),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(4),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
});
|
||||
|
||||
// Ensure that if we start at 0 we find 10 (just: 0, fin: 0).
|
||||
@@ -220,25 +232,28 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
// | |
|
||||
// 9 10 <-- head
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(0),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: get_checkpoint(0),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(10),
|
||||
});
|
||||
// Same as above, but with justified epoch 2.
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(4),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(10),
|
||||
});
|
||||
// Same as above, but with justified epoch 3 (should be invalid).
|
||||
ops.push(Operation::InvalidFindHead {
|
||||
justified_epoch: Epoch::new(3),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(3),
|
||||
root: get_hash(6),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
});
|
||||
|
||||
@@ -275,25 +290,28 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
// | |
|
||||
// head -> 9 10
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(0),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: get_checkpoint(0),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(9),
|
||||
});
|
||||
// Save as above but justified epoch 2.
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(3),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(9),
|
||||
});
|
||||
// Save as above but justified epoch 3 (should fail).
|
||||
ops.push(Operation::InvalidFindHead {
|
||||
justified_epoch: Epoch::new(3),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(3),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
});
|
||||
|
||||
@@ -330,25 +348,28 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
// | |
|
||||
// 9 10 <-- head
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(0),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: get_checkpoint(0),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(10),
|
||||
});
|
||||
// Same as above but justified epoch 2.
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(4),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(10),
|
||||
});
|
||||
// Same as above but justified epoch 3 (should fail).
|
||||
ops.push(Operation::InvalidFindHead {
|
||||
justified_epoch: Epoch::new(3),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(3),
|
||||
root: get_hash(6),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
});
|
||||
|
||||
@@ -366,25 +387,31 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
// | |
|
||||
// head -> 9 10
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(0),
|
||||
justified_root: get_hash(1),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(0),
|
||||
root: get_hash(1),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(9),
|
||||
});
|
||||
// Same as above but justified epoch 2.
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(1),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(3),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(9),
|
||||
});
|
||||
// Same as above but justified epoch 3 (should fail).
|
||||
ops.push(Operation::InvalidFindHead {
|
||||
justified_epoch: Epoch::new(3),
|
||||
justified_root: get_hash(1),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(3),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
});
|
||||
|
||||
@@ -402,34 +429,36 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
|
||||
// | |
|
||||
// 9 10 <- head
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(0),
|
||||
justified_root: get_hash(2),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: get_checkpoint(0),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(10),
|
||||
});
|
||||
// Same as above but justified epoch 2.
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(2),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(4),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(10),
|
||||
});
|
||||
// Same as above but justified epoch 3 (should fail).
|
||||
ops.push(Operation::InvalidFindHead {
|
||||
justified_epoch: Epoch::new(3),
|
||||
justified_root: get_hash(2),
|
||||
finalized_epoch: Epoch::new(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(3),
|
||||
root: get_hash(6),
|
||||
},
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
justified_state_balances: balances,
|
||||
});
|
||||
|
||||
// END OF TESTS
|
||||
ForkChoiceTestDefinition {
|
||||
finalized_block_slot: Slot::new(0),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
finalized_root: get_hash(0),
|
||||
justified_checkpoint: get_checkpoint(0),
|
||||
finalized_checkpoint: get_checkpoint(0),
|
||||
operations: ops,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,14 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
let operations = vec![
|
||||
// Check that the head is the finalized block.
|
||||
Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: Hash256::zero(),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: Hash256::zero(),
|
||||
},
|
||||
@@ -18,11 +23,17 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// /
|
||||
// 2
|
||||
Operation::ProcessBlock {
|
||||
slot: Slot::new(0),
|
||||
slot: Slot::new(1),
|
||||
root: get_hash(2),
|
||||
parent_root: get_hash(0),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
parent_root: Hash256::zero(),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
},
|
||||
// Ensure the head is 2
|
||||
//
|
||||
@@ -30,9 +41,14 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// /
|
||||
// 2 <- head
|
||||
Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: Hash256::zero(),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(2),
|
||||
},
|
||||
@@ -42,11 +58,17 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// / \
|
||||
// 2 1
|
||||
Operation::ProcessBlock {
|
||||
slot: Slot::new(0),
|
||||
slot: Slot::new(1),
|
||||
root: get_hash(1),
|
||||
parent_root: get_hash(0),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
},
|
||||
// Ensure the head is still 2
|
||||
//
|
||||
@@ -54,9 +76,14 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// / \
|
||||
// head-> 2 1
|
||||
Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: Hash256::zero(),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(2),
|
||||
},
|
||||
@@ -68,11 +95,17 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 3
|
||||
Operation::ProcessBlock {
|
||||
slot: Slot::new(0),
|
||||
slot: Slot::new(2),
|
||||
root: get_hash(3),
|
||||
parent_root: get_hash(1),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
},
|
||||
// Ensure 2 is still the head
|
||||
//
|
||||
@@ -82,9 +115,14 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 3
|
||||
Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: Hash256::zero(),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(2),
|
||||
},
|
||||
@@ -96,11 +134,17 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// | |
|
||||
// 4 3
|
||||
Operation::ProcessBlock {
|
||||
slot: Slot::new(0),
|
||||
slot: Slot::new(2),
|
||||
root: get_hash(4),
|
||||
parent_root: get_hash(2),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
},
|
||||
// Ensure the head is 4.
|
||||
//
|
||||
@@ -110,9 +154,14 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// | |
|
||||
// head-> 4 3
|
||||
Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: Hash256::zero(),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(4),
|
||||
},
|
||||
@@ -126,11 +175,14 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 5 <- justified epoch = 2
|
||||
Operation::ProcessBlock {
|
||||
slot: Slot::new(0),
|
||||
slot: Slot::new(3),
|
||||
root: get_hash(5),
|
||||
parent_root: get_hash(4),
|
||||
justified_epoch: Epoch::new(2),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: get_checkpoint(2),
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
},
|
||||
// Ensure the head is still 4 whilst the justified epoch is 0.
|
||||
//
|
||||
@@ -142,9 +194,14 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 5
|
||||
Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: Hash256::zero(),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(4),
|
||||
},
|
||||
@@ -158,9 +215,14 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 5 <- starting from 5 with justified epoch 0 should error.
|
||||
Operation::InvalidFindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: get_hash(5),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
},
|
||||
// Set the justified epoch to 2 and the start block to 5 and ensure 5 is the head.
|
||||
@@ -173,9 +235,11 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 5 <- head
|
||||
Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(5),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: get_checkpoint(2),
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(5),
|
||||
},
|
||||
@@ -191,11 +255,14 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 6
|
||||
Operation::ProcessBlock {
|
||||
slot: Slot::new(0),
|
||||
slot: Slot::new(4),
|
||||
root: get_hash(6),
|
||||
parent_root: get_hash(5),
|
||||
justified_epoch: Epoch::new(2),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: get_checkpoint(2),
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
},
|
||||
// Ensure 6 is the head
|
||||
//
|
||||
@@ -209,9 +276,11 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 6 <- head
|
||||
Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(5),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: get_checkpoint(2),
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
justified_state_balances: balances,
|
||||
expected_head: get_hash(6),
|
||||
},
|
||||
@@ -219,9 +288,14 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
|
||||
ForkChoiceTestDefinition {
|
||||
finalized_block_slot: Slot::new(0),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
finalized_root: get_hash(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
operations,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
|
||||
// Ensure that the head starts at the finalized block.
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(0),
|
||||
});
|
||||
@@ -19,11 +24,17 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// /
|
||||
// 2
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(0),
|
||||
slot: Slot::new(1),
|
||||
root: get_hash(2),
|
||||
parent_root: get_hash(0),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
});
|
||||
|
||||
// Ensure that the head is 2
|
||||
@@ -32,9 +43,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// /
|
||||
// head-> 2
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(2),
|
||||
});
|
||||
@@ -46,11 +62,17 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// / \
|
||||
// 2 1
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(0),
|
||||
slot: Slot::new(1),
|
||||
root: get_hash(1),
|
||||
parent_root: get_hash(0),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
});
|
||||
|
||||
// Ensure that the head is still 2
|
||||
@@ -59,9 +81,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// / \
|
||||
// head-> 2 1
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(2),
|
||||
});
|
||||
@@ -77,15 +104,20 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
target_epoch: Epoch::new(2),
|
||||
});
|
||||
|
||||
// Ensure that the head is now 1, beacuse 1 has a vote.
|
||||
// Ensure that the head is now 1, because 1 has a vote.
|
||||
//
|
||||
// 0
|
||||
// / \
|
||||
// 2 1 <- head
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(1),
|
||||
});
|
||||
@@ -107,9 +139,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// / \
|
||||
// head-> 2 1
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(2),
|
||||
});
|
||||
@@ -122,11 +159,17 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 3
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(0),
|
||||
slot: Slot::new(2),
|
||||
root: get_hash(3),
|
||||
parent_root: get_hash(1),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
});
|
||||
|
||||
// Ensure that the head is still 2
|
||||
@@ -137,9 +180,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 3
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(2),
|
||||
});
|
||||
@@ -165,9 +213,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 3
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(2),
|
||||
});
|
||||
@@ -194,9 +247,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 3 <- head
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(3),
|
||||
});
|
||||
@@ -211,11 +269,17 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 4
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(0),
|
||||
slot: Slot::new(3),
|
||||
root: get_hash(4),
|
||||
parent_root: get_hash(3),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
});
|
||||
|
||||
// Ensure that the head is now 4
|
||||
@@ -228,9 +292,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// 4 <- head
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(4),
|
||||
});
|
||||
@@ -247,11 +316,17 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// /
|
||||
// 5 <- justified epoch = 2
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(0),
|
||||
slot: Slot::new(4),
|
||||
root: get_hash(5),
|
||||
parent_root: get_hash(4),
|
||||
justified_epoch: Epoch::new(2),
|
||||
finalized_epoch: Epoch::new(2),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(1),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(1),
|
||||
},
|
||||
});
|
||||
|
||||
// Ensure that 5 is filtered out and the head stays at 4.
|
||||
@@ -266,9 +341,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// /
|
||||
// 5
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(4),
|
||||
});
|
||||
@@ -288,8 +368,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
slot: Slot::new(0),
|
||||
root: get_hash(6),
|
||||
parent_root: get_hash(4),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
});
|
||||
|
||||
// Move both votes to 5.
|
||||
@@ -336,22 +422,40 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
slot: Slot::new(0),
|
||||
root: get_hash(7),
|
||||
parent_root: get_hash(5),
|
||||
justified_epoch: Epoch::new(2),
|
||||
finalized_epoch: Epoch::new(2),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
});
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(0),
|
||||
root: get_hash(8),
|
||||
parent_root: get_hash(7),
|
||||
justified_epoch: Epoch::new(2),
|
||||
finalized_epoch: Epoch::new(2),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
});
|
||||
ops.push(Operation::ProcessBlock {
|
||||
slot: Slot::new(0),
|
||||
root: get_hash(9),
|
||||
parent_root: get_hash(8),
|
||||
justified_epoch: Epoch::new(2),
|
||||
finalized_epoch: Epoch::new(2),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
});
|
||||
|
||||
// Ensure that 6 is the head, even though 5 has all the votes. This is testing to ensure
|
||||
@@ -373,9 +477,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// /
|
||||
// 9
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(1),
|
||||
justified_root: get_hash(0),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(6),
|
||||
});
|
||||
@@ -401,9 +510,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// /
|
||||
// head-> 9
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(5),
|
||||
finalized_epoch: Epoch::new(2),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(9),
|
||||
});
|
||||
@@ -460,15 +574,26 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
slot: Slot::new(0),
|
||||
root: get_hash(10),
|
||||
parent_root: get_hash(8),
|
||||
justified_epoch: Epoch::new(2),
|
||||
finalized_epoch: Epoch::new(2),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
});
|
||||
|
||||
// Double-check the head is still 9 (no diagram this time)
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(5),
|
||||
finalized_epoch: Epoch::new(2),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(9),
|
||||
});
|
||||
@@ -522,9 +647,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// / \
|
||||
// 9 10 <- head
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(5),
|
||||
finalized_epoch: Epoch::new(2),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(10),
|
||||
});
|
||||
@@ -542,9 +672,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// / \
|
||||
// head-> 9 10
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(5),
|
||||
finalized_epoch: Epoch::new(2),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(9),
|
||||
});
|
||||
@@ -562,9 +697,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// / \
|
||||
// 9 10 <- head
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(5),
|
||||
finalized_epoch: Epoch::new(2),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(10),
|
||||
});
|
||||
@@ -583,9 +723,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// / \
|
||||
// head-> 9 10
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(5),
|
||||
finalized_epoch: Epoch::new(2),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(9),
|
||||
});
|
||||
@@ -599,9 +744,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
|
||||
// Run find-head, ensure the no-op prune didn't change the head.
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(5),
|
||||
finalized_epoch: Epoch::new(2),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(9),
|
||||
});
|
||||
@@ -632,9 +782,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
|
||||
// Run find-head, ensure the prune didn't change the head.
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(5),
|
||||
finalized_epoch: Epoch::new(2),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
justified_state_balances: balances.clone(),
|
||||
expected_head: get_hash(9),
|
||||
});
|
||||
@@ -654,8 +809,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
slot: Slot::new(0),
|
||||
root: get_hash(11),
|
||||
parent_root: get_hash(9),
|
||||
justified_epoch: Epoch::new(2),
|
||||
finalized_epoch: Epoch::new(2),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
});
|
||||
|
||||
// Ensure the head is now 11
|
||||
@@ -670,18 +831,28 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
|
||||
// |
|
||||
// head-> 11
|
||||
ops.push(Operation::FindHead {
|
||||
justified_epoch: Epoch::new(2),
|
||||
justified_root: get_hash(5),
|
||||
finalized_epoch: Epoch::new(2),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(2),
|
||||
root: get_hash(5),
|
||||
},
|
||||
justified_state_balances: balances,
|
||||
expected_head: get_hash(11),
|
||||
});
|
||||
|
||||
ForkChoiceTestDefinition {
|
||||
finalized_block_slot: Slot::new(0),
|
||||
justified_epoch: Epoch::new(1),
|
||||
finalized_epoch: Epoch::new(1),
|
||||
finalized_root: get_hash(0),
|
||||
justified_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
finalized_checkpoint: Checkpoint {
|
||||
epoch: Epoch::new(1),
|
||||
root: get_hash(0),
|
||||
},
|
||||
operations: ops,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user