Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Upgrade to libp2p 0.51.3 #13587

Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
1f838db
client/network: upgrade to libp2p 0.51.0
melekes Mar 6, 2023
a96ec02
make discovery.rs compile
melekes Mar 13, 2023
1feeea5
make peer_info.rs compile
melekes Mar 13, 2023
7f5bd59
changes to notifications and request-response proto
melekes Mar 14, 2023
6fa1fec
make service.rs compile
melekes Mar 14, 2023
84fa16e
towards making request_responses.rs compile
melekes Mar 14, 2023
b469184
make request_responses.rs compile
melekes Mar 15, 2023
82381e7
make request_responses.rs compile
melekes Mar 15, 2023
5d47761
fix notifications/behaviour.rs tests
melekes Mar 15, 2023
683f7d0
fix warnings
melekes Mar 15, 2023
88faef0
remove old code
melekes Mar 16, 2023
0e4e650
allow deprecated code (temporary)
melekes Mar 16, 2023
44734ce
upgrade to libp2p 0.51.1
melekes Mar 23, 2023
38db38c
add TODO for behaviour tests
melekes Mar 23, 2023
a02f891
return empty vec if peer_id is absent
melekes Mar 23, 2023
dfd5c3e
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes Mar 24, 2023
7a981ab
update comment to reflect new defaults
melekes Mar 27, 2023
943c031
Revert "update comment to reflect new defaults"
melekes Mar 28, 2023
17365d1
remove config.rs (from wrong merge)
melekes Mar 29, 2023
6b87f23
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes Mar 30, 2023
4fc9c96
upgrade to libp2p 0.51.2
melekes Mar 30, 2023
fd6429d
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes Mar 30, 2023
890ce96
fix formatting
melekes Mar 31, 2023
df205b6
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes Mar 31, 2023
c1cf2e8
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes Apr 3, 2023
31f5653
use handle_pending_outbound_connection in networt_state RPC
melekes Apr 3, 2023
ae2c0c4
update deps
melekes Apr 3, 2023
3f0ca7e
use re-exports when we use other libp2p packages
melekes Apr 3, 2023
83f5373
Apply suggestions from code review
melekes Apr 3, 2023
854509b
format code
melekes Apr 3, 2023
3a865c5
handle potential errors in network_state RPC
melekes Apr 3, 2023
7571f9d
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes Apr 3, 2023
9a8861f
only update libp2p crate
melekes Apr 3, 2023
8ee6f65
update libp2p-core
melekes Apr 4, 2023
29caff6
fix docs
melekes Apr 4, 2023
c69c0a6
use libp2p-identity instead of libp2p
melekes Apr 4, 2023
866d522
Update client/network/src/discovery.rs
melekes Apr 5, 2023
a3c9038
Merge remote-tracking branch 'origin/master' into anton/13537-upgrade…
Apr 5, 2023
1068d77
Merge remote-tracking branch 'origin/master' into anton/13537-upgrade…
Apr 6, 2023
724188d
update Cargo.lock
melekes Apr 6, 2023
60e1634
add comment for per_connection_event_buffer_size
melekes Apr 6, 2023
bb1b5db
fix link format
melekes Apr 6, 2023
f5a2828
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes Apr 7, 2023
b3d43e3
update Cargo.lock
melekes Apr 7, 2023
b675df1
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes May 3, 2023
6544dd4
upgrade to libp2p 0.51.3
melekes May 4, 2023
9e25820
deprecate mplex
melekes May 4, 2023
39ffe48
Revert "deprecate mplex"
melekes May 4, 2023
0bf1bfa
Revert "upgrade to libp2p 0.51.3"
melekes May 4, 2023
3c69044
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes May 5, 2023
979d076
use new libp2p version in `statement` crate
melekes May 5, 2023
82b3956
pin version temporarily
melekes May 6, 2023
90691b9
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes May 6, 2023
1c35b82
libp2p 0.51.3
melekes May 6, 2023
7c7ff40
deprecate mplex
melekes May 6, 2023
bb161c7
Merge branch 'master' into anton/13537-upgrade-to-libp2p-0.51.0
melekes May 11, 2023
0630e6d
deprecate legacy noise handshake
melekes May 11, 2023
5551d23
fix build error
melekes May 11, 2023
97e75cf
update libp2p-identity
melekes May 11, 2023
a7a5b8e
enable libp2p-identity:ed25519 feature in sc-consensus
melekes May 11, 2023
0a0defc
enable ed25519 for peerset as well
melekes May 12, 2023
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
373 changes: 166 additions & 207 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/authority-discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ codec = { package = "parity-scale-codec", version = "3.2.2", default-features =
futures = "0.3.21"
futures-timer = "3.0.1"
ip_network = "0.4.1"
libp2p = { version = "0.50.0", features = ["kad"] }
libp2p = { version = "0.51.3", features = ["kad", "ed25519"] }
log = "0.4.17"
prost = "0.11"
rand = "0.8.5"
Expand Down
2 changes: 1 addition & 1 deletion client/authority-discovery/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub enum Error {
ParsingMultiaddress(#[from] libp2p::core::multiaddr::Error),

#[error("Failed to parse a libp2p key.")]
ParsingLibp2pIdentity(#[from] libp2p::identity::error::DecodingError),
ParsingLibp2pIdentity(#[from] libp2p::identity::DecodingError),

#[error("Failed to sign: {0}.")]
CannotSign(String),
Expand Down
17 changes: 8 additions & 9 deletions client/authority-discovery/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ use crate::{
};

use futures::{channel::mpsc::channel, executor::LocalPool, task::LocalSpawn};
use libp2p::core::{
multiaddr::{Multiaddr, Protocol},
use libp2p::{
core::multiaddr::{Multiaddr, Protocol},
identity::ed25519,
PeerId,
};
use std::{collections::HashSet, sync::Arc};
Expand Down Expand Up @@ -86,18 +87,16 @@ fn get_addresses_and_authority_id() {
fn cryptos_are_compatible() {
use sp_core::crypto::Pair;

let libp2p_secret = libp2p::identity::Keypair::generate_ed25519();
let libp2p_public = libp2p_secret.public();
let libp2p_keypair = ed25519::Keypair::generate();
let libp2p_public = libp2p_keypair.public();

let sp_core_secret = {
let libp2p::identity::Keypair::Ed25519(libp2p_ed_secret) = libp2p_secret.clone();
sp_core::ed25519::Pair::from_seed_slice(&libp2p_ed_secret.secret().as_ref()).unwrap()
};
let sp_core_secret =
{ sp_core::ed25519::Pair::from_seed_slice(&libp2p_keypair.secret().as_ref()).unwrap() };
let sp_core_public = sp_core_secret.public();

let message = b"we are more powerful than not to be better";

let libp2p_signature = libp2p_secret.sign(message).unwrap();
let libp2p_signature = libp2p_keypair.sign(message);
let sp_core_signature = sp_core_secret.sign(message); // no error expected...

assert!(sp_core::ed25519::Pair::verify(
Expand Down
8 changes: 4 additions & 4 deletions client/authority-discovery/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ use codec::{Decode, Encode};
use ip_network::IpNetwork;
use libp2p::{
core::multiaddr,
identity::PublicKey,
multihash::{Multihash, MultihashDigest},
Multiaddr, PeerId,
};

use log::{debug, error, log_enabled};
use prometheus_endpoint::{register, Counter, CounterVec, Gauge, Opts, U64};
use prost::Message;
Expand Down Expand Up @@ -551,10 +553,8 @@ where
// properly signed by the owner of the PeerId

if let Some(peer_signature) = peer_signature {
let public_key = libp2p::identity::PublicKey::from_protobuf_encoding(
&peer_signature.public_key,
)
.map_err(Error::ParsingLibp2pIdentity)?;
let public_key = PublicKey::from_protobuf_encoding(&peer_signature.public_key)
.map_err(Error::ParsingLibp2pIdentity)?;
let signature = Signature { public_key, bytes: peer_signature.signature };

if !signature.verify(record, &remote_peer_id) {
Expand Down
4 changes: 2 additions & 2 deletions client/authority-discovery/src/worker/schema/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod schema_v1 {
}

use super::*;
use libp2p::{multiaddr::Multiaddr, PeerId};
use libp2p::{identity::Keypair, multiaddr::Multiaddr, PeerId};
use prost::Message;

#[test]
Expand Down Expand Up @@ -55,7 +55,7 @@ fn v2_decodes_v1() {

#[test]
fn v1_decodes_v2() {
let peer_secret = libp2p::identity::Keypair::generate_ed25519();
let peer_secret = Keypair::generate_ed25519();
let peer_public = peer_secret.public();
let peer_id = peer_public.to_peer_id();
let multiaddress: Multiaddr =
Expand Down
2 changes: 1 addition & 1 deletion client/authority-discovery/src/worker/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use futures::{
};
use libp2p::{
core::multiaddr,
identity::{error::SigningError, Keypair},
identity::{Keypair, SigningError},
kad::record::Key as KademliaKey,
PeerId,
};
Expand Down
2 changes: 1 addition & 1 deletion client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ chrono = "0.4.10"
clap = { version = "4.2.5", features = ["derive", "string"] }
fdlimit = "0.2.1"
futures = "0.3.21"
libp2p = "0.50.0"
libp2p-identity = { version = "0.1.0", features = ["peerid", "ed25519"]}
log = "0.4.17"
names = { version = "0.13.0", default-features = false }
parity-scale-codec = "3.2.2"
Expand Down
6 changes: 3 additions & 3 deletions client/cli/src/commands/generate_node_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use crate::Error;
use clap::Parser;
use libp2p::identity::{ed25519 as libp2p_ed25519, PublicKey};
use libp2p_identity::{ed25519, Keypair};
use std::{
fs,
io::{self, Write},
Expand Down Expand Up @@ -48,7 +48,7 @@ pub struct GenerateNodeKeyCmd {
impl GenerateNodeKeyCmd {
/// Run the command
pub fn run(&self) -> Result<(), Error> {
let keypair = libp2p_ed25519::Keypair::generate();
let keypair = ed25519::Keypair::generate();

let secret = keypair.secret();

Expand All @@ -63,7 +63,7 @@ impl GenerateNodeKeyCmd {
None => io::stdout().lock().write_all(&file_data)?,
}

eprintln!("{}", PublicKey::Ed25519(keypair.public()).to_peer_id());
eprintln!("{}", Keypair::from(keypair).public().to_peer_id());

Ok(())
}
Expand Down
10 changes: 4 additions & 6 deletions client/cli/src/commands/inspect_node_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use crate::Error;
use clap::Parser;
use libp2p::identity::{ed25519, PublicKey};
use libp2p_identity::Keypair;
use std::{
fs,
io::{self, Read},
Expand Down Expand Up @@ -68,12 +68,10 @@ impl InspectNodeKeyCmd {
.map_err(|_| "failed to decode secret as hex")?;
}

let secret =
ed25519::SecretKey::from_bytes(&mut file_data).map_err(|_| "Bad node key file")?;
let keypair =
Keypair::ed25519_from_bytes(&mut file_data).map_err(|_| "Bad node key file")?;

let keypair = ed25519::Keypair::from(secret);

println!("{}", PublicKey::Ed25519(keypair.public()).to_peer_id());
println!("{}", keypair.public().to_peer_id());

Ok(())
}
Expand Down
11 changes: 7 additions & 4 deletions client/cli/src/params/node_key_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn parse_ed25519_secret(hex: &str) -> error::Result<sc_network::config::Ed25519S
mod tests {
use super::*;
use clap::ValueEnum;
use sc_network::config::identity::{ed25519, Keypair};
use libp2p_identity::ed25519;
use std::fs;

#[test]
Expand Down Expand Up @@ -154,9 +154,12 @@ mod tests {
.into_keypair()
.expect("Creates node key pair");

match node_key {
Keypair::Ed25519(ref pair) if pair.secret().as_ref() == key.as_ref() => {},
_ => panic!("Invalid key"),
if let Some(pair) = node_key.into_ed25519() {
if pair.secret().as_ref() != key.as_ref() {
panic!("Invalid key")
}
} else {
panic!("Invalid key")
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/consensus/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
async-trait = "0.1.57"
futures = { version = "0.3.21", features = ["thread-pool"] }
futures-timer = "3.0.1"
libp2p = "0.50.0"
libp2p-identity = { version = "0.1", features = ["peerid"] }
log = "0.4.17"
mockall = "0.11.3"
parking_lot = "0.12.1"
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/common/src/import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub type BoxJustificationImport<B> =
Box<dyn JustificationImport<B, Error = ConsensusError> + Send + Sync>;

/// Maps to the RuntimeOrigin used by the network.
pub type RuntimeOrigin = libp2p::PeerId;
pub type RuntimeOrigin = libp2p_identity::PeerId;

/// Block data used by the queue.
#[derive(Debug, PartialEq, Eq, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/common/src/import_queue/basic_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ mod tests {
let hash = Hash::random();
finality_sender
.unbounded_send(worker_messages::ImportJustification(
libp2p::PeerId::random(),
libp2p_identity::PeerId::random(),
hash,
1,
(*b"TEST", Vec::new()),
Expand Down
2 changes: 1 addition & 1 deletion client/network-gossip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ targets = ["x86_64-unknown-linux-gnu"]
ahash = "0.8.2"
futures = "0.3.21"
futures-timer = "3.0.1"
libp2p = "0.50.0"
libp2p = "0.51.3"
log = "0.4.17"
lru = "0.8.1"
tracing = "0.1.29"
Expand Down
2 changes: 1 addition & 1 deletion client/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fnv = "1.0.6"
futures = "0.3.21"
futures-timer = "3.0.2"
ip_network = "0.4.1"
libp2p = { version = "0.50.0", features = ["dns", "identify", "kad", "macros", "mdns", "mplex", "noise", "ping", "tcp", "tokio", "yamux", "websocket"] }
libp2p = { version = "0.51.3", features = ["dns", "identify", "kad", "macros", "mdns", "noise", "ping", "tcp", "tokio", "yamux", "websocket", "request-response"] }
linked_hash_set = "0.1.3"
log = "0.4.17"
lru = "0.8.1"
Expand Down
2 changes: 0 additions & 2 deletions client/network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ negotiated and applied. The exact handshake protocol is experimental and is subj

The following multiplexing protocols are supported:

- [Mplex](https://github.com/libp2p/specs/tree/master/mplex). Support for mplex will likely
be deprecated in the future.
- [Yamux](https://github.com/hashicorp/yamux/blob/master/spec.md).

## Substreams
Expand Down
2 changes: 1 addition & 1 deletion client/network/bitswap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ prost-build = "0.11"
[dependencies]
cid = "0.8.6"
futures = "0.3.21"
libp2p = "0.50.0"
libp2p-identity = { version = "0.1.0", features = ["peerid"] }
log = "0.4.17"
prost = "0.11"
thiserror = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion client/network/bitswap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

use cid::{self, Version};
use futures::{channel::mpsc, StreamExt};
use libp2p::core::PeerId;
use libp2p_identity::PeerId;
use log::{debug, error, trace};
use prost::Message;
use sc_client_api::BlockBackend;
Expand Down
2 changes: 1 addition & 1 deletion client/network/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ codec = { package = "parity-scale-codec", version = "3.2.2", features = [
] }
futures = "0.3.21"
futures-timer = "3.0.2"
libp2p = { version = "0.50.0", features = ["request-response", "kad"] }
libp2p-identity = { version = "0.1", features = ["peerid"] }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.10.0-dev", path = "../../../utils/prometheus" }
smallvec = "1.8.0"
sc-consensus = { version = "0.10.0-dev", path = "../../consensus/common" }
Expand Down
2 changes: 1 addition & 1 deletion client/network/common/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub mod warp;
use crate::role::Roles;
use futures::Stream;

use libp2p::PeerId;
use libp2p_identity::PeerId;

use message::{BlockAnnounce, BlockData, BlockRequest, BlockResponse};
use sc_consensus::{import_queue::RuntimeOrigin, IncomingBlock};
Expand Down
2 changes: 1 addition & 1 deletion client/network/light/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ codec = { package = "parity-scale-codec", version = "3.2.2", features = [
"derive",
] }
futures = "0.3.21"
libp2p = "0.50.0"
libp2p-identity = { version = "0.1", features = ["peerid"] }
log = "0.4.16"
prost = "0.11"
sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" }
Expand Down
2 changes: 1 addition & 1 deletion client/network/light/src/light_client_requests/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use crate::schema;
use codec::{self, Decode, Encode};
use futures::{channel::mpsc, prelude::*};
use libp2p::PeerId;
use libp2p_identity::PeerId;
use log::{debug, trace};
use prost::Message;
use sc_client_api::{BlockBackend, ProofProvider};
Expand Down
6 changes: 2 additions & 4 deletions client/network/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ use crate::{
use bytes::Bytes;
use futures::channel::oneshot;
use libp2p::{
core::{Multiaddr, PeerId, PublicKey},
identify::Info as IdentifyInfo,
kad::record,
swarm::NetworkBehaviour,
core::Multiaddr, identify::Info as IdentifyInfo, identity::PublicKey, kad::record,
swarm::NetworkBehaviour, PeerId,
};

use sc_network_common::role::{ObservedRole, Roles};
Expand Down
24 changes: 15 additions & 9 deletions client/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ pub use crate::{
types::ProtocolName,
};

pub use libp2p::{identity::Keypair, multiaddr, Multiaddr, PeerId};

use codec::Encode;
use libp2p::{identity::Keypair, multiaddr, Multiaddr, PeerId};
use prometheus_endpoint::Registry;
pub use sc_network_common::{
role::{Role, Roles},
Expand Down Expand Up @@ -366,7 +367,7 @@ impl NodeKeyConfig {
match self {
Ed25519(Secret::New) => Ok(Keypair::generate_ed25519()),

Ed25519(Secret::Input(k)) => Ok(Keypair::Ed25519(k.into())),
Ed25519(Secret::Input(k)) => Ok(ed25519::Keypair::from(k).into()),

Ed25519(Secret::File(f)) => get_secret(
f,
Expand All @@ -384,7 +385,7 @@ impl NodeKeyConfig {
|b| b.as_ref().to_vec(),
)
.map(ed25519::Keypair::from)
.map(Keypair::Ed25519),
.map(Keypair::from),
}
}
}
Expand Down Expand Up @@ -741,9 +742,14 @@ mod tests {
tempfile::Builder::new().prefix(prefix).tempdir().unwrap()
}

fn secret_bytes(kp: &Keypair) -> Vec<u8> {
let Keypair::Ed25519(p) = kp;
p.secret().as_ref().iter().cloned().collect()
fn secret_bytes(kp: Keypair) -> Vec<u8> {
kp.into_ed25519()
.expect("ed25519 keypair")
.secret()
.as_ref()
.iter()
.cloned()
.collect()
}

#[test]
Expand All @@ -753,21 +759,21 @@ mod tests {
let file = tmp.path().join("x").to_path_buf();
let kp1 = NodeKeyConfig::Ed25519(Secret::File(file.clone())).into_keypair().unwrap();
let kp2 = NodeKeyConfig::Ed25519(Secret::File(file.clone())).into_keypair().unwrap();
assert!(file.is_file() && secret_bytes(&kp1) == secret_bytes(&kp2))
assert!(file.is_file() && secret_bytes(kp1) == secret_bytes(kp2))
}

#[test]
fn test_secret_input() {
let sk = ed25519::SecretKey::generate();
let kp1 = NodeKeyConfig::Ed25519(Secret::Input(sk.clone())).into_keypair().unwrap();
let kp2 = NodeKeyConfig::Ed25519(Secret::Input(sk)).into_keypair().unwrap();
assert!(secret_bytes(&kp1) == secret_bytes(&kp2));
assert!(secret_bytes(kp1) == secret_bytes(kp2));
}

#[test]
fn test_secret_new() {
let kp1 = NodeKeyConfig::Ed25519(Secret::New).into_keypair().unwrap();
let kp2 = NodeKeyConfig::Ed25519(Secret::New).into_keypair().unwrap();
assert!(secret_bytes(&kp1) != secret_bytes(&kp2));
assert!(secret_bytes(kp1) != secret_bytes(kp2));
}
}
Loading