Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
*: Add authority discovery to the set of session keys
  • Loading branch information
mxinden committed Oct 29, 2019
commit 1be93d35878e062b195e5bbb1978f3a05e197fd7
5 changes: 5 additions & 0 deletions 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/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod app {
}

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

/// An authority discovery authority identifier.
Expand Down
3 changes: 3 additions & 0 deletions node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ balances = { package = "srml-balances", path = "../../srml/balances" }
transaction-payment = { package = "srml-transaction-payment", path = "../../srml/transaction-payment" }
support = { package = "srml-support", path = "../../srml/support", default-features = false }
im_online = { package = "srml-im-online", path = "../../srml/im-online", default-features = false }
sr-authority-discovery = { package = "srml-authority-discovery", path = "../../srml/authority-discovery", default-features = false }
authority-discovery = { package = "substrate-authority-discovery", path = "../../core/authority-discovery"}
authority-discovery-primitives = { package = "substrate-authority-discovery-primitives", path = "../../core/authority-discovery/primitives"}
serde = { version = "1.0.101", features = [ "derive" ] }
client_db = { package = "substrate-client-db", path = "../../core/client/db", features = ["kvdb-rocksdb"] }
offchain = { package = "substrate-offchain", path = "../../core/offchain" }
Expand Down
41 changes: 32 additions & 9 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use chain_spec::ChainSpecExtension;
use primitives::{Pair, Public, crypto::UncheckedInto, sr25519};
use serde::{Serialize, Deserialize};
use node_runtime::{
BabeConfig, BalancesConfig, ContractsConfig, CouncilConfig, DemocracyConfig, GrandpaConfig,
ImOnlineConfig, IndicesConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig,
SudoConfig, SystemConfig, TechnicalCommitteeConfig, WASM_BINARY,
AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ContractsConfig, CouncilConfig, DemocracyConfig,
GrandpaConfig, ImOnlineConfig, IndicesConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig, SudoConfig,
SystemConfig, TechnicalCommitteeConfig, WASM_BINARY,
};
use node_runtime::Block;
use node_runtime::constants::currency::*;
Expand All @@ -32,6 +32,7 @@ use substrate_telemetry::TelemetryEndpoints;
use grandpa_primitives::{AuthorityId as GrandpaId};
use babe_primitives::{AuthorityId as BabeId};
use im_online::sr25519::{AuthorityId as ImOnlineId};
use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use sr_primitives::{Perbill, traits::{Verify, IdentifyAccount}};

pub use node_primitives::{AccountId, Balance, Signature};
Expand Down Expand Up @@ -61,8 +62,13 @@ pub fn flaming_fir_config() -> Result<ChainSpec, String> {
ChainSpec::from_json_bytes(&include_bytes!("../res/flaming-fir.json")[..])
}

