@@ -51,7 +51,6 @@ pub enum Error<T> {
51
51
MissingFinalizedBlock {
52
52
finalized_checkpoint : Checkpoint ,
53
53
} ,
54
- CannotCreateAnchorFromState ( BeaconStateError ) ,
55
54
}
56
55
57
56
impl < T > From < InvalidAttestation > for Error < T > {
@@ -60,59 +59,6 @@ impl<T> From<InvalidAttestation> for Error<T> {
60
59
}
61
60
}
62
61
63
- #[ derive( Debug ) ]
64
- pub struct Anchor {
65
- finalized_block_slot : Slot ,
66
- finalized_block_state_root : Hash256 ,
67
- finalized_block_execution_status : ExecutionStatus ,
68
- current_epoch_shuffling_id : AttestationShufflingId ,
69
- next_epoch_shuffling_id : AttestationShufflingId ,
70
- }
71
-
72
- impl Anchor {
73
- pub fn from_state < E : EthSpec > (
74
- anchor_state : & BeaconState < E > ,
75
- anchor_state_root : Hash256 ,
76
- ) -> Result < Self , BeaconStateError > {
77
- let finalized_block_slot = anchor_state. latest_block_header ( ) . slot ;
78
- let finalized_block_root = anchor_state. latest_block_header ( ) . canonical_root ( ) ;
79
- let finalized_block_state_root = if finalized_block_slot == anchor_state. slot ( ) {
80
- anchor_state_root
81
- } else {
82
- anchor_state. latest_block_header ( ) . state_root
83
- } ;
84
- let finalized_block_execution_status =
85
- anchor_state. latest_execution_payload_header ( ) . map_or_else (
86
- |_| ExecutionStatus :: irrelevant ( ) ,
87
- |payload_header| {
88
- if payload_header == & <_ >:: default ( ) {
89
- // A default payload does not have execution enabled.
90
- ExecutionStatus :: irrelevant ( )
91
- } else {
92
- // Assume that this payload is valid, since the anchor should be a trusted block and
93
- // state.
94
- ExecutionStatus :: Valid ( payload_header. block_hash )
95
- }
96
- } ,
97
- ) ;
98
- let current_epoch_shuffling_id = AttestationShufflingId :: new (
99
- finalized_block_root,
100
- anchor_state,
101
- RelativeEpoch :: Current ,
102
- ) ?;
103
- let next_epoch_shuffling_id =
104
- AttestationShufflingId :: new ( finalized_block_root, anchor_state, RelativeEpoch :: Next ) ?;
105
-
106
- Ok ( Anchor {
107
- finalized_block_slot,
108
- finalized_block_state_root,
109
- finalized_block_execution_status,
110
- current_epoch_shuffling_id,
111
- next_epoch_shuffling_id,
112
- } )
113
- }
114
- }
115
-
116
62
#[ derive( Debug ) ]
117
63
pub enum InvalidBlock {
118
64
UnknownParent ( Hash256 ) ,
@@ -365,8 +311,8 @@ where
365
311
T : ForkChoiceStore < E > ,
366
312
E : EthSpec ,
367
313
{
368
- /// Instantiates `Self` from an anchor state (genesis or another finalized checkpoint).
369
- pub fn from_anchor_state (
314
+ /// Instantiates `Self` from an anchor (genesis or another finalized checkpoint).
315
+ pub fn from_anchor (
370
316
fc_store : T ,
371
317
anchor_block_root : Hash256 ,
372
318
anchor_block : & SignedBeaconBlock < E > ,
@@ -407,32 +353,6 @@ where
407
353
} ,
408
354
) ;
409
355
410
- let anchor = Anchor {
411
- finalized_block_slot,
412
- finalized_block_state_root,
413
- finalized_block_execution_status : execution_status,
414
- current_epoch_shuffling_id,
415
- next_epoch_shuffling_id,
416
- } ;
417
-
418
- Self :: from_anchor ( fc_store, anchor, current_slot, spec)
419
- }
420
-
421
- /// Instantiates `Self` from an `Anchor`.
422
- pub fn from_anchor (
423
- fc_store : T ,
424
- anchor : Anchor ,
425
- current_slot : Option < Slot > ,
426
- spec : & ChainSpec ,
427
- ) -> Result < Self , Error < T :: Error > > {
428
- let Anchor {
429
- finalized_block_slot,
430
- finalized_block_state_root,
431
- finalized_block_execution_status,
432
- current_epoch_shuffling_id,
433
- next_epoch_shuffling_id,
434
- } = anchor;
435
-
436
356
// If the current slot is not provided, use the value that was last provided to the store.
437
357
let current_slot = current_slot. unwrap_or_else ( || fc_store. get_current_slot ( ) ) ;
438
358
@@ -443,7 +363,7 @@ where
443
363
* fc_store. finalized_checkpoint ( ) ,
444
364
current_epoch_shuffling_id,
445
365
next_epoch_shuffling_id,
446
- finalized_block_execution_status ,
366
+ execution_status ,
447
367
) ?;
448
368
449
369
let mut fork_choice = Self {
@@ -463,16 +383,31 @@ where
463
383
} ;
464
384
465
385
// Ensure that `fork_choice.head_block_root` is updated.
466
- //
467
- // It's possible that this function will return an error if the only valid head with regard
468
- // to FFG checkpoints is invalid. When starting from an anchor state, this would mean that
469
- // we've started from an invalid anchor which should be impossible and is fundamentally
470
- // flawed.
471
386
fork_choice. get_head ( current_slot, spec) ?;
472
387
473
388
Ok ( fork_choice)
474
389
}
475
390
391
+ /*
392
+ /// Instantiates `Self` from some existing components.
393
+ ///
394
+ /// This is useful if the existing components have been loaded from disk after a process
395
+ /// restart.
396
+ pub fn from_components(
397
+ fc_store: T,
398
+ proto_array: ProtoArrayForkChoice,
399
+ queued_attestations: Vec<QueuedAttestation>,
400
+ ) -> Self {
401
+ Self {
402
+ fc_store,
403
+ proto_array,
404
+ queued_attestations,
405
+ forkchoice_update_parameters: None,
406
+ _phantom: PhantomData,
407
+ }
408
+ }
409
+ */
410
+
476
411
/// Returns cached information that can be used to issue a `forkchoiceUpdated` message to an
477
412
/// execution engine.
478
413
///
@@ -1292,34 +1227,9 @@ where
1292
1227
_phantom : PhantomData ,
1293
1228
} ;
1294
1229
1295
- if fork_choice. get_head ( current_slot, spec) . is_ok ( ) {
1296
- // We were successful in finding a head block, use the `fork_choice` we have already
1297
- // constructed.
1298
- Ok ( fork_choice)
1299
- } else {
1300
- // Fork choice returned an error whilst getting the head, therefore there are no
1301
- // valid candidates for the head. Rebuild fork choice from the current finalized
1302
- // checkpoint, potentially losing some history for the sake of having a functioning
1303
- // client.
1304
- let fc_store = fork_choice. fc_store ;
1305
- let proto_array = fork_choice. proto_array ;
1306
-
1307
- let finalized_checkpoint = * fc_store. finalized_checkpoint ( ) ;
1308
- let finalized_block = proto_array. get_block ( & finalized_checkpoint. root ) . ok_or (
1309
- Error :: MissingFinalizedBlock {
1310
- finalized_checkpoint,
1311
- } ,
1312
- ) ?;
1313
-
1314
- let anchor = Anchor {
1315
- finalized_block_slot : finalized_block. slot ,
1316
- finalized_block_state_root : finalized_block. state_root ,
1317
- finalized_block_execution_status : finalized_block. execution_status ,
1318
- current_epoch_shuffling_id : finalized_block. current_epoch_shuffling_id ,
1319
- next_epoch_shuffling_id : finalized_block. next_epoch_shuffling_id ,
1320
- } ;
1321
- Self :: from_anchor ( fc_store, anchor, None , spec)
1322
- }
1230
+ fork_choice. get_head ( current_slot, spec) ?;
1231
+
1232
+ Ok ( fork_choice)
1323
1233
}
1324
1234
1325
1235
/// Takes a snapshot of `Self` and stores it in `PersistedForkChoice`, allowing this struct to
0 commit comments