Retrospective invalidation of exec. payloads for opt. sync (#2837)

## Issue Addressed

NA

## Proposed Changes

Adds the functionality to allow blocks to be validated/invalidated after their import as per the [optimistic sync spec](https://github.com/ethereum/consensus-specs/blob/dev/sync/optimistic.md#how-to-optimistically-import-blocks). This means:

- Updating `ProtoArray` to allow flipping the `execution_status` of ancestors/descendants based on payload validity updates.
- Creating separation between `execution_layer` and the `beacon_chain` by creating a `PayloadStatus` struct.
- Refactoring how the `execution_layer` selects a `PayloadStatus` from the multiple statuses returned from multiple EEs.
- Adding testing framework for optimistic imports.
- Add `ExecutionBlockHash(Hash256)` new-type struct to avoid confusion between *beacon block roots* and *execution payload hashes*.
- Add `merge` to [`FORKS`](c3a793fd73/Makefile (L17)) in the `Makefile` to ensure we test the beacon chain with merge settings.
    - Fix some tests here that were failing due to a missing execution layer.

## TODO

- [ ] Balance tests

Co-authored-by: Mark Mackey <mark@sigmaprime.io>
This commit is contained in:
Paul Hauner
2022-02-28 22:07:48 +00:00
parent 5e1f8a8480
commit 27e83b888c
50 changed files with 3358 additions and 768 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -9,7 +9,7 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
expected_head: get_hash(0),
expected_head: get_root(0),
});
// Build the following tree (stick? lol).
@@ -23,22 +23,22 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
// 3 <- just: 2, fin: 1
ops.push(Operation::ProcessBlock {
slot: Slot::new(1),
root: get_hash(1),
parent_root: get_hash(0),
root: get_root(1),
parent_root: get_root(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),
root: get_root(2),
parent_root: get_root(1),
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),
root: get_root(3),
parent_root: get_root(2),
justified_checkpoint: get_checkpoint(2),
finalized_checkpoint: get_checkpoint(1),
});
@@ -56,7 +56,7 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
expected_head: get_hash(3),
expected_head: get_root(3),
});
// Ensure that with justified epoch 1 we find 2
@@ -72,7 +72,7 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
justified_checkpoint: get_checkpoint(1),
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
expected_head: get_hash(2),
expected_head: get_root(2),
});
// Ensure that with justified epoch 2 we find 3
@@ -88,7 +88,7 @@ pub fn get_ffg_case_01_test_definition() -> ForkChoiceTestDefinition {
justified_checkpoint: get_checkpoint(2),
finalized_checkpoint: get_checkpoint(1),
justified_state_balances: balances,
expected_head: get_hash(3),
expected_head: get_root(3),
});
// END OF TESTS
@@ -109,7 +109,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
expected_head: get_hash(0),
expected_head: get_root(0),
});
// Build the following tree.
@@ -129,48 +129,48 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
// Left branch
ops.push(Operation::ProcessBlock {
slot: Slot::new(1),
root: get_hash(1),
parent_root: get_hash(0),
root: get_root(1),
parent_root: get_root(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),
root: get_root(3),
parent_root: get_root(1),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(1),
root: get_root(1),
},
finalized_checkpoint: get_checkpoint(0),
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(3),
root: get_hash(5),
parent_root: get_hash(3),
root: get_root(5),
parent_root: get_root(3),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(1),
root: get_root(1),
},
finalized_checkpoint: get_checkpoint(0),
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(4),
root: get_hash(7),
parent_root: get_hash(5),
root: get_root(7),
parent_root: get_root(5),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(1),
root: get_root(1),
},
finalized_checkpoint: get_checkpoint(0),
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(5),
root: get_hash(9),
parent_root: get_hash(7),
root: get_root(9),
parent_root: get_root(7),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(3),
root: get_root(3),
},
finalized_checkpoint: get_checkpoint(0),
});
@@ -178,42 +178,42 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
// Right branch
ops.push(Operation::ProcessBlock {
slot: Slot::new(1),
root: get_hash(2),
parent_root: get_hash(0),
root: get_root(2),
parent_root: get_root(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),
root: get_root(4),
parent_root: get_root(2),
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),
root: get_root(6),
parent_root: get_root(4),
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),
root: get_root(8),
parent_root: get_root(6),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(2),
root: get_root(2),
},
finalized_checkpoint: get_checkpoint(0),
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(5),
root: get_hash(10),
parent_root: get_hash(8),
root: get_root(10),
parent_root: get_root(8),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(4),
root: get_root(4),
},
finalized_checkpoint: get_checkpoint(0),
});
@@ -235,23 +235,23 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
expected_head: get_hash(10),
expected_head: get_root(10),
});
// Same as above, but with justified epoch 2.
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(4),
root: get_root(4),
},
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
expected_head: get_hash(10),
expected_head: get_root(10),
});
// Same as above, but with justified epoch 3 (should be invalid).
ops.push(Operation::InvalidFindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(3),
root: get_hash(6),
root: get_root(6),
},
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
@@ -272,7 +272,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
// 9 10
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_hash(1),
block_root: get_root(1),
target_epoch: Epoch::new(0),
});
@@ -293,23 +293,23 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
expected_head: get_hash(9),
expected_head: get_root(9),
});
// Save as above but justified epoch 2.
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(3),
root: get_root(3),
},
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
expected_head: get_hash(9),
expected_head: get_root(9),
});
// Save as above but justified epoch 3 (should fail).
ops.push(Operation::InvalidFindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(3),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
@@ -330,7 +330,7 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
// 9 10
ops.push(Operation::ProcessAttestation {
validator_index: 1,
block_root: get_hash(2),
block_root: get_root(2),
target_epoch: Epoch::new(0),
});
@@ -351,23 +351,23 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
expected_head: get_hash(10),
expected_head: get_root(10),
});
// Same as above but justified epoch 2.
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(4),
root: get_root(4),
},
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
expected_head: get_hash(10),
expected_head: get_root(10),
});
// Same as above but justified epoch 3 (should fail).
ops.push(Operation::InvalidFindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(3),
root: get_hash(6),
root: get_root(6),
},
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
@@ -389,27 +389,27 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(0),
root: get_hash(1),
root: get_root(1),
},
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
expected_head: get_hash(9),
expected_head: get_root(9),
});
// Same as above but justified epoch 2.
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(3),
root: get_root(3),
},
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
expected_head: get_hash(9),
expected_head: get_root(9),
});
// Same as above but justified epoch 3 (should fail).
ops.push(Operation::InvalidFindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(3),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
@@ -432,23 +432,23 @@ pub fn get_ffg_case_02_test_definition() -> ForkChoiceTestDefinition {
justified_checkpoint: get_checkpoint(0),
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
expected_head: get_hash(10),
expected_head: get_root(10),
});
// Same as above but justified epoch 2.
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(4),
root: get_root(4),
},
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances.clone(),
expected_head: get_hash(10),
expected_head: get_root(10),
});
// Same as above but justified epoch 3 (should fail).
ops.push(Operation::InvalidFindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(3),
root: get_hash(6),
root: get_root(6),
},
finalized_checkpoint: get_checkpoint(0),
justified_state_balances: balances,

