Skip to content

Commit

Permalink
Merge branch 'unstable' into tx-opaque
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Dec 4, 2024
2 parents 56ad1ce + fec502d commit ff5258d
Show file tree
Hide file tree
Showing 76 changed files with 1,811 additions and 2,136 deletions.
1,215 changes: 760 additions & 455 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,20 @@ clap = { version = "4.5.4", features = ["derive", "cargo", "wrap_help"] }
c-kzg = { version = "1", default-features = false }
compare_fields_derive = { path = "common/compare_fields_derive" }
criterion = "0.5"
delay_map = "0.3"
delay_map = "0.4"
derivative = "2"
dirs = "3"
either = "1.9"
rust_eth_kzg = "0.5.1"
# TODO: rust_eth_kzg is pinned for now while a perf regression is investigated
# The crate_crypto_* dependencies can be removed from this file completely once we update
rust_eth_kzg = "=0.5.1"
crate_crypto_internal_eth_kzg_bls12_381 = "=0.5.1"
crate_crypto_internal_eth_kzg_erasure_codes = "=0.5.1"
crate_crypto_internal_eth_kzg_maybe_rayon = "=0.5.1"
crate_crypto_internal_eth_kzg_polynomial = "=0.5.1"
crate_crypto_kzg_multi_open_fk20 = "=0.5.1"
discv5 = { version = "0.9", features = ["libp2p"] }
env_logger = "0.9"
error-chain = "0.12"
ethereum_hashing = "0.7.0"
ethereum_serde_utils = "0.7"
ethereum_ssz = "0.7"
Expand Down
9 changes: 8 additions & 1 deletion FUNDING.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
"drips": {
"ethereum": {
"ownedBy": "0x25c4a76E7d118705e7Ea2e9b7d8C59930d8aCD3b"
},
"filecoin": {
"ownedBy": "0x25c4a76E7d118705e7Ea2e9b7d8C59930d8aCD3b"
}
},
"opRetro": {
"projectId": "0x04b1cd5a7c59117474ce414b309fa48e985bdaab4b0dab72045f74d04ebd8cff"
}
}
}

2 changes: 1 addition & 1 deletion beacon_node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "beacon_node"
version = "5.3.0"
version = "6.0.0"
authors = [
"Paul Hauner <[email protected]>",
"Age Manning <[email protected]",
Expand Down
10 changes: 5 additions & 5 deletions beacon_node/beacon_chain/src/attestation_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ pub struct VerifiedAggregatedAttestation<'a, T: BeaconChainTypes> {
indexed_attestation: IndexedAttestation<T::EthSpec>,
}

impl<'a, T: BeaconChainTypes> VerifiedAggregatedAttestation<'a, T> {
impl<T: BeaconChainTypes> VerifiedAggregatedAttestation<'_, T> {
pub fn into_indexed_attestation(self) -> IndexedAttestation<T::EthSpec> {
self.indexed_attestation
}
Expand All @@ -319,15 +319,15 @@ pub struct VerifiedUnaggregatedAttestation<'a, T: BeaconChainTypes> {
subnet_id: SubnetId,
}

impl<'a, T: BeaconChainTypes> VerifiedUnaggregatedAttestation<'a, T> {
impl<T: BeaconChainTypes> VerifiedUnaggregatedAttestation<'_, T> {
pub fn into_indexed_attestation(self) -> IndexedAttestation<T::EthSpec> {
self.indexed_attestation
}
}