fn session_keys(grandpa: GrandpaId, babe: BabeId, im_online: ImOnlineId) -> SessionKeys {
SessionKeys { grandpa, babe, im_online, }
fn session_keys(
grandpa: GrandpaId,
babe: BabeId,
im_online: ImOnlineId,
authority_discovery: AuthorityDiscoveryId,
) -> SessionKeys {
SessionKeys { grandpa, babe, im_online, authority_discovery}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SessionKeys { grandpa, babe, im_online, authority_discovery}
SessionKeys { grandpa, babe, im_online, authority_discovery }

}

fn staging_testnet_config_genesis() -> GenesisConfig {
Expand All @@ -72,7 +78,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
// and
// for i in 1 2 3 4 ; do for j in session; do subkey --ed25519 inspect "$secret"//fir//$j//$i; done; done

let initial_authorities: Vec<(AccountId, AccountId, GrandpaId, BabeId, ImOnlineId)> = vec![(
let initial_authorities: Vec<(AccountId, AccountId, GrandpaId, BabeId, ImOnlineId, AuthorityDiscoveryId)> = vec![(
// 5Fbsd6WXDGiLTxunqeK5BATNiocfCqu9bS1yArVjCgeBLkVy
hex!["9c7a2ee14e565db0c69f78c7b4cd839fbf52b607d867e9e9c5a79042898a0d12"].into(),
// 5EnCiV7wSHeNhjW3FSUwiJNkcc2SBkPLn5Nj93FmbLtBjQUq
Expand All @@ -83,6 +89,9 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
hex!["6e7e4eb42cbd2e0ab4cae8708ce5509580b8c04d11f6758dbf686d50fe9f9106"].unchecked_into(),
// 5EZaeQ8djPcq9pheJUhgerXQZt9YaHnMJpiHMRhwQeinqUW8
hex!["6e7e4eb42cbd2e0ab4cae8708ce5509580b8c04d11f6758dbf686d50fe9f9106"].unchecked_into(),
// TODO: Is it safe to just copy like ImOnlineId did from BabeId?
// 5EZaeQ8djPcq9pheJUhgerXQZt9YaHnMJpiHMRhwQeinqUW8
hex!["6e7e4eb42cbd2e0ab4cae8708ce5509580b8c04d11f6758dbf686d50fe9f9106"].unchecked_into(),
),(
// 5ERawXCzCWkjVq3xz1W5KGNtVx2VdefvZ62Bw1FEuZW4Vny2
hex!["68655684472b743e456907b398d3a44c113f189e56d1bbfd55e889e295dfde78"].into(),
Expand All @@ -94,6 +103,9 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
hex!["482dbd7297a39fa145c570552249c2ca9dd47e281f0c500c971b59c9dcdcd82e"].unchecked_into(),
// 5DhLtiaQd1L1LU9jaNeeu9HJkP6eyg3BwXA7iNMzKm7qqruQ
hex!["482dbd7297a39fa145c570552249c2ca9dd47e281f0c500c971b59c9dcdcd82e"].unchecked_into(),
// TODO: Is it safe to just copy like ImOnlineId did from BabeId?
// 5DhLtiaQd1L1LU9jaNeeu9HJkP6eyg3BwXA7iNMzKm7qqruQ
hex!["482dbd7297a39fa145c570552249c2ca9dd47e281f0c500c971b59c9dcdcd82e"].unchecked_into(),
),(
// 5DyVtKWPidondEu8iHZgi6Ffv9yrJJ1NDNLom3X9cTDi98qp
hex!["547ff0ab649283a7ae01dbc2eb73932eba2fb09075e9485ff369082a2ff38d65"].into(),
Expand All @@ -105,6 +117,9 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
hex!["482a3389a6cf42d8ed83888cfd920fec738ea30f97e44699ada7323f08c3380a"].unchecked_into(),
// 5DhKqkHRkndJu8vq7pi2Q5S3DfftWJHGxbEUNH43b46qNspH
hex!["482a3389a6cf42d8ed83888cfd920fec738ea30f97e44699ada7323f08c3380a"].unchecked_into(),
// TODO: Is it safe to just copy like ImOnlineId did from BabeId?
// 5DhKqkHRkndJu8vq7pi2Q5S3DfftWJHGxbEUNH43b46qNspH
hex!["482a3389a6cf42d8ed83888cfd920fec738ea30f97e44699ada7323f08c3380a"].unchecked_into(),
),(
// 5HYZnKWe5FVZQ33ZRJK1rG3WaLMztxWrrNDb1JRwaHHVWyP9
hex!["f26cdb14b5aec7b2789fd5ca80f979cef3761897ae1f37ffb3e154cbcc1c2663"].into(),
Expand All @@ -116,6 +131,9 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
hex!["00299981a2b92f878baaf5dbeba5c18d4e70f2a1fcd9c61b32ea18daf38f4378"].unchecked_into(),
// 5C4vDQxA8LTck2xJEy4Yg1hM9qjDt4LvTQaMo4Y8ne43aU6x
hex!["00299981a2b92f878baaf5dbeba5c18d4e70f2a1fcd9c61b32ea18daf38f4378"].unchecked_into(),
// TODO: Is it safe to just copy like ImOnlineId did from BabeId?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be fine.

// 5C4vDQxA8LTck2xJEy4Yg1hM9qjDt4LvTQaMo4Y8ne43aU6x
hex!["00299981a2b92f878baaf5dbeba5c18d4e70f2a1fcd9c61b32ea18daf38f4378"].unchecked_into(),
)];

// generated with secret: subkey inspect "$secret"/fir
Expand Down Expand Up @@ -164,19 +182,20 @@ pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId where
}

/// Helper function to generate stash, controller and session key from seed
pub fn get_authority_keys_from_seed(seed: &str) -> (AccountId, AccountId, GrandpaId, BabeId, ImOnlineId) {
pub fn get_authority_keys_from_seed(seed: &str) -> (AccountId, AccountId, GrandpaId, BabeId, ImOnlineId, AuthorityDiscoveryId) {
(
get_account_id_from_seed::<sr25519::Public>(&format!("{}//stash", seed)),
get_account_id_from_seed::<sr25519::Public>(seed),
get_from_seed::<GrandpaId>(seed),
get_from_seed::<BabeId>(seed),
get_from_seed::<ImOnlineId>(seed),
get_from_seed::<AuthorityDiscoveryId>(seed),
)
}

/// Helper function to create GenesisConfig for testing
pub fn testnet_genesis(
initial_authorities: Vec<(AccountId, AccountId, GrandpaId, BabeId, ImOnlineId)>,
initial_authorities: Vec<(AccountId, AccountId, GrandpaId, BabeId, ImOnlineId, AuthorityDiscoveryId)>,
root_key: AccountId,
endowed_accounts: Option<Vec<AccountId>>,
enable_println: bool,
Expand Down Expand Up @@ -220,7 +239,8 @@ pub fn testnet_genesis(
}),
session: Some(SessionConfig {
keys: initial_authorities.iter().map(|x| {
(x.0.clone(), session_keys(x.2.clone(), x.3.clone(), x.4.clone()))
// TODO: Again, is this safe to do?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is safe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is related to the comment above asking whether it is safe to use the same seed for BabeId, ImOnlineId and AuthorityDiscoveryId. I guess given that this is only ever used as a testnetwork it does not matter @bkchr?

(x.0.clone(), session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone()))
}).collect::<Vec<_>>(),
}),
staking: Some(StakingConfig {
Expand Down Expand Up @@ -259,6 +279,9 @@ pub fn testnet_genesis(
im_online: Some(ImOnlineConfig {
keys: vec![],
}),
authority_discovery: Some(AuthorityDiscoveryConfig {
keys: vec![],
}),
grandpa: Some(GrandpaConfig {
authorities: vec![],
}),
Expand Down
4 changes: 4 additions & 0 deletions node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ safe-mix = { version = "1.0", default-features = false }
serde = { version = "1.0.101", optional = true }

babe-primitives = { package = "substrate-consensus-babe-primitives", path = "../../core/consensus/babe/primitives", default-features = false }
authority-discovery-primitives = { package = "substrate-authority-discovery-primitives", path = "../../core/authority-discovery/primitives", default-features = false }
client = { package = "substrate-client", path = "../../core/client", default-features = false }
node-primitives = { path = "../primitives", default-features = false }
offchain-primitives = { package = "substrate-offchain-primitives", path = "../../core/offchain/primitives", default-features = false }
Expand All @@ -36,6 +37,7 @@ executive = { package = "srml-executive", path = "../../srml/executive", default
finality-tracker = { package = "srml-finality-tracker", path = "../../srml/finality-tracker", default-features = false }
grandpa = { package = "srml-grandpa", path = "../../srml/grandpa", default-features = false }
im-online = { package = "srml-im-online", path = "../../srml/im-online", default-features = false }
authority-discovery = { package = "srml-authority-discovery", path = "../../srml/authority-discovery", default-features = false }
indices = { package = "srml-indices", path = "../../srml/indices", default-features = false }
membership = { package = "srml-membership", path = "../../srml/membership", default-features = false }
nicks = { package = "srml-nicks", path = "../../srml/nicks", default-features = false }
Expand Down Expand Up @@ -63,6 +65,8 @@ runtime_io = { package = "sr-io", path = "../../core/sr-io" }
[features]
default = ["std"]
std = [
"authority-discovery/std",
"authority-discovery-primitives/std",
"authorship/std",
"babe-primitives/std",
"babe/std",
Expand Down
18 changes: 18 additions & 0 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ use version::NativeVersion;
use primitives::OpaqueMetadata;
use grandpa::{AuthorityId as GrandpaId, AuthorityWeight as GrandpaWeight};
use im_online::sr25519::{AuthorityId as ImOnlineId};
use authority_discovery_primitives::{
AuthorityId as AuthorityDiscoveryId,
AuthoritySignature as AuthorityDiscoverySignature,
};
use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
use contracts_rpc_runtime_api::ContractExecResult;
use system::offchain::TransactionSubmitter;
Expand Down Expand Up @@ -214,6 +218,7 @@ impl_opaque_keys! {
pub grandpa: Grandpa,
pub babe: Babe,
pub im_online: ImOnline,
pub authority_discovery: AuthorityDiscovery,
}
}

Expand Down Expand Up @@ -433,6 +438,8 @@ impl offences::Trait for Runtime {
type OnOffenceHandler = Staking;
}

impl authority_discovery::Trait for Runtime {}

impl grandpa::Trait for Runtime {
type Event = Event;
}
Expand Down Expand Up @@ -521,6 +528,7 @@ construct_runtime!(
Contracts: contracts,
Sudo: sudo,
ImOnline: im_online::{Module, Call, Storage, Event<T>, ValidateUnsigned, Config<T>},
AuthorityDiscovery: authority_discovery::{Module, Call, Config},
Offences: offences::{Module, Call, Storage, Event},
RandomnessCollectiveFlip: randomness_collective_flip::{Module, Call, Storage},
Nicks: nicks::{Module, Call, Storage, Event<T>},
Expand Down Expand Up @@ -635,6 +643,16 @@ impl_runtime_apis! {
}
}

impl authority_discovery_primitives::AuthorityDiscoveryApi<Block> for Runtime {
fn authorities() -> Vec<AuthorityDiscoveryId> {
AuthorityDiscovery::authorities()
}

fn sign(payload: &Vec<u8>) -> Option<(AuthorityDiscoverySignature, AuthorityDiscoveryId)> {
AuthorityDiscovery::sign(payload)
}
}

impl system_rpc_runtime_api::AccountNonceApi<Block, AccountId, Index> for Runtime {
fn account_nonce(account: AccountId) -> Index {
System::account_nonce(account)
Expand Down
2 changes: 1 addition & 1 deletion node/testing/src/keyring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub fn to_session_keys(
grandpa: ed25519_keyring.to_owned().public().into(),
babe: sr25519_keyring.to_owned().public().into(),
im_online: sr25519_keyring.to_owned().public().into(),
authority_discovery: sr25519_keyring.to_owned().public().into(),
}
}

Expand Down Expand Up @@ -99,4 +100,3 @@ pub fn sign(xt: CheckedExtrinsic, version: u32, genesis_hash: [u8; 32]) -> Unche
},
}
}

11 changes: 3 additions & 8 deletions srml/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl<T: Trait> Module<T> {
/// Returns own authority identifier iff it is part of the current authority
/// set, otherwise this function returns None. The restriction might be
/// softened in the future in case a consumer needs to learn own authority
/// identifier.
/// identifier anyways.
fn authority_id() -> Option<AuthorityId> {
let authorities = Keys::get();

Expand All @@ -77,12 +77,7 @@ impl<T: Trait> Module<T> {
}

/// Sign the given payload with the private key corresponding to the given authority id.
pub fn sign(
payload: &Vec<u8>,
) -> Option<(
AuthoritySignature,
AuthorityId,
)> {
pub fn sign(payload: &Vec<u8>) -> Option<(AuthoritySignature, AuthorityId)> {
let authority_id = Module::<T>::authority_id()?;
authority_id.sign(payload).map(|s| (s, authority_id))
}
Expand All @@ -106,7 +101,7 @@ impl<T: Trait> Module<T> {
}

impl<T: Trait> sr_primitives::BoundToRuntimeAppPublic for Module<T> {
type Public = T::AuthorityId;
type Public = AuthorityId;
}

impl<T: Trait> session::OneSessionHandler<T::AccountId> for Module<T> {
Expand Down
7 changes: 6 additions & 1 deletion test-utils/chain-spec-builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn generate_authority_keys_and_store(
None,
).map_err(|err| err.to_string())?;

let (_, _, grandpa, babe, im_online) =
let (_, _, grandpa, babe, im_online, authority_discovery) =
chain_spec::get_authority_keys_from_seed(seed);

let insert_key = |key_type, public| {
Expand All @@ -166,6 +166,11 @@ fn generate_authority_keys_and_store(
primitives::crypto::key_types::IM_ONLINE,
im_online.as_slice(),
)?;

insert_key(
primitives::crypto::key_types::AUTHORITY_DISCOVERY,
authority_discovery.as_slice(),
)?;
}

Ok(())
Expand Down