View File

@@ -24,7 +24,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
// 2
Operation::ProcessBlock {
slot: Slot::new(1),
root: get_hash(2),
root: get_root(2),
parent_root: Hash256::zero(),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
@@ -50,7 +50,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
root: Hash256::zero(),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(2),
expected_head: get_root(2),
},
// Add block 1
//
@@ -59,8 +59,8 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
// 2 1
Operation::ProcessBlock {
slot: Slot::new(1),
root: get_hash(1),
parent_root: get_hash(0),
root: get_root(1),
parent_root: get_root(0),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: Hash256::zero(),
@@ -85,7 +85,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
root: Hash256::zero(),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(2),
expected_head: get_root(2),
},
// Add block 3
//
@@ -96,8 +96,8 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
// 3
Operation::ProcessBlock {
slot: Slot::new(2),
root: get_hash(3),
parent_root: get_hash(1),
root: get_root(3),
parent_root: get_root(1),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: Hash256::zero(),
@@ -124,7 +124,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
root: Hash256::zero(),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(2),
expected_head: get_root(2),
},
// Add block 4
//
@@ -135,8 +135,8 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
// 4 3
Operation::ProcessBlock {
slot: Slot::new(2),
root: get_hash(4),
parent_root: get_hash(2),
root: get_root(4),
parent_root: get_root(2),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: Hash256::zero(),
@@ -163,7 +163,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
root: Hash256::zero(),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(4),
expected_head: get_root(4),
},
// Add block 5 with a justified epoch of 2
//
@@ -176,8 +176,8 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
// 5 <- justified epoch = 2
Operation::ProcessBlock {
slot: Slot::new(3),
root: get_hash(5),
parent_root: get_hash(4),
root: get_root(5),
parent_root: get_root(4),
justified_checkpoint: get_checkpoint(2),
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
@@ -203,7 +203,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
root: Hash256::zero(),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(4),
expected_head: get_root(4),
},
// Ensure there is an error when starting from a block that has the wrong justified epoch.
//
@@ -217,7 +217,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
Operation::InvalidFindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
@@ -241,7 +241,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
root: Hash256::zero(),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(5),
expected_head: get_root(5),
},
// Add block 6
//
@@ -256,8 +256,8 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
// 6
Operation::ProcessBlock {
slot: Slot::new(4),
root: get_hash(6),
parent_root: get_hash(5),
root: get_root(6),
parent_root: get_root(5),
justified_checkpoint: get_checkpoint(2),
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
@@ -282,7 +282,7 @@ pub fn get_no_votes_test_definition() -> ForkChoiceTestDefinition {
root: Hash256::zero(),
},
justified_state_balances: balances,
expected_head: get_hash(6),
expected_head: get_root(6),
},
];

