Skip to content

Commit 6c0c41c

Browse files
upgrade libp2p to v0.53.* (#4935)
* update libp2p and address compiler errors * remove bandwidth logging from transport * use libp2p registry * make clippy happy * use rust 1.73 * correct rpc keep alive * remove comments and obsolte code * remove libp2p prefix * make clippy happy * use quic under facade * remove fast msg id * bubble up close statements * fix wrong comment
1 parent 67e0569 commit 6c0c41c

File tree

17 files changed

+526
-605
lines changed

17 files changed

+526
-605
lines changed

Cargo.lock

Lines changed: 272 additions & 255 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM rust:1.69.0-bullseye AS builder
1+
FROM rust:1.73.0-bullseye AS builder
22
RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev
33
COPY . lighthouse
44
ARG FEATURES
@@ -15,4 +15,4 @@ RUN apt-get update && apt-get -y upgrade && apt-get install -y --no-install-reco
1515
ca-certificates \
1616
&& apt-get clean \
1717
&& rm -rf /var/lib/apt/lists/*
18-
COPY --from=builder /usr/local/cargo/bin/lighthouse /usr/local/bin/lighthouse
18+
COPY --from=builder /usr/local/cargo/bin/lighthouse /usr/local/bin/lighthouse

beacon_node/client/src/builder.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub struct ClientBuilder<T: BeaconChainTypes> {
6868
eth1_service: Option<Eth1Service>,
6969
network_globals: Option<Arc<NetworkGlobals<T::EthSpec>>>,
7070
network_senders: Option<NetworkSenders<T::EthSpec>>,
71-
gossipsub_registry: Option<Registry>,
71+
libp2p_registry: Option<Registry>,
7272
db_path: Option<PathBuf>,
7373
freezer_db_path: Option<PathBuf>,
7474
http_api_config: http_api::Config,
@@ -102,7 +102,7 @@ where
102102
eth1_service: None,
103103
network_globals: None,
104104
network_senders: None,
105-
gossipsub_registry: None,
105+
libp2p_registry: None,
106106
db_path: None,
107107
freezer_db_path: None,
108108
http_api_config: <_>::default(),
@@ -531,7 +531,7 @@ where
531531
.ok_or("network requires beacon_processor_channels")?;
532532

533533
// If gossipsub metrics are required we build a registry to record them
534-
let mut gossipsub_registry = if config.metrics_enabled {
534+
let mut libp2p_registry = if config.metrics_enabled {
535535
Some(Registry::default())
536536
} else {
537537
None
@@ -541,9 +541,7 @@ where
541541
beacon_chain,
542542
config,
543543
context.executor,
544-
gossipsub_registry
545-
.as_mut()
546-
.map(|registry| registry.sub_registry_with_prefix("gossipsub")),
544+
libp2p_registry.as_mut(),
547545
beacon_processor_channels.beacon_processor_tx.clone(),
548546
beacon_processor_channels.work_reprocessing_tx.clone(),
549547
)
@@ -552,7 +550,7 @@ where
552550

553551
self.network_globals = Some(network_globals);
554552
self.network_senders = Some(network_senders);
555-
self.gossipsub_registry = gossipsub_registry;
553+
self.libp2p_registry = libp2p_registry;
556554

557555
Ok(self)
558556
}
@@ -718,7 +716,7 @@ where
718716
chain: self.beacon_chain.clone(),
719717
db_path: self.db_path.clone(),
720718
freezer_db_path: self.freezer_db_path.clone(),
721-
gossipsub_registry: self.gossipsub_registry.take().map(std::sync::Mutex::new),
719+
gossipsub_registry: self.libp2p_registry.take().map(std::sync::Mutex::new),
722720
log: log.clone(),
723721
});
724722

beacon_node/lighthouse_network/Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,16 @@ directory = { workspace = true }
3939
regex = { workspace = true }
4040
strum = { workspace = true }
4141
superstruct = { workspace = true }
42-
prometheus-client = "0.21.0"
42+
prometheus-client = "0.22.0"
4343
unused_port = { workspace = true }
4444
delay_map = { workspace = true }
4545
void = "1"
46-
libp2p-quic= { version = "0.9.2", features=["tokio"]}
47-
libp2p-mplex = "0.40.0"
46+
libp2p-mplex = "0.41.0"
4847

4948
[dependencies.libp2p]
50-
version = "0.52"
49+
version = "0.53"
5150
default-features = false
52-
features = ["identify", "yamux", "noise", "gossipsub", "dns", "tcp", "tokio", "plaintext", "secp256k1", "macros", "ecdsa"]
51+
features = ["identify", "yamux", "noise", "gossipsub", "dns", "tcp", "tokio", "plaintext", "secp256k1", "macros", "ecdsa", "metrics", "quic"]
5352

5453
[dev-dependencies]
5554
slog-term = { workspace = true }

beacon_node/lighthouse_network/src/config.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,6 @@ pub fn gossipsub_config(
455455
fork_context: Arc<ForkContext>,
456456
gossipsub_config_params: GossipsubConfigParams,
457457
) -> gossipsub::Config {
458-
// The function used to generate a gossipsub message id
459-
// We use the first 8 bytes of SHA256(topic, data) for content addressing
460-
let fast_gossip_message_id = |message: &gossipsub::RawMessage| {
461-
let data = [message.topic.as_str().as_bytes(), &message.data].concat();
462-
gossipsub::FastMessageId::from(&Sha256::digest(&data)[..8])
463-
};
464458
fn prefix(
465459
prefix: [u8; 4],
466460
message: &gossipsub::Message,
@@ -518,7 +512,6 @@ pub fn gossipsub_config(
518512
.validation_mode(gossipsub::ValidationMode::Anonymous)
519513
.duplicate_cache_time(DUPLICATE_CACHE_TIME)
520514
.message_id_fn(gossip_message_id)
521-
.fast_message_id_fn(fast_gossip_message_id)
522515
.allow_self_origin(true)
523516
.build()
524517
.expect("valid gossipsub configuration")

beacon_node/lighthouse_network/src/discovery/mod.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub use libp2p::{
2929
identity::PeerId,
3030
swarm::{
3131
dummy::ConnectionHandler, ConnectionId, DialError, NetworkBehaviour, NotifyHandler,
32-
PollParameters, SubstreamProtocol, ToSwarm,
32+
SubstreamProtocol, ToSwarm,
3333
},
3434
};
3535
use lru::LruCache;
@@ -955,11 +955,7 @@ impl<TSpec: EthSpec> NetworkBehaviour for Discovery<TSpec> {
955955
}
956956

957957
// Main execution loop to drive the behaviour
958-
fn poll(
959-
&mut self,
960-
cx: &mut Context,
961-
_: &mut impl PollParameters,
962-
) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
958+
fn poll(&mut self, cx: &mut Context) -> Poll<ToSwarm<Self::ToSwarm, THandlerInEvent<Self>>> {
963959
if !self.started {
964960
return Poll::Pending;
965961
}
@@ -1041,7 +1037,7 @@ impl<TSpec: EthSpec> NetworkBehaviour for Discovery<TSpec> {
10411037
Poll::Pending
10421038
}
10431039

1044-
fn on_swarm_event(&mut self, event: FromSwarm<Self::ConnectionHandler>) {
1040+
fn on_swarm_event(&mut self, event: FromSwarm) {
10451041
match event {
10461042
FromSwarm::DialFailure(DialFailure { peer_id, error, .. }) => {
10471043
self.on_dial_failure(peer_id, error)
@@ -1114,17 +1110,7 @@ impl<TSpec: EthSpec> NetworkBehaviour for Discovery<TSpec> {
11141110
Err(e) => warn!(self.log, "Failed to update ENR"; "error" => ?e),
11151111
}
11161112
}
1117-
FromSwarm::ConnectionEstablished(_)
1118-
| FromSwarm::ConnectionClosed(_)
1119-
| FromSwarm::AddressChange(_)
1120-
| FromSwarm::ListenFailure(_)
1121-
| FromSwarm::NewListener(_)
1122-
| FromSwarm::ExpiredListenAddr(_)
1123-
| FromSwarm::ListenerError(_)
1124-
| FromSwarm::ListenerClosed(_)
1125-
| FromSwarm::NewExternalAddrCandidate(_)
1126-
| FromSwarm::ExternalAddrExpired(_)
1127-
| FromSwarm::ExternalAddrConfirmed(_) => {
1113+
_ => {
11281114
// Ignore events not relevant to discovery
11291115
}
11301116
}

beacon_node/lighthouse_network/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ pub use config::Config as NetworkConfig;
115115
pub use discovery::{CombinedKeyExt, EnrExt, Eth2Enr};
116116
pub use discv5;
117117
pub use libp2p;
118-
pub use libp2p::bandwidth::BandwidthSinks;
119118
pub use libp2p::gossipsub::{IdentTopic, MessageAcceptance, MessageId, Topic, TopicHash};
120119
pub use libp2p::{core::ConnectedPoint, PeerId, Swarm};
121120
pub use libp2p::{multiaddr, Multiaddr};

beacon_node/lighthouse_network/src/metrics.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use libp2p::bandwidth::BandwidthSinks;
2-
use std::sync::Arc;
3-
41
pub use lighthouse_metrics::*;
52

63
lazy_static! {
@@ -187,46 +184,3 @@ pub fn scrape_discovery_metrics() {
187184
set_gauge(&DISCOVERY_SENT_BYTES, metrics.bytes_sent as i64);
188185
set_gauge(&DISCOVERY_RECV_BYTES, metrics.bytes_recv as i64);
189186
}
190-
191-
/// Aggregated `BandwidthSinks` of tcp and quic transports
192-
/// used in libp2p.
193-
pub struct AggregatedBandwidthSinks {
194-
tcp_sinks: Arc<BandwidthSinks>,
195-
quic_sinks: Option<Arc<BandwidthSinks>>,
196-
}
197-
198-
impl AggregatedBandwidthSinks {
199-
/// Create a new `AggregatedBandwidthSinks`.
200-
pub fn new(tcp_sinks: Arc<BandwidthSinks>, quic_sinks: Option<Arc<BandwidthSinks>>) -> Self {
201-
AggregatedBandwidthSinks {
202-
tcp_sinks,
203-
quic_sinks,
204-
}
205-
}
206-
207-
/// Total QUIC inbound bandwidth.
208-
pub fn total_quic_inbound(&self) -> u64 {
209-
self.quic_sinks
210-
.as_ref()
211-
.map(|q| q.total_inbound())
212-
.unwrap_or_default()
213-
}
214-
215-
/// Total TCP inbound bandwidth.
216-
pub fn total_tcp_inbound(&self) -> u64 {
217-
self.tcp_sinks.total_inbound()
218-
}
219-
220-
/// Total QUIC outbound bandwidth.
221-
pub fn total_quic_outbound(&self) -> u64 {
222-
self.quic_sinks
223-
.as_ref()
224-
.map(|q| q.total_outbound())
225-
.unwrap_or_default()
226-
}
227-
228-
/// Total TCP outbound bandwidth.
229-
pub fn total_tcp_outbound(&self) -> u64 {
230-
self.tcp_sinks.total_outbound()
231-
}
232-
}

beacon_node/lighthouse_network/src/peer_manager/network_behaviour.rs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use libp2p::identity::PeerId;
99
use libp2p::swarm::behaviour::{ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm};
1010
use libp2p::swarm::dial_opts::{DialOpts, PeerCondition};
1111
use libp2p::swarm::dummy::ConnectionHandler;
12-
use libp2p::swarm::{ConnectionDenied, ConnectionId, NetworkBehaviour, PollParameters, ToSwarm};
12+
use libp2p::swarm::{ConnectionDenied, ConnectionId, NetworkBehaviour, ToSwarm};
1313
use slog::{debug, error, trace};
1414
use types::EthSpec;
1515

@@ -36,11 +36,7 @@ impl<TSpec: EthSpec> NetworkBehaviour for PeerManager<TSpec> {
3636
// no events from the dummy handler
3737
}
3838

39-
fn poll(
40-
&mut self,
41-
cx: &mut Context<'_>,
42-
_params: &mut impl PollParameters,
43-
) -> Poll<ToSwarm<Self::ToSwarm, void::Void>> {
39+
fn poll(&mut self, cx: &mut Context<'_>) -> Poll<ToSwarm<Self::ToSwarm, void::Void>> {
4440
// perform the heartbeat when necessary
4541
while self.heartbeat.poll_tick(cx).is_ready() {
4642
self.heartbeat();
@@ -121,7 +117,7 @@ impl<TSpec: EthSpec> NetworkBehaviour for PeerManager<TSpec> {
121117
Poll::Pending
122118
}
123119

124-
fn on_swarm_event(&mut self, event: FromSwarm<Self::ConnectionHandler>) {
120+
fn on_swarm_event(&mut self, event: FromSwarm) {
125121
match event {
126122
FromSwarm::ConnectionEstablished(ConnectionEstablished {
127123
peer_id,
@@ -155,15 +151,9 @@ impl<TSpec: EthSpec> NetworkBehaviour for PeerManager<TSpec> {
155151
// TODO: we likely want to check this against our assumed external tcp
156152
// address
157153
}
158-
FromSwarm::AddressChange(_)
159-
| FromSwarm::ListenFailure(_)
160-
| FromSwarm::NewListener(_)
161-
| FromSwarm::NewListenAddr(_)
162-
| FromSwarm::ExpiredListenAddr(_)
163-
| FromSwarm::ListenerError(_)
164-
| FromSwarm::ListenerClosed(_)
165-
| FromSwarm::NewExternalAddrCandidate(_)
166-
| FromSwarm::ExternalAddrExpired(_) => {
154+
_ => {
155+
// NOTE: FromSwarm is a non exhaustive enum so updates should be based on release
156+
// notes more than compiler feedback
167157
// The rest of the events we ignore since they are handled in their associated
168158
// `SwarmEvent`
169159
}

0 commit comments

Comments
 (0)