@@ -17,7 +17,7 @@ use std::sync::Arc;
1717use tokio_util:: codec:: { Decoder , Encoder } ;
1818use types:: {
1919 EthSpec , ForkContext , ForkName , SignedBeaconBlock , SignedBeaconBlockAltair ,
20- SignedBeaconBlockBase , SignedBeaconBlockMerge ,
20+ SignedBeaconBlockBase , SignedBeaconBlockCapella , SignedBeaconBlockMerge ,
2121} ;
2222use unsigned_varint:: codec:: Uvi ;
2323
@@ -407,6 +407,10 @@ fn context_bytes<T: EthSpec>(
407407 return match * * ref_box_block {
408408 // NOTE: If you are adding another fork type here, be sure to modify the
409409 // `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+ }
410414 SignedBeaconBlock :: Merge { .. } => {
411415 // Merge context being `None` implies that "merge never happened".
412416 fork_context. to_context_bytes ( ForkName :: Merge )
@@ -441,7 +445,7 @@ fn handle_length(
441445 // Note: length-prefix of > 10 bytes(uint64) would be a decoding error
442446 match uvi_codec. decode ( bytes) . map_err ( RPCError :: from) ? {
443447 Some ( length) => {
444- * len = Some ( length as usize ) ;
448+ * len = Some ( length) ;
445449 Ok ( Some ( length) )
446450 }
447451 None => Ok ( None ) , // need more bytes to decode length
@@ -586,6 +590,11 @@ fn handle_v2_response<T: EthSpec>(
586590 decoded_buffer,
587591 ) ?) ,
588592 ) ) ) ) ,
593+ ForkName :: Capella => Ok ( Some ( RPCResponse :: BlocksByRange ( Arc :: new (
594+ SignedBeaconBlock :: Capella ( SignedBeaconBlockCapella :: from_ssz_bytes (
595+ decoded_buffer,
596+ ) ?) ,
597+ ) ) ) ) ,
589598 } ,
590599 Protocol :: BlocksByRoot => match fork_name {
591600 ForkName :: Altair => Ok ( Some ( RPCResponse :: BlocksByRoot ( Arc :: new (
@@ -601,6 +610,11 @@ fn handle_v2_response<T: EthSpec>(
601610 decoded_buffer,
602611 ) ?) ,
603612 ) ) ) ) ,
613+ ForkName :: Capella => Ok ( Some ( RPCResponse :: BlocksByRoot ( Arc :: new (
614+ SignedBeaconBlock :: Capella ( SignedBeaconBlockCapella :: from_ssz_bytes (
615+ decoded_buffer,
616+ ) ?) ,
617+ ) ) ) ) ,
604618 } ,
605619 _ => Err ( RPCError :: ErrorResponse (
606620 RPCResponseErrorCode :: InvalidRequest ,
@@ -625,9 +639,9 @@ fn context_bytes_to_fork_name(
625639 )
626640 } )
627641}
642+
628643#[ cfg( test) ]
629644mod tests {
630-
631645 use super :: * ;
632646 use crate :: rpc:: { protocol:: * , MetaData } ;
633647 use crate :: {
@@ -636,8 +650,8 @@ mod tests {
636650 } ;
637651 use std:: sync:: Arc ;
638652 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 ,
641655 } ;
642656
643657 use snap:: write:: FrameEncoder ;
@@ -650,14 +664,17 @@ mod tests {
650664 let mut chain_spec = Spec :: default_spec ( ) ;
651665 let altair_fork_epoch = Epoch :: new ( 1 ) ;
652666 let merge_fork_epoch = Epoch :: new ( 2 ) ;
667+ let capella_fork_epoch = Epoch :: new ( 3 ) ;
653668
654669 chain_spec. altair_fork_epoch = Some ( altair_fork_epoch) ;
655670 chain_spec. bellatrix_fork_epoch = Some ( merge_fork_epoch) ;
671+ chain_spec. capella_fork_epoch = Some ( capella_fork_epoch) ;
656672
657673 let current_slot = match fork_name {
658674 ForkName :: Base => Slot :: new ( 0 ) ,
659675 ForkName :: Altair => altair_fork_epoch. start_slot ( Spec :: slots_per_epoch ( ) ) ,
660676 ForkName :: Merge => merge_fork_epoch. start_slot ( Spec :: slots_per_epoch ( ) ) ,
677+ ForkName :: Capella => capella_fork_epoch. start_slot ( Spec :: slots_per_epoch ( ) ) ,
661678 } ;
662679 ForkContext :: new :: < Spec > ( current_slot, Hash256 :: zero ( ) , & chain_spec)
663680 }
0 commit comments