From 0798629118a884469aac3ba5a3fccd46925182fb Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Mon, 14 Oct 2024 09:45:16 -0700 Subject: [PATCH] remove ethspec dependency --- beacon_node/lighthouse_network/src/rpc/methods.rs | 12 ++++-------- beacon_node/lighthouse_network/src/rpc/protocol.rs | 2 +- .../src/network_beacon_processor/rpc_methods.rs | 4 ++-- consensus/types/src/eth_spec.rs | 8 -------- consensus/types/src/light_client_update.rs | 4 ++++ 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/beacon_node/lighthouse_network/src/rpc/methods.rs b/beacon_node/lighthouse_network/src/rpc/methods.rs index 1c1733ece18..38d0e0133dd 100644 --- a/beacon_node/lighthouse_network/src/rpc/methods.rs +++ b/beacon_node/lighthouse_network/src/rpc/methods.rs @@ -14,21 +14,17 @@ use std::sync::Arc; use strum::IntoStaticStr; use superstruct::superstruct; use types::blob_sidecar::BlobIdentifier; -use types::LightClientUpdate; +use types::light_client_update::MAX_REQUEST_LIGHT_CLIENT_UPDATES; use types::{ blob_sidecar::BlobSidecar, ChainSpec, ColumnIndex, DataColumnIdentifier, DataColumnSidecar, Epoch, EthSpec, Hash256, LightClientBootstrap, LightClientFinalityUpdate, - LightClientOptimisticUpdate, RuntimeVariableList, SignedBeaconBlock, Slot, + LightClientOptimisticUpdate, LightClientUpdate, RuntimeVariableList, SignedBeaconBlock, Slot, }; /// Maximum length of error message. pub type MaxErrorLen = U256; pub const MAX_ERROR_LEN: u64 = 256; -// Max light client updates by range request limits -// spec: https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/p2p-interface.md#configuration -pub const MAX_REQUEST_LIGHT_CLIENT_UPDATES: u64 = 128; - /// Wrapper over SSZ List to represent error message in rpc responses. #[derive(Debug, Clone)] pub struct ErrorType(pub VariableList); @@ -492,8 +488,8 @@ pub struct LightClientUpdatesByRangeRequest { } impl LightClientUpdatesByRangeRequest { - pub fn max_requested(&self) -> u64 { - E::max_light_client_updates_by_range_requests() as u64 + pub fn max_requested(&self) -> u64 { + MAX_REQUEST_LIGHT_CLIENT_UPDATES } pub fn ssz_min_len() -> usize { diff --git a/beacon_node/lighthouse_network/src/rpc/protocol.rs b/beacon_node/lighthouse_network/src/rpc/protocol.rs index d7308ca0653..16c3a133912 100644 --- a/beacon_node/lighthouse_network/src/rpc/protocol.rs +++ b/beacon_node/lighthouse_network/src/rpc/protocol.rs @@ -791,7 +791,7 @@ impl RequestType { RequestType::LightClientBootstrap(_) => 1, RequestType::LightClientOptimisticUpdate => 1, RequestType::LightClientFinalityUpdate => 1, - RequestType::LightClientUpdatesByRange(_) => MAX_REQUEST_LIGHT_CLIENT_UPDATES, + RequestType::LightClientUpdatesByRange(req) => req.max_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 fefabc05fa8..310901f7325 100644 --- a/beacon_node/network/src/network_beacon_processor/rpc_methods.rs +++ b/beacon_node/network/src/network_beacon_processor/rpc_methods.rs @@ -10,7 +10,7 @@ use lighthouse_network::rpc::methods::{ }; use lighthouse_network::rpc::*; use lighthouse_network::{PeerId, PeerRequestId, ReportSource, Response, SyncInfo}; -use methods::{LightClientUpdatesByRangeRequest, MAX_REQUEST_LIGHT_CLIENT_UPDATES}; +use methods::LightClientUpdatesByRangeRequest; use slog::{debug, error, warn}; use slot_clock::SlotClock; use std::collections::{hash_map::Entry, HashMap}; @@ -470,7 +470,7 @@ impl NetworkBeaconProcessor { ); // Should not send more than max light client updates - let max_request_size: u64 = MAX_REQUEST_LIGHT_CLIENT_UPDATES; + let max_request_size: u64 = req.max_requested(); if req.count > max_request_size { return Err(( RpcErrorResponse::InvalidRequest, diff --git a/consensus/types/src/eth_spec.rs b/consensus/types/src/eth_spec.rs index b2eef0ce674..09ef8e3c1a7 100644 --- a/consensus/types/src/eth_spec.rs +++ b/consensus/types/src/eth_spec.rs @@ -92,7 +92,6 @@ pub trait EthSpec: type SyncCommitteeSize: Unsigned + Clone + Sync + Send + Debug + PartialEq; /// The number of `sync_committee` subnets. type SyncCommitteeSubnetCount: Unsigned + Clone + Sync + Send + Debug + PartialEq; - type MaxLightClientUpdates: Unsigned + Clone + Sync + Send + Debug + PartialEq; /* * New in Bellatrix */ @@ -375,10 +374,6 @@ pub trait EthSpec: fn kzg_commitments_inclusion_proof_depth() -> usize { Self::KzgCommitmentsInclusionProofDepth::to_usize() } - - fn max_light_client_updates_by_range_requests() -> usize { - Self::MaxLightClientUpdates::to_usize() - } } /// Macro to inherit some type values from another EthSpec. @@ -443,7 +438,6 @@ impl EthSpec for MainnetEthSpec { type MaxAttesterSlashingsElectra = U1; type MaxAttestationsElectra = U8; type MaxWithdrawalRequestsPerPayload = U16; - type MaxLightClientUpdates = U128; fn default_spec() -> ChainSpec { ChainSpec::mainnet() @@ -483,7 +477,6 @@ impl EthSpec for MinimalEthSpec { type FieldElementsPerExtBlob = U8192; type BytesPerCell = U2048; type KzgCommitmentsInclusionProofDepth = U4; - type MaxLightClientUpdates = U128; params_from_eth_spec!(MainnetEthSpec { JustificationBitsLength, @@ -576,7 +569,6 @@ impl EthSpec for GnosisEthSpec { type FieldElementsPerExtBlob = U8192; type BytesPerCell = U2048; type KzgCommitmentsInclusionProofDepth = U4; - type MaxLightClientUpdates = U128; fn default_spec() -> ChainSpec { ChainSpec::gnosis() diff --git a/consensus/types/src/light_client_update.rs b/consensus/types/src/light_client_update.rs index 34f6c34437a..1f5592a929f 100644 --- a/consensus/types/src/light_client_update.rs +++ b/consensus/types/src/light_client_update.rs @@ -36,6 +36,10 @@ pub const CURRENT_SYNC_COMMITTEE_PROOF_LEN: usize = 5; pub const NEXT_SYNC_COMMITTEE_PROOF_LEN: usize = 5; pub const EXECUTION_PAYLOAD_PROOF_LEN: usize = 4; +// Max light client updates by range request limits +// spec: https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/p2p-interface.md#configuration +pub const MAX_REQUEST_LIGHT_CLIENT_UPDATES: u64 = 128; + type FinalityBranch = FixedVector; type NextSyncCommitteeBranch = FixedVector;