@@ -17,7 +17,7 @@ use std::sync::Arc;
17
17
use tokio_util:: codec:: { Decoder , Encoder } ;
18
18
use types:: {
19
19
EthSpec , ForkContext , ForkName , SignedBeaconBlock , SignedBeaconBlockAltair ,
20
- SignedBeaconBlockBase , SignedBeaconBlockMerge ,
20
+ SignedBeaconBlockBase , SignedBeaconBlockCapella , SignedBeaconBlockMerge ,
21
21
} ;
22
22
use unsigned_varint:: codec:: Uvi ;
23
23
@@ -407,6 +407,10 @@ fn context_bytes<T: EthSpec>(
407
407
return match * * ref_box_block {
408
408
// NOTE: If you are adding another fork type here, be sure to modify the
409
409
// `fork_context.to_context_bytes()` function to support it as well!
410
+ SignedBeaconBlock :: Capella { .. } => {
411
+ // Capella context being `None` implies that "merge never happened".
412
+ fork_context. to_context_bytes ( ForkName :: Capella )
413
+ }
410
414
SignedBeaconBlock :: Merge { .. } => {
411
415
// Merge context being `None` implies that "merge never happened".
412
416
fork_context. to_context_bytes ( ForkName :: Merge )
@@ -441,7 +445,7 @@ fn handle_length(
441
445
// Note: length-prefix of > 10 bytes(uint64) would be a decoding error
442
446
match uvi_codec. decode ( bytes) . map_err ( RPCError :: from) ? {
443
447
Some ( length) => {
444
- * len = Some ( length as usize ) ;
448
+ * len = Some ( length) ;
445
449
Ok ( Some ( length) )
446
450
}
447
451
None => Ok ( None ) , // need more bytes to decode length
@@ -586,6 +590,11 @@ fn handle_v2_response<T: EthSpec>(
586
590
decoded_buffer,
587
591
) ?) ,
588
592
) ) ) ) ,
593
+ ForkName :: Capella => Ok ( Some ( RPCResponse :: BlocksByRange ( Arc :: new (
594
+ SignedBeaconBlock :: Capella ( SignedBeaconBlockCapella :: from_ssz_bytes (
595
+ decoded_buffer,
596
+ ) ?) ,
597
+ ) ) ) ) ,
589
598
} ,
590
599
Protocol :: BlocksByRoot => match fork_name {
591
600
ForkName :: Altair => Ok ( Some ( RPCResponse :: BlocksByRoot ( Arc :: new (
@@ -601,6 +610,11 @@ fn handle_v2_response<T: EthSpec>(
601
610
decoded_buffer,
602
611
) ?) ,
603
612
) ) ) ) ,
613
+ ForkName :: Capella => Ok ( Some ( RPCResponse :: BlocksByRoot ( Arc :: new (
614
+ SignedBeaconBlock :: Capella ( SignedBeaconBlockCapella :: from_ssz_bytes (
615
+ decoded_buffer,
616
+ ) ?) ,
617
+ ) ) ) ) ,
604
618
} ,
605
619
_ => Err ( RPCError :: ErrorResponse (
606
620
RPCResponseErrorCode :: InvalidRequest ,
@@ -625,9 +639,9 @@ fn context_bytes_to_fork_name(
625
639
)
626
640
} )
627
641
}
642
+
628
643
#[ cfg( test) ]
629
644
mod tests {
630
-
631
645
use super :: * ;
632
646
use crate :: rpc:: { protocol:: * , MetaData } ;
633
647
use crate :: {
@@ -636,8 +650,8 @@ mod tests {
636
650
} ;
637
651
use std:: sync:: Arc ;
638
652
use types:: {
639
- BeaconBlock , BeaconBlockAltair , BeaconBlockBase , BeaconBlockMerge , Epoch , ForkContext ,
640
- FullPayload , Hash256 , Signature , SignedBeaconBlock , Slot ,
653
+ BeaconBlock , BeaconBlockAltair , BeaconBlockBase , BeaconBlockMerge , EmptyBlock , Epoch ,
654
+ ForkContext , FullPayload , Hash256 , Signature , SignedBeaconBlock , Slot ,
641
655
} ;
642
656
643
657
use snap:: write:: FrameEncoder ;
@@ -650,14 +664,17 @@ mod tests {
650
664
let mut chain_spec = Spec :: default_spec ( ) ;
651
665
let altair_fork_epoch = Epoch :: new ( 1 ) ;
652
666
let merge_fork_epoch = Epoch :: new ( 2 ) ;
667
+ let capella_fork_epoch = Epoch :: new ( 3 ) ;
653
668
654
669
chain_spec. altair_fork_epoch = Some ( altair_fork_epoch) ;
655
670
chain_spec. bellatrix_fork_epoch = Some ( merge_fork_epoch) ;
671
+ chain_spec. capella_fork_epoch = Some ( capella_fork_epoch) ;
656
672
657
673
let current_slot = match fork_name {
658
674
ForkName :: Base => Slot :: new ( 0 ) ,
659
675
ForkName :: Altair => altair_fork_epoch. start_slot ( Spec :: slots_per_epoch ( ) ) ,
660
676
ForkName :: Merge => merge_fork_epoch. start_slot ( Spec :: slots_per_epoch ( ) ) ,
677
+ ForkName :: Capella => capella_fork_epoch. start_slot ( Spec :: slots_per_epoch ( ) ) ,
661
678
} ;
662
679
ForkContext :: new :: < Spec > ( current_slot, Hash256 :: zero ( ) , & chain_spec)
663
680
}
0 commit comments