diff --git a/build.rs b/build.rs
index afc39d3b6..ce3d5bc53 100644
--- a/build.rs
+++ b/build.rs
@@ -1,8 +1,8 @@
-use vergen::{ConstantsFlags, generate_cargo_keys};
+use vergen::{generate_cargo_keys, ConstantsFlags};
const ERROR_MSG: &str = "Failed to generate metadata files";
fn main() {
- generate_cargo_keys(ConstantsFlags::all()).expect(ERROR_MSG);
- println!("cargo:rerun-if-changed=.git/HEAD");
+ generate_cargo_keys(ConstantsFlags::all()).expect(ERROR_MSG);
+ println!("cargo:rerun-if-changed=.git/HEAD");
}
diff --git a/node/cli/build.rs b/node/cli/build.rs
index e7a7b271f..671c3f473 100644
--- a/node/cli/build.rs
+++ b/node/cli/build.rs
@@ -14,37 +14,40 @@
// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see .
-use cli::{NoCustom, CoreParams};
+use cli::{CoreParams, NoCustom};
-use std::{fs, env, path::Path};
+use std::{env, fs, path::Path};
-use structopt::{StructOpt, clap::Shell};
+use structopt::{clap::Shell, StructOpt};
fn main() {
- build_shell_completion();
+ build_shell_completion();
}
/// Build shell completion scripts for all known shells
/// Full list in https://github.com/kbknapp/clap-rs/blob/e9d0562a1dc5dfe731ed7c767e6cee0af08f0cf9/src/app/parser.rs#L123
fn build_shell_completion() {
- for shell in &[Shell::Bash, Shell::Fish, Shell::Zsh, Shell::Elvish, Shell::PowerShell] {
- build_completion(shell);
- }
+ for shell in &[Shell::Bash, Shell::Fish, Shell::Zsh, Shell::Elvish, Shell::PowerShell] {
+ build_completion(shell);
+ }
}
/// Build the shell auto-completion for a given Shell
fn build_completion(shell: &Shell) {
- let outdir = match env::var_os("OUT_DIR") {
- None => return,
- Some(dir) => dir,
- };
- let path = Path::new(&outdir)
- .parent().unwrap()
- .parent().unwrap()
- .parent().unwrap()
- .join("completion-scripts");
-
- fs::create_dir(&path).ok();
-
- CoreParams::::clap().gen_completions("substrate-node", *shell, &path);
+ let outdir = match env::var_os("OUT_DIR") {
+ None => return,
+ Some(dir) => dir,
+ };
+ let path = Path::new(&outdir)
+ .parent()
+ .unwrap()
+ .parent()
+ .unwrap()
+ .parent()
+ .unwrap()
+ .join("completion-scripts");
+
+ fs::create_dir(&path).ok();
+
+ CoreParams::::clap().gen_completions("substrate-node", *shell, &path);
}
diff --git a/node/cli/src/chain_spec.rs b/node/cli/src/chain_spec.rs
index 74b5eb6ff..25ea83daf 100644
--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -19,20 +19,18 @@
use grandpa::AuthorityId as GrandpaId;
use hex_literal::hex;
use node_primitives::{AccountId, AuraId, Balance};
+pub use node_runtime::GenesisConfig;
use node_runtime::{
- AuraConfig, BalancesConfig, ContractsConfig, DAYS,
- COIN, GrandpaConfig, IndicesConfig, MILLI,
- Perbill, SECS_PER_BLOCK, KtonConfig,
- SessionConfig, SessionKeys, StakerStatus,
- StakingConfig, SudoConfig, SystemConfig, TimestampConfig,
+ AuraConfig, BalancesConfig, ContractsConfig, GrandpaConfig, IndicesConfig, KtonConfig, Perbill, SessionConfig,
+ SessionKeys, StakerStatus, StakingConfig, SudoConfig, SystemConfig, TimestampConfig, COIN, DAYS, MILLI,
+ SECS_PER_BLOCK,
};
-pub use node_runtime::GenesisConfig;
-use primitives::{crypto::UncheckedInto, ed25519, Pair, sr25519};
+use primitives::{crypto::UncheckedInto, ed25519, sr25519, Pair};
+use serde_json::de::ParserNumber;
+use serde_json::Number;
use substrate_service;
-use substrate_telemetry::TelemetryEndpoints;
use substrate_service::Properties;
-use serde_json::Number;
-use serde_json::de::ParserNumber;
+use substrate_telemetry::TelemetryEndpoints;
const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
@@ -55,44 +53,48 @@ 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, AuraId, GrandpaId)> =
- vec![(
- // 5Fbsd6WXDGiLTxunqeK5BATNiocfCqu9bS1yArVjCgeBLkVy
- hex!["9c7a2ee14e565db0c69f78c7b4cd839fbf52b607d867e9e9c5a79042898a0d12"].unchecked_into(),
- // 5EnCiV7wSHeNhjW3FSUwiJNkcc2SBkPLn5Nj93FmbLtBjQUq
- hex!["781ead1e2fa9ccb74b44c19d29cb2a7a4b5be3972927ae98cd3877523976a276"].unchecked_into(),
- // 5Fb9ayurnxnaXj56CjmyQLBiadfRCqUbL2VWNbbe1nZU6wiC
- hex!["9becad03e6dcac03cee07edebca5475314861492cdfc96a2144a67bbe9699332"].unchecked_into(),
- // 5Fb9ayurnxnaXj56CjmyQLBiadfRCqUbL2VWNbbe1nZU6wiC
- hex!["9becad03e6dcac03cee07edebca5475314861492cdfc96a2144a67bbe9699332"].unchecked_into(),
- ), (
- // 5ERawXCzCWkjVq3xz1W5KGNtVx2VdefvZ62Bw1FEuZW4Vny2
- hex!["68655684472b743e456907b398d3a44c113f189e56d1bbfd55e889e295dfde78"].unchecked_into(),
- // 5Gc4vr42hH1uDZc93Nayk5G7i687bAQdHHc9unLuyeawHipF
- hex!["c8dc79e36b29395413399edaec3e20fcca7205fb19776ed8ddb25d6f427ec40e"].unchecked_into(),
- // 5EockCXN6YkiNCDjpqqnbcqd4ad35nU4RmA1ikM4YeRN4WcE
- hex!["7932cff431e748892fa48e10c63c17d30f80ca42e4de3921e641249cd7fa3c2f"].unchecked_into(),
- // 5EockCXN6YkiNCDjpqqnbcqd4ad35nU4RmA1ikM4YeRN4WcE
- hex!["7932cff431e748892fa48e10c63c17d30f80ca42e4de3921e641249cd7fa3c2f"].unchecked_into(),
- ), (
- // 5DyVtKWPidondEu8iHZgi6Ffv9yrJJ1NDNLom3X9cTDi98qp
- hex!["547ff0ab649283a7ae01dbc2eb73932eba2fb09075e9485ff369082a2ff38d65"].unchecked_into(),
- // 5FeD54vGVNpFX3PndHPXJ2MDakc462vBCD5mgtWRnWYCpZU9
- hex!["9e42241d7cd91d001773b0b616d523dd80e13c6c2cab860b1234ef1b9ffc1526"].unchecked_into(),
- // 5E1jLYfLdUQKrFrtqoKgFrRvxM3oQPMbf6DfcsrugZZ5Bn8d
- hex!["5633b70b80a6c8bb16270f82cca6d56b27ed7b76c8fd5af2986a25a4788ce440"].unchecked_into(),
- // 5E1jLYfLdUQKrFrtqoKgFrRvxM3oQPMbf6DfcsrugZZ5Bn8d
- hex!["5633b70b80a6c8bb16270f82cca6d56b27ed7b76c8fd5af2986a25a4788ce440"].unchecked_into(),
- ), (
- // 5HYZnKWe5FVZQ33ZRJK1rG3WaLMztxWrrNDb1JRwaHHVWyP9
- hex!["f26cdb14b5aec7b2789fd5ca80f979cef3761897ae1f37ffb3e154cbcc1c2663"].unchecked_into(),
- // 5EPQdAQ39WQNLCRjWsCk5jErsCitHiY5ZmjfWzzbXDoAoYbn
- hex!["66bc1e5d275da50b72b15de072a2468a5ad414919ca9054d2695767cf650012f"].unchecked_into(),
- // 5DMa31Hd5u1dwoRKgC4uvqyrdK45RHv3CpwvpUC1EzuwDit4
- hex!["3919132b851ef0fd2dae42a7e734fe547af5a6b809006100f48944d7fae8e8ef"].unchecked_into(),
- // 5DMa31Hd5u1dwoRKgC4uvqyrdK45RHv3CpwvpUC1EzuwDit4
- hex!["3919132b851ef0fd2dae42a7e734fe547af5a6b809006100f48944d7fae8e8ef"].unchecked_into(),
- )];
+ let initial_authorities: Vec<(AccountId, AccountId, AuraId, GrandpaId)> = vec![
+ (
+ // 5Fbsd6WXDGiLTxunqeK5BATNiocfCqu9bS1yArVjCgeBLkVy
+ hex!["9c7a2ee14e565db0c69f78c7b4cd839fbf52b607d867e9e9c5a79042898a0d12"].unchecked_into(),
+ // 5EnCiV7wSHeNhjW3FSUwiJNkcc2SBkPLn5Nj93FmbLtBjQUq
+ hex!["781ead1e2fa9ccb74b44c19d29cb2a7a4b5be3972927ae98cd3877523976a276"].unchecked_into(),
+ // 5Fb9ayurnxnaXj56CjmyQLBiadfRCqUbL2VWNbbe1nZU6wiC
+ hex!["9becad03e6dcac03cee07edebca5475314861492cdfc96a2144a67bbe9699332"].unchecked_into(),
+ // 5Fb9ayurnxnaXj56CjmyQLBiadfRCqUbL2VWNbbe1nZU6wiC
+ hex!["9becad03e6dcac03cee07edebca5475314861492cdfc96a2144a67bbe9699332"].unchecked_into(),
+ ),
+ (
+ // 5ERawXCzCWkjVq3xz1W5KGNtVx2VdefvZ62Bw1FEuZW4Vny2
+ hex!["68655684472b743e456907b398d3a44c113f189e56d1bbfd55e889e295dfde78"].unchecked_into(),
+ // 5Gc4vr42hH1uDZc93Nayk5G7i687bAQdHHc9unLuyeawHipF
+ hex!["c8dc79e36b29395413399edaec3e20fcca7205fb19776ed8ddb25d6f427ec40e"].unchecked_into(),
+ // 5EockCXN6YkiNCDjpqqnbcqd4ad35nU4RmA1ikM4YeRN4WcE
+ hex!["7932cff431e748892fa48e10c63c17d30f80ca42e4de3921e641249cd7fa3c2f"].unchecked_into(),
+ // 5EockCXN6YkiNCDjpqqnbcqd4ad35nU4RmA1ikM4YeRN4WcE
+ hex!["7932cff431e748892fa48e10c63c17d30f80ca42e4de3921e641249cd7fa3c2f"].unchecked_into(),
+ ),
+ (
+ // 5DyVtKWPidondEu8iHZgi6Ffv9yrJJ1NDNLom3X9cTDi98qp
+ hex!["547ff0ab649283a7ae01dbc2eb73932eba2fb09075e9485ff369082a2ff38d65"].unchecked_into(),
+ // 5FeD54vGVNpFX3PndHPXJ2MDakc462vBCD5mgtWRnWYCpZU9
+ hex!["9e42241d7cd91d001773b0b616d523dd80e13c6c2cab860b1234ef1b9ffc1526"].unchecked_into(),
+ // 5E1jLYfLdUQKrFrtqoKgFrRvxM3oQPMbf6DfcsrugZZ5Bn8d
+ hex!["5633b70b80a6c8bb16270f82cca6d56b27ed7b76c8fd5af2986a25a4788ce440"].unchecked_into(),
+ // 5E1jLYfLdUQKrFrtqoKgFrRvxM3oQPMbf6DfcsrugZZ5Bn8d
+ hex!["5633b70b80a6c8bb16270f82cca6d56b27ed7b76c8fd5af2986a25a4788ce440"].unchecked_into(),
+ ),
+ (
+ // 5HYZnKWe5FVZQ33ZRJK1rG3WaLMztxWrrNDb1JRwaHHVWyP9
+ hex!["f26cdb14b5aec7b2789fd5ca80f979cef3761897ae1f37ffb3e154cbcc1c2663"].unchecked_into(),
+ // 5EPQdAQ39WQNLCRjWsCk5jErsCitHiY5ZmjfWzzbXDoAoYbn
+ hex!["66bc1e5d275da50b72b15de072a2468a5ad414919ca9054d2695767cf650012f"].unchecked_into(),
+ // 5DMa31Hd5u1dwoRKgC4uvqyrdK45RHv3CpwvpUC1EzuwDit4
+ hex!["3919132b851ef0fd2dae42a7e734fe547af5a6b809006100f48944d7fae8e8ef"].unchecked_into(),
+ // 5DMa31Hd5u1dwoRKgC4uvqyrdK45RHv3CpwvpUC1EzuwDit4
+ hex!["3919132b851ef0fd2dae42a7e734fe547af5a6b809006100f48944d7fae8e8ef"].unchecked_into(),
+ ),
+ ];
// generated with secret: subkey inspect "$secret"/fir
let endowed_accounts: Vec = vec![
@@ -105,31 +107,41 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
GenesisConfig {
system: Some(SystemConfig {
- code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm").to_vec(), // FIXME change once we have #1252
+ code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm")
+ .to_vec(), // FIXME change once we have #1252
changes_trie_config: Default::default(),
}),
balances: Some(BalancesConfig {
- balances: endowed_accounts.iter().cloned()
+ balances: endowed_accounts
+ .iter()
+ .cloned()
.map(|k| (k, ENDOWMENT))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH)))
.collect(),
vesting: vec![],
}),
kton: Some(KtonConfig {
- balances: endowed_accounts.iter().cloned()
+ balances: endowed_accounts
+ .iter()
+ .cloned()
.map(|k| (k, ENDOWMENT))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), ENDOWMENT)))
.collect(),
vesting: vec![],
}),
indices: Some(IndicesConfig {
- ids: endowed_accounts.iter().cloned()
+ ids: endowed_accounts
+ .iter()
+ .cloned()
.chain(initial_authorities.iter().map(|x| x.0.clone()))
.collect::>(),
}),
session: Some(SessionConfig {
validators: initial_authorities.iter().map(|x| x.1.clone()).collect(),
- keys: initial_authorities.iter().map(|x| (x.1.clone(), SessionKeys(x.2.clone(), x.2.clone()))).collect::>(),
+ keys: initial_authorities
+ .iter()
+ .map(|x| (x.1.clone(), SessionKeys(x.2.clone(), x.2.clone())))
+ .collect::>(),
}),
staking: Some(StakingConfig {
current_era: 0,
@@ -139,7 +151,10 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
validator_count: 7,
offline_slash_grace: 4,
minimum_validator_count: 4,
- stakers: initial_authorities.iter().map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)).collect(),
+ stakers: initial_authorities
+ .iter()
+ .map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator))
+ .collect(),
invulnerables: initial_authorities.iter().map(|x| x.1.clone()).collect(),
}),
timestamp: Some(TimestampConfig {
@@ -158,7 +173,6 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
grandpa: Some(GrandpaConfig {
authorities: initial_authorities.iter().map(|x| (x.3.clone(), 1)).collect(),
}),
-
}
}
@@ -204,7 +218,7 @@ pub fn get_authority_keys_from_seed(seed: &str) -> (AccountId, AccountId, AuraId
get_account_id_from_seed(&format!("{}//stash", seed)),
get_account_id_from_seed(seed),
get_aura_id_from_seed(seed),
- get_grandpa_id_from_seed(seed)
+ get_grandpa_id_from_seed(seed),
)
}
@@ -237,7 +251,8 @@ pub fn testnet_genesis(
GenesisConfig {
system: Some(SystemConfig {
- code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm").to_vec(),
+ code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm")
+ .to_vec(),
changes_trie_config: Default::default(),
}),
indices: Some(IndicesConfig {
@@ -248,7 +263,9 @@ pub fn testnet_genesis(
vesting: vec![],
}),
kton: Some(KtonConfig {
- balances: endowed_accounts.iter().cloned()
+ balances: endowed_accounts
+ .iter()
+ .cloned()
.map(|k| (k, ENDOWMENT))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), ENDOWMENT)))
.collect(),
@@ -256,7 +273,10 @@ pub fn testnet_genesis(
}),
session: Some(SessionConfig {
validators: initial_authorities.iter().map(|x| x.1.clone()).collect(),
- keys: initial_authorities.iter().map(|x| (x.1.clone(), SessionKeys(x.2.clone(), x.2.clone()))).collect::>(),
+ keys: initial_authorities
+ .iter()
+ .map(|x| (x.1.clone(), SessionKeys(x.2.clone(), x.2.clone())))
+ .collect::>(),
}),
staking: Some(StakingConfig {
current_era: 0,
@@ -267,11 +287,14 @@ pub fn testnet_genesis(
offline_slash: Perbill::from_parts(1_000_000),
session_reward: Perbill::from_percent(90),
offline_slash_grace: 4,
- stakers: initial_authorities.iter().map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)).collect(),
+ stakers: initial_authorities
+ .iter()
+ .map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator))
+ .collect(),
invulnerables: initial_authorities.iter().map(|x| x.1.clone()).collect(),
}),
timestamp: Some(TimestampConfig {
- minimum_period: 3, // 3*2=6 second block time.
+ minimum_period: 3, // 3*2=6 second block time.
}),
contracts: Some(ContractsConfig {
current_schedule: contracts::Schedule {
@@ -280,9 +303,7 @@ pub fn testnet_genesis(
},
gas_price: 1 * MILLI,
}),
- sudo: Some(SudoConfig {
- key: root_key,
- }),
+ sudo: Some(SudoConfig { key: root_key }),
aura: Some(AuraConfig {
authorities: initial_authorities.iter().map(|x| x.2.clone()).collect(),
}),
@@ -294,9 +315,7 @@ pub fn testnet_genesis(
fn development_config_genesis() -> GenesisConfig {
testnet_genesis(
- vec![
- get_authority_keys_from_seed("Alice"),
- ],
+ vec![get_authority_keys_from_seed("Alice")],
get_account_id_from_seed("Alice"),
None,
true,
@@ -315,7 +334,6 @@ fn crayfish_config_genesis() -> GenesisConfig {
)
}
-
/// Helper function to create GenesisConfig for testing
pub fn crayfish_testnet_genesis(
initial_authorities: Vec<(AccountId, AccountId, AuraId, GrandpaId)>,
@@ -345,14 +363,17 @@ pub fn crayfish_testnet_genesis(
GenesisConfig {
system: Some(SystemConfig {
- code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm").to_vec(),
+ code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm")
+ .to_vec(),
changes_trie_config: Default::default(),
}),
indices: Some(IndicesConfig {
ids: endowed_accounts.clone(),
}),
balances: Some(BalancesConfig {
- balances: endowed_accounts.iter().cloned()
+ balances: endowed_accounts
+ .iter()
+ .cloned()
.map(|k| (k, 1 * ENDOWMENT))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), 4 * ENDOWMENT)))
.collect(),
@@ -364,7 +385,10 @@ pub fn crayfish_testnet_genesis(
}),
session: Some(SessionConfig {
validators: initial_authorities.iter().map(|x| x.1.clone()).collect(),
- keys: initial_authorities.iter().map(|x| (x.1.clone(), SessionKeys(x.2.clone(), x.2.clone()))).collect::>(),
+ keys: initial_authorities
+ .iter()
+ .map(|x| (x.1.clone(), SessionKeys(x.2.clone(), x.2.clone())))
+ .collect::>(),
}),
staking: Some(StakingConfig {
current_era: 0,
@@ -374,11 +398,14 @@ pub fn crayfish_testnet_genesis(
offline_slash: Perbill::from_parts(1_000_000),
session_reward: Perbill::from_percent(90),
offline_slash_grace: 4,
- stakers: initial_authorities.iter().map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)).collect(),
+ stakers: initial_authorities
+ .iter()
+ .map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator))
+ .collect(),
invulnerables: initial_authorities.iter().map(|x| x.1.clone()).collect(),
}),
timestamp: Some(TimestampConfig {
- minimum_period: 3, // 3*2=6 second block time.
+ minimum_period: 3, // 3*2=6 second block time.
}),
contracts: Some(ContractsConfig {
current_schedule: contracts::Schedule {
@@ -387,9 +414,7 @@ pub fn crayfish_testnet_genesis(
},
gas_price: 1 * MILLI,
}),
- sudo: Some(SudoConfig {
- key: root_key,
- }),
+ sudo: Some(SudoConfig { key: root_key }),
aura: Some(AuraConfig {
authorities: initial_authorities.iter().map(|x| x.2.clone()).collect(),
}),
@@ -399,10 +424,18 @@ pub fn crayfish_testnet_genesis(
}
}
-
/// Development config (single validator Alice)
pub fn development_config() -> ChainSpec {
- ChainSpec::from_genesis("Development", "dev", development_config_genesis, vec![], None, None, None, None)
+ ChainSpec::from_genesis(
+ "Development",
+ "dev",
+ development_config_genesis,
+ vec![],
+ None,
+ None,
+ None,
+ None,
+ )
}
fn local_testnet_genesis() -> GenesisConfig {
@@ -419,14 +452,26 @@ fn local_testnet_genesis() -> GenesisConfig {
fn token_properties() -> Option {
let mut properties = Properties::new();
- properties.insert("tokenDecimals".to_owned(), serde_json::Value::Number(Number::from(ParserNumber::U64(9))));
+ properties.insert(
+ "tokenDecimals".to_owned(),
+ serde_json::Value::Number(Number::from(ParserNumber::U64(9))),
+ );
properties.insert("tokenSymbol".to_owned(), serde_json::Value::String("RING".to_owned()));
Some(properties)
}
/// Local testnet config (multivalidator Alice + Bob)
pub fn local_testnet_config() -> ChainSpec {
- ChainSpec::from_genesis("Local Testnet", "local_testnet", local_testnet_genesis, vec![], None, None, None, token_properties())
+ ChainSpec::from_genesis(
+ "Local Testnet",
+ "local_testnet",
+ local_testnet_genesis,
+ vec![],
+ None,
+ None,
+ None,
+ token_properties(),
+ )
}
/// crayfish testnet config (multivalidator Alice + Bob)
@@ -439,7 +484,8 @@ pub fn crayfish_testnet_config() -> ChainSpec {
Some(TelemetryEndpoints::new(vec![(STAGING_TELEMETRY_URL.to_string(), 0)])),
Some("DAR"),
None,
- token_properties())
+ token_properties(),
+ )
}
#[cfg(test)]
@@ -458,9 +504,7 @@ pub(crate) mod tests {
fn local_testnet_genesis_instant_single() -> GenesisConfig {
let mut genesis = testnet_genesis(
- vec![
- get_authority_keys_from_seed("Alice"),
- ],
+ vec![get_authority_keys_from_seed("Alice")],
get_account_id_from_seed("Alice"),
None,
false,
@@ -485,7 +529,16 @@ pub(crate) mod tests {
/// Local testnet config (multivalidator Alice + Bob)
pub fn integration_test_config_with_two_authorities() -> ChainSpec {
- ChainSpec::from_genesis("Integration Test", "test", local_testnet_genesis_instant, vec![], None, None, None, None)
+ ChainSpec::from_genesis(
+ "Integration Test",
+ "test",
+ local_testnet_genesis_instant,
+ vec![],
+ None,
+ None,
+ None,
+ None,
+ )
}
#[test]
diff --git a/node/cli/src/factory_impl.rs b/node/cli/src/factory_impl.rs
index 3cb16ee6f..bac3c8fb0 100644
--- a/node/cli/src/factory_impl.rs
+++ b/node/cli/src/factory_impl.rs
@@ -18,242 +18,240 @@
//! using the cli to manufacture transactions and distribute them
//! to accounts.
-use rand::{Rng, SeedableRng};
use rand::rngs::StdRng;
+use rand::{Rng, SeedableRng};
-use parity_codec::Decode;
+use crate::service;
+use finality_tracker;
+use inherents::InherentData;
use keyring::sr25519::Keyring;
use node_primitives::Hash;
-use node_runtime::{Call, CheckedExtrinsic, UncheckedExtrinsic, BalancesCall};
-use primitives::sr25519;
-use primitives::crypto::Pair;
+use node_runtime::{BalancesCall, Call, CheckedExtrinsic, UncheckedExtrinsic};
+use parity_codec::Decode;
use parity_codec::Encode;
+use primitives::crypto::Pair;
+use primitives::sr25519;
use sr_primitives::generic::Era;
use sr_primitives::traits::{Block as BlockT, Header as HeaderT};
use substrate_service::ServiceFactory;
-use transaction_factory::RuntimeAdapter;
-use transaction_factory::modes::Mode;
-use crate::service;
-use inherents::InherentData;
use timestamp;
-use finality_tracker;
+use transaction_factory::modes::Mode;
+use transaction_factory::RuntimeAdapter;
// TODO get via api: >::minimum_period(). See #2587.
const MINIMUM_PERIOD: u64 = 99;
pub struct FactoryState {
- block_no: N,
-
- mode: Mode,
- start_number: u64,
- rounds: u64,
- round: u64,
- block_in_round: u64,
- num: u64,
+ block_no: N,
+
+ mode: Mode,
+ start_number: u64,
+ rounds: u64,
+ round: u64,
+ block_in_round: u64,
+ num: u64,
}
type Number = <::Header as HeaderT>::Number;
impl RuntimeAdapter for FactoryState {
- type AccountId = node_primitives::AccountId;
- type Balance = node_primitives::Balance;
- type Block = node_primitives::Block;
- type Phase = sr_primitives::generic::Phase;
- type Secret = sr25519::Pair;
- type Index = node_primitives::Nonce;
-
- type Number = Number;
-
- fn new(
- mode: Mode,
- num: u64,
- rounds: u64,
- ) -> FactoryState {
- FactoryState {
- mode,
- num: num,
- round: 0,
- rounds,
- block_in_round: 0,
- block_no: 0,
- start_number: 0,
- }
- }
-
- fn block_no(&self) -> Self::Number {
- self.block_no
- }
-
- fn block_in_round(&self) -> Self::Number {
- self.block_in_round
- }
-
- fn rounds(&self) -> Self::Number {
- self.rounds
- }
-
- fn num(&self) -> Self::Number {
- self.num
- }
-
- fn round(&self) -> Self::Number {
- self.round
- }
-
- fn start_number(&self) -> Self::Number {
- self.start_number
- }
-
- fn mode(&self) -> &Mode {
- &self.mode
- }
-
- fn set_block_no(&mut self, val: Self::Number) {
- self.block_no = val;
- }
-
- fn set_block_in_round(&mut self, val: Self::Number) {
- self.block_in_round = val;
- }
-
- fn set_round(&mut self, val: Self::Number) {
- self.round = val;
- }
-
- fn transfer_extrinsic(
- &self,
- sender: &Self::AccountId,
- key: &Self::Secret,
- destination: &Self::AccountId,
- amount: &Self::Number,
- prior_block_hash: &::Hash,
- ) -> ::Extrinsic {
- let index = self.extract_index(&sender, prior_block_hash);
- let phase = self.extract_phase(*prior_block_hash);
-
- sign::(CheckedExtrinsic {
- signed: Some((sender.clone(), index)),
- function: Call::Balances(
- BalancesCall::transfer(
- indices::address::Address::Id(
- destination.clone().into()
- ),
- (*amount).into()
- )
- )
- }, key, &prior_block_hash, phase)
- }
-
- fn inherent_extrinsics(&self) -> InherentData {
- let timestamp = self.block_no * MINIMUM_PERIOD;
-
- let mut inherent = InherentData::new();
- inherent.put_data(timestamp::INHERENT_IDENTIFIER, ×tamp)
- .expect("Failed putting timestamp inherent");
- inherent.put_data(finality_tracker::INHERENT_IDENTIFIER, &self.block_no)
- .expect("Failed putting finalized number inherent");
- inherent
- }
-
- fn minimum_balance() -> Self::Number {
- // TODO get correct amount via api. See #2587.
- 1337
- }
-
- fn master_account_id() -> Self::AccountId {
- Keyring::Alice.pair().public()
- }
-
- fn master_account_secret() -> Self::Secret {
- Keyring::Alice.pair()
- }
-
- /// Generates a random `AccountId` from `seed`.
- fn gen_random_account_id(seed: &Self::Number) -> Self::AccountId {
- let pair: sr25519::Pair = sr25519::Pair::from_seed(&gen_seed_bytes(*seed));
- pair.public().into()
- }
-
- /// Generates a random `Secret` from `seed`.
- fn gen_random_account_secret(seed: &Self::Number) -> Self::Secret {
- let pair: sr25519::Pair = sr25519::Pair::from_seed(&gen_seed_bytes(*seed));
- pair
- }
-
- fn extract_index(
- &self,
- _account_id: &Self::AccountId,
- _block_hash: &::Hash,
- ) -> Self::Index {
- // TODO get correct index for account via api. See #2587.
- // This currently prevents the factory from being used
- // without a preceding purge of the database.
- if self.mode == Mode::MasterToN || self.mode == Mode::MasterTo1 {
- self.block_no()
- } else {
- match self.round() {
- 0 =>
- // if round is 0 all transactions will be done with master as a sender
- self.block_no(),
- _ =>
- // if round is e.g. 1 every sender account will be new and not yet have
- // any transactions done
- 0
- }
- }
- }
-
- fn extract_phase(
- &self,
- _block_hash: ::Hash
- ) -> Self::Phase {
- // TODO get correct phase via api. See #2587.
- // This currently prevents the factory from being used
- // without a preceding purge of the database.
- self.block_no
- }
+ type AccountId = node_primitives::AccountId;
+ type Balance = node_primitives::Balance;
+ type Block = node_primitives::Block;
+ type Phase = sr_primitives::generic::Phase;
+ type Secret = sr25519::Pair;
+ type Index = node_primitives::Nonce;
+
+ type Number = Number;
+
+ fn new(mode: Mode, num: u64, rounds: u64) -> FactoryState {
+ FactoryState {
+ mode,
+ num: num,
+ round: 0,
+ rounds,
+ block_in_round: 0,
+ block_no: 0,
+ start_number: 0,
+ }
+ }
+
+ fn block_no(&self) -> Self::Number {
+ self.block_no
+ }
+
+ fn block_in_round(&self) -> Self::Number {
+ self.block_in_round
+ }
+
+ fn rounds(&self) -> Self::Number {
+ self.rounds
+ }
+
+ fn num(&self) -> Self::Number {
+ self.num
+ }
+
+ fn round(&self) -> Self::Number {
+ self.round
+ }
+
+ fn start_number(&self) -> Self::Number {
+ self.start_number
+ }
+
+ fn mode(&self) -> &Mode {
+ &self.mode
+ }
+
+ fn set_block_no(&mut self, val: Self::Number) {
+ self.block_no = val;
+ }
+
+ fn set_block_in_round(&mut self, val: Self::Number) {
+ self.block_in_round = val;
+ }
+
+ fn set_round(&mut self, val: Self::Number) {
+ self.round = val;
+ }
+
+ fn transfer_extrinsic(
+ &self,
+ sender: &Self::AccountId,
+ key: &Self::Secret,
+ destination: &Self::AccountId,
+ amount: &Self::Number,
+ prior_block_hash: &::Hash,
+ ) -> ::Extrinsic {
+ let index = self.extract_index(&sender, prior_block_hash);
+ let phase = self.extract_phase(*prior_block_hash);
+
+ sign::(
+ CheckedExtrinsic {
+ signed: Some((sender.clone(), index)),
+ function: Call::Balances(BalancesCall::transfer(
+ indices::address::Address::Id(destination.clone().into()),
+ (*amount).into(),
+ )),
+ },
+ key,
+ &prior_block_hash,
+ phase,
+ )
+ }
+
+ fn inherent_extrinsics(&self) -> InherentData {
+ let timestamp = self.block_no * MINIMUM_PERIOD;
+
+ let mut inherent = InherentData::new();
+ inherent
+ .put_data(timestamp::INHERENT_IDENTIFIER, ×tamp)
+ .expect("Failed putting timestamp inherent");
+ inherent
+ .put_data(finality_tracker::INHERENT_IDENTIFIER, &self.block_no)
+ .expect("Failed putting finalized number inherent");
+ inherent
+ }
+
+ fn minimum_balance() -> Self::Number {
+ // TODO get correct amount via api. See #2587.
+ 1337
+ }
+
+ fn master_account_id() -> Self::AccountId {
+ Keyring::Alice.pair().public()
+ }
+
+ fn master_account_secret() -> Self::Secret {
+ Keyring::Alice.pair()
+ }
+
+ /// Generates a random `AccountId` from `seed`.
+ fn gen_random_account_id(seed: &Self::Number) -> Self::AccountId {
+ let pair: sr25519::Pair = sr25519::Pair::from_seed(&gen_seed_bytes(*seed));
+ pair.public().into()
+ }
+
+ /// Generates a random `Secret` from `seed`.
+ fn gen_random_account_secret(seed: &Self::Number) -> Self::Secret {
+ let pair: sr25519::Pair = sr25519::Pair::from_seed(&gen_seed_bytes(*seed));
+ pair
+ }
+
+ fn extract_index(&self, _account_id: &Self::AccountId, _block_hash: &::Hash) -> Self::Index {
+ // TODO get correct index for account via api. See #2587.
+ // This currently prevents the factory from being used
+ // without a preceding purge of the database.
+ if self.mode == Mode::MasterToN || self.mode == Mode::MasterTo1 {
+ self.block_no()
+ } else {
+ match self.round() {
+ 0 =>
+ // if round is 0 all transactions will be done with master as a sender
+ {
+ self.block_no()
+ }
+ _ =>
+ // if round is e.g. 1 every sender account will be new and not yet have
+ // any transactions done
+ {
+ 0
+ }
+ }
+ }
+ }
+
+ fn extract_phase(&self, _block_hash: ::Hash) -> Self::Phase {
+ // TODO get correct phase via api. See #2587.
+ // This currently prevents the factory from being used
+ // without a preceding purge of the database.
+ self.block_no
+ }
}
fn gen_seed_bytes(seed: u64) -> [u8; 32] {
- let mut rng: StdRng = SeedableRng::seed_from_u64(seed);
+ let mut rng: StdRng = SeedableRng::seed_from_u64(seed);
- let mut seed_bytes = [0u8; 32];
- for i in 0..32 {
- seed_bytes[i] = rng.gen::();
- }
- seed_bytes
+ let mut seed_bytes = [0u8; 32];
+ for i in 0..32 {
+ seed_bytes[i] = rng.gen::();
+ }
+ seed_bytes
}
/// Creates an `UncheckedExtrinsic` containing the appropriate signature for
/// a `CheckedExtrinsics`.
fn sign(
- xt: CheckedExtrinsic,
- key: &sr25519::Pair,
- prior_block_hash: &Hash,
- phase: u64,
+ xt: CheckedExtrinsic,
+ key: &sr25519::Pair,
+ prior_block_hash: &Hash,
+ phase: u64,
) -> ::Extrinsic {
- let s = match xt.signed {
- Some((signed, index)) => {
- let era = Era::mortal(256, phase);
- let payload = (index.into(), xt.function, era, prior_block_hash);
- let signature = payload.using_encoded(|b| {
- if b.len() > 256 {
- key.sign(&sr_io::blake2_256(b))
- } else {
- key.sign(b)
- }
- }).into();
- UncheckedExtrinsic {
- signature: Some((indices::address::Address::Id(signed), signature, payload.0, era)),
- function: payload.1,
- }
- }
- None => UncheckedExtrinsic {
- signature: None,
- function: xt.function,
- },
- };
-
- let e = Encode::encode(&s);
- Decode::decode(&mut &e[..]).expect("Failed to decode signed unchecked extrinsic")
+ let s = match xt.signed {
+ Some((signed, index)) => {
+ let era = Era::mortal(256, phase);
+ let payload = (index.into(), xt.function, era, prior_block_hash);
+ let signature = payload
+ .using_encoded(|b| {
+ if b.len() > 256 {
+ key.sign(&sr_io::blake2_256(b))
+ } else {
+ key.sign(b)
+ }
+ })
+ .into();
+ UncheckedExtrinsic {
+ signature: Some((indices::address::Address::Id(signed), signature, payload.0, era)),
+ function: payload.1,
+ }
+ }
+ None => UncheckedExtrinsic {
+ signature: None,
+ function: xt.function,
+ },
+ };
+
+ let e = Encode::encode(&s);
+ Decode::decode(&mut &e[..]).expect("Failed to decode signed unchecked extrinsic")
}
diff --git a/node/cli/src/lib.rs b/node/cli/src/lib.rs
index e112ceaf3..81e2097ac 100644
--- a/node/cli/src/lib.rs
+++ b/node/cli/src/lib.rs
@@ -23,218 +23,213 @@ extern crate serde;
pub use cli::error;
pub mod chain_spec;
-mod service;
mod factory_impl;
mod panic_handle;
+mod service;
-use tokio::prelude::Future;
-use tokio::runtime::{Builder as RuntimeBuilder, Runtime};
-pub use cli::{VersionInfo, IntoExit, NoCustom, SharedParams};
-use substrate_service::{ServiceFactory, Roles as ServiceRoles};
-use std::ops::Deref;
-use log::info;
-use structopt::{StructOpt, clap::App};
-use cli::{AugmentClap, GetLogFilter};
use crate::factory_impl::FactoryState;
use crate::panic_handle::set as panic_set;
+use cli::{AugmentClap, GetLogFilter};
+pub use cli::{IntoExit, NoCustom, SharedParams, VersionInfo};
+use log::info;
+use std::ops::Deref;
+use structopt::{clap::App, StructOpt};
+use substrate_service::{Roles as ServiceRoles, ServiceFactory};
+use tokio::prelude::Future;
+use tokio::runtime::{Builder as RuntimeBuilder, Runtime};
use transaction_factory::RuntimeAdapter;
/// The chain specification option.
#[derive(Clone, Debug, PartialEq)]
pub enum ChainSpec {
- /// Whatever the current runtime is, with just Alice as an auth.
- Development,
- /// Whatever the current runtime is, with simple Alice/Bob auths.
- LocalTestnet,
- /// The Flaming Fir testnet.
- FlamingFir,
- /// Whatever the current runtime is with the "global testnet" defaults.
- StagingTestnet,
- /// Crayfish, darwinia network poc-2
- CrayfishTestnet,
- CrayfishTestnetFir,
+ /// Whatever the current runtime is, with just Alice as an auth.
+ Development,
+ /// Whatever the current runtime is, with simple Alice/Bob auths.
+ LocalTestnet,
+ /// The Flaming Fir testnet.
+ FlamingFir,
+ /// Whatever the current runtime is with the "global testnet" defaults.
+ StagingTestnet,
+ /// Crayfish, darwinia network poc-2
+ CrayfishTestnet,
+ CrayfishTestnetFir,
}
/// Custom subcommands.
#[derive(Clone, Debug, StructOpt)]
pub enum CustomSubcommands {
- /// The custom factory subcommmand for manufacturing transactions.
- #[structopt(
- name = "factory",
- about = "Manufactures num transactions from Alice to random accounts. \
- Only supported for development or local testnet."
- )]
- Factory(FactoryCmd),
+ /// The custom factory subcommmand for manufacturing transactions.
+ #[structopt(
+ name = "factory",
+ about = "Manufactures num transactions from Alice to random accounts. \
+ Only supported for development or local testnet."
+ )]
+ Factory(FactoryCmd),
}
impl GetLogFilter for CustomSubcommands {
- fn get_log_filter(&self) -> Option {
- None
- }
+ fn get_log_filter(&self) -> Option {
+ None
+ }
}
/// The `factory` command used to generate transactions.
/// Please note: this command currently only works on an empty database!
#[derive(Debug, StructOpt, Clone)]
pub struct FactoryCmd {
- /// How often to repeat. This option only has an effect in mode `MasterToNToM`.
- #[structopt(long="rounds", default_value = "1")]
- pub rounds: u64,
-
- /// MasterToN: Manufacture `num` transactions from the master account
- /// to `num` randomly created accounts, one each.
- ///
- /// MasterTo1: Manufacture `num` transactions from the master account
- /// to exactly one other randomly created account.
- ///
- /// MasterToNToM: Manufacture `num` transactions from the master account
- /// to `num` randomly created accounts.
- /// From each of these randomly created accounts manufacture
- /// a transaction to another randomly created account.
- /// Repeat this `rounds` times. If `rounds` = 1 the behavior
- /// is the same as `MasterToN`.{n}
- /// A -> B, A -> C, A -> D, ... x `num`{n}
- /// B -> E, C -> F, D -> G, ...{n}
- /// ... x `rounds`
- ///
- /// These three modes control manufacturing.
- #[structopt(long="mode", default_value = "MasterToN")]
- pub mode: transaction_factory::Mode,
-
- /// Number of transactions to generate. In mode `MasterNToNToM` this is
- /// the number of transactions per round.
- #[structopt(long="num", default_value = "8")]
- pub num: u64,
-
- #[allow(missing_docs)]
- #[structopt(flatten)]
- pub shared_params: SharedParams,
+ /// How often to repeat. This option only has an effect in mode `MasterToNToM`.
+ #[structopt(long = "rounds", default_value = "1")]
+ pub rounds: u64,
+
+ /// MasterToN: Manufacture `num` transactions from the master account
+ /// to `num` randomly created accounts, one each.
+ ///
+ /// MasterTo1: Manufacture `num` transactions from the master account
+ /// to exactly one other randomly created account.
+ ///
+ /// MasterToNToM: Manufacture `num` transactions from the master account
+ /// to `num` randomly created accounts.
+ /// From each of these randomly created accounts manufacture
+ /// a transaction to another randomly created account.
+ /// Repeat this `rounds` times. If `rounds` = 1 the behavior
+ /// is the same as `MasterToN`.{n}
+ /// A -> B, A -> C, A -> D, ... x `num`{n}
+ /// B -> E, C -> F, D -> G, ...{n}
+ /// ... x `rounds`
+ ///
+ /// These three modes control manufacturing.
+ #[structopt(long = "mode", default_value = "MasterToN")]
+ pub mode: transaction_factory::Mode,
+
+ /// Number of transactions to generate. In mode `MasterNToNToM` this is
+ /// the number of transactions per round.
+ #[structopt(long = "num", default_value = "8")]
+ pub num: u64,
+
+ #[allow(missing_docs)]
+ #[structopt(flatten)]
+ pub shared_params: SharedParams,
}
impl AugmentClap for FactoryCmd {
- fn augment_clap<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
- FactoryCmd::augment_clap(app)
- }
+ fn augment_clap<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
+ FactoryCmd::augment_clap(app)
+ }
}
/// Get a chain config from a spec setting.
impl ChainSpec {
- pub(crate) fn load(self) -> Result {
- Ok(match self {
- ChainSpec::FlamingFir => chain_spec::flaming_fir_config()?,
- ChainSpec::Development => chain_spec::development_config(),
- ChainSpec::LocalTestnet => chain_spec::local_testnet_config(),
- ChainSpec::StagingTestnet => chain_spec::staging_testnet_config(),
- ChainSpec::CrayfishTestnet => chain_spec::crayfish_testnet_config(),
- ChainSpec::CrayfishTestnetFir => chain_spec::crayfish_fir_config()?,
- })
- }
-
- pub(crate) fn from(s: &str) -> Option {
- match s {
- "dev" => Some(ChainSpec::Development),
- "" => Some(ChainSpec::CrayfishTestnetFir),
- "local" => Some(ChainSpec::LocalTestnet),
- "crayfish" => Some(ChainSpec::CrayfishTestnet),
- "flaming-fir" => Some(ChainSpec::FlamingFir),
- "staging" => Some(ChainSpec::StagingTestnet),
- _ => None,
- }
- }
+ pub(crate) fn load(self) -> Result {
+ Ok(match self {
+ ChainSpec::FlamingFir => chain_spec::flaming_fir_config()?,
+ ChainSpec::Development => chain_spec::development_config(),
+ ChainSpec::LocalTestnet => chain_spec::local_testnet_config(),
+ ChainSpec::StagingTestnet => chain_spec::staging_testnet_config(),
+ ChainSpec::CrayfishTestnet => chain_spec::crayfish_testnet_config(),
+ ChainSpec::CrayfishTestnetFir => chain_spec::crayfish_fir_config()?,
+ })
+ }
+
+ pub(crate) fn from(s: &str) -> Option {
+ match s {
+ "dev" => Some(ChainSpec::Development),
+ "" => Some(ChainSpec::CrayfishTestnetFir),
+ "local" => Some(ChainSpec::LocalTestnet),
+ "crayfish" => Some(ChainSpec::CrayfishTestnet),
+ "flaming-fir" => Some(ChainSpec::FlamingFir),
+ "staging" => Some(ChainSpec::StagingTestnet),
+ _ => None,
+ }
+ }
}
fn load_spec(id: &str) -> Result