11use crate :: error:: Error ;
22use crate :: proto_array:: ProtoArray ;
3- use crate :: ssz_container:: SszContainer ;
3+ use crate :: ssz_container:: { LegacySszContainer , SszContainer } ;
44use ssz:: { Decode , Encode } ;
55use ssz_derive:: { Decode , Encode } ;
66use std:: collections:: HashMap ;
@@ -29,6 +29,7 @@ pub struct Block {
2929 pub next_epoch_shuffling_id : AttestationShufflingId ,
3030 pub justified_epoch : Epoch ,
3131 pub finalized_epoch : Epoch ,
32+ pub execution_block_hash : Hash256 ,
3233}
3334
3435/// A Vec-wrapper which will grow to match any request.
@@ -66,6 +67,7 @@ pub struct ProtoArrayForkChoice {
6667}
6768
6869impl ProtoArrayForkChoice {
70+ #[ allow( clippy:: too_many_arguments) ]
6971 pub fn new (
7072 finalized_block_slot : Slot ,
7173 finalized_block_state_root : Hash256 ,
@@ -74,6 +76,7 @@ impl ProtoArrayForkChoice {
7476 finalized_root : Hash256 ,
7577 current_epoch_shuffling_id : AttestationShufflingId ,
7678 next_epoch_shuffling_id : AttestationShufflingId ,
79+ execution_block_hash : Hash256 ,
7780 ) -> Result < Self , String > {
7881 let mut proto_array = ProtoArray {
7982 prune_threshold : DEFAULT_PRUNE_THRESHOLD ,
@@ -95,6 +98,7 @@ impl ProtoArrayForkChoice {
9598 next_epoch_shuffling_id,
9699 justified_epoch,
97100 finalized_epoch,
101+ execution_block_hash,
98102 } ;
99103
100104 proto_array
@@ -204,6 +208,7 @@ impl ProtoArrayForkChoice {
204208 next_epoch_shuffling_id : block. next_epoch_shuffling_id . clone ( ) ,
205209 justified_epoch : block. justified_epoch ,
206210 finalized_epoch : block. finalized_epoch ,
211+ execution_block_hash : block. execution_block_hash ,
207212 } )
208213 }
209214
@@ -252,6 +257,22 @@ impl ProtoArrayForkChoice {
252257 . map_err ( |e| format ! ( "Failed to decode ProtoArrayForkChoice: {:?}" , e) )
253258 }
254259
260+ /// Only used for SSZ deserialization of the persisted fork choice during the database migration
261+ /// from schema 4 to schema 5.
262+ pub fn from_bytes_legacy ( bytes : & [ u8 ] ) -> Result < Self , String > {
263+ LegacySszContainer :: from_ssz_bytes ( bytes)
264+ . map ( |legacy_container| {
265+ let container: SszContainer = legacy_container. into ( ) ;
266+ container. into ( )
267+ } )
268+ . map_err ( |e| {
269+ format ! (
270+ "Failed to decode ProtoArrayForkChoice during schema migration: {:?}" ,
271+ e
272+ )
273+ } )
274+ }
275+
255276 /// Returns a read-lock to core `ProtoArray` struct.
256277 ///
257278 /// Should only be used when encoding/decoding during troubleshooting.
@@ -351,6 +372,7 @@ mod test_compute_deltas {
351372 let unknown = Hash256 :: from_low_u64_be ( 4 ) ;
352373 let junk_shuffling_id =
353374 AttestationShufflingId :: from_components ( Epoch :: new ( 0 ) , Hash256 :: zero ( ) ) ;
375+ let execution_block_hash = Hash256 :: zero ( ) ;
354376
355377 let mut fc = ProtoArrayForkChoice :: new (
356378 genesis_slot,
@@ -360,6 +382,7 @@ mod test_compute_deltas {
360382 finalized_root,
361383 junk_shuffling_id. clone ( ) ,
362384 junk_shuffling_id. clone ( ) ,
385+ execution_block_hash,
363386 )
364387 . unwrap ( ) ;
365388
@@ -375,6 +398,7 @@ mod test_compute_deltas {
375398 next_epoch_shuffling_id : junk_shuffling_id. clone ( ) ,
376399 justified_epoch : genesis_epoch,
377400 finalized_epoch : genesis_epoch,
401+ execution_block_hash,
378402 } )
379403 . unwrap ( ) ;
380404
@@ -390,6 +414,7 @@ mod test_compute_deltas {
390414 next_epoch_shuffling_id : junk_shuffling_id,
391415 justified_epoch : genesis_epoch,
392416 finalized_epoch : genesis_epoch,
417+ execution_block_hash,
393418 } )
394419 . unwrap ( ) ;
395420
0 commit comments