Skip to content

Commit 1ab1c43

Browse files
committed
Add execution_status FC tests
Start adding execution_status tests Complete test 01 Add tests 2, 3 Appease clippy
1 parent 6dee54c commit 1ab1c43

7 files changed

Lines changed: 1391 additions & 207 deletions

File tree

consensus/proto_array/src/bin.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ fn main() {
66
write_test_def_to_yaml("no_votes.yaml", get_no_votes_test_definition());
77
write_test_def_to_yaml("ffg_01.yaml", get_ffg_case_01_test_definition());
88
write_test_def_to_yaml("ffg_02.yaml", get_ffg_case_02_test_definition());
9+
write_test_def_to_yaml(
10+
"execution_status_01.yaml",
11+
get_execution_status_test_definition_01(),
12+
);
13+
write_test_def_to_yaml(
14+
"execution_status_02.yaml",
15+
get_execution_status_test_definition_02(),
16+
);
17+
write_test_def_to_yaml(
18+
"execution_status_03.yaml",
19+
get_execution_status_test_definition_03(),
20+
);
921
}
1022

1123
fn write_test_def_to_yaml(filename: &str, def: ForkChoiceTestDefinition) {

consensus/proto_array/src/fork_choice_test_definition.rs

Lines changed: 81 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
mod execution_status;
12
mod ffg_updates;
23
mod no_votes;
34
mod votes;
45

56
use crate::proto_array_fork_choice::{Block, ExecutionStatus, ProtoArrayForkChoice};
67
use serde_derive::{Deserialize, Serialize};
7-
use types::{AttestationShufflingId, Checkpoint, Epoch, EthSpec, Hash256, MainnetEthSpec, Slot};
8+
use types::{
9+
AttestationShufflingId, Checkpoint, Epoch, EthSpec, ExecutionBlockHash, Hash256,
10+
MainnetEthSpec, Slot,
11+
};
812

13+
pub use execution_status::*;
914
pub use ffg_updates::*;
1015
pub use no_votes::*;
1116
pub use votes::*;
@@ -18,6 +23,13 @@ pub enum Operation {
1823
justified_state_balances: Vec<u64>,
1924
expected_head: Hash256,
2025
},
26+
ProposerBoostFindHead {
27+
justified_checkpoint: Checkpoint,
28+
finalized_checkpoint: Checkpoint,
29+
justified_state_balances: Vec<u64>,
30+
expected_head: Hash256,
31+
proposer_boost_root: Hash256,
32+
},
2133
InvalidFindHead {
2234
justified_checkpoint: Checkpoint,
2335
finalized_checkpoint: Checkpoint,
@@ -40,6 +52,14 @@ pub enum Operation {
4052
prune_threshold: usize,
4153
expected_len: usize,
4254
},
55+
InvalidatePayload {
56+
head_block_root: Hash256,
57+
latest_valid_ancestor_root: Option<ExecutionBlockHash>,
58+
},
59+
AssertWeight {
60+
block_root: Hash256,
61+
weight: u64,
62+
},
4363
}
4464

4565
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -52,17 +72,19 @@ pub struct ForkChoiceTestDefinition {
5272

5373
impl ForkChoiceTestDefinition {
5474
pub fn run(self) {
75+
let mut spec = MainnetEthSpec::default_spec();
76+
spec.proposer_score_boost = Some(50);
77+
5578
let junk_shuffling_id =
5679
AttestationShufflingId::from_components(Epoch::new(0), Hash256::zero());
57-
let execution_status = ExecutionStatus::irrelevant();
5880
let mut fork_choice = ProtoArrayForkChoice::new(
5981
self.finalized_block_slot,
6082
Hash256::zero(),
6183
self.justified_checkpoint,
6284
self.finalized_checkpoint,
6385
junk_shuffling_id.clone(),
6486
junk_shuffling_id,
65-
execution_status,
87+
ExecutionStatus::Unknown(ExecutionBlockHash::zero()),
6688
)
6789
.expect("should create fork choice struct");
6890

@@ -80,7 +102,7 @@ impl ForkChoiceTestDefinition {
80102
finalized_checkpoint,
81103
&justified_state_balances,
82104
Hash256::zero(),
83-
&MainnetEthSpec::default_spec(),
105+
&spec,
84106
)
85107
.map_err(|e| e)
86108
.unwrap_or_else(|e| {
@@ -89,7 +111,34 @@ impl ForkChoiceTestDefinition {
89111

90112
assert_eq!(
91113
head, expected_head,
92-
"Operation at index {} failed checks. Operation: {:?}",
114+
"Operation at index {} failed head check. Operation: {:?}",
115+
op_index, op
116+
);
117+
check_bytes_round_trip(&fork_choice);
118+
}
119+
Operation::ProposerBoostFindHead {
120+
justified_checkpoint,
121+
finalized_checkpoint,
122+
justified_state_balances,
123+
expected_head,
124+
proposer_boost_root,
125+
} => {
126+
let head = fork_choice
127+
.find_head::<MainnetEthSpec>(
128+
justified_checkpoint,
129+
finalized_checkpoint,
130+
&justified_state_balances,
131+
proposer_boost_root,
132+
&spec,
133+
)
134+
.map_err(|e| e)
135+
.unwrap_or_else(|e| {
136+
panic!("find_head op at index {} returned error {}", op_index, e)
137+
});
138+
139+
assert_eq!(
140+
head, expected_head,
141+
"Operation at index {} failed head check. Operation: {:?}",
93142
op_index, op
94143
);
95144
check_bytes_round_trip(&fork_choice);
@@ -104,7 +153,7 @@ impl ForkChoiceTestDefinition {
104153
finalized_checkpoint,
105154
&justified_state_balances,
106155
Hash256::zero(),
107-
&MainnetEthSpec::default_spec(),
156+
&spec,
108157
);
109158

110159
assert!(
@@ -138,7 +187,10 @@ impl ForkChoiceTestDefinition {
138187
),
139188
justified_checkpoint,
140189
finalized_checkpoint,
141-
execution_status,
190+
// All blocks are imported optimistically.
191+
execution_status: ExecutionStatus::Unknown(ExecutionBlockHash::from_root(
192+
root,
193+
)),
142194
};
143195
fork_choice.process_block(block).unwrap_or_else(|e| {
144196
panic!(
@@ -183,22 +235,41 @@ impl ForkChoiceTestDefinition {
183235
expected_len
184236
);
185237
}
238+
Operation::InvalidatePayload {
239+
head_block_root,
240+
latest_valid_ancestor_root,
241+
} => fork_choice
242+
.process_execution_payload_invalidation(
243+
head_block_root,
244+
latest_valid_ancestor_root,
245+
)
246+
.unwrap(),
247+
Operation::AssertWeight { block_root, weight } => assert_eq!(
248+
fork_choice.get_weight(&block_root).unwrap(),
249+
weight,
250+
"block weight"
251+
),
186252
}
187253
}
188254
}
189255
}
190256

191-
/// Gives a hash that is not the zero hash (unless i is `usize::max_value)`.
192-
fn get_hash(i: u64) -> Hash256 {
257+
/// Gives a root that is not the zero hash (unless i is `usize::max_value)`.
258+
fn get_root(i: u64) -> Hash256 {
193259
Hash256::from_low_u64_be(i + 1)
194260
}
195261

262+
/// Gives a hash that is not the zero hash (unless i is `usize::max_value)`.
263+
fn get_hash(i: u64) -> ExecutionBlockHash {
264+
ExecutionBlockHash::from_root(get_root(i))
265+
}
266+
196267
/// Gives a checkpoint with a root that is not the zero hash (unless i is `usize::max_value)`.
197268
/// `Epoch` will always equal `i`.
198269
fn get_checkpoint(i: u64) -> Checkpoint {
199270
Checkpoint {
200271
epoch: Epoch::new(i),
201-
root: get_hash(i),
272+
root: get_root(i),
202273
}
203274
}
204275

0 commit comments

Comments
 (0)