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

*: Refactor authority discovery (key mngmt, runtime API) #3955

Merged
merged 34 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
47b4f7c
{core,srml}/authority-discovery: Move generic to specific session keys
mxinden Oct 25, 2019
4d80316
{srml,core}/authority-discovery: Verify signature outside of runtime
mxinden Oct 28, 2019
1be93d3
*: Add authority discovery to the set of session keys
mxinden Oct 28, 2019
3551221
*: Sign authority discovery DHT payload with keystore instead of runtime
mxinden Oct 28, 2019
b516aee
core/authority-discovery: Give libp2p Kademlia time to start up
mxinden Oct 29, 2019
404d9a9
core/authority-discovery: Move authorities priority group name to const
mxinden Oct 29, 2019
e922805
node/runtime/src/lib.rs: Bump runtime spec version
mxinden Oct 29, 2019
38cf886
*: Fix lints and node/testing test failures
mxinden Oct 29, 2019
50e90a9
Merge remote-tracking branch 'paritytech/master' into refactor-author…
mxinden Oct 31, 2019
db05799
*: Fix formatting
mxinden Nov 4, 2019
b7b49c4
Merge remote-tracking branch 'master' into refactor-authority-discovery
mxinden Nov 4, 2019
1d72997
Merge branch 'master' of https://github.com/paritytech/substrate into…
mxinden Nov 4, 2019
180f5ec
core/authority-discovery: Box dht event channel in unit tests
mxinden Nov 5, 2019
8aca3d7
Merge remote-tracking branch 'paritytech/master' into refactor-author…
mxinden Nov 6, 2019
f8cfff7
node/cli/src/service.rs: Fix future import
mxinden Nov 6, 2019
642ca6c
Merge remote-tracking branch 'paritytech/master' into refactor-author…
mxinden Nov 8, 2019
1f5241c
node/cli/src/service.rs: Replace unwrap by expect with proof
mxinden Nov 8, 2019
744c218
node/cli/src/chain_spec: Remove TODO for testnet key generation
mxinden Nov 8, 2019
409d885
core/authority-discovery/src/lib: Remove scale encoding TODOs
mxinden Nov 8, 2019
79de0c0
srml/authority-discovery: Make comment a doc comment
mxinden Nov 10, 2019
0b8f7dd
core/authority-discovery: Remove unused StreamExt import
mxinden Nov 10, 2019
a6d8f6c
Merge remote-tracking branch 'paritytech/master' into refactor-author…
mxinden Nov 10, 2019
1a90903
node/runtime: Bump impl version to debug CI
mxinden Nov 10, 2019
a2c9df5
Test ci.
tomusdrw Nov 10, 2019
edff1f8
Change the line width to 100.
tomusdrw Nov 10, 2019
ae5108a
Revert "Change the line width to 100."
tomusdrw Nov 10, 2019
3b71b57
Fix a check for polkadot to work on forked repos.
tomusdrw Nov 10, 2019
65756f9
Revert "node/runtime: Bump impl version to debug CI"
mxinden Nov 10, 2019
0ae3bfe
Merge remote-tracking branch 'paritytech/master' into refactor-author…
mxinden Nov 11, 2019
fc5156c
Revert "Test ci."
mxinden Nov 11, 2019
4d36114
Merge remote-tracking branch 'paritytech/master' into refactor-author…
mxinden Nov 12, 2019
56d630c
Cargo.lock: Fix wrong lock file merge
mxinden Nov 12, 2019
b689a1f
srml/authority-discovery: Keep track of new validator set not upcoming
mxinden Nov 14, 2019
89f5018
core/authority-discovery: Document key retrieval functions
mxinden Nov 14, 2019
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
9 changes: 8 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions core/authority-discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ client = { package = "substrate-client", path = "../../core/client" }
codec = { package = "parity-scale-codec", default-features = false, version = "1.0.3" }
derive_more = "0.15.0"
futures = "0.1.29"
keystore = { package = "substrate-keystore", path = "../keystore" }
libp2p = { version = "0.12.0", default-features = false, features = ["secp256k1", "libp2p-websocket"] }
log = "0.4.8"
network = { package = "substrate-network", path = "../../core/network" }
Expand Down
14 changes: 8 additions & 6 deletions core/authority-discovery/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ description = "Authority discovery primitives"
edition = "2018"

