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 1a6045e7528..9787ca0e500 100644 --- a/beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs +++ b/beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs @@ -17,9 +17,9 @@ use std::sync::Arc; use tokio_util::codec::{Decoder, Encoder}; use types::{light_client_bootstrap::LightClientBootstrap, BlobSidecar, ChainSpec}; use types::{ - EthSpec, ForkContext, ForkName, Hash256, RuntimeVariableList, SignedBeaconBlock, SignedBeaconBlockAltair, - SignedBeaconBlockBase, SignedBeaconBlockCapella, SignedBeaconBlockDeneb, - SignedBeaconBlockMerge, + EthSpec, ForkContext, ForkName, Hash256, RuntimeVariableList, SignedBeaconBlock, + SignedBeaconBlockAltair, SignedBeaconBlockBase, SignedBeaconBlockCapella, + SignedBeaconBlockDeneb, SignedBeaconBlockMerge, }; use unsigned_varint::codec::Uvi; @@ -163,7 +163,11 @@ impl Decoder for SSZSnappyInboundCodec { let n = reader.get_ref().get_ref().position(); self.len = None; let _read_bytes = src.split_to(n as usize); - handle_rpc_request(self.protocol.versioned_protocol, &decoded_buffer, &self.fork_context) + handle_rpc_request( + self.protocol.versioned_protocol, + &decoded_buffer, + &self.fork_context, + ) } Err(e) => handle_error(e, reader.get_ref().get_ref().position(), max_compressed_len), } @@ -455,7 +459,7 @@ fn handle_length( fn handle_rpc_request( versioned_protocol: SupportedProtocol, decoded_buffer: &[u8], - fork_context: &ForkContext + fork_context: &ForkContext, ) -> Result>, RPCError> { match versioned_protocol { SupportedProtocol::StatusV1 => Ok(Some(InboundRequest::Status( diff --git a/beacon_node/lighthouse_network/src/rpc/methods.rs b/beacon_node/lighthouse_network/src/rpc/methods.rs index e8ffe7f8564..747e588285c 100644 --- a/beacon_node/lighthouse_network/src/rpc/methods.rs +++ b/beacon_node/lighthouse_network/src/rpc/methods.rs @@ -18,13 +18,9 @@ use types::blob_sidecar::BlobIdentifier; use types::consts::deneb::MAX_BLOBS_PER_BLOCK; use types::{ blob_sidecar::BlobSidecar, light_client_bootstrap::LightClientBootstrap, Epoch, EthSpec, - Hash256, SignedBeaconBlock, Slot, RuntimeVariableList + Hash256, RuntimeVariableList, SignedBeaconBlock, Slot, }; -/// Maximum number of blocks in a single request. -pub type MaxRequestBlocks = U1024; -pub const MAX_REQUEST_BLOCKS: u64 = 1024; - /// Maximum length of error message. pub type MaxErrorLen = U256; pub const MAX_ERROR_LEN: u64 = 256; @@ -343,12 +339,8 @@ impl OldBlocksByRangeRequest { } } - /// Request a number of beacon block bodies from a peer. -#[superstruct( - variants(V1, V2), - variant_attributes(derive(Clone, Debug, PartialEq)) -)] +#[superstruct(variants(V1, V2), variant_attributes(derive(Clone, Debug, PartialEq)))] #[derive(Clone, Debug, PartialEq)] pub struct BlocksByRootRequest { /// The list of beacon block bodies being requested. diff --git a/beacon_node/network/src/network_beacon_processor/rpc_methods.rs b/beacon_node/network/src/network_beacon_processor/rpc_methods.rs index bc35c059c84..7d7c2d4c18b 100644 --- a/beacon_node/network/src/network_beacon_processor/rpc_methods.rs +++ b/beacon_node/network/src/network_beacon_processor/rpc_methods.rs @@ -376,14 +376,15 @@ impl NetworkBeaconProcessor { ); // Should not send more than max request blocks - let max_request_size = self.chain.epoch().map_or(MAX_REQUEST_BLOCKS, |epoch| { - match self.chain.spec.fork_name_at_epoch(epoch) { - ForkName::Deneb => MAX_REQUEST_BLOCKS_DENEB, - ForkName::Base | ForkName::Altair | ForkName::Merge | ForkName::Capella => { - MAX_REQUEST_BLOCKS + let max_request_size = + self.chain.epoch().map_or(self.chain.spec.max_blo, |epoch| { + match self.chain.spec.fork_name_at_epoch(epoch) { + ForkName::Deneb => MAX_REQUEST_BLOCKS_DENEB, + ForkName::Base | ForkName::Altair | ForkName::Merge | ForkName::Capella => { + MAX_REQUEST_BLOCKS + } } - } - }); + }); if *req.count() > max_request_size { return self.send_error_response( peer_id, diff --git a/beacon_node/network/src/sync/block_lookups/common.rs b/beacon_node/network/src/sync/block_lookups/common.rs index b238192f137..2cac7e7f44a 100644 --- a/beacon_node/network/src/sync/block_lookups/common.rs +++ b/beacon_node/network/src/sync/block_lookups/common.rs @@ -20,7 +20,7 @@ use std::ops::IndexMut; use std::sync::Arc; use std::time::Duration; use types::blob_sidecar::{BlobIdentifier, FixedBlobSidecarList}; -use types::{BlobSidecar, ChainSpec, EthSpec, Hash256, RuntimeVariableList ,SignedBeaconBlock}; +use types::{BlobSidecar, ChainSpec, EthSpec, Hash256, RuntimeVariableList, SignedBeaconBlock}; #[derive(Debug, Copy, Clone)] pub enum ResponseType { @@ -89,7 +89,10 @@ pub trait RequestState { /* Request building methods */ /// Construct a new request. - fn build_request(&mut self, spec: &ChainSpec) -> Result<(PeerShouldHave, Self::RequestType), LookupRequestError> { + fn build_request( + &mut self, + spec: &ChainSpec, + ) -> Result<(PeerShouldHave, Self::RequestType), LookupRequestError> { // Verify and construct request. self.too_many_attempts()?; let peer = self.get_peer()?; @@ -273,10 +276,10 @@ impl RequestState for BlockRequestState type ReconstructedResponseType = RpcBlock; fn new_request(&self, spec: &ChainSpec) -> Result { - Ok(BlocksByRootRequest::new(RuntimeVariableList::new(vec![self.requested_block_root], 1) - .map_err(|_e|{ - LookupRequestError::SszError("invalid request length") - })?)) + Ok(BlocksByRootRequest::new( + RuntimeVariableList::new(vec![self.requested_block_root], 1) + .map_err(|_e| LookupRequestError::SszError("invalid request length"))?, + )) } fn make_request( diff --git a/beacon_node/network/src/sync/block_lookups/parent_lookup.rs b/beacon_node/network/src/sync/block_lookups/parent_lookup.rs index 1baae1c20f3..4b36088e5e9 100644 --- a/beacon_node/network/src/sync/block_lookups/parent_lookup.rs +++ b/beacon_node/network/src/sync/block_lookups/parent_lookup.rs @@ -55,7 +55,7 @@ pub enum RequestError { cannot_process: bool, }, NoPeers, - SszError(&'static str) + SszError(&'static str), } impl ParentLookup { diff --git a/consensus/types/src/chain_spec.rs b/consensus/types/src/chain_spec.rs index 680db57c227..9a5dc117335 100644 --- a/consensus/types/src/chain_spec.rs +++ b/consensus/types/src/chain_spec.rs @@ -177,19 +177,28 @@ pub struct ChainSpec { pub attestation_propagation_slot_range: u64, pub maximum_gossip_clock_disparity_millis: u64, pub target_aggregators_per_committee: u64, - pub attestation_subnet_count: u64, - pub subnets_per_node: u8, - pub epochs_per_subnet_subscription: u64, pub gossip_max_size: u64, + pub max_request_blocks: u64, + pub epochs_per_subnet_subscription: u64, pub min_epochs_for_block_requests: u64, pub max_chunk_size: u64, pub ttfb_timeout: u64, pub resp_timeout: u64, pub message_domain_invalid_snappy: [u8; 4], pub message_domain_valid_snappy: [u8; 4], + pub subnets_per_node: u8, + pub attestation_subnet_count: u64, pub attestation_subnet_extra_bits: u8, pub attestation_subnet_prefix_bits: u8, + /* + * Networking Deneb + */ + pub max_request_blocks_deneb: u64, + pub max_request_blob_sidecars: u64, + pub min_epochs_for_blob_sidecars_requests: u64, + pub blob_sidecar_subnet_count: u64, + /* * Application params */ @@ -667,6 +676,16 @@ impl ChainSpec { message_domain_valid_snappy: default_message_domain_valid_snappy(), attestation_subnet_extra_bits: default_attestation_subnet_extra_bits(), attestation_subnet_prefix_bits: default_attestation_subnet_prefix_bits(), + max_request_blocks: default_max_request_blocks(), + + /* + * Networking Deneb Specific + */ + max_request_blocks_deneb: default_max_request_blocks_deneb(), + max_request_blob_sidecars: default_max_request_blob_sidecars(), + min_epochs_for_blob_sidecars_requests: default_min_epochs_for_blob_sidecars_requests(), + blob_sidecar_subnet_count: default_blob_sidecar_subnet_count(), + /* * Application specific */ @@ -912,6 +931,15 @@ impl ChainSpec { message_domain_valid_snappy: default_message_domain_valid_snappy(), attestation_subnet_extra_bits: default_attestation_subnet_extra_bits(), attestation_subnet_prefix_bits: default_attestation_subnet_prefix_bits(), + max_request_blocks: default_max_request_blocks(), + + /* + * Networking Deneb Specific + */ + max_request_blocks_deneb: default_max_request_blocks_deneb(), + max_request_blob_sidecars: default_max_request_blob_sidecars(), + min_epochs_for_blob_sidecars_requests: default_min_epochs_for_blob_sidecars_requests(), + blob_sidecar_subnet_count: default_blob_sidecar_subnet_count(), /* * Application specific @@ -1142,6 +1170,26 @@ const fn default_attestation_subnet_prefix_bits() -> u8 { 6 } +const fn default_max_request_blocks() -> u64 { + 1024 +} + +const fn default_max_request_blocks_deneb() -> u64 { + 128 +} + +const fn default_max_request_blob_sidecars() -> u64 { + 768 +} + +const fn default_min_epochs_for_blob_sidecars_requests() -> u64 { + 4096 +} + +const fn default_blob_sidecar_subnet_count() -> u64 { + 6 +} + impl Default for Config { fn default() -> Self { let chain_spec = MainnetEthSpec::default_spec(); diff --git a/consensus/types/src/lib.rs b/consensus/types/src/lib.rs index a7b5ba77876..59a690d4115 100644 --- a/consensus/types/src/lib.rs +++ b/consensus/types/src/lib.rs @@ -99,9 +99,9 @@ pub mod slot_data; pub mod sqlite; pub mod blob_sidecar; +pub mod runtime_var_list; pub mod sidecar; pub mod signed_blob; -pub mod runtime_var_list; use ethereum_types::{H160, H256}; diff --git a/consensus/types/src/runtime_var_list.rs b/consensus/types/src/runtime_var_list.rs index 87d0fc20be4..dcf24084cd3 100644 --- a/consensus/types/src/runtime_var_list.rs +++ b/consensus/types/src/runtime_var_list.rs @@ -21,7 +21,7 @@ impl RuntimeVariableList { } } - pub fn to_vec(&self)-> Vec { + pub fn to_vec(&self) -> Vec { self.vec.clone() } @@ -37,4 +37,4 @@ impl RuntimeVariableList { }; Ok(Self { vec, max_len }) } -} \ No newline at end of file +}