Skip to content

Commit

Permalink
chore(node)!: Upgrade libp2p to 0.54.0 (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
oblique authored Aug 13, 2024
1 parent 1fa3cb3 commit 7bfe2fa
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 277 deletions.
194 changes: 133 additions & 61 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ resolver = "2"
members = ["cli", "node", "node-wasm", "proto", "rpc", "types"]

[workspace.dependencies]
blockstore = "0.5.0"
blockstore = "0.6.1"
lumina-node = { version = "0.2.0", path = "node" }
lumina-node-wasm = { version = "0.1.1", path = "node-wasm" }
celestia-proto = { version = "0.2.0", path = "proto" }
celestia-rpc = { version = "0.2.0", path = "rpc", default-features = false }
celestia-types = { version = "0.2.0", path = "types", default-features = false }
libp2p = "0.54"
libp2p = "0.54.0"
nmt-rs = "0.2.1"
celestia-tendermint = { version = "0.32.1", default-features = false }
celestia-tendermint-proto = "0.32.1"
Expand All @@ -24,10 +24,6 @@ celestia-tendermint-proto = "0.32.1"
#libp2p-core = { path = "../../rust-libp2p/core" }
#libp2p-swarm = { path = "../../rust-libp2p/swarm" }

libp2p = { git = "https://github.com/libp2p/rust-libp2p", rev = "60e32c9d3b4bee42ac698791e917e1587eaa1388" }
libp2p-core = { git = "https://github.com/libp2p/rust-libp2p", rev = "60e32c9d3b4bee42ac698791e917e1587eaa1388" }
libp2p-swarm = { git = "https://github.com/libp2p/rust-libp2p", rev = "60e32c9d3b4bee42ac698791e917e1587eaa1388" }

# Uncomment this if you need debug symbols in release.
# Also check node-wasm's `Cargo.toml`.
#[profile.release]
Expand Down
7 changes: 3 additions & 4 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ libp2p = { workspace = true, features = [
] }

async-trait = "0.1.80"
beetswap = "0.1.1"
beetswap = "0.3.1"
cid = { version = "0.11.1", features = ["serde-codec"] }
dashmap = "5.5.3"
futures = "0.3.30"
instant = "0.1.13"
prost = "0.12.6"
rand = "0.8.5"
serde = { version = "1.0.203", features = ["derive"] }
Expand Down Expand Up @@ -72,7 +71,7 @@ rustls-pki-types = "1.7.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
backoff = { version = "0.4.0", features = ["wasm-bindgen"] }
beetswap = { version = "0.1.1", features = ["wasm-bindgen"] }
beetswap = { version = "0.3.1", features = ["wasm-bindgen"] }
blockstore = { workspace = true, features = ["indexeddb"] }
celestia-types = { workspace = true, features = ["wasm-bindgen"] }
getrandom = { version = "0.2.15", features = ["js"] }
Expand All @@ -81,6 +80,7 @@ js-sys = "0.3.69"
libp2p = { workspace = true, features = [
"noise",
"wasm-bindgen",
"websocket-websys",
"webtransport-websys",
"yamux",
] }
Expand All @@ -90,7 +90,6 @@ send_wrapper = { version = "0.6.0", features = ["futures"] }
serde-wasm-bindgen = "0.6.5"
wasm-bindgen = "0.2.92"
wasm-bindgen-futures = "0.4.42"
libp2p-websocket-websys = "0.3.3"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
function_name = "0.3.0"
Expand Down
2 changes: 1 addition & 1 deletion node/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use std::fmt;
use std::panic::Location;
use std::time::Duration;

use instant::SystemTime;
use libp2p::PeerId;
use serde::Serialize;
use tokio::sync::broadcast;
use web_time::SystemTime;

const EVENT_CHANNEL_CAPACITY: usize = 1024;

Expand Down
3 changes: 2 additions & 1 deletion node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ where
let event_channel = EventChannel::new();
let event_sub = event_channel.subscribe();
let store = Arc::new(config.store);
let blockstore = Arc::new(config.blockstore);

let p2p = Arc::new(
P2p::start(P2pArgs {
network_id: config.network_id,
local_keypair: config.p2p_local_keypair,
bootnodes: config.p2p_bootnodes,
listen_on: config.p2p_listen_on,
blockstore: config.blockstore,
blockstore,
store: store.clone(),
event_pub: event_channel.publisher(),
})
Expand Down
25 changes: 13 additions & 12 deletions node/src/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ use tracing::{debug, error, info, instrument, trace, warn};

mod header_ex;
pub(crate) mod header_session;
mod kademlia;
pub(crate) mod shwap;
mod swarm;

Expand Down Expand Up @@ -193,7 +192,7 @@ where
/// List of the addresses on which to listen for incoming connections.
pub listen_on: Vec<Multiaddr>,
/// The store for headers.
pub blockstore: B,
pub blockstore: Arc<B>,
/// The store for headers.
pub store: Arc<S>,
/// Event publisher.
Expand Down Expand Up @@ -572,7 +571,7 @@ where
identify: identify::Behaviour,
header_ex: HeaderExBehaviour<S>,
gossipsub: gossipsub::Behaviour,
kademlia: kademlia::Behaviour,
kademlia: kad::Behaviour<kad::store::MemoryStore>,
}

struct Worker<B, S>
Expand Down Expand Up @@ -624,7 +623,11 @@ where
let gossipsub = init_gossipsub(&args, [&header_sub_topic, &bad_encoding_fraud_sub_topic])?;

let kademlia = init_kademlia(&args)?;
let bitswap = init_bitswap(args.blockstore, args.store.clone(), &args.network_id)?;
let bitswap = init_bitswap(
args.blockstore.clone(),
args.store.clone(),
&args.network_id,
)?;

let header_ex = HeaderExBehaviour::new(HeaderExConfig {
network_id: &args.network_id,
Expand Down Expand Up @@ -731,9 +734,6 @@ where
for (peer_id, addrs) in &self.bootnodes {
let dial_opts = DialOpts::peer_id(*peer_id)
.addresses(addrs.clone())
// Without this set, `kademlia::Behaviour` won't be able to canonicalize
// `/tls/ws` to `/wss`.
.extend_addresses_through_behaviour()
// Tell Swarm not to dial if peer is already connected or there
// is an ongoing dialing.
.condition(PeerCondition::DisconnectedAndNotDialing)
Expand Down Expand Up @@ -866,9 +866,9 @@ where
#[instrument(level = "trace", skip(self))]
async fn on_identify_event(&mut self, ev: identify::Event) -> Result<()> {
match ev {
identify::Event::Received { peer_id, info } => {
identify::Event::Received { peer_id, info, .. } => {
// Inform Kademlia about the listening addresses
// TODO: Remove this when rust-libp2p#4302 is implemented
// TODO: Remove this when rust-libp2p#5103 is implemented
for addr in info.listen_addrs {
self.swarm
.behaviour_mut()
Expand Down Expand Up @@ -1002,6 +1002,7 @@ where
ConnectedPoint::Dialer {
address,
role_override: Endpoint::Dialer,
..
} => Some(address),
_ => None,
};
Expand Down Expand Up @@ -1173,7 +1174,7 @@ where
Ok(gossipsub)
}

fn init_kademlia<B, S>(args: &P2pArgs<B, S>) -> Result<kademlia::Behaviour>
fn init_kademlia<B, S>(args: &P2pArgs<B, S>) -> Result<kad::Behaviour<kad::store::MemoryStore>>
where
B: Blockstore,
S: Store,
Expand All @@ -1196,11 +1197,11 @@ where
kademlia.set_mode(Some(kad::Mode::Server));
}

Ok(kademlia::Behaviour::new(kademlia))
Ok(kademlia)
}

fn init_bitswap<B, S>(
blockstore: B,
blockstore: Arc<B>,
store: Arc<S>,
network_id: &str,
) -> Result<beetswap::Behaviour<MAX_MH_SIZE, B>>
Expand Down
10 changes: 9 additions & 1 deletion node/src/p2p/header_ex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use async_trait::async_trait;
use celestia_proto::p2p::pb::{HeaderRequest, HeaderResponse};
use celestia_types::ExtendedHeader;
use futures::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
use libp2p::core::transport::PortUse;
use libp2p::{
core::Endpoint,
request_response::{self, Codec, InboundFailure, OutboundFailure, ProtocolSupport},
Expand Down Expand Up @@ -211,9 +212,16 @@ where
peer: PeerId,
addr: &Multiaddr,
role_override: Endpoint,
port_use: PortUse,
) -> Result<Self::ConnectionHandler, ConnectionDenied> {
self.req_resp
.handle_established_outbound_connection(connection_id, peer, addr, role_override)
.handle_established_outbound_connection(
connection_id,
peer,
addr,
role_override,
port_use,
)
.map(ConnHandler)
}

Expand Down
Loading

0 comments on commit 7bfe2fa

Please sign in to comment.