Skip to content

Commit

Permalink
add configs to ChainSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
realbigsean committed Oct 12, 2023
1 parent d0fe2ce commit ac5eb9a
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 35 deletions.
14 changes: 9 additions & 5 deletions beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -163,7 +163,11 @@ impl<TSpec: EthSpec> Decoder for SSZSnappyInboundCodec<TSpec> {
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),
}
Expand Down Expand Up @@ -455,7 +459,7 @@ fn handle_length(
fn handle_rpc_request<T: EthSpec>(
versioned_protocol: SupportedProtocol,
decoded_buffer: &[u8],
fork_context: &ForkContext
fork_context: &ForkContext,
) -> Result<Option<InboundRequest<T>>, RPCError> {
match versioned_protocol {
SupportedProtocol::StatusV1 => Ok(Some(InboundRequest::Status(
Expand Down
12 changes: 2 additions & 10 deletions beacon_node/lighthouse_network/src/rpc/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 8 additions & 7 deletions beacon_node/network/src/network_beacon_processor/rpc_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,15 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
);

// 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,
Expand Down
15 changes: 9 additions & 6 deletions beacon_node/network/src/sync/block_lookups/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -89,7 +89,10 @@ pub trait RequestState<L: Lookup, T: BeaconChainTypes> {
/* 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()?;
Expand Down Expand Up @@ -273,10 +276,10 @@ impl<L: Lookup, T: BeaconChainTypes> RequestState<L, T> for BlockRequestState<L>
type ReconstructedResponseType = RpcBlock<T::EthSpec>;

fn new_request(&self, spec: &ChainSpec) -> Result<BlocksByRootRequest, LookupRequestError> {
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub enum RequestError {
cannot_process: bool,
},
NoPeers,
SszError(&'static str)
SszError(&'static str),
}

impl<T: BeaconChainTypes> ParentLookup<T> {
Expand Down
54 changes: 51 additions & 3 deletions consensus/types/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
4 changes: 2 additions & 2 deletions consensus/types/src/runtime_var_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<T: Encode + Decode + Clone> RuntimeVariableList<T> {
}
}

pub fn to_vec(&self)-> Vec<T> {
pub fn to_vec(&self) -> Vec<T> {
self.vec.clone()
}

Expand All @@ -37,4 +37,4 @@ impl<T: Encode + Decode + Clone> RuntimeVariableList<T> {
};
Ok(Self { vec, max_len })
}
}
}

0 comments on commit ac5eb9a

Please sign in to comment.