diff --git a/beacon_node/lighthouse_network/src/rpc/codec/base.rs b/beacon_node/lighthouse_network/src/rpc/codec/base.rs index fc5393c347f..4085ac17b73 100644 --- a/beacon_node/lighthouse_network/src/rpc/codec/base.rs +++ b/beacon_node/lighthouse_network/src/rpc/codec/base.rs @@ -316,7 +316,7 @@ mod tests { )); // Request limits - let limit = protocol_id.rpc_request_limits(&fork_context); + let limit = protocol_id.rpc_request_limits(&fork_context.spec); let mut max = encode_len(limit.max + 1); let mut codec = SSZSnappyOutboundCodec::::new( protocol_id.clone(), diff --git a/beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs b/beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs index fd40d2bb44e..5a58c4cad4c 100644 --- a/beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs +++ b/beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs @@ -15,7 +15,7 @@ use std::io::{Read, Write}; use std::marker::PhantomData; use std::sync::Arc; use tokio_util::codec::{Decoder, Encoder}; -use types::{light_client_bootstrap::LightClientBootstrap, BlobSidecar}; +use types::{light_client_bootstrap::LightClientBootstrap, BlobSidecar, ChainSpec}; use types::{ EthSpec, ForkContext, ForkName, Hash256, RuntimeVariableList, SignedBeaconBlock, SignedBeaconBlockAltair, SignedBeaconBlockBase, SignedBeaconBlockCapella, @@ -142,7 +142,7 @@ impl Decoder for SSZSnappyInboundCodec { // Should not attempt to decode rpc chunks with `length > max_packet_size` or not within bounds of // packet size for ssz container corresponding to `self.protocol`. - let ssz_limits = self.protocol.rpc_request_limits(&self.fork_context); + let ssz_limits = self.protocol.rpc_request_limits(&self.fork_context.spec); if ssz_limits.is_out_of_bounds(length, self.max_packet_size) { return Err(RPCError::InvalidData(format!( "RPC request length for protocol {:?} is out of bounds, length {}", @@ -166,7 +166,7 @@ impl Decoder for SSZSnappyInboundCodec { handle_rpc_request( self.protocol.versioned_protocol, &decoded_buffer, - &self.fork_context, + &self.fork_context.spec, ) } Err(e) => handle_error(e, reader.get_ref().get_ref().position(), max_compressed_len), @@ -459,7 +459,7 @@ fn handle_length( fn handle_rpc_request( versioned_protocol: SupportedProtocol, decoded_buffer: &[u8], - fork_context: &ForkContext, + spec: &ChainSpec, ) -> Result>, RPCError> { match versioned_protocol { SupportedProtocol::StatusV1 => Ok(Some(InboundRequest::Status( @@ -478,7 +478,7 @@ fn handle_rpc_request( BlocksByRootRequest::V2(BlocksByRootRequestV2 { block_roots: RuntimeVariableList::from_ssz_bytes( decoded_buffer, - fork_context.max_request_blocks(), + spec.max_request_blocks as usize, )?, }), ))), @@ -486,7 +486,7 @@ fn handle_rpc_request( BlocksByRootRequest::V1(BlocksByRootRequestV1 { block_roots: RuntimeVariableList::from_ssz_bytes( decoded_buffer, - fork_context.max_request_blocks(), + spec.max_request_blocks as usize, )?, }), ))), @@ -497,7 +497,7 @@ fn handle_rpc_request( Ok(Some(InboundRequest::BlobsByRoot(BlobsByRootRequest { blob_ids: RuntimeVariableList::from_ssz_bytes( decoded_buffer, - fork_context.max_request_blob_sidecars(), + spec.max_request_blob_sidecars as usize, )?, }))) } diff --git a/beacon_node/lighthouse_network/src/rpc/methods.rs b/beacon_node/lighthouse_network/src/rpc/methods.rs index 9047fa4e370..a7bfc630e88 100644 --- a/beacon_node/lighthouse_network/src/rpc/methods.rs +++ b/beacon_node/lighthouse_network/src/rpc/methods.rs @@ -340,13 +340,13 @@ pub struct BlocksByRootRequest { impl BlocksByRootRequest { pub fn new(block_roots: Vec, spec: &ChainSpec) -> Self { let block_roots = - RuntimeVariableList::from_vec(block_roots, spec.max_request_blocks_deneb as usize); + RuntimeVariableList::from_vec(block_roots, spec.max_request_blocks as usize); Self::V2(BlocksByRootRequestV2 { block_roots }) } pub fn new_v1(block_roots: Vec, spec: &ChainSpec) -> Self { let block_roots = - RuntimeVariableList::from_vec(block_roots, spec.max_request_blocks_deneb as usize); + RuntimeVariableList::from_vec(block_roots, spec.max_request_blocks as usize); Self::V1(BlocksByRootRequestV1 { block_roots }) } } diff --git a/beacon_node/lighthouse_network/src/rpc/protocol.rs b/beacon_node/lighthouse_network/src/rpc/protocol.rs index 46652b363bf..fa10e231c05 100644 --- a/beacon_node/lighthouse_network/src/rpc/protocol.rs +++ b/beacon_node/lighthouse_network/src/rpc/protocol.rs @@ -21,7 +21,7 @@ use tokio_util::{ }; use types::{ BeaconBlock, BeaconBlockAltair, BeaconBlockBase, BeaconBlockCapella, BeaconBlockMerge, - BlobSidecar, EmptyBlock, EthSpec, ForkContext, ForkName, MainnetEthSpec, Signature, + BlobSidecar, ChainSpec, EmptyBlock, EthSpec, ForkContext, ForkName, MainnetEthSpec, Signature, SignedBeaconBlock, }; @@ -348,7 +348,7 @@ impl AsRef for ProtocolId { impl ProtocolId { /// Returns min and max size for messages of given protocol id requests. - pub fn rpc_request_limits(&self, fork_context: &ForkContext) -> RpcLimits { + pub fn rpc_request_limits(&self, spec: &ChainSpec) -> RpcLimits { match self.versioned_protocol.protocol() { Protocol::Status => RpcLimits::new( ::ssz_fixed_len(), @@ -364,16 +364,16 @@ impl ProtocolId { ::ssz_fixed_len(), ), Protocol::BlocksByRoot => RpcLimits::new( - fork_context.min_blocks_by_root_request(), - fork_context.max_blocks_by_root_request(), + spec.min_blocks_by_root_request, + spec.max_blocks_by_root_request, ), Protocol::BlobsByRange => RpcLimits::new( ::ssz_fixed_len(), ::ssz_fixed_len(), ), Protocol::BlobsByRoot => RpcLimits::new( - fork_context.min_blobs_by_root_request(), - fork_context.max_blobs_by_root_request(), + spec.min_blobs_by_root_request, + spec.max_blobs_by_root_request, ), Protocol::Ping => RpcLimits::new( ::ssz_fixed_len(), diff --git a/consensus/types/src/fork_context.rs b/consensus/types/src/fork_context.rs index 87e0dab9b23..9992892714c 100644 --- a/consensus/types/src/fork_context.rs +++ b/consensus/types/src/fork_context.rs @@ -117,37 +117,4 @@ impl ForkContext { pub fn all_fork_digests(&self) -> Vec<[u8; 4]> { self.digest_to_fork.keys().cloned().collect() } - - /// Returns the `min_blocks_by_root_request` corresponding to the current fork. - pub fn min_blocks_by_root_request(&self) -> usize { - let fork_name = self.current_fork(); - self.spec.min_blocks_by_root_request(fork_name) - } - - /// Returns the `max_blocks_by_root_request` corresponding to the current fork. - pub fn max_blocks_by_root_request(&self) -> usize { - let fork_name = self.current_fork(); - self.spec.max_blocks_by_root_request(fork_name) - } - - /// Returns the `max_request_blocks` corresponding to the current fork. - pub fn max_request_blocks(&self) -> usize { - let fork_name = self.current_fork(); - self.spec.max_request_blocks(fork_name) - } - - /// Returns the `min_blobs_by_root_request` set in `ChainSpec`. - pub fn min_blobs_by_root_request(&self) -> usize { - self.spec.min_blobs_by_root_request - } - - /// Returns the `max_blobs_by_root_request` set in `ChainSpec`. - pub fn max_blobs_by_root_request(&self) -> usize { - self.spec.max_blobs_by_root_request - } - - /// Returns the `max_request_blob_sidecars` set in `ChainSpec`. - pub fn max_request_blob_sidecars(&self) -> usize { - self.spec.max_request_blob_sidecars as usize - } }