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

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 10233
Browse files Browse the repository at this point in the history
  • Loading branch information
gui1117 committed Dec 7, 2021
2 parents b7e8047 + 264da3b commit da0f59f
Show file tree
Hide file tree
Showing 21 changed files with 765 additions and 228 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions client/api/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ pub trait Finalizer<Block: BlockT, B: Backend<Block>> {
}

/// Provides access to an auxiliary database.
///
/// This is a simple global database not aware of forks. Can be used for storing auxiliary
/// information like total block weight/difficulty for fork resolution purposes as a common use
/// case.
pub trait AuxStore {
/// Insert auxiliary data into key-value store.
///
Expand Down
4 changes: 2 additions & 2 deletions client/authority-discovery/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Substrate authority discovery.
# Substrate authority discovery

This crate enables Substrate authorities to discover and directly connect to
other authorities. It is split into two components the [`Worker`] and the
[`Service`].

See [`Worker`] and [`Service`] for more documentation.

License: GPL-3.0-or-later WITH Classpath-exception-2.0
License: GPL-3.0-or-later WITH Classpath-exception-2.0
6 changes: 5 additions & 1 deletion client/authority-discovery/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
fn main() {
prost_build::compile_protos(&["src/worker/schema/dht.proto"], &["src/worker/schema"]).unwrap();
prost_build::compile_protos(
&["src/worker/schema/dht-v1.proto", "src/worker/schema/dht-v2.proto"],
&["src/worker/schema"],
)
.unwrap();
}
8 changes: 8 additions & 0 deletions client/authority-discovery/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ pub enum Error {
EncodingDecodingScale(codec::Error),
/// Failed to parse a libp2p multi address.
ParsingMultiaddress(libp2p::core::multiaddr::Error),
/// Failed to parse a libp2p key.
ParsingLibp2pIdentity(sc_network::DecodingError),
/// Failed to sign using a specific public key.
MissingSignature(CryptoTypePublicPair),
/// Failed to sign using all public keys.
Signing,
/// Failed to register Prometheus metric.
Prometheus(prometheus_endpoint::PrometheusError),
/// Received authority record that contains addresses with multiple peer ids
ReceivingDhtValueFoundEventWithDifferentPeerIds,
/// Received authority record without any addresses having a peer id
ReceivingDhtValueFoundEventWithNoPeerIds,
/// Received authority record without a valid signature for the remote peer id.
MissingPeerIdSignature,
}
6 changes: 6 additions & 0 deletions client/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ pub struct WorkerConfig {
///
/// Defaults to `true` to avoid the surprise factor.
pub publish_non_global_ips: bool,

/// Reject authority discovery records that are not signed by their network identity (PeerId)
///
/// Defaults to `false` to provide compatibility with old versions
pub strict_record_validation: bool,
}

impl Default for WorkerConfig {
Expand All @@ -98,6 +103,7 @@ impl Default for WorkerConfig {
// `authority_discovery_dht_event_received`.
max_query_interval: Duration::from_secs(10 * 60),
publish_non_global_ips: true,
strict_record_validation: false,
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions client/authority-discovery/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,32 @@ fn get_addresses_and_authority_id() {
);
});
}

#[test]
fn cryptos_are_compatible() {
use sp_core::crypto::Pair;

let libp2p_secret = sc_network::Keypair::generate_ed25519();
let libp2p_public = libp2p_secret.public();

let sp_core_secret = {
let libp2p_ed_secret = match libp2p_secret.clone() {
sc_network::Keypair::Ed25519(x) => x,
_ => panic!("generate_ed25519 should have generated an Ed25519 key ¯\\_(ツ)_/¯"),
};
sp_core::ed25519::Pair::from_seed_slice(&libp2p_ed_secret.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 sp_core_signature = sp_core_secret.sign(message); // no error expected...

assert!(sp_core::ed25519::Pair::verify(
&sp_core::ed25519::Signature::from_slice(&libp2p_signature),
message,
&sp_core_public
));
assert!(libp2p_public.verify(message, sp_core_signature.as_ref()));
}
Loading

0 comments on commit da0f59f

Please sign in to comment.