mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Fulu update to spec v1.6.0-alpha.4 (#7890)
Fulu update to spec [v1.6.0-alpha.4](https://github.com/ethereum/consensus-specs/releases/tag/v1.6.0-alpha.4). - Make `number_of_columns` a preset - Optimise `get_custody_groups` to avoid computing if cgc = 128 - Add support for additional typenum values in type_dispatch macro
This commit is contained in:
@@ -35,7 +35,7 @@ where
|
||||
.is_ok_and(|b| b.get(*s.deref() as usize).unwrap_or(false)),
|
||||
Subnet::DataColumn(s) => {
|
||||
if let Ok(custody_group_count) = enr.custody_group_count::<E>(&spec) {
|
||||
compute_subnets_for_node(enr.node_id().raw(), custody_group_count, &spec)
|
||||
compute_subnets_for_node::<E>(enr.node_id().raw(), custody_group_count, &spec)
|
||||
.is_ok_and(|subnets| subnets.contains(s))
|
||||
} else {
|
||||
false
|
||||
|
||||
@@ -167,10 +167,12 @@ impl<E: EthSpec> PeerManager<E> {
|
||||
let subnets_by_custody_group = if network_globals.spec.is_peer_das_scheduled() {
|
||||
(0..network_globals.spec.number_of_custody_groups)
|
||||
.map(|custody_index| {
|
||||
let subnets =
|
||||
compute_subnets_from_custody_group(custody_index, &network_globals.spec)
|
||||
.expect("Should compute subnets for all custody groups")
|
||||
.collect();
|
||||
let subnets = compute_subnets_from_custody_group::<E>(
|
||||
custody_index,
|
||||
&network_globals.spec,
|
||||
)
|
||||
.expect("Should compute subnets for all custody groups")
|
||||
.collect();
|
||||
(custody_index, subnets)
|
||||
})
|
||||
.collect::<HashMap<_, Vec<DataColumnSubnetId>>>()
|
||||
|
||||
@@ -822,8 +822,9 @@ impl<E: EthSpec> PeerDB<E> {
|
||||
} else {
|
||||
let peer_info = self.peers.get_mut(&peer_id).expect("peer exists");
|
||||
let node_id = peer_id_to_node_id(&peer_id).expect("convert peer_id to node_id");
|
||||
let subnets = compute_subnets_for_node(node_id.raw(), spec.custody_requirement, spec)
|
||||
.expect("should compute custody subnets");
|
||||
let subnets =
|
||||
compute_subnets_for_node::<E>(node_id.raw(), spec.custody_requirement, spec)
|
||||
.expect("should compute custody subnets");
|
||||
peer_info.set_custody_subnets(subnets);
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,9 @@ impl<E: EthSpec> Decoder for SSZSnappyInboundCodec<E> {
|
||||
|
||||
// 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.spec);
|
||||
let ssz_limits = self
|
||||
.protocol
|
||||
.rpc_request_limits::<E>(&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 {}",
|
||||
@@ -560,10 +562,9 @@ fn handle_rpc_request<E: EthSpec>(
|
||||
SupportedProtocol::DataColumnsByRootV1 => Ok(Some(RequestType::DataColumnsByRoot(
|
||||
DataColumnsByRootRequest {
|
||||
data_column_ids:
|
||||
<RuntimeVariableList<DataColumnsByRootIdentifier>>::from_ssz_bytes_with_nested(
|
||||
<RuntimeVariableList<DataColumnsByRootIdentifier<E>>>::from_ssz_bytes(
|
||||
decoded_buffer,
|
||||
spec.max_request_blocks(current_fork),
|
||||
spec.number_of_columns as usize,
|
||||
)?,
|
||||
},
|
||||
))),
|
||||
@@ -1066,13 +1067,12 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn dcbroot_request(fork_name: ForkName, spec: &ChainSpec) -> DataColumnsByRootRequest {
|
||||
let number_of_columns = spec.number_of_columns as usize;
|
||||
fn dcbroot_request(fork_name: ForkName, spec: &ChainSpec) -> DataColumnsByRootRequest<Spec> {
|
||||
DataColumnsByRootRequest {
|
||||
data_column_ids: RuntimeVariableList::new(
|
||||
vec![DataColumnsByRootIdentifier {
|
||||
block_root: Hash256::zero(),
|
||||
columns: RuntimeVariableList::from_vec(vec![0, 1, 2], number_of_columns),
|
||||
columns: VariableList::from(vec![0, 1, 2]),
|
||||
}],
|
||||
spec.max_request_blocks(fork_name),
|
||||
)
|
||||
@@ -2283,7 +2283,7 @@ mod tests {
|
||||
));
|
||||
|
||||
// Request limits
|
||||
let limit = protocol_id.rpc_request_limits(&fork_context.spec);
|
||||
let limit = protocol_id.rpc_request_limits::<Spec>(&fork_context.spec);
|
||||
let mut max = encode_len(limit.max + 1);
|
||||
let mut codec = SSZSnappyOutboundCodec::<Spec>::new(
|
||||
protocol_id.clone(),
|
||||
|
||||
@@ -400,11 +400,11 @@ impl DataColumnsByRangeRequest {
|
||||
.len()
|
||||
}
|
||||
|
||||
pub fn ssz_max_len(spec: &ChainSpec) -> usize {
|
||||
pub fn ssz_max_len<E: EthSpec>() -> usize {
|
||||
DataColumnsByRangeRequest {
|
||||
start_slot: 0,
|
||||
count: 0,
|
||||
columns: vec![0; spec.number_of_columns as usize],
|
||||
columns: vec![0; E::number_of_columns()],
|
||||
}
|
||||
.as_ssz_bytes()
|
||||
.len()
|
||||
@@ -517,14 +517,14 @@ impl BlobsByRootRequest {
|
||||
|
||||
/// Request a number of data columns from a peer.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct DataColumnsByRootRequest {
|
||||
pub struct DataColumnsByRootRequest<E: EthSpec> {
|
||||
/// The list of beacon block roots and column indices being requested.
|
||||
pub data_column_ids: RuntimeVariableList<DataColumnsByRootIdentifier>,
|
||||
pub data_column_ids: RuntimeVariableList<DataColumnsByRootIdentifier<E>>,
|
||||
}
|
||||
|
||||
impl DataColumnsByRootRequest {
|
||||
impl<E: EthSpec> DataColumnsByRootRequest<E> {
|
||||
pub fn new(
|
||||
data_column_ids: Vec<DataColumnsByRootIdentifier>,
|
||||
data_column_ids: Vec<DataColumnsByRootIdentifier<E>>,
|
||||
max_request_blocks: usize,
|
||||
) -> Self {
|
||||
let data_column_ids = RuntimeVariableList::from_vec(data_column_ids, max_request_blocks);
|
||||
@@ -924,7 +924,7 @@ impl std::fmt::Display for BlobsByRangeRequest {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for DataColumnsByRootRequest {
|
||||
impl<E: EthSpec> std::fmt::Display for DataColumnsByRootRequest<E> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
|
||||
@@ -493,7 +493,7 @@ impl AsRef<str> for ProtocolId {
|
||||
|
||||
impl ProtocolId {
|
||||
/// Returns min and max size for messages of given protocol id requests.
|
||||
pub fn rpc_request_limits(&self, spec: &ChainSpec) -> RpcLimits {
|
||||
pub fn rpc_request_limits<E: EthSpec>(&self, spec: &ChainSpec) -> RpcLimits {
|
||||
match self.versioned_protocol.protocol() {
|
||||
Protocol::Status => RpcLimits::new(
|
||||
<StatusMessageV1 as Encode>::ssz_fixed_len(),
|
||||
@@ -517,7 +517,7 @@ impl ProtocolId {
|
||||
Protocol::DataColumnsByRoot => RpcLimits::new(0, spec.max_data_columns_by_root_request),
|
||||
Protocol::DataColumnsByRange => RpcLimits::new(
|
||||
DataColumnsByRangeRequest::ssz_min_len(),
|
||||
DataColumnsByRangeRequest::ssz_max_len(spec),
|
||||
DataColumnsByRangeRequest::ssz_max_len::<E>(),
|
||||
),
|
||||
Protocol::Ping => RpcLimits::new(
|
||||
<Ping as Encode>::ssz_fixed_len(),
|
||||
@@ -725,7 +725,7 @@ pub enum RequestType<E: EthSpec> {
|
||||
BlocksByRoot(BlocksByRootRequest),
|
||||
BlobsByRange(BlobsByRangeRequest),
|
||||
BlobsByRoot(BlobsByRootRequest),
|
||||
DataColumnsByRoot(DataColumnsByRootRequest),
|
||||
DataColumnsByRoot(DataColumnsByRootRequest<E>),
|
||||
DataColumnsByRange(DataColumnsByRangeRequest),
|
||||
LightClientBootstrap(LightClientBootstrapRequest),
|
||||
LightClientOptimisticUpdate,
|
||||
|
||||
@@ -70,7 +70,7 @@ impl<E: EthSpec> NetworkGlobals<E> {
|
||||
|
||||
let mut sampling_subnets = HashSet::new();
|
||||
for custody_index in &custody_groups {
|
||||
let subnets = compute_subnets_from_custody_group(*custody_index, &spec)
|
||||
let subnets = compute_subnets_from_custody_group::<E>(*custody_index, &spec)
|
||||
.expect("should compute custody subnets for node");
|
||||
sampling_subnets.extend(subnets);
|
||||
}
|
||||
@@ -106,7 +106,7 @@ impl<E: EthSpec> NetworkGlobals<E> {
|
||||
|
||||
let mut sampling_subnets = self.sampling_subnets.write();
|
||||
for custody_index in &custody_groups {
|
||||
let subnets = compute_subnets_from_custody_group(*custody_index, &self.spec)
|
||||
let subnets = compute_subnets_from_custody_group::<E>(*custody_index, &self.spec)
|
||||
.expect("should compute custody subnets for node");
|
||||
sampling_subnets.extend(subnets);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user