Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ tracing_samplers = { path = "common/tracing_samplers" }
tree_hash = "0.12.0"
tree_hash_derive = "0.12.0"
typenum = "1"
types = { path = "consensus/types" }
types = { path = "consensus/types", features = ["saturating-arith"] }
url = "2"
uuid = { version = "0.8", features = ["serde", "v4"] }
validator_client = { path = "validator_client" }
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ alloy-primitives = { workspace = true }
bitvec = { workspace = true }
bls = { workspace = true }
educe = { workspace = true }
eth2 = { workspace = true, features = ["lighthouse"] }
eth2 = { workspace = true, features = ["lighthouse", "network"] }
eth2_network_config = { workspace = true }
ethereum_hashing = { workspace = true }
ethereum_serde_utils = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let validator_index = *validator_index as usize;
committee_cache.get_attestation_duties(validator_index)
})
.collect();
.collect::<Result<Vec<_>, _>>()?;

Ok((duties, dependent_root))
},
Expand Down
8 changes: 5 additions & 3 deletions beacon_node/beacon_chain/src/early_attester_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::data_availability_checker::{AvailableBlock, AvailableBlockData};
use crate::{BeaconChainError as Error, metrics};
use parking_lot::RwLock;
use proto_array::Block as ProtoBlock;
use safe_arith::SafeArith;
use std::sync::Arc;
use tracing::instrument;
use types::*;
Expand Down Expand Up @@ -59,12 +60,13 @@ impl CommitteeLengths {
slots_per_epoch,
committees_per_slot,
committee_index as usize,
);
)?;
let epoch_committee_count = committees_per_slot.safe_mul(slots_per_epoch)?;
let range = compute_committee_range_in_epoch(
epoch_committee_count(committees_per_slot, slots_per_epoch),
epoch_committee_count,
index_in_epoch,
self.active_validator_indices_len,
)
)?
.ok_or(Error::EarlyAttesterCacheError)?;

