Skip to content

Commit a8fac74

Browse files
authored
Merge of #8324
2 parents 11d1f60 + 06acfc7 commit a8fac74

File tree

9 files changed

+204
-82
lines changed

9 files changed

+204
-82
lines changed

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,10 +1412,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
14121412
///
14131413
/// Returns `(block_root, block_slot)`.
14141414
pub fn heads(&self) -> Vec<(Hash256, Slot)> {
1415-
self.canonical_head
1416-
.fork_choice_read_lock()
1415+
let fork_choice = self.canonical_head.fork_choice_read_lock();
1416+
fork_choice
14171417
.proto_array()
1418-
.heads_descended_from_finalization::<T::EthSpec>()
1418+
.heads_descended_from_finalization::<T::EthSpec>(fork_choice.finalized_checkpoint())
14191419
.iter()
14201420
.map(|node| (node.root, node.slot))
14211421
.collect()

beacon_node/beacon_chain/src/schema_change/migration_schema_v23.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub fn downgrade_from_v23<T: BeaconChainTypes>(
122122

123123
let heads = fork_choice
124124
.proto_array()
125-
.heads_descended_from_finalization::<T::EthSpec>();
125+
.heads_descended_from_finalization::<T::EthSpec>(fork_choice.finalized_checkpoint());
126126

127127
let head_roots = heads.iter().map(|node| node.root).collect();
128128
let head_slots = heads.iter().map(|node| node.slot).collect();

beacon_node/http_api/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,8 +3037,8 @@ pub fn serve<T: BeaconChainTypes>(
30373037
})
30383038
.collect::<Vec<_>>();
30393039
Ok(ForkChoice {
3040-
justified_checkpoint: proto_array.justified_checkpoint,
3041-
finalized_checkpoint: proto_array.finalized_checkpoint,
3040+
justified_checkpoint: beacon_fork_choice.justified_checkpoint(),
3041+
finalized_checkpoint: beacon_fork_choice.finalized_checkpoint(),
30423042
fork_choice_nodes,
30433043
})
30443044
})

beacon_node/http_api/tests/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3057,11 +3057,11 @@ impl ApiTester {
30573057

30583058
assert_eq!(
30593059
result.justified_checkpoint,
3060-
expected_proto_array.justified_checkpoint
3060+
beacon_fork_choice.justified_checkpoint()
30613061
);
30623062
assert_eq!(
30633063
result.finalized_checkpoint,
3064-
expected_proto_array.finalized_checkpoint
3064+
beacon_fork_choice.finalized_checkpoint()
30653065
);
30663066

30673067
let expected_fork_choice_nodes: Vec<ForkChoiceNode> = expected_proto_array

consensus/fork_choice/src/fork_choice.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ where
627627
op: &InvalidationOperation,
628628
) -> Result<(), Error<T::Error>> {
629629
self.proto_array
630-
.process_execution_payload_invalidation::<E>(op)
630+
.process_execution_payload_invalidation::<E>(op, self.finalized_checkpoint())
631631
.map_err(Error::FailedToProcessInvalidExecutionPayload)
632632
}
633633

@@ -908,6 +908,8 @@ where
908908
unrealized_finalized_checkpoint: Some(unrealized_finalized_checkpoint),
909909
},
910910
current_slot,
911+
self.justified_checkpoint(),
912+
self.finalized_checkpoint(),
911913
)?;
912914

913915
Ok(())
@@ -1288,7 +1290,7 @@ where
12881290
/// Return `true` if `block_root` is equal to the finalized checkpoint, or a known descendant of it.
12891291
pub fn is_finalized_checkpoint_or_descendant(&self, block_root: Hash256) -> bool {
12901292
self.proto_array
1291-
.is_finalized_checkpoint_or_descendant::<E>(block_root)
1293+
.is_finalized_checkpoint_or_descendant::<E>(block_root, self.finalized_checkpoint())
12921294
}
12931295

12941296
pub fn is_descendant(&self, ancestor_root: Hash256, descendant_root: Hash256) -> bool {
@@ -1508,7 +1510,9 @@ where
15081510
/// be instantiated again later.
15091511
pub fn to_persisted(&self) -> PersistedForkChoice {
15101512
PersistedForkChoice {
1511-
proto_array: self.proto_array().as_ssz_container(),
1513+
proto_array: self
1514+
.proto_array()
1515+
.as_ssz_container(self.justified_checkpoint(), self.finalized_checkpoint()),
15121516
queued_attestations: self.queued_attestations().to_vec(),
15131517
}
15141518
}

consensus/proto_array/src/fork_choice_test_definition.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ impl ForkChoiceTestDefinition {
212212
unrealized_finalized_checkpoint: None,
213213
};
214214
fork_choice
215-
.process_block::<MainnetEthSpec>(block, slot)
215+
.process_block::<MainnetEthSpec>(
216+
block,
217+
slot,
218+
self.justified_checkpoint,
219+
self.finalized_checkpoint,
220+
)
216221
.unwrap_or_else(|e| {
217222
panic!(
218223
"process_block op at index {} returned error: {:?}",
@@ -272,7 +277,10 @@ impl ForkChoiceTestDefinition {
272277
}
273278
};
274279
fork_choice
275-
.process_execution_payload_invalidation::<MainnetEthSpec>(&op)
280+
.process_execution_payload_invalidation::<MainnetEthSpec>(
281+
&op,
282+
self.finalized_checkpoint,
283+
)
276284
.unwrap()
277285
}
278286
Operation::AssertWeight { block_root, weight } => assert_eq!(
@@ -305,7 +313,8 @@ fn get_checkpoint(i: u64) -> Checkpoint {
305313
}
306314

307315
fn check_bytes_round_trip(original: &ProtoArrayForkChoice) {
308-
let bytes = original.as_bytes();
316+
// The checkpoint are ignored `ProtoArrayForkChoice::from_bytes` so any value is ok
317+
let bytes = original.as_bytes(Checkpoint::default(), Checkpoint::default());
309318
let decoded = ProtoArrayForkChoice::from_bytes(&bytes, original.balances.clone())
310319
.expect("fork choice should decode from bytes");
311320
assert!(

0 commit comments

Comments
 (0)