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

Commit bcf40a0

Browse files
melekesdmitry-markinaltonen
authored andcommitted
Upgrade to libp2p 0.51.3 (#13587)
* client/network: upgrade to libp2p 0.51.0 * make discovery.rs compile * make peer_info.rs compile * changes to notifications and request-response proto * make service.rs compile * towards making request_responses.rs compile * make request_responses.rs compile * make request_responses.rs compile * fix notifications/behaviour.rs tests * fix warnings * remove old code * allow deprecated code (temporary) * upgrade to libp2p 0.51.1 * add TODO for behaviour tests * return empty vec if peer_id is absent #13587 (comment) fyi: I don't really know what the old behaviour was. * update comment to reflect new defaults Closes #13338 * Revert "update comment to reflect new defaults" This reverts commit 7a981ab. * remove config.rs (from wrong merge) * upgrade to libp2p 0.51.2 * fix formatting * use handle_pending_outbound_connection in networt_state RPC * update deps * use re-exports when we use other libp2p packages * Apply suggestions from code review Co-authored-by: Dmitry Markin <[email protected]> * format code * handle potential errors in network_state RPC * only update libp2p crate * update libp2p-core * fix docs * use libp2p-identity instead of libp2p where it's possible. libp2p-identity is much smaller, hence makes sense to use it instead of larger libp2p crate. * Update client/network/src/discovery.rs Co-authored-by: Aaro Altonen <[email protected]> * update Cargo.lock * add comment for per_connection_event_buffer_size current value is somewhat arbitrary and needs to be tweaked depending on memory usage and network worker sleep stats. * fix link format * update Cargo.lock * upgrade to libp2p 0.51.3 * deprecate mplex * Revert "deprecate mplex" This reverts commit 9e25820. * Revert "upgrade to libp2p 0.51.3" This reverts commit 6544dd4. * use new libp2p version in `statement` crate * pin version temporarily * libp2p 0.51.3 * deprecate mplex * deprecate legacy noise handshake * fix build error * update libp2p-identity * enable libp2p-identity:ed25519 feature in sc-consensus * enable ed25519 for peerset as well --------- Co-authored-by: Dmitry Markin <[email protected]> Co-authored-by: Aaro Altonen <[email protected]> Co-authored-by: parity-processbot <>
1 parent 657ac6e commit bcf40a0

File tree

48 files changed

+1002
-924
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1002
-924
lines changed

Cargo.lock

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

client/authority-discovery/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ codec = { package = "parity-scale-codec", version = "3.2.2", default-features =
2121
futures = "0.3.21"
2222
futures-timer = "3.0.1"
2323
ip_network = "0.4.1"
24-
libp2p = { version = "0.50.0", features = ["kad"] }
24+
libp2p = { version = "0.51.3", features = ["kad", "ed25519"] }
25+
multihash = { version = "0.17.0", default-features = false, features = ["std", "sha2"] }
2526
log = "0.4.17"
2627
prost = "0.11"
2728
rand = "0.8.5"

client/authority-discovery/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub enum Error {
5656
ParsingMultiaddress(#[from] libp2p::core::multiaddr::Error),
5757

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

6161
#[error("Failed to sign: {0}.")]
6262
CannotSign(String),

client/authority-discovery/src/tests.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ use crate::{
2525
};
2626

2727
use futures::{channel::mpsc::channel, executor::LocalPool, task::LocalSpawn};
28-
use libp2p::core::{
29-
multiaddr::{Multiaddr, Protocol},
28+
use libp2p::{
29+
core::multiaddr::{Multiaddr, Protocol},
30+
identity::ed25519,
3031
PeerId,
3132
};
3233
use std::{collections::HashSet, sync::Arc};
@@ -86,18 +87,16 @@ fn get_addresses_and_authority_id() {
8687
fn cryptos_are_compatible() {
8788
use sp_core::crypto::Pair;
8889

89-
let libp2p_secret = libp2p::identity::Keypair::generate_ed25519();
90-
let libp2p_public = libp2p_secret.public();
90+
let libp2p_keypair = ed25519::Keypair::generate();
91+
let libp2p_public = libp2p_keypair.public();
9192

92-
let sp_core_secret = {
93-
let libp2p::identity::Keypair::Ed25519(libp2p_ed_secret) = libp2p_secret.clone();
94-
sp_core::ed25519::Pair::from_seed_slice(&libp2p_ed_secret.secret().as_ref()).unwrap()
95-
};
93+
let sp_core_secret =
94+
{ sp_core::ed25519::Pair::from_seed_slice(&libp2p_keypair.secret().as_ref()).unwrap() };
9695
let sp_core_public = sp_core_secret.public();
9796

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

100-
let libp2p_signature = libp2p_secret.sign(message).unwrap();
99+
let libp2p_signature = libp2p_keypair.sign(message);
101100
let sp_core_signature = sp_core_secret.sign(message); // no error expected...
102101

103102
assert!(sp_core::ed25519::Pair::verify(

client/authority-discovery/src/worker.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ use futures::{channel::mpsc, future, stream::Fuse, FutureExt, Stream, StreamExt}
3434
use addr_cache::AddrCache;
3535
use codec::{Decode, Encode};
3636
use ip_network::IpNetwork;
37-
use libp2p::{
38-
core::multiaddr,
39-
multihash::{Multihash, MultihashDigest},
40-
Multiaddr, PeerId,
41-
};
37+
use libp2p::{core::multiaddr, identity::PublicKey, multihash::Multihash, Multiaddr, PeerId};
38+
use multihash::{Code, MultihashDigest};
39+
4240
use log::{debug, error, log_enabled};
4341
use prometheus_endpoint::{register, Counter, CounterVec, Gauge, Opts, U64};
4442
use prost::Message;
@@ -551,10 +549,8 @@ where
551549
// properly signed by the owner of the PeerId
552550

553551
if let Some(peer_signature) = peer_signature {
554-
let public_key = libp2p::identity::PublicKey::from_protobuf_encoding(
555-
&peer_signature.public_key,
556-
)
557-
.map_err(Error::ParsingLibp2pIdentity)?;
552+
let public_key = PublicKey::try_decode_protobuf(&peer_signature.public_key)
553+
.map_err(Error::ParsingLibp2pIdentity)?;
558554
let signature = Signature { public_key, bytes: peer_signature.signature };
559555

560556
if !signature.verify(record, &remote_peer_id) {
@@ -625,7 +621,7 @@ pub trait NetworkProvider: NetworkDHTProvider + NetworkStateInfo + NetworkSigner
625621
impl<T> NetworkProvider for T where T: NetworkDHTProvider + NetworkStateInfo + NetworkSigner {}
626622

627623
fn hash_authority_id(id: &[u8]) -> KademliaKey {
628-
KademliaKey::new(&libp2p::multihash::Code::Sha2_256.digest(id).digest())
624+
KademliaKey::new(&Code::Sha2_256.digest(id).digest())
629625
}
630626

631627
// Makes sure all values are the same and returns it
@@ -662,7 +658,7 @@ fn sign_record_with_peer_id(
662658
let signature = network
663659
.sign_with_local_identity(serialized_record)
664660
.map_err(|e| Error::CannotSign(format!("{} (network packet)", e)))?;
665-
let public_key = signature.public_key.to_protobuf_encoding();
661+
let public_key = signature.public_key.encode_protobuf();
666662
let signature = signature.bytes;
667663
Ok(schema::PeerSignature { signature, public_key })
668664
}

client/authority-discovery/src/worker/schema/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod schema_v1 {
2121
}
2222

2323
use super::*;
24-
use libp2p::{multiaddr::Multiaddr, PeerId};
24+
use libp2p::{identity::Keypair, multiaddr::Multiaddr, PeerId};
2525
use prost::Message;
2626

2727
#[test]
@@ -55,7 +55,7 @@ fn v2_decodes_v1() {
5555

5656
#[test]
5757
fn v1_decodes_v2() {
58-
let peer_secret = libp2p::identity::Keypair::generate_ed25519();
58+
let peer_secret = Keypair::generate_ed25519();
5959
let peer_public = peer_secret.public();
6060
let peer_id = peer_public.to_peer_id();
6161
let multiaddress: Multiaddr =
@@ -67,7 +67,7 @@ fn v1_decodes_v2() {
6767
let record_v2 = AuthorityRecord { addresses: vec_addresses.clone() };
6868
let mut vec_record_v2 = vec![];
6969
record_v2.encode(&mut vec_record_v2).unwrap();
70-
let vec_peer_public = peer_public.to_protobuf_encoding();
70+
let vec_peer_public = peer_public.encode_protobuf();
7171
let peer_signature_v2 =
7272
PeerSignature { public_key: vec_peer_public, signature: vec_peer_signature };
7373
let signed_record_v2 = SignedAuthorityRecord {

client/authority-discovery/src/worker/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use futures::{
3131
};
3232
use libp2p::{
3333
core::multiaddr,
34-
identity::{error::SigningError, Keypair},
34+
identity::{Keypair, SigningError},
3535
kad::record::Key as KademliaKey,
3636
PeerId,
3737
};

client/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ chrono = "0.4.10"
1818
clap = { version = "4.2.5", features = ["derive", "string"] }
1919
fdlimit = "0.2.1"
2020
futures = "0.3.21"
21-
libp2p = "0.50.0"
21+
libp2p-identity = { version = "0.1.2", features = ["peerid", "ed25519"]}
2222
log = "0.4.17"
2323
names = { version = "0.13.0", default-features = false }
2424
parity-scale-codec = "3.2.2"

client/cli/src/commands/generate_node_key.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
use crate::Error;
2121
use clap::Parser;
22-
use libp2p::identity::{ed25519 as libp2p_ed25519, PublicKey};
22+
use libp2p_identity::{ed25519, Keypair};
2323
use std::{
2424
fs,
2525
io::{self, Write},
@@ -48,7 +48,7 @@ pub struct GenerateNodeKeyCmd {
4848
impl GenerateNodeKeyCmd {
4949
/// Run the command
5050
pub fn run(&self) -> Result<(), Error> {
51-
let keypair = libp2p_ed25519::Keypair::generate();
51+
let keypair = ed25519::Keypair::generate();
5252

5353
let secret = keypair.secret();
5454

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

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

6868
Ok(())
6969
}

client/cli/src/commands/inspect_node_key.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
use crate::Error;
2121
use clap::Parser;
22-
use libp2p::identity::{ed25519, PublicKey};
22+
use libp2p_identity::Keypair;
2323
use std::{
2424
fs,
2525
io::{self, Read},
@@ -68,12 +68,10 @@ impl InspectNodeKeyCmd {
6868
.map_err(|_| "failed to decode secret as hex")?;
6969
}
7070

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

74-
let keypair = ed25519::Keypair::from(secret);
75-
76-
println!("{}", PublicKey::Ed25519(keypair.public()).to_peer_id());
74+
println!("{}", keypair.public().to_peer_id());
7775

7876
Ok(())
7977
}

0 commit comments

Comments
 (0)