Skip to content

Commit

Permalink
remove ethspec dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
eserilev committed Oct 14, 2024
1 parent 4aa26b3 commit 0798629
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 19 deletions.
12 changes: 4 additions & 8 deletions beacon_node/lighthouse_network/src/rpc/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8, MaxErrorLen>);
Expand Down Expand Up @@ -492,8 +488,8 @@ pub struct LightClientUpdatesByRangeRequest {
}

impl LightClientUpdatesByRangeRequest {
pub fn max_requested<E: EthSpec>(&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 {
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/lighthouse_network/src/rpc/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ impl<E: EthSpec> RequestType<E> {
RequestType::LightClientBootstrap(_) => 1,
RequestType::LightClientOptimisticUpdate => 1,
RequestType::LightClientFinalityUpdate => 1,
RequestType::LightClientUpdatesByRange(_) => MAX_REQUEST_LIGHT_CLIENT_UPDATES,
RequestType::LightClientUpdatesByRange(req) => req.max_requested(),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -470,7 +470,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
);

// 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,
Expand Down
8 changes: 0 additions & 8 deletions consensus/types/src/eth_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions consensus/types/src/light_client_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Hash256, FinalizedRootProofLen>;
type NextSyncCommitteeBranch = FixedVector<Hash256, NextSyncCommitteeProofLen>;

Expand Down

0 comments on commit 0798629

Please sign in to comment.