View File

@@ -8,14 +8,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(0),
expected_head: get_root(0),
});
// Add a block with a hash of 2.
@@ -25,15 +25,15 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// 2
ops.push(Operation::ProcessBlock {
slot: Slot::new(1),
root: get_hash(2),
parent_root: get_hash(0),
root: get_root(2),
parent_root: get_root(0),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
});
@@ -45,14 +45,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(2),
expected_head: get_root(2),
});
// Add a block with a hash of 1 that comes off the genesis block (this is a fork compared
@@ -63,15 +63,15 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// 2 1
ops.push(Operation::ProcessBlock {
slot: Slot::new(1),
root: get_hash(1),
parent_root: get_hash(0),
root: get_root(1),
parent_root: get_root(0),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
});
@@ -83,14 +83,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(2),
expected_head: get_root(2),
});
// Add a vote to block 1
@@ -100,7 +100,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// 2 1 <- +vote
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_hash(1),
block_root: get_root(1),
target_epoch: Epoch::new(2),
});
@@ -112,14 +112,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(1),
expected_head: get_root(1),
});
// Add a vote to block 2
@@ -129,7 +129,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// +vote-> 2 1
ops.push(Operation::ProcessAttestation {
validator_index: 1,
block_root: get_hash(2),
block_root: get_root(2),
target_epoch: Epoch::new(2),
});
@@ -141,14 +141,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(2),
expected_head: get_root(2),
});
// Add block 3.
@@ -160,15 +160,15 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// 3
ops.push(Operation::ProcessBlock {
slot: Slot::new(2),
root: get_hash(3),
parent_root: get_hash(1),
root: get_root(3),
parent_root: get_root(1),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
});
@@ -182,14 +182,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(2),
expected_head: get_root(2),
});
// Move validator #0 vote from 1 to 3
@@ -201,7 +201,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// 3 <- +vote
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_hash(3),
block_root: get_root(3),
target_epoch: Epoch::new(3),
});
@@ -215,14 +215,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(2),
expected_head: get_root(2),
});
// Move validator #1 vote from 2 to 1 (this is an equivocation, but fork choice doesn't
@@ -235,7 +235,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// 3
ops.push(Operation::ProcessAttestation {
validator_index: 1,
block_root: get_hash(1),
block_root: get_root(1),
target_epoch: Epoch::new(3),
});
@@ -249,14 +249,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(3),
expected_head: get_root(3),
});
// Add block 4.
@@ -270,15 +270,15 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// 4
ops.push(Operation::ProcessBlock {
slot: Slot::new(3),
root: get_hash(4),
parent_root: get_hash(3),
root: get_root(4),
parent_root: get_root(3),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
});
@@ -294,14 +294,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(4),
expected_head: get_root(4),
});
// Add block 5, which has a justified epoch of 2.
@@ -317,15 +317,15 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// 5 <- justified epoch = 2
ops.push(Operation::ProcessBlock {
slot: Slot::new(4),
root: get_hash(5),
parent_root: get_hash(4),
root: get_root(5),
parent_root: get_root(4),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(1),
root: get_root(1),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(1),
root: get_root(1),
},
});
@@ -343,14 +343,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(4),
expected_head: get_root(4),
});
// Add block 6, which has a justified epoch of 0.
@@ -366,15 +366,15 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// 5 6 <- justified epoch = 0
ops.push(Operation::ProcessBlock {
slot: Slot::new(0),
root: get_hash(6),
parent_root: get_hash(4),
root: get_root(6),
parent_root: get_root(4),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
});
@@ -391,12 +391,12 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// +2 vote-> 5 6
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_hash(5),
block_root: get_root(5),
target_epoch: Epoch::new(4),
});
ops.push(Operation::ProcessAttestation {
validator_index: 1,
block_root: get_hash(5),
block_root: get_root(5),
target_epoch: Epoch::new(4),
});
@@ -420,41 +420,41 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// 9
ops.push(Operation::ProcessBlock {
slot: Slot::new(0),
root: get_hash(7),
parent_root: get_hash(5),
root: get_root(7),
parent_root: get_root(5),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(0),
root: get_hash(8),
parent_root: get_hash(7),
root: get_root(8),
parent_root: get_root(7),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
});
ops.push(Operation::ProcessBlock {
slot: Slot::new(0),
root: get_hash(9),
parent_root: get_hash(8),
root: get_root(9),
parent_root: get_root(8),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
});
@@ -479,14 +479,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(6),
expected_head: get_root(6),
});
// Change fork-choice justified epoch to 1, and the start block to 5 and ensure that 9 is
@@ -512,14 +512,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(9),
expected_head: get_root(9),
});
// Change fork-choice justified epoch to 1, and the start block to 5 and ensure that 9 is
@@ -544,12 +544,12 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// 9 <- +2 votes
ops.push(Operation::ProcessAttestation {
validator_index: 0,
block_root: get_hash(9),
block_root: get_root(9),
target_epoch: Epoch::new(5),
});
ops.push(Operation::ProcessAttestation {
validator_index: 1,
block_root: get_hash(9),
block_root: get_root(9),
target_epoch: Epoch::new(5),
});
@@ -572,15 +572,15 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// 9 10
ops.push(Operation::ProcessBlock {
slot: Slot::new(0),
root: get_hash(10),
parent_root: get_hash(8),
root: get_root(10),
parent_root: get_root(8),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
});
@@ -588,14 +588,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(9),
expected_head: get_root(9),
});
// Introduce 2 more validators into the system
@@ -620,12 +620,12 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// 9 10 <- +2 votes
ops.push(Operation::ProcessAttestation {
validator_index: 2,
block_root: get_hash(10),
block_root: get_root(10),
target_epoch: Epoch::new(5),
});
ops.push(Operation::ProcessAttestation {
validator_index: 3,
block_root: get_hash(10),
block_root: get_root(10),
target_epoch: Epoch::new(5),
});
@@ -649,14 +649,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(10),
expected_head: get_root(10),
});
// Set the balances of the last two validators to zero
@@ -674,14 +674,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(9),
expected_head: get_root(9),
});
// Set the balances of the last two validators back to 1
@@ -699,14 +699,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(10),
expected_head: get_root(10),
});
// Remove the last two validators
@@ -725,19 +725,19 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(9),
expected_head: get_root(9),
});
// Ensure that pruning below the prune threshold does not prune.
ops.push(Operation::Prune {
finalized_root: get_hash(5),
finalized_root: get_root(5),
prune_threshold: usize::max_value(),
expected_len: 11,
});
@@ -746,14 +746,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(9),
expected_head: get_root(9),
});
// Ensure that pruning above the prune threshold does prune.
@@ -775,7 +775,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// / \
// 9 10
ops.push(Operation::Prune {
finalized_root: get_hash(5),
finalized_root: get_root(5),
prune_threshold: 1,
expected_len: 6,
});
@@ -784,14 +784,14 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
justified_state_balances: balances.clone(),
expected_head: get_hash(9),
expected_head: get_root(9),
});
// Add block 11
@@ -807,15 +807,15 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// 11
ops.push(Operation::ProcessBlock {
slot: Slot::new(0),
root: get_hash(11),
parent_root: get_hash(9),
root: get_root(11),
parent_root: get_root(9),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
});
@@ -833,25 +833,25 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
ops.push(Operation::FindHead {
justified_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(2),
root: get_hash(5),
root: get_root(5),
},
justified_state_balances: balances,
expected_head: get_hash(11),
expected_head: get_root(11),
});
ForkChoiceTestDefinition {
finalized_block_slot: Slot::new(0),
justified_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
finalized_checkpoint: Checkpoint {
epoch: Epoch::new(1),
root: get_hash(0),
root: get_root(0),
},
operations: ops,
}