/// Custom `Clone` implementation is to avoid the restrictive trait bounds applied by the usual derive
/// macro.
impl<'a, T: BeaconChainTypes> Clone for IndexedUnaggregatedAttestation<'a, T> {
impl<T: BeaconChainTypes> Clone for IndexedUnaggregatedAttestation<'_, T> {
fn clone(&self) -> Self {
Self {
attestation: self.attestation,
Expand All @@ -353,7 +353,7 @@ pub trait VerifiedAttestation<T: BeaconChainTypes>: Sized {
}
}

impl<'a, T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedAggregatedAttestation<'a, T> {
impl<T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedAggregatedAttestation<'_, T> {
fn attestation(&self) -> AttestationRef<T::EthSpec> {
self.attestation()
}
Expand All @@ -363,7 +363,7 @@ impl<'a, T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedAggregatedAttes
}
}

impl<'a, T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedUnaggregatedAttestation<'a, T> {
impl<T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedUnaggregatedAttestation<'_, T> {
fn attestation(&self) -> AttestationRef<T::EthSpec> {
self.attestation
}
Expand Down
2 changes: 2 additions & 0 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
/// ## Errors
///
/// May return a database error.
#[allow(clippy::type_complexity)]
pub fn get_blocks_checking_caches(
self: &Arc<Self>,
block_roots: Vec<Hash256>,
Expand All @@ -1127,6 +1128,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
Ok(BeaconBlockStreamer::<T>::new(self, CheckCaches::Yes)?.launch_stream(block_roots))
}

#[allow(clippy::type_complexity)]
pub fn get_blocks(
self: &Arc<Self>,
block_roots: Vec<Hash256>,
Expand Down
1 change: 1 addition & 0 deletions beacon_node/beacon_chain/src/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,7 @@ pub fn get_validator_pubkey_cache<T: BeaconChainTypes>(
///
/// The signature verifier is empty because it does not yet have any of this block's signatures
/// added to it. Use `Self::apply_to_signature_verifier` to apply the signatures.
#[allow(clippy::type_complexity)]
fn get_signature_verifier<'a, T: BeaconChainTypes>(
state: &'a BeaconState<T::EthSpec>,
validator_pubkey_cache: &'a ValidatorPubkeyCache<T>,
Expand Down
3 changes: 1 addition & 2 deletions beacon_node/beacon_chain/src/eth1_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ fn get_sync_status<E: EthSpec>(

// Determine how many voting periods are contained in distance between
// now and genesis, rounding up.
let voting_periods_past =
(seconds_till_genesis + voting_period_duration - 1) / voting_period_duration;
let voting_periods_past = seconds_till_genesis.div_ceil(voting_period_duration);

// Return the start time of the current voting period*.
//
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/beacon_chain/src/observed_aggregates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub trait SubsetItem {
fn root(&self) -> Result<Hash256, Error>;
}

impl<'a, E: EthSpec> SubsetItem for AttestationRef<'a, E> {
impl<E: EthSpec> SubsetItem for AttestationRef<'_, E> {
type Item = BitList<E::MaxValidatorsPerSlot>;
fn is_subset(&self, other: &Self::Item) -> bool {
match self {
Expand Down Expand Up @@ -159,7 +159,7 @@ impl<'a, E: EthSpec> SubsetItem for AttestationRef<'a, E> {
}
}

impl<'a, E: EthSpec> SubsetItem for &'a SyncCommitteeContribution<E> {
impl<E: EthSpec> SubsetItem for &SyncCommitteeContribution<E> {
type Item = BitVector<E::SyncSubcommitteeSize>;
fn is_subset(&self, other: &Self::Item) -> bool {
self.aggregation_bits.is_subset(other)
Expand Down
1 change: 0 additions & 1 deletion beacon_node/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ eth2_config = { workspace = true }
slot_clock = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
error-chain = { workspace = true }
slog = { workspace = true }
tokio = { workspace = true }
futures = { workspace = true }
Expand Down
7 changes: 0 additions & 7 deletions beacon_node/client/src/error.rs

This file was deleted.

1 change: 0 additions & 1 deletion beacon_node/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod metrics;
mod notifier;

pub mod builder;
pub mod error;

use beacon_chain::BeaconChain;
use lighthouse_network::{Enr, Multiaddr, NetworkGlobals};
Expand Down
1 change: 0 additions & 1 deletion beacon_node/lighthouse_network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ slog = { workspace = true }
lighthouse_version = { workspace = true }
tokio = { workspace = true }
futures = { workspace = true }
error-chain = { workspace = true }
dirs = { workspace = true }
fnv = { workspace = true }
metrics = { workspace = true }
Expand Down
3 changes: 1 addition & 2 deletions beacon_node/lighthouse_network/gossipsub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]

[features]
wasm-bindgen = ["getrandom/js"]
wasm-bindgen = ["getrandom/js", "futures-timer/wasm-bindgen"]
rsa = []

[dependencies]
Expand All @@ -22,7 +22,6 @@ bytes = "1.5"
either = "1.9"
fnv = "1.0.7"
futures = "0.3.30"
futures-ticker = "0.0.3"
futures-timer = "3.0.2"
getrandom = "0.2.12"
hashlink.workspace = true
Expand Down
3 changes: 1 addition & 2 deletions beacon_node/lighthouse_network/gossipsub/src/backoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ pub(crate) struct BackoffStorage {

impl BackoffStorage {
fn heartbeats(d: &Duration, heartbeat_interval: &Duration) -> usize {
((d.as_nanos() + heartbeat_interval.as_nanos() - 1) / heartbeat_interval.as_nanos())
as usize
d.as_nanos().div_ceil(heartbeat_interval.as_nanos()) as usize
}

pub(crate) fn new(
Expand Down
25 changes: 12 additions & 13 deletions beacon_node/lighthouse_network/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ use std::{
time::Duration,
};

use futures::StreamExt;
use futures_ticker::Ticker;
use futures::FutureExt;
use hashlink::LinkedHashMap;
use prometheus_client::registry::Registry;
use rand::{seq::SliceRandom, thread_rng};
Expand Down Expand Up @@ -74,6 +73,7 @@ use super::{
types::RpcOut,
};
use super::{PublishError, SubscriptionError, TopicScoreParams, ValidationError};
use futures_timer::Delay;
use quick_protobuf::{MessageWrite, Writer};
use std::{cmp::Ordering::Equal, fmt::Debug};

Expand Down Expand Up @@ -301,7 +301,7 @@ pub struct Behaviour<D = IdentityTransform, F = AllowAllSubscriptionFilter> {
mcache: MessageCache,

/// Heartbeat interval stream.
heartbeat: Ticker,
heartbeat: Delay,

/// Number of heartbeats since the beginning of time; this allows us to amortize some resource
/// clean up -- eg backoff clean up.
Expand All @@ -318,7 +318,7 @@ pub struct Behaviour<D = IdentityTransform, F = AllowAllSubscriptionFilter> {
outbound_peers: HashSet<PeerId>,

/// Stores optional peer score data together with thresholds and decay interval.
peer_score: Option<(PeerScore, PeerScoreThresholds, Ticker)>,
peer_score: Option<(PeerScore, PeerScoreThresholds, Delay)>,

/// Counts the number of `IHAVE` received from each peer since the last heartbeat.
count_received_ihave: HashMap<PeerId, usize>,
Expand Down Expand Up @@ -466,10 +466,7 @@ where
config.backoff_slack(),
),
mcache: MessageCache::new(config.history_gossip(), config.history_length()),
heartbeat: Ticker::new_with_next(
config.heartbeat_interval(),
config.heartbeat_initial_delay(),
),
heartbeat: Delay::new(config.heartbeat_interval() + config.heartbeat_initial_delay()),
heartbeat_ticks: 0,
px_peers: HashSet::new(),
outbound_peers: HashSet::new(),
Expand Down Expand Up @@ -938,7 +935,7 @@ where
return Err("Peer score set twice".into());
}

let interval = Ticker::new(params.decay_interval);
let interval = Delay::new(params.decay_interval);
let peer_score = PeerScore::new_with_message_delivery_time_callback(params, callback);
self.peer_score = Some((peer_score, threshold, interval));
Ok(())
Expand Down Expand Up @@ -1208,7 +1205,7 @@ where
}

fn score_below_threshold_from_scores(
peer_score: &Option<(PeerScore, PeerScoreThresholds, Ticker)>,
peer_score: &Option<(PeerScore, PeerScoreThresholds, Delay)>,
peer_id: &PeerId,
threshold: impl Fn(&PeerScoreThresholds) -> f64,
) -> (bool, f64) {
Expand Down Expand Up @@ -3427,14 +3424,16 @@ where
}

// update scores
if let Some((peer_score, _, interval)) = &mut self.peer_score {
while let Poll::Ready(Some(_)) = interval.poll_next_unpin(cx) {
if let Some((peer_score, _, delay)) = &mut self.peer_score {
if delay.poll_unpin(cx).is_ready() {
peer_score.refresh_scores();
delay.reset(peer_score.params.decay_interval);
}
}

while let Poll::Ready(Some(_)) = self.heartbeat.poll_next_unpin(cx) {
if self.heartbeat.poll_unpin(cx).is_ready() {
self.heartbeat();
self.heartbeat.reset(self.config.heartbeat_interval());
}

Poll::Pending
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::subscription_filter::WhitelistSubscriptionFilter;
use crate::types::RpcReceiver;
use crate::{config::ConfigBuilder, types::Rpc, IdentTopic as Topic};
use byteorder::{BigEndian, ByteOrder};
use futures::StreamExt;
use libp2p::core::ConnectedPoint;
use rand::Rng;
use std::net::Ipv4Addr;
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/lighthouse_network/gossipsub/src/peer_score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod tests;
const TIME_CACHE_DURATION: u64 = 120;

pub(crate) struct PeerScore {
params: PeerScoreParams,
pub(crate) params: PeerScoreParams,
/// The score parameters.
peer_stats: HashMap<PeerId, PeerStats>,
/// Tracking peers per IP.
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/lighthouse_network/src/discovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pub mod enr_ext;

// Allow external use of the lighthouse ENR builder
use crate::service::TARGET_SUBNET_PEERS;
use crate::{error, Enr, NetworkConfig, NetworkGlobals, Subnet, SubnetDiscovery};
use crate::{metrics, ClearDialError};
use crate::{Enr, NetworkConfig, NetworkGlobals, Subnet, SubnetDiscovery};
use discv5::{enr::NodeId, Discv5};
pub use enr::{build_enr, load_enr_from_disk, use_or_load_enr, CombinedKey, Eth2Enr};
pub use enr_ext::{peer_id_to_node_id, CombinedKeyExt, EnrExt};
Expand Down Expand Up @@ -205,7 +205,7 @@ impl<E: EthSpec> Discovery<E> {
network_globals: Arc<NetworkGlobals<E>>,
log: &slog::Logger,
spec: &ChainSpec,
) -> error::Result<Self> {
) -> Result<Self, String> {
let log = log.clone();

let enr_dir = match config.network_dir.to_str() {
Expand Down
6 changes: 3 additions & 3 deletions beacon_node/lighthouse_network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<'de> Deserialize<'de> for PeerIdSerialized {
// A wrapper struct that prints a dial error nicely.
struct ClearDialError<'a>(&'a DialError);

impl<'a> ClearDialError<'a> {
impl ClearDialError<'_> {
fn most_inner_error(err: &(dyn std::error::Error)) -> &(dyn std::error::Error) {
let mut current = err;
while let Some(source) = current.source() {
Expand All @@ -73,7 +73,7 @@ impl<'a> ClearDialError<'a> {
}
}

impl<'a> std::fmt::Display for ClearDialError<'a> {
impl std::fmt::Display for ClearDialError<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
match &self.0 {
DialError::Transport(errors) => {
Expand Down Expand Up @@ -101,7 +101,7 @@ impl<'a> std::fmt::Display for ClearDialError<'a> {
}

pub use crate::types::{
error, Enr, EnrSyncCommitteeBitfield, GossipTopic, NetworkGlobals, PubsubMessage, Subnet,
Enr, EnrSyncCommitteeBitfield, GossipTopic, NetworkGlobals, PubsubMessage, Subnet,
SubnetDiscovery,
};

Expand Down
4 changes: 2 additions & 2 deletions beacon_node/lighthouse_network/src/peer_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::discovery::enr_ext::EnrExt;
use crate::discovery::peer_id_to_node_id;
use crate::rpc::{GoodbyeReason, MetaData, Protocol, RPCError, RpcErrorResponse};
use crate::service::TARGET_SUBNET_PEERS;
use crate::{error, metrics, Gossipsub, NetworkGlobals, PeerId, Subnet, SubnetDiscovery};
use crate::{metrics, Gossipsub, NetworkGlobals, PeerId, Subnet, SubnetDiscovery};
use delay_map::HashSetDelay;
use discv5::Enr;
use libp2p::identify::Info as IdentifyInfo;
Expand Down Expand Up @@ -144,7 +144,7 @@ impl<E: EthSpec> PeerManager<E> {
cfg: config::Config,
network_globals: Arc<NetworkGlobals<E>>,
log: &slog::Logger,
) -> error::Result<Self> {
) -> Result<Self, String> {
let config::Config {
discovery_enabled,
metrics_enabled,
Expand Down
15 changes: 7 additions & 8 deletions beacon_node/lighthouse_network/src/rpc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,14 @@ impl RateLimiterConfig {
pub const DEFAULT_META_DATA_QUOTA: Quota = Quota::n_every(2, 5);
pub const DEFAULT_STATUS_QUOTA: Quota = Quota::n_every(5, 15);
pub const DEFAULT_GOODBYE_QUOTA: Quota = Quota::one_every(10);
pub const DEFAULT_BLOCKS_BY_RANGE_QUOTA: Quota = Quota::n_every(1024, 10);
// The number is chosen to balance between upload bandwidth required to serve
// blocks and a decent syncing rate for honest nodes. Malicious nodes would need to
// spread out their requests over the time window to max out bandwidth on the server.
pub const DEFAULT_BLOCKS_BY_RANGE_QUOTA: Quota = Quota::n_every(128, 10);
pub const DEFAULT_BLOCKS_BY_ROOT_QUOTA: Quota = Quota::n_every(128, 10);
// `BlocksByRange` and `BlobsByRange` are sent together during range sync.
// It makes sense for blocks and blobs quotas to be equivalent in terms of the number of blocks:
// 1024 blocks * 6 max blobs per block.
// This doesn't necessarily mean that we are sending this many blobs, because the quotas are
// measured against the maximum request size.
pub const DEFAULT_BLOBS_BY_RANGE_QUOTA: Quota = Quota::n_every(6144, 10);
pub const DEFAULT_BLOBS_BY_ROOT_QUOTA: Quota = Quota::n_every(768, 10);
// `DEFAULT_BLOCKS_BY_RANGE_QUOTA` * (target + 1) to account for high usage
pub const DEFAULT_BLOBS_BY_RANGE_QUOTA: Quota = Quota::n_every(512, 10);
pub const DEFAULT_BLOBS_BY_ROOT_QUOTA: Quota = Quota::n_every(512, 10);
// 320 blocks worth of columns for regular node, or 40 blocks for supernode.
// Range sync load balances when requesting blocks, and each batch is 32 blocks.
pub const DEFAULT_DATA_COLUMNS_BY_RANGE_QUOTA: Quota = Quota::n_every(5120, 10);
Expand Down
Loading

0 comments on commit ff5258d

Please sign in to comment.