[dependencies]
codec = { package = "parity-scale-codec", default-features = false, version = "1.0.3" }
app-crypto = { package = "substrate-application-crypto", path = "../../application-crypto", default-features = false }
client = { package = "substrate-client", path = "../../client", default-features = false }
sr-primitives = { path = "../../sr-primitives", default-features = false }
codec = { package = "parity-scale-codec", default-features = false, version = "1.0.3" }
rstd = { package = "sr-std", path = "../../sr-std", default-features = false }
sr-primitives = { path = "../../sr-primitives", default-features = false }

[features]
default = ["std"]
std = [
"rstd/std",
"client/std",
"codec/std",
"sr-primitives/std"
"app-crypto/std",
"client/std",
"codec/std",
"rstd/std",
"sr-primitives/std"
]
33 changes: 15 additions & 18 deletions core/authority-discovery/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,28 @@

use client::decl_runtime_apis;
use rstd::vec::Vec;
use sr_primitives::RuntimeDebug;

#[derive(codec::Encode, codec::Decode, Eq, PartialEq, Clone, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Hash))]
pub struct Signature(pub Vec<u8>);
#[derive(codec::Encode, codec::Decode, Eq, PartialEq, Clone, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Hash))]
pub struct AuthorityId(pub Vec<u8>);
mod app {
use app_crypto::{app_crypto, key_types::AUTHORITY_DISCOVERY, sr25519};
bkchr marked this conversation as resolved.
Show resolved Hide resolved
app_crypto!(sr25519, AUTHORITY_DISCOVERY);
}

/// An authority discovery authority keypair.
#[cfg(feature = "std")]
pub type AuthorityPair = app::Pair;

/// An authority discovery authority identifier.
pub type AuthorityId = app::Public;

/// An authority discovery authority signature.
pub type AuthoritySignature = app::Signature;

decl_runtime_apis! {
/// The authority discovery api.
///
/// This api is used by the `core/authority-discovery` module to retrieve our
/// own authority identifier, to retrieve identifiers of the current authority
/// set, as well as sign and verify Kademlia Dht external address payloads
/// from and to other authorities.
/// This api is used by the `core/authority-discovery` module to retrieve identifiers of the current authority set.
pub trait AuthorityDiscoveryApi {
/// Retrieve authority identifiers of the current authority set.
fn authorities() -> Vec<AuthorityId>;

/// Sign the given payload with the private key corresponding to the given authority id.
fn sign(payload: &Vec<u8>) -> Option<(Signature, AuthorityId)>;

/// Verify the given signature for the given payload with the given
/// authority identifier.
fn verify(payload: &Vec<u8>, signature: &Signature, authority_id: &AuthorityId) -> bool;
}
}
14 changes: 7 additions & 7 deletions core/authority-discovery/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ pub enum Error {
HashingAuthorityId(libp2p::core::multiaddr::multihash::EncodeError),
/// Failed calling into the Substrate runtime.
CallingRuntime(client::error::Error),
/// Failed signing the dht payload via the Substrate runtime.
SigningDhtPayload,
/// From the Dht we only get the hashed authority id. In order to retrieve the actual authority id and to ensure it
/// is actually an authority, we match the hash against the hash of the authority id of all other authorities. This
/// error is the result of the above failing.
MatchingHashedAuthorityIdWithAuthorityId,
/// Failed to set the authority discovery peerset priority group in the peerset module.
SettingPeersetPriorityGroup(String),
/// Failed to encode a dht payload.
Encoding(prost::EncodeError),
/// Failed to decode a dht payload.
Decoding(prost::DecodeError),
/// Failed to encode a protobuf payload.
EncodingProto(prost::EncodeError),
/// Failed to decode a protobuf payload.
DecodingProto(prost::DecodeError),
/// Failed to encode or decode scale payload
EncodingDecodingScale(codec::Error),
/// Failed to parse a libp2p multi address.
ParsingMultiaddress(libp2p::core::multiaddr::Error),
/// Tokio timer error.
PollingTokioTimer(tokio_timer::Error)
PollingTokioTimer(tokio_timer::Error),
}
Loading