@@ -945,34 +945,62 @@ mod tests {
945945 SignedBeaconBlock :: from_block ( empty_block, Signature :: empty ( ) )
946946 }
947947
948- fn altair_block ( ) -> SignedBeaconBlock < Spec > {
949- let full_block =
948+ fn altair_block ( spec : & ChainSpec ) -> SignedBeaconBlock < Spec > {
949+ // The context bytes are now derived from the block epoch, so we need to have the slot set
950+ // here.
951+ let mut full_block =
950952 BeaconBlock :: Altair ( BeaconBlockAltair :: < Spec > :: full ( & Spec :: default_spec ( ) ) ) ;
953+ * full_block. slot_mut ( ) = spec
954+ . altair_fork_epoch
955+ . expect ( "altair fork epoch must be set" )
956+ . start_slot ( Spec :: slots_per_epoch ( ) ) ;
951957 SignedBeaconBlock :: from_block ( full_block, Signature :: empty ( ) )
952958 }
953959
954- fn empty_blob_sidecar ( ) -> Arc < BlobSidecar < Spec > > {
955- Arc :: new ( BlobSidecar :: empty ( ) )
960+ fn empty_blob_sidecar ( spec : & ChainSpec ) -> Arc < BlobSidecar < Spec > > {
961+ // The context bytes are now derived from the block epoch, so we need to have the slot set
962+ // here.
963+ let mut blob_sidecar = BlobSidecar :: < Spec > :: empty ( ) ;
964+ blob_sidecar. signed_block_header . message . slot = spec
965+ . deneb_fork_epoch
966+ . expect ( "deneb fork epoch must be set" )
967+ . start_slot ( Spec :: slots_per_epoch ( ) ) ;
968+ Arc :: new ( blob_sidecar)
956969 }
957970
958- fn empty_data_column_sidecar ( ) -> Arc < DataColumnSidecar < Spec > > {
959- Arc :: new ( DataColumnSidecar {
971+ fn empty_data_column_sidecar ( spec : & ChainSpec ) -> Arc < DataColumnSidecar < Spec > > {
972+ // The context bytes are now derived from the block epoch, so we need to have the slot set
973+ // here.
974+ let data_column_sidecar = DataColumnSidecar {
960975 index : 0 ,
961976 column : VariableList :: new ( vec ! [ Cell :: <Spec >:: default ( ) ] ) . unwrap ( ) ,
962977 kzg_commitments : VariableList :: new ( vec ! [ KzgCommitment :: empty_for_testing( ) ] ) . unwrap ( ) ,
963978 kzg_proofs : VariableList :: new ( vec ! [ KzgProof :: empty( ) ] ) . unwrap ( ) ,
964979 signed_block_header : SignedBeaconBlockHeader {
965- message : BeaconBlockHeader :: empty ( ) ,
980+ message : BeaconBlockHeader {
981+ slot : spec
982+ . fulu_fork_epoch
983+ . expect ( "fulu fork epoch must be set" )
984+ . start_slot ( Spec :: slots_per_epoch ( ) ) ,
985+ ..BeaconBlockHeader :: empty ( )
986+ } ,
966987 signature : Signature :: empty ( ) ,
967988 } ,
968989 kzg_commitments_inclusion_proof : Default :: default ( ) ,
969- } )
990+ } ;
991+ Arc :: new ( data_column_sidecar)
970992 }
971993
972994 /// Bellatrix block with length < max_rpc_size.
973995 fn bellatrix_block_small ( spec : & ChainSpec ) -> SignedBeaconBlock < Spec > {
996+ // The context bytes are now derived from the block epoch, so we need to have the slot set
997+ // here.
974998 let mut block: BeaconBlockBellatrix < _ , FullPayload < Spec > > =
975- BeaconBlockBellatrix :: empty ( & Spec :: default_spec ( ) ) ;
999+ BeaconBlockBellatrix :: empty ( spec) ;
1000+ block. slot = spec
1001+ . bellatrix_fork_epoch
1002+ . expect ( "Bellatrix epoch must be set" )
1003+ . start_slot ( Spec :: slots_per_epoch ( ) ) ;
9761004
9771005 let tx = VariableList :: from ( vec ! [ 0 ; 1024 ] ) ;
9781006 let txs = VariableList :: from ( std:: iter:: repeat_n ( tx, 5000 ) . collect :: < Vec < _ > > ( ) ) ;
@@ -988,8 +1016,14 @@ mod tests {
9881016 /// The max limit for a Bellatrix block is in the order of ~16GiB which wouldn't fit in memory.
9891017 /// Hence, we generate a Bellatrix block just greater than `MAX_RPC_SIZE` to test rejection on the rpc layer.
9901018 fn bellatrix_block_large ( spec : & ChainSpec ) -> SignedBeaconBlock < Spec > {
1019+ // The context bytes are now derived from the block epoch, so we need to have the slot set
1020+ // here.
9911021 let mut block: BeaconBlockBellatrix < _ , FullPayload < Spec > > =
992- BeaconBlockBellatrix :: empty ( & Spec :: default_spec ( ) ) ;
1022+ BeaconBlockBellatrix :: empty ( & spec) ;
1023+ block. slot = spec
1024+ . bellatrix_fork_epoch
1025+ . expect ( "Bellatrix epoch must be set" )
1026+ . start_slot ( Spec :: slots_per_epoch ( ) ) ;
9931027
9941028 let tx = VariableList :: from ( vec ! [ 0 ; 1024 ] ) ;
9951029 let txs = VariableList :: from ( std:: iter:: repeat_n ( tx, 100000 ) . collect :: < Vec < _ > > ( ) ) ;
@@ -1255,7 +1289,9 @@ mod tests {
12551289 // Test RPCResponse encoding/decoding for V1 messages
12561290 #[ test]
12571291 fn test_encode_then_decode_v1 ( ) {
1258- let chain_spec = Spec :: default_spec ( ) ;
1292+ let mut chain_spec = Spec :: default_spec ( ) ;
1293+ // Set a fulu fork epoch so we can encode / decode data columns
1294+ chain_spec. fulu_fork_epoch = Some ( Epoch :: new ( 1401280 ) ) ;
12591295
12601296 assert_eq ! (
12611297 encode_then_decode_response(
@@ -1307,7 +1343,7 @@ mod tests {
13071343 encode_then_decode_response(
13081344 SupportedProtocol :: BlocksByRangeV1 ,
13091345 RpcResponse :: Success ( RpcSuccessResponse :: BlocksByRange ( Arc :: new(
1310- altair_block( )
1346+ altair_block( & chain_spec )
13111347 ) ) ) ,
13121348 ForkName :: Altair ,
13131349 & chain_spec,
@@ -1336,9 +1372,9 @@ mod tests {
13361372 matches!(
13371373 encode_then_decode_response(
13381374 SupportedProtocol :: BlocksByRootV1 ,
1339- RpcResponse :: Success ( RpcSuccessResponse :: BlocksByRoot (
1340- Arc :: new ( altair_block ( ) )
1341- ) ) ,
1375+ RpcResponse :: Success ( RpcSuccessResponse :: BlocksByRoot ( Arc :: new ( altair_block (
1376+ & chain_spec
1377+ ) ) ) ) ,
13421378 ForkName :: Altair ,
13431379 & chain_spec,
13441380 )
@@ -1383,152 +1419,178 @@ mod tests {
13831419 assert_eq ! (
13841420 encode_then_decode_response(
13851421 SupportedProtocol :: BlobsByRangeV1 ,
1386- RpcResponse :: Success ( RpcSuccessResponse :: BlobsByRange ( empty_blob_sidecar( ) ) ) ,
1422+ RpcResponse :: Success ( RpcSuccessResponse :: BlobsByRange ( empty_blob_sidecar(
1423+ & chain_spec
1424+ ) ) ) ,
13871425 ForkName :: Deneb ,
13881426 & chain_spec
13891427 ) ,
1390- Ok ( Some ( RpcSuccessResponse :: BlobsByRange ( empty_blob_sidecar( ) ) ) ) ,
1428+ Ok ( Some ( RpcSuccessResponse :: BlobsByRange ( empty_blob_sidecar(
1429+ & chain_spec
1430+ ) ) ) ) ,
13911431 ) ;
13921432
13931433 assert_eq ! (
13941434 encode_then_decode_response(
13951435 SupportedProtocol :: BlobsByRangeV1 ,
1396- RpcResponse :: Success ( RpcSuccessResponse :: BlobsByRange ( empty_blob_sidecar( ) ) ) ,
1436+ RpcResponse :: Success ( RpcSuccessResponse :: BlobsByRange ( empty_blob_sidecar(
1437+ & chain_spec
1438+ ) ) ) ,
13971439 ForkName :: Electra ,
13981440 & chain_spec
13991441 ) ,
1400- Ok ( Some ( RpcSuccessResponse :: BlobsByRange ( empty_blob_sidecar( ) ) ) ) ,
1442+ Ok ( Some ( RpcSuccessResponse :: BlobsByRange ( empty_blob_sidecar(
1443+ & chain_spec
1444+ ) ) ) ) ,
14011445 ) ;
14021446
14031447 assert_eq ! (
14041448 encode_then_decode_response(
14051449 SupportedProtocol :: BlobsByRangeV1 ,
1406- RpcResponse :: Success ( RpcSuccessResponse :: BlobsByRange ( empty_blob_sidecar( ) ) ) ,
1450+ RpcResponse :: Success ( RpcSuccessResponse :: BlobsByRange ( empty_blob_sidecar(
1451+ & chain_spec
1452+ ) ) ) ,
14071453 ForkName :: Fulu ,
14081454 & chain_spec
14091455 ) ,
1410- Ok ( Some ( RpcSuccessResponse :: BlobsByRange ( empty_blob_sidecar( ) ) ) ) ,
1456+ Ok ( Some ( RpcSuccessResponse :: BlobsByRange ( empty_blob_sidecar(
1457+ & chain_spec
1458+ ) ) ) ) ,
14111459 ) ;
14121460
14131461 assert_eq ! (
14141462 encode_then_decode_response(
14151463 SupportedProtocol :: BlobsByRootV1 ,
1416- RpcResponse :: Success ( RpcSuccessResponse :: BlobsByRoot ( empty_blob_sidecar( ) ) ) ,
1464+ RpcResponse :: Success ( RpcSuccessResponse :: BlobsByRoot ( empty_blob_sidecar(
1465+ & chain_spec
1466+ ) ) ) ,
14171467 ForkName :: Deneb ,
14181468 & chain_spec
14191469 ) ,
1420- Ok ( Some ( RpcSuccessResponse :: BlobsByRoot ( empty_blob_sidecar( ) ) ) ) ,
1470+ Ok ( Some ( RpcSuccessResponse :: BlobsByRoot ( empty_blob_sidecar(
1471+ & chain_spec
1472+ ) ) ) ) ,
14211473 ) ;
14221474
14231475 assert_eq ! (
14241476 encode_then_decode_response(
14251477 SupportedProtocol :: BlobsByRootV1 ,
1426- RpcResponse :: Success ( RpcSuccessResponse :: BlobsByRoot ( empty_blob_sidecar( ) ) ) ,
1478+ RpcResponse :: Success ( RpcSuccessResponse :: BlobsByRoot ( empty_blob_sidecar(
1479+ & chain_spec
1480+ ) ) ) ,
14271481 ForkName :: Electra ,
14281482 & chain_spec
14291483 ) ,
1430- Ok ( Some ( RpcSuccessResponse :: BlobsByRoot ( empty_blob_sidecar( ) ) ) ) ,
1484+ Ok ( Some ( RpcSuccessResponse :: BlobsByRoot ( empty_blob_sidecar(
1485+ & chain_spec
1486+ ) ) ) ) ,
14311487 ) ;
14321488
14331489 assert_eq ! (
14341490 encode_then_decode_response(
14351491 SupportedProtocol :: BlobsByRootV1 ,
1436- RpcResponse :: Success ( RpcSuccessResponse :: BlobsByRoot ( empty_blob_sidecar( ) ) ) ,
1492+ RpcResponse :: Success ( RpcSuccessResponse :: BlobsByRoot ( empty_blob_sidecar(
1493+ & chain_spec
1494+ ) ) ) ,
14371495 ForkName :: Fulu ,
14381496 & chain_spec
14391497 ) ,
1440- Ok ( Some ( RpcSuccessResponse :: BlobsByRoot ( empty_blob_sidecar( ) ) ) ) ,
1498+ Ok ( Some ( RpcSuccessResponse :: BlobsByRoot ( empty_blob_sidecar(
1499+ & chain_spec
1500+ ) ) ) ) ,
14411501 ) ;
14421502
14431503 assert_eq ! (
14441504 encode_then_decode_response(
14451505 SupportedProtocol :: DataColumnsByRangeV1 ,
14461506 RpcResponse :: Success ( RpcSuccessResponse :: DataColumnsByRange (
1447- empty_data_column_sidecar( )
1507+ empty_data_column_sidecar( & chain_spec )
14481508 ) ) ,
14491509 ForkName :: Deneb ,
14501510 & chain_spec
14511511 ) ,
14521512 Ok ( Some ( RpcSuccessResponse :: DataColumnsByRange (
1453- empty_data_column_sidecar( )
1513+ empty_data_column_sidecar( & chain_spec )
14541514 ) ) ) ,
14551515 ) ;
14561516
14571517 assert_eq ! (
14581518 encode_then_decode_response(
14591519 SupportedProtocol :: DataColumnsByRangeV1 ,
14601520 RpcResponse :: Success ( RpcSuccessResponse :: DataColumnsByRange (
1461- empty_data_column_sidecar( )
1521+ empty_data_column_sidecar( & chain_spec )
14621522 ) ) ,
14631523 ForkName :: Electra ,
14641524 & chain_spec
14651525 ) ,
14661526 Ok ( Some ( RpcSuccessResponse :: DataColumnsByRange (
1467- empty_data_column_sidecar( )
1527+ empty_data_column_sidecar( & chain_spec )
14681528 ) ) ) ,
14691529 ) ;
14701530
14711531 assert_eq ! (
14721532 encode_then_decode_response(
14731533 SupportedProtocol :: DataColumnsByRangeV1 ,
14741534 RpcResponse :: Success ( RpcSuccessResponse :: DataColumnsByRange (
1475- empty_data_column_sidecar( )
1535+ empty_data_column_sidecar( & chain_spec )
14761536 ) ) ,
14771537 ForkName :: Fulu ,
14781538 & chain_spec
14791539 ) ,
14801540 Ok ( Some ( RpcSuccessResponse :: DataColumnsByRange (
1481- empty_data_column_sidecar( )
1541+ empty_data_column_sidecar( & chain_spec )
14821542 ) ) ) ,
14831543 ) ;
14841544
14851545 assert_eq ! (
14861546 encode_then_decode_response(
14871547 SupportedProtocol :: DataColumnsByRootV1 ,
14881548 RpcResponse :: Success ( RpcSuccessResponse :: DataColumnsByRoot (
1489- empty_data_column_sidecar( )
1549+ empty_data_column_sidecar( & chain_spec )
14901550 ) ) ,
14911551 ForkName :: Deneb ,
14921552 & chain_spec
14931553 ) ,
14941554 Ok ( Some ( RpcSuccessResponse :: DataColumnsByRoot (
1495- empty_data_column_sidecar( )
1555+ empty_data_column_sidecar( & chain_spec )
14961556 ) ) ) ,
14971557 ) ;
14981558
14991559 assert_eq ! (
15001560 encode_then_decode_response(
15011561 SupportedProtocol :: DataColumnsByRootV1 ,
15021562 RpcResponse :: Success ( RpcSuccessResponse :: DataColumnsByRoot (
1503- empty_data_column_sidecar( )
1563+ empty_data_column_sidecar( & chain_spec )
15041564 ) ) ,
15051565 ForkName :: Electra ,
15061566 & chain_spec
15071567 ) ,
15081568 Ok ( Some ( RpcSuccessResponse :: DataColumnsByRoot (
1509- empty_data_column_sidecar( )
1569+ empty_data_column_sidecar( & chain_spec )
15101570 ) ) ) ,
15111571 ) ;
15121572
15131573 assert_eq ! (
15141574 encode_then_decode_response(
15151575 SupportedProtocol :: DataColumnsByRootV1 ,
15161576 RpcResponse :: Success ( RpcSuccessResponse :: DataColumnsByRoot (
1517- empty_data_column_sidecar( )
1577+ empty_data_column_sidecar( & chain_spec )
15181578 ) ) ,
15191579 ForkName :: Fulu ,
15201580 & chain_spec
15211581 ) ,
15221582 Ok ( Some ( RpcSuccessResponse :: DataColumnsByRoot (
1523- empty_data_column_sidecar( )
1583+ empty_data_column_sidecar( & chain_spec )
15241584 ) ) ) ,
15251585 ) ;
15261586 }
15271587
15281588 // Test RPCResponse encoding/decoding for V1 messages
15291589 #[ test]
15301590 fn test_encode_then_decode_v2 ( ) {
1531- let chain_spec = Spec :: default_spec ( ) ;
1591+ let mut chain_spec = Spec :: default_spec ( ) ;
1592+ // Set a fulu fork epoch so we can encode / decode data columns
1593+ chain_spec. fulu_fork_epoch = Some ( Epoch :: new ( 1401280 ) ) ;
15321594
15331595 assert_eq ! (
15341596 encode_then_decode_response(
@@ -1564,12 +1626,14 @@ mod tests {
15641626 assert_eq ! (
15651627 encode_then_decode_response(
15661628 SupportedProtocol :: BlocksByRangeV2 ,
1567- RpcResponse :: Success ( RpcSuccessResponse :: BlocksByRange ( Arc :: new( altair_block( ) ) ) ) ,
1629+ RpcResponse :: Success ( RpcSuccessResponse :: BlocksByRange ( Arc :: new( altair_block(
1630+ & chain_spec
1631+ ) ) ) ) ,
15681632 ForkName :: Altair ,
15691633 & chain_spec,
15701634 ) ,
15711635 Ok ( Some ( RpcSuccessResponse :: BlocksByRange ( Arc :: new(
1572- altair_block( )
1636+ altair_block( & chain_spec )
15731637 ) ) ) )
15741638 ) ;
15751639
@@ -1642,12 +1706,14 @@ mod tests {
16421706 assert_eq ! (
16431707 encode_then_decode_response(
16441708 SupportedProtocol :: BlocksByRootV2 ,
1645- RpcResponse :: Success ( RpcSuccessResponse :: BlocksByRoot ( Arc :: new( altair_block( ) ) ) ) ,
1709+ RpcResponse :: Success ( RpcSuccessResponse :: BlocksByRoot ( Arc :: new( altair_block(
1710+ & chain_spec
1711+ ) ) ) ) ,
16461712 ForkName :: Altair ,
16471713 & chain_spec,
16481714 ) ,
16491715 Ok ( Some ( RpcSuccessResponse :: BlocksByRoot ( Arc :: new(
1650- altair_block( )
1716+ altair_block( & chain_spec )
16511717 ) ) ) )
16521718 ) ;
16531719
@@ -1810,7 +1876,9 @@ mod tests {
18101876 // Trying to decode an altair block with base context bytes should give ssz decoding error
18111877 let mut encoded_bytes = encode_response (
18121878 SupportedProtocol :: BlocksByRootV2 ,
1813- RpcResponse :: Success ( RpcSuccessResponse :: BlocksByRoot ( Arc :: new ( altair_block ( ) ) ) ) ,
1879+ RpcResponse :: Success ( RpcSuccessResponse :: BlocksByRoot ( Arc :: new ( altair_block (
1880+ & chain_spec,
1881+ ) ) ) ) ,
18141882 ForkName :: Altair ,
18151883 & chain_spec,
18161884 )
@@ -2024,7 +2092,7 @@ mod tests {
20242092 let malicious_padding: & ' static [ u8 ] = b"\xFE \x00 \x00 \x00 " ;
20252093
20262094 // Full altair block is 157916 bytes uncompressed. `max_compressed_len` is 32 + 157916 + 157916/6 = 184267.
2027- let block_message_bytes = altair_block ( ) . as_ssz_bytes ( ) ;
2095+ let block_message_bytes = altair_block ( & fork_context . spec ) . as_ssz_bytes ( ) ;
20282096
20292097 assert_eq ! ( block_message_bytes. len( ) , 157916 ) ;
20302098 assert_eq ! (
0 commit comments