range
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/execution_layer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ arc-swap = "1.6.0"
bls = { workspace = true }
builder_client = { path = "../builder_client" }
bytes = { workspace = true }
eth2 = { workspace = true, features = ["events", "lighthouse"] }
eth2 = { workspace = true, features = ["events", "lighthouse", "network"] }
ethereum_serde_utils = { workspace = true }
ethereum_ssz = { workspace = true }
fixed_bytes = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/http_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bytes = { workspace = true }
context_deserialize = { workspace = true }
directory = { workspace = true }
either = { workspace = true }
eth2 = { workspace = true, features = ["lighthouse"] }
eth2 = { workspace = true, features = ["lighthouse", "network"] }
ethereum_serde_utils = { workspace = true }
ethereum_ssz = { workspace = true }
execution_layer = { workspace = true }
Expand Down
9 changes: 3 additions & 6 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2140,12 +2140,9 @@ pub fn serve<T: BeaconChainTypes>(
let discovery_addresses = enr.multiaddr_p2p_udp();
Ok(api_types::GenericResponse::from(api_types::IdentityData {
peer_id: network_globals.local_peer_id().to_base58(),
enr: enr.to_base64(),
p2p_addresses: p2p_addresses.iter().map(|a| a.to_string()).collect(),
discovery_addresses: discovery_addresses
.iter()
.map(|a| a.to_string())
.collect(),
enr,
p2p_addresses,
discovery_addresses,
metadata: utils::from_meta_data::<T::EthSpec>(
&network_globals.local_metadata,
&chain.spec,
Expand Down
18 changes: 4 additions & 14 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2855,19 +2855,9 @@ impl ApiTester {

let expected = IdentityData {
peer_id: self.local_enr.peer_id().to_string(),
enr: self.local_enr.to_base64(),
p2p_addresses: self
.local_enr
.multiaddr_p2p_tcp()
.iter()
.map(|a| a.to_string())
.collect(),
discovery_addresses: self
.local_enr
.multiaddr_p2p_udp()
.iter()
.map(|a| a.to_string())
.collect(),
enr: self.local_enr.clone(),
p2p_addresses: self.local_enr.multiaddr_p2p_tcp(),
discovery_addresses: self.local_enr.multiaddr_p2p_udp(),
metadata: MetaData::V2(MetaDataV2 {
seq_number: 0,
attnets: "0x0000000000000000".to_string(),
Expand Down Expand Up @@ -2896,7 +2886,7 @@ impl ApiTester {
pub async fn test_get_node_peers_by_id(self) -> Self {
let result = self
.client
.get_node_peers_by_id(&self.external_peer_id.to_string())
.get_node_peers_by_id(self.external_peer_id)
.await
.unwrap()
.data;
Expand Down
4 changes: 4 additions & 0 deletions common/eth2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ edition = { workspace = true }
default = []
lighthouse = ["proto_array", "eth2_keystore", "eip_3076", "zeroize"]
events = ["reqwest-eventsource", "futures", "futures-util"]
network = ["libp2p-identity", "enr", "multiaddr"]

[dependencies]
bls = { workspace = true }
context_deserialize = { workspace = true }
educe = { workspace = true }
eip_3076 = { workspace = true, optional = true }
enr = { version = "0.13.0", features = ["ed25519"], optional = true }
eth2_keystore = { workspace = true, optional = true }
ethereum_serde_utils = { workspace = true }
ethereum_ssz = { workspace = true }
ethereum_ssz_derive = { workspace = true }
futures = { workspace = true, optional = true }
futures-util = { version = "0.3.8", optional = true }
libp2p-identity = { version = "0.2", features = ["peerid"], optional = true }
mediatype = "0.19.13"
multiaddr = { version = "0.18.2", optional = true }
pretty_reqwest_error = { workspace = true }
proto_array = { workspace = true, optional = true }
reqwest = { workspace = true }
Expand Down
8 changes: 6 additions & 2 deletions common/eth2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ use educe::Educe;
use futures::Stream;
#[cfg(feature = "events")]
use futures_util::StreamExt;
#[cfg(feature = "network")]
use libp2p_identity::PeerId;
use reqwest::{
Body, IntoUrl, RequestBuilder, Response,
header::{HeaderMap, HeaderValue},
Expand Down Expand Up @@ -1939,6 +1941,7 @@ impl BeaconNodeHttpClient {
}

/// `GET node/identity`
#[cfg(feature = "network")]
pub async fn get_node_identity(&self) -> Result<GenericResponse<IdentityData>, Error> {
let mut path = self.eth_path(V1)?;

Expand Down Expand Up @@ -1986,17 +1989,18 @@ impl BeaconNodeHttpClient {
}

/// `GET node/peers/{peer_id}`
#[cfg(feature = "network")]
pub async fn get_node_peers_by_id(
&self,
peer_id: &str,
peer_id: PeerId,
) -> Result<GenericResponse<PeerData>, Error> {
let mut path = self.eth_path(V1)?;

path.path_segments_mut()
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
.push("node")
.push("peers")
.push(peer_id);
.push(&peer_id.to_string());

self.get(path).await
}
Expand Down
11 changes: 8 additions & 3 deletions common/eth2/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ use crate::{
};
use bls::{PublicKeyBytes, SecretKey, Signature, SignatureBytes};
use context_deserialize::ContextDeserialize;
#[cfg(feature = "network")]
use enr::{CombinedKey, Enr};
use mediatype::{MediaType, MediaTypeList, names};
#[cfg(feature = "network")]
use multiaddr::Multiaddr;
use reqwest::header::HeaderMap;
use serde::{Deserialize, Deserializer, Serialize};
use serde_utils::quoted_u64::Quoted;
Expand Down Expand Up @@ -559,12 +563,13 @@ pub struct ChainHeadData {
pub execution_optimistic: Option<bool>,
}

#[cfg(feature = "network")]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct IdentityData {
pub peer_id: String,
pub enr: String,
pub p2p_addresses: Vec<String>,
pub discovery_addresses: Vec<String>,
pub enr: Enr<CombinedKey>,
pub p2p_addresses: Vec<Multiaddr>,
pub discovery_addresses: Vec<Multiaddr>,
pub metadata: MetaData,
}

Expand Down
3 changes: 1 addition & 2 deletions consensus/state_processing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ authors = ["Paul Hauner <paul@paulhauner.com>", "Michael Sproul <michael@sigmapr
edition = { workspace = true }

[features]
default = ["legacy-arith"]
default = []
fake_crypto = ["bls/fake_crypto"]
legacy-arith = ["types/legacy-arith"]
arbitrary-fuzz = [
"types/arbitrary-fuzz",
"merkle_proof/arbitrary",
Expand Down
7 changes: 4 additions & 3 deletions consensus/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ authors = [
edition = { workspace = true }

[features]
default = ["legacy-arith"]
# Allow saturating arithmetic on slots and epochs. Enabled by default, but deprecated.
legacy-arith = []
default = []
# Enable +, -, *, /, % operators for Slot and Epoch types.
# Operations saturate instead of wrapping.
saturating-arith = []
sqlite = ["dep:rusqlite"]
arbitrary = [
"dep:arbitrary",
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/core/slot_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
test_utils::TestRandom,
};

#[cfg(feature = "legacy-arith")]
#[cfg(feature = "saturating-arith")]
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, Sub, SubAssign};

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
Expand Down
6 changes: 3 additions & 3 deletions consensus/types/src/core/slot_epoch_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ macro_rules! impl_safe_arith {
}

// Deprecated: prefer `SafeArith` methods for new code.
#[cfg(feature = "legacy-arith")]
#[cfg(feature = "saturating-arith")]
macro_rules! impl_math_between {
($main: ident, $other: ident) => {
impl Add<$other> for $main {
Expand Down Expand Up @@ -321,9 +321,9 @@ macro_rules! impl_common {
impl_u64_eq_ord!($type);
impl_safe_arith!($type, $type);
impl_safe_arith!($type, u64);
#[cfg(feature = "legacy-arith")]
#[cfg(feature = "saturating-arith")]
impl_math_between!($type, $type);
#[cfg(feature = "legacy-arith")]
#[cfg(feature = "saturating-arith")]
impl_math_between!($type, u64);
impl_math!($type);
impl_display!($type);
Expand Down
7 changes: 2 additions & 5 deletions consensus/types/src/state/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ impl<E: EthSpec> BeaconState<E> {
relative_epoch: RelativeEpoch,
) -> Result<u64, BeaconStateError> {
let cache = self.committee_cache(relative_epoch)?;
Ok(cache.epoch_committee_count() as u64)
Ok(cache.epoch_committee_count()? as u64)
}

/// Return the cached active validator indices at some epoch.
Expand Down Expand Up @@ -2150,7 +2150,7 @@ impl<E: EthSpec> BeaconState<E> {
) -> Result<Option<AttestationDuty>, BeaconStateError> {
let cache = self.committee_cache(relative_epoch)?;

Ok(cache.get_attestation_duties(validator_index))
Ok(cache.get_attestation_duties(validator_index)?)
}

/// Check if the attestation is for the block proposed at the attestation slot.
Expand Down Expand Up @@ -2909,7 +2909,6 @@ impl<E: EthSpec> BeaconState<E> {
}
}

#[allow(clippy::arithmetic_side_effects)]
pub fn rebase_on(&mut self, base: &Self, spec: &ChainSpec) -> Result<(), BeaconStateError> {
// Required for macros (which use type-hints internally).

Expand Down Expand Up @@ -3218,7 +3217,6 @@ impl<E: EthSpec> BeaconState<E> {
))
}

#[allow(clippy::arithmetic_side_effects)]
pub fn apply_pending_mutations(&mut self) -> Result<(), BeaconStateError> {
match self {
Self::Base(inner) => {
Expand Down Expand Up @@ -3321,7 +3319,6 @@ impl<E: EthSpec> BeaconState<E> {

pub fn get_beacon_state_leaves(&self) -> Vec<Hash256> {
let mut leaves = vec![];
#[allow(clippy::arithmetic_side_effects)]
match self {
BeaconState::Base(state) => {
map_beacon_state_base_fields!(state, |_, field| {
Expand Down
Loading