mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
Update to latest Substrate master. (#353)
* Integrate srml/im-online * Fix all build errors with old aura. * Fix most of the build errors. * Builds and tests seem to pass (I will not trust this commit yet) * Apply suggestions from code review Co-Authored-By: Robert Habermeier <rphmeier@gmail.com> * Kill some warnings. * fix panics on 0 validators * Fix dev chain. * Fix author stuff * fix im online integration. * Some tweaks * Introduce app-crypto * Initial build work * codec update / tweaks * patch polkadot-erasure-coding input * More fixes for new crypto * More fixes * Update parachains module * evamp parachain crypto * More crypto work. * Chain spec and service. * ChainSpec stuff * Last bits for a clean build * Tweak coment * adapt polkadot-validation to the new keystore * polkadot-network compiles, but tests don't * Integrate the new parachain validation stuff * delete message_routing file * make polkadot-network tests compile and pass * runtime tests compile and pass * update substrate ref * service compiles * all tests pass * Add TODO, change branch back to polkadot-master * Lock file * TODOs done * Issue number * Remove old tODO * Remove commented code
This commit is contained in:
@@ -8,6 +8,8 @@ edition = "2018"
|
||||
parking_lot = "0.9.0"
|
||||
lazy_static = "1.0"
|
||||
log = "0.4.6"
|
||||
futures = "0.1"
|
||||
exit-future = "0.1"
|
||||
slog = "^2"
|
||||
hex-literal = "0.2"
|
||||
av_store = { package = "polkadot-availability-store", path = "../availability-store" }
|
||||
@@ -20,7 +22,6 @@ sr-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-ma
|
||||
sr-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
client = { package = "substrate-client", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
aura = { package = "substrate-consensus-aura", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
consensus_common = { package = "substrate-consensus-common", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
grandpa = { package = "substrate-finality-grandpa", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
grandpa_primitives = { package = "substrate-finality-grandpa-primitives", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
@@ -29,3 +30,7 @@ service = { package = "substrate-service", git = "https://github.com/paritytech/
|
||||
telemetry = { package = "substrate-telemetry", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
transaction_pool = { package = "substrate-transaction-pool", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
substrate-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
srml_babe = { package = "srml-babe", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
|
||||
im-online = { package = "srml-im-online", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
|
||||
babe = { package = "substrate-consensus-babe", git = "https://github.com/paritytech/substrate", branch = "polkadot-master" }
|
||||
babe-primitives = { package = "substrate-consensus-babe-primitives", git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-master" }
|
||||
|
||||
@@ -16,17 +16,20 @@
|
||||
|
||||
//! Polkadot chain configurations.
|
||||
|
||||
use primitives::{ed25519, sr25519, Pair, crypto::UncheckedInto};
|
||||
use polkadot_primitives::{AccountId, SessionKey};
|
||||
use primitives::{Pair, Public, crypto::UncheckedInto};
|
||||
use polkadot_primitives::{AccountId, parachain::ValidatorId};
|
||||
use polkadot_runtime::{
|
||||
GenesisConfig, CouncilConfig, ElectionsConfig, DemocracyConfig, SystemConfig, AuraConfig,
|
||||
GenesisConfig, CouncilConfig, ElectionsConfig, DemocracyConfig, SystemConfig, BabeConfig,
|
||||
SessionConfig, StakingConfig, BalancesConfig, Perbill, SessionKeys, TechnicalCommitteeConfig,
|
||||
GrandpaConfig, SudoConfig, IndicesConfig, CuratedGrandpaConfig, StakerStatus, WASM_BINARY,
|
||||
ClaimsConfig,
|
||||
ClaimsConfig, ImOnlineConfig, ParachainsConfig
|
||||
};
|
||||
use polkadot_runtime::constants::{currency::DOTS, time::*};
|
||||
use telemetry::TelemetryEndpoints;
|
||||
use hex_literal::hex;
|
||||
use babe_primitives::AuthorityId as BabeId;
|
||||
use grandpa::AuthorityId as GrandpaId;
|
||||
use im_online::AuthorityId as ImOnlineId;
|
||||
|
||||
const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";
|
||||
const DEFAULT_PROTOCOL_ID: &str = "dot";
|
||||
@@ -34,34 +37,58 @@ const DEFAULT_PROTOCOL_ID: &str = "dot";
|
||||
/// Specialised `ChainSpec`.
|
||||
pub type ChainSpec = ::service::ChainSpec<GenesisConfig>;
|
||||
|
||||
pub fn poc_3_testnet_config() -> Result<ChainSpec, String> {
|
||||
ChainSpec::from_embedded(include_bytes!("../res/alexander.json"))
|
||||
pub fn kusama_config() -> Result<ChainSpec, String> {
|
||||
ChainSpec::from_json_bytes(&include_bytes!("../res/kusama.json")[..])
|
||||
}
|
||||
|
||||
fn session_keys(
|
||||
babe: BabeId,
|
||||
grandpa: GrandpaId,
|
||||
im_online: ImOnlineId,
|
||||
parachain_validator: ValidatorId
|
||||
) -> SessionKeys {
|
||||
SessionKeys { babe, grandpa, im_online, parachain_validator }
|
||||
}
|
||||
|
||||
fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
// subkey inspect "$SECRET"
|
||||
let endowed_accounts = vec![
|
||||
hex!["42d69e4222c08885a4d6ff65f01852ba4a1599b683ad66286e4603d825e26b49"].unchecked_into(), // 5DaLmkrGTFvSTHBpShqqqRYaydw1sT4u3NCogYiE8Q1LqUUp
|
||||
hex!["12b782529c22032ed4694e0f6e7d486be7daa6d12088f6bc74d593b3900b8438"].unchecked_into(), // 5CVFESwfkk7NmhQ6FwHCM9roBvr9BGa4vJHFYU8DnGQxrXvz
|
||||
];
|
||||
|
||||
// for i in 1 2 3 4; do for j in stash controller; do subkey inspect "$SECRET//$i//$j"; done; done
|
||||
// for i in 1 2 3 4; do for j in session; do subkey -e inspect "$SECRET//$i//$j"; done; done
|
||||
let initial_authorities: Vec<(AccountId, AccountId, SessionKey)> = vec![(
|
||||
hex!["543cf15f6a0289e48eb4f30d451d1731c5fb0e1b2c5a4b99439c11808af3432d"].unchecked_into(), // 5Dy9yz2mjwDmTgjkDFxjPBpovKmKAgTndiRiTp4DfrTEdUvi
|
||||
hex!["8a6ea654337e4a28ce7be124f73ad84702619942722d01cc271e5b421653c56d"].unchecked_into(), // 5FCDLPUMZpZPRfouRfQDZp74typV9SjSxPgG6ymwe5Z3Sbko
|
||||
hex!["03644a181bc4e4197914aa109f3c97b6fe8c4787a82a1ddfab54e4ebedd8ab20"].unchecked_into(), // 5C99nwu8Ucq1yUJfajviwbqMAejpmaERHpmkPVWiFdxiF6yg
|
||||
// for i in 1 2 3 4; do for j in babe; do subkey --sr25519 inspect "$SECRET//$i//$j"; done; done
|
||||
// for i in 1 2 3 4; do for j in grandpa; do subkey --ed25519 inspect "$SECRET//$i//$j"; done; done
|
||||
// for i in 1 2 3 4; do for j in im_online; do subkey --sr25519 inspect "$SECRET//$i//$j"; done; done
|
||||
// for i in 1 2 3 4; do for j in parachains; do subkey --sr25519 inspect "$SECRET//$i//$j"; done; done
|
||||
let initial_authorities: Vec<(AccountId, AccountId, BabeId, GrandpaId, ImOnlineId, ValidatorId)> = vec![(
|
||||
hex!["32a5718e87d16071756d4b1370c411bbbb947eb62f0e6e0b937d5cbfc0ea633b"].unchecked_into(), // 5DD7Q4VEfPTLEdn11CnThoHT5f9xKCrnofWJL5SsvpTghaAT
|
||||
hex!["bee39fe862c85c91aaf343e130d30b643c6ea0b4406a980206f1df8331f7093b"].unchecked_into(), // 5GNzaEqhrZAtUQhbMe2gn9jBuNWfamWFZHULryFwBUXyd1cG
|
||||
hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"].unchecked_into(), // 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1
|
||||
hex!["76620f7c98bce8619979c2b58cf2b0aff71824126d2b039358729dad993223db"].unchecked_into(), // 5EjvdwATjyFFikdZibVvx1q5uBHhphS2Mnsq5c7yfaYK25vm
|
||||
hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"].unchecked_into(), // 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1
|
||||
hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"].unchecked_into(), // 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1
|
||||
),(
|
||||
hex!["c4957aa922910004f3b006d638b034070407dcb21e0905cb5cca9b58aec7fa3e"].unchecked_into(), // 5GWTeVF49JR9dAMVe4rRAAMXuhEjRAhSiYqQV4LbwpHTDLei
|
||||
hex!["1adea46f5c3d272cd6426b338dd77d5bca3aff615338c82a0f02f4c62d89280f"].unchecked_into(), // 5CfwEv8TQKnszHNhYPuij6EtLZHCcaN3DgzfPCozcS9oxZzB
|
||||
hex!["d739e1bb4c2b13ea1fff9be72e72d3bb1b364eb3b26176ab9a9512d386b7510b"].unchecked_into(), // 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY
|
||||
hex!["b496c98a405ceab59b9e970e59ef61acd7765a19b704e02ab06c1cdfe171e40f"].unchecked_into(), // 5G9VGb8ESBeS8Ca4or43RfhShzk9y7T5iTmxHk5RJsjZwsRx
|
||||
hex!["86d3a7571dd60139d297e55d8238d0c977b2e208c5af088f7f0136b565b0c103"].unchecked_into(), // 5F7V9Y5FcxKXe1aroqvPeRiUmmeQwTFcL3u9rrPXcMuMiCNx
|
||||
hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"].unchecked_into(), // 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY
|
||||
hex!["e2234d661bee4a04c38392c75d1566200aa9e6ae44dd98ee8765e4cc9af63cb7"].unchecked_into(), // 5HBDAaybNqjmY7ww8ZcZZY1L5LHxvpnyfqJwoB7HhR6raTmG
|
||||
hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"].unchecked_into(), // 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY
|
||||
hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"].unchecked_into(), // 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY
|
||||
),(
|
||||
hex!["6c3d14686e97d393814a09bea4246b9f273dcdbdef6731dcab3430b36820f135"].unchecked_into(), // 5EWdAzp9aJseLKVNeWJwE2K8PD47qzMbKVysCXr67xnEohYL
|
||||
hex!["7a73b9fcb97cee5c2240d88ca9baea06758fac450efe6f90a72014c939d41857"].unchecked_into(), // 5EqG5RSujgrtSBB5DQvR1Z2EMxAe92sAdWNTNHtX4nL2MkPi
|
||||
hex!["145791f7187d91398d8b445598f62be39b766d6e33e9d57b69c4d23fca218d7f"].unchecked_into(), // 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5
|
||||
hex!["ae12f70078a22882bf5135d134468f77301927aa67c376e8c55b7ff127ace115"].unchecked_into(), // 5FzwpgGvk2kk9agow6KsywLYcPzjYc8suKej2bne5G5b9YU3
|
||||
hex!["7addb914ec8486bbc60643d2647685dcc06373401fa80e09813b630c5831d54b"].unchecked_into(), // 5EqoZhVC2BcsM4WjvZNidu2muKAbu5THQTBKe3EjvxXkdP7A
|
||||
hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"].unchecked_into(), // 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5
|
||||
hex!["5b57ed1443c8967f461db1f6eb2ada24794d163a668f1cf9d9ce3235dfad8799"].unchecked_into(), // 5E8ULLQrDAtWhfnVfZmX41Yux86zNAwVJYguWJZVWrJvdhBe
|
||||
hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"].unchecked_into(), // 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5
|
||||
hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"].unchecked_into(), // 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5
|
||||
),(
|
||||
hex!["be6726c17ad7b5844c9e0ab6a1698d00d88bf183f0f82d8ec9627531c9ddc934"].unchecked_into(), // 5GNMbce1P2FfjvcPcoUxzjj6bYSRdQ2RpsbCyF9ozwMxx3NS
|
||||
hex!["123b9048ba61265547ad3f336dfa48c16851ba1a96691e5d1ab3be1725db0614"].unchecked_into(), // 5CUcQvAgMzXMpQSz8mgzeiswDFHED88NiEK4byfS5TLaTJow
|
||||
hex!["8abecfa66704176be23df099bf441ea65444992d63b3ced3e76a17a4d38b0b0e"].unchecked_into(), // 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd
|
||||
hex!["0867dbb49721126df589db100dda728dc3b475cbf414dad8f72a1d5e84897252"].unchecked_into(), // 5CFj6Kg9rmVn1vrqpyjau2ztyBzKeVdRKwNPiA3tqhB5HPqq
|
||||
hex!["26ab2b4b2eba2263b1e55ceb48f687bb0018130a88df0712fbdaf6a347d50e2a"].unchecked_into(), // 5CwQXP6nvWzigFqNhh2jvCaW9zWVzkdveCJY3tz2MhXMjTon
|
||||
hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"].unchecked_into(), // 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd
|
||||
hex!["e60d23f49e93c1c1f2d7c115957df5bbd7faf5ebf138d1e9d02e8b39a1f63df0"].unchecked_into(), // 5HGLmrZsiTFTPp3QoS1W8w9NxByt8PVq79reqvdxNcQkByqK
|
||||
hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"].unchecked_into(), // 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd
|
||||
hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"].unchecked_into(), // 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd
|
||||
)];
|
||||
|
||||
const ENDOWMENT: u128 = 1_000_000 * DOTS;
|
||||
@@ -87,7 +114,7 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
session: Some(SessionConfig {
|
||||
keys: initial_authorities.iter().map(|x| (
|
||||
x.0.clone(),
|
||||
SessionKeys { ed25519: x.2.clone() },
|
||||
session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone()),
|
||||
)).collect::<Vec<_>>(),
|
||||
}),
|
||||
staking: Some(StakingConfig {
|
||||
@@ -114,16 +141,25 @@ fn staging_testnet_config_genesis() -> GenesisConfig {
|
||||
term_duration: 28 * DAYS,
|
||||
desired_seats: 0,
|
||||
}),
|
||||
membership_Instance1: Some(Default::default()),
|
||||
babe: Some(BabeConfig {
|
||||
authorities: initial_authorities.iter().map(|x| (x.2.clone(), 1)).collect(),
|
||||
}),
|
||||
grandpa: Some(GrandpaConfig {
|
||||
authorities: initial_authorities.iter().map(|x| (x.3.clone(), 1)).collect(),
|
||||
}),
|
||||
im_online: Some(ImOnlineConfig {
|
||||
gossip_at: 0,
|
||||
keys: initial_authorities.iter().map(|x| x.4.clone()).collect(),
|
||||
}),
|
||||
parachains: Some(ParachainsConfig {
|
||||
authorities: initial_authorities.iter().map(|x| x.5.clone()).collect(),
|
||||
parachains: vec![],
|
||||
_phdata: Default::default(),
|
||||
}),
|
||||
sudo: Some(SudoConfig {
|
||||
key: endowed_accounts[0].clone(),
|
||||
}),
|
||||
grandpa: Some(GrandpaConfig {
|
||||
authorities: initial_authorities.iter().map(|x| (x.2.clone(), 1)).collect(),
|
||||
}),
|
||||
aura: Some(AuraConfig {
|
||||
authorities: initial_authorities.iter().map(|x| x.2.clone()).collect(),
|
||||
}),
|
||||
parachains: Some(Default::default()),
|
||||
curated_grandpa: Some(CuratedGrandpaConfig {
|
||||
shuffle_period: 1024,
|
||||
}),
|
||||
@@ -148,49 +184,53 @@ pub fn staging_testnet_config() -> ChainSpec {
|
||||
)
|
||||
}
|
||||
|
||||
/// Helper function to generate AccountId from seed
|
||||
pub fn get_account_id_from_seed(seed: &str) -> AccountId {
|
||||
sr25519::Pair::from_string(&format!("//{}", seed), None)
|
||||
/// Helper function to generate a crypto pair from seed
|
||||
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
|
||||
TPublic::Pair::from_string(&format!("//{}", seed), None)
|
||||
.expect("static values are valid; qed")
|
||||
.public()
|
||||
}
|
||||
|
||||
/// Helper function to generate SessionKey from seed
|
||||
pub fn get_session_key_from_seed(seed: &str) -> SessionKey {
|
||||
ed25519::Pair::from_string(&format!("//{}", seed), None)
|
||||
.expect("static values are valid; qed")
|
||||
.public()
|
||||
}
|
||||
|
||||
/// Helper function to generate stash, controller and session key from seed
|
||||
pub fn get_authority_keys_from_seed(seed: &str) -> (AccountId, AccountId, SessionKey) {
|
||||
pub fn get_authority_keys_from_seed(seed: &str) -> (
|
||||
AccountId,
|
||||
AccountId,
|
||||
BabeId,
|
||||
GrandpaId,
|
||||
ImOnlineId,
|
||||
ValidatorId
|
||||
) {
|
||||
(
|
||||
get_account_id_from_seed(&format!("{}//stash", seed)),
|
||||
get_account_id_from_seed(seed),
|
||||
get_session_key_from_seed(seed),
|
||||
get_from_seed::<AccountId>(&format!("{}//stash", seed)),
|
||||
get_from_seed::<AccountId>(seed),
|
||||
get_from_seed::<BabeId>(seed),
|
||||
get_from_seed::<GrandpaId>(seed),
|
||||
get_from_seed::<ImOnlineId>(seed),
|
||||
get_from_seed::<ValidatorId>(seed),
|
||||
)
|
||||
}
|
||||
|
||||
/// Helper function to create GenesisConfig for testing
|
||||
pub fn testnet_genesis(
|
||||
initial_authorities: Vec<(AccountId, AccountId, SessionKey)>,
|
||||
initial_authorities: Vec<(AccountId, AccountId, BabeId, GrandpaId, ImOnlineId, ValidatorId)>,
|
||||
root_key: AccountId,
|
||||
endowed_accounts: Option<Vec<AccountId>>,
|
||||
) -> GenesisConfig {
|
||||
let endowed_accounts: Vec<AccountId> = endowed_accounts.unwrap_or_else(|| {
|
||||
vec![
|
||||
get_account_id_from_seed("Alice"),
|
||||
get_account_id_from_seed("Bob"),
|
||||
get_account_id_from_seed("Charlie"),
|
||||
get_account_id_from_seed("Dave"),
|
||||
get_account_id_from_seed("Eve"),
|
||||
get_account_id_from_seed("Ferdie"),
|
||||
get_account_id_from_seed("Alice//stash"),
|
||||
get_account_id_from_seed("Bob//stash"),
|
||||
get_account_id_from_seed("Charlie//stash"),
|
||||
get_account_id_from_seed("Dave//stash"),
|
||||
get_account_id_from_seed("Eve//stash"),
|
||||
get_account_id_from_seed("Ferdie//stash"),
|
||||
get_from_seed::<AccountId>("Alice"),
|
||||
get_from_seed::<AccountId>("Bob"),
|
||||
get_from_seed::<AccountId>("Charlie"),
|
||||
get_from_seed::<AccountId>("Dave"),
|
||||
get_from_seed::<AccountId>("Eve"),
|
||||
get_from_seed::<AccountId>("Ferdie"),
|
||||
get_from_seed::<AccountId>("Alice//stash"),
|
||||
get_from_seed::<AccountId>("Bob//stash"),
|
||||
get_from_seed::<AccountId>("Charlie//stash"),
|
||||
get_from_seed::<AccountId>("Dave//stash"),
|
||||
get_from_seed::<AccountId>("Eve//stash"),
|
||||
get_from_seed::<AccountId>("Ferdie//stash"),
|
||||
]
|
||||
});
|
||||
|
||||
@@ -214,7 +254,7 @@ pub fn testnet_genesis(
|
||||
session: Some(SessionConfig {
|
||||
keys: initial_authorities.iter().map(|x| (
|
||||
x.0.clone(),
|
||||
SessionKeys { ed25519: x.2.clone() },
|
||||
session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone()),
|
||||
)).collect::<Vec<_>>(),
|
||||
}),
|
||||
staking: Some(StakingConfig {
|
||||
@@ -240,22 +280,31 @@ pub fn testnet_genesis(
|
||||
elections: Some(ElectionsConfig {
|
||||
members: endowed_accounts.iter()
|
||||
.filter(|&endowed| initial_authorities.iter()
|
||||
.find(|&(_, controller, _)| controller == endowed)
|
||||
.find(|&(_, controller, _, _, _, _)| controller == endowed)
|
||||
.is_none()
|
||||
).map(|a| (a.clone(), 1000000)).collect(),
|
||||
presentation_duration: 10,
|
||||
term_duration: 1000000,
|
||||
desired_seats,
|
||||
}),
|
||||
parachains: Some(Default::default()),
|
||||
sudo: Some(SudoConfig {
|
||||
key: root_key,
|
||||
}),
|
||||
grandpa: Some(GrandpaConfig {
|
||||
membership_Instance1: Some(Default::default()),
|
||||
babe: Some(BabeConfig {
|
||||
authorities: initial_authorities.iter().map(|x| (x.2.clone(), 1)).collect(),
|
||||
}),
|
||||
aura: Some(AuraConfig {
|
||||
authorities: initial_authorities.iter().map(|x| x.2.clone()).collect(),
|
||||
grandpa: Some(GrandpaConfig {
|
||||
authorities: initial_authorities.iter().map(|x| (x.3.clone(), 1)).collect(),
|
||||
}),
|
||||
im_online: Some(ImOnlineConfig {
|
||||
gossip_at: 0,
|
||||
keys: initial_authorities.iter().map(|x| x.4.clone()).collect(),
|
||||
}),
|
||||
parachains: Some(ParachainsConfig {
|
||||
authorities: initial_authorities.iter().map(|x| x.5.clone()).collect(),
|
||||
parachains: vec![],
|
||||
_phdata: Default::default(),
|
||||
}),
|
||||
sudo: Some(SudoConfig {
|
||||
key: root_key,
|
||||
}),
|
||||
curated_grandpa: Some(CuratedGrandpaConfig {
|
||||
shuffle_period: 1024,
|
||||
@@ -272,7 +321,7 @@ fn development_config_genesis() -> GenesisConfig {
|
||||
vec![
|
||||
get_authority_keys_from_seed("Alice"),
|
||||
],
|
||||
get_account_id_from_seed("Alice"),
|
||||
get_from_seed::<AccountId>("Alice"),
|
||||
None,
|
||||
)
|
||||
}
|
||||
@@ -297,7 +346,7 @@ fn local_testnet_genesis() -> GenesisConfig {
|
||||
get_authority_keys_from_seed("Alice"),
|
||||
get_authority_keys_from_seed("Bob"),
|
||||
],
|
||||
get_account_id_from_seed("Alice"),
|
||||
get_from_seed::<AccountId>("Alice"),
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
+192
-121
@@ -18,18 +18,21 @@
|
||||
|
||||
pub mod chain_spec;
|
||||
|
||||
use futures::prelude::*;
|
||||
use client::LongestChain;
|
||||
use consensus_common::SelectChain;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use grandpa_primitives::AuthorityPair as GrandpaPair;
|
||||
use polkadot_primitives::{parachain, Block, Hash, BlockId, AuraPair};
|
||||
use polkadot_primitives::{parachain, Block, Hash, BlockId};
|
||||
use polkadot_runtime::{GenesisConfig, RuntimeApi};
|
||||
use polkadot_network::gossip::{self as network_gossip, Known};
|
||||
use primitives::{ed25519, Pair};
|
||||
use service::{FactoryFullConfiguration, FullBackend, LightBackend, FullExecutor, LightExecutor};
|
||||
use service::{
|
||||
FactoryFullConfiguration, FullBackend, LightBackend, FullExecutor, LightExecutor,
|
||||
error::Error as ServiceError, TelemetryOnConnect
|
||||
};
|
||||
use transaction_pool::txpool::{Pool as TransactionPool};
|
||||
use aura::{import_queue, start_aura, AuraImportQueue, SlotDuration};
|
||||
use babe::{import_queue, start_babe, BabeImportQueue, Config};
|
||||
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider};
|
||||
use inherents::InherentDataProviders;
|
||||
use log::info;
|
||||
pub use service::{
|
||||
@@ -49,6 +52,20 @@ pub use consensus::run_validation_worker;
|
||||
/// All configuration for the polkadot node.
|
||||
pub type Configuration = FactoryFullConfiguration<Factory>;
|
||||
|
||||
type BabeBlockImportForService<F> = babe::BabeBlockImport<
|
||||
FullBackend<F>,
|
||||
FullExecutor<F>,
|
||||
<F as crate::ServiceFactory>::Block,
|
||||
grandpa::BlockImportForService<F>,
|
||||
<F as crate::ServiceFactory>::RuntimeApi,
|
||||
client::Client<
|
||||
FullBackend<F>,
|
||||
FullExecutor<F>,
|
||||
<F as crate::ServiceFactory>::Block,
|
||||
<F as crate::ServiceFactory>::RuntimeApi
|
||||
>,
|
||||
>;
|
||||
|
||||
/// Polkadot-specific configuration.
|
||||
pub struct CustomConfiguration {
|
||||
/// Set to `Some` with a collator `CollatorId` and desired parachain
|
||||
@@ -58,11 +75,15 @@ pub struct CustomConfiguration {
|
||||
/// Intermediate state during setup. Will be removed in future. Set to `None`.
|
||||
// FIXME: rather than putting this on the config, let's have an actual intermediate setup state
|
||||
// https://github.com/paritytech/substrate/issues/1134
|
||||
pub grandpa_import_setup: Option<(
|
||||
grandpa::BlockImportForService<Factory>,
|
||||
grandpa::LinkHalfForService<Factory>
|
||||
pub import_setup: Option<(
|
||||
BabeBlockImportForService<Factory>,
|
||||
grandpa::LinkHalfForService<Factory>,
|
||||
babe::BabeLink,
|
||||
)>,
|
||||
|
||||
/// Tasks that were created by previous setup steps and should be spawned.
|
||||
pub tasks_to_spawn: Option<Vec<Box<dyn Future<Item = (), Error = ()> + Send>>>,
|
||||
|
||||
/// Maximal `block_data` size.
|
||||
pub max_block_data_size: Option<u64>,
|
||||
|
||||
@@ -73,8 +94,9 @@ impl Default for CustomConfiguration {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
collating_for: None,
|
||||
grandpa_import_setup: None,
|
||||
import_setup: None,
|
||||
inherent_data_providers: InherentDataProviders::new(),
|
||||
tasks_to_spawn: None,
|
||||
max_block_data_size: None,
|
||||
}
|
||||
}
|
||||
@@ -150,93 +172,37 @@ impl PolkadotService for Service<LightComponents<Factory>> {
|
||||
service::construct_service_factory! {
|
||||
struct Factory {
|
||||
Block = Block,
|
||||
ConsensusPair = AuraPair,
|
||||
FinalityPair = GrandpaPair,
|
||||
RuntimeApi = RuntimeApi,
|
||||
NetworkProtocol = PolkadotProtocol {
|
||||
|config: &Configuration| Ok(PolkadotProtocol::new(config.custom.collating_for.clone()))
|
||||
},
|
||||
NetworkProtocol = PolkadotProtocol { |config: &Configuration| Ok(PolkadotProtocol::new(config.custom.collating_for.clone())) },
|
||||
RuntimeDispatch = polkadot_executor::Executor,
|
||||
FullTransactionPoolApi = TxChainApi<FullBackend<Self>, FullExecutor<Self>>
|
||||
{ |config, client| Ok(TransactionPool::new(config, TxChainApi::new(client))) },
|
||||
LightTransactionPoolApi = TxChainApi<LightBackend<Self>, LightExecutor<Self>>
|
||||
{ |config, client| Ok(TransactionPool::new(config, TxChainApi::new(client))) },
|
||||
FullTransactionPoolApi = transaction_pool::ChainApi<client::Client<FullBackend<Self>, FullExecutor<Self>, Block, RuntimeApi>, Block>
|
||||
{ |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) },
|
||||
LightTransactionPoolApi = transaction_pool::ChainApi<client::Client<LightBackend<Self>, LightExecutor<Self>, Block, RuntimeApi>, Block>
|
||||
{ |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) },
|
||||
Genesis = GenesisConfig,
|
||||
Configuration = CustomConfiguration,
|
||||
FullService = FullComponents<Self>
|
||||
{ |config: FactoryFullConfiguration<Self>| {
|
||||
FullComponents::<Factory>::new(config)
|
||||
} },
|
||||
AuthoritySetup = { |mut service: Self::FullService| {
|
||||
use polkadot_network::validation::ValidationNetwork;
|
||||
|
||||
let (block_import, link_half) = service.config.custom.grandpa_import_setup.take()
|
||||
FullService = FullComponents<Self> { |config: FactoryFullConfiguration<Self>| FullComponents::<Factory>::new(config) },
|
||||
AuthoritySetup = {
|
||||
|mut service: Self::FullService| {
|
||||
let (block_import, link_half, babe_link) = service.config_mut().custom.import_setup.take()
|
||||
.expect("Link Half and Block Import are present for Full Services or setup failed before. qed");
|
||||
|
||||
// always run GRANDPA in order to sync.
|
||||
{
|
||||
let grandpa_key = if service.config.disable_grandpa {
|
||||
None
|
||||
} else {
|
||||
service.authority_key()
|
||||
};
|
||||
|
||||
let config = grandpa::Config {
|
||||
local_key: grandpa_key.map(Arc::new),
|
||||
// FIXME #1578 make this available through chainspec
|
||||
gossip_duration: Duration::from_millis(333),
|
||||
justification_period: 4096,
|
||||
name: Some(service.config.name.clone())
|
||||
};
|
||||
|
||||
match config.local_key {
|
||||
None => {
|
||||
service.spawn_task(grandpa::run_grandpa_observer(
|
||||
config,
|
||||
link_half,
|
||||
service.network(),
|
||||
service.on_exit(),
|
||||
)?);
|
||||
},
|
||||
Some(_) => {
|
||||
use service::TelemetryOnConnect;
|
||||
|
||||
let telemetry_on_connect = TelemetryOnConnect {
|
||||
telemetry_connection_sinks: service.telemetry_on_connect_stream(),
|
||||
};
|
||||
|
||||
let grandpa_config = grandpa::GrandpaParams {
|
||||
config: config,
|
||||
link: link_half,
|
||||
network: service.network(),
|
||||
inherent_data_providers: service.config.custom.inherent_data_providers.clone(),
|
||||
on_exit: service.on_exit(),
|
||||
telemetry_on_connect: Some(telemetry_on_connect),
|
||||
};
|
||||
service.spawn_task(grandpa::run_grandpa_voter(grandpa_config)?);
|
||||
},
|
||||
// spawn any futures that were created in the previous setup steps
|
||||
if let Some(tasks) = service.config_mut().custom.tasks_to_spawn.take() {
|
||||
for task in tasks {
|
||||
service.spawn_task(
|
||||
task.select(service.on_exit())
|
||||
.map(|_| ())
|
||||
.map_err(|_| ())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
let extrinsic_store = {
|
||||
use std::path::PathBuf;
|
||||
if service.config().roles != service::Roles::AUTHORITY {
|
||||
return Ok(service);
|
||||
}
|
||||
|
||||
let mut path = PathBuf::from(service.config.database_path.clone());
|
||||
path.push("availability");
|
||||
|
||||
av_store::Store::new(::av_store::Config {
|
||||
cache_size: None,
|
||||
path,
|
||||
})?
|
||||
};
|
||||
|
||||
// run authorship only if authority.
|
||||
let aura_key = match service.authority_key() {
|
||||
Some(key) => Arc::new(key),
|
||||
None => return Ok(service),
|
||||
};
|
||||
|
||||
if service.config.custom.collating_for.is_some() {
|
||||
if service.config().custom.collating_for.is_some() {
|
||||
info!(
|
||||
"The node cannot start as an authority because it is also configured to run as a collator."
|
||||
);
|
||||
@@ -275,6 +241,19 @@ service::construct_service_factory! {
|
||||
},
|
||||
);
|
||||
|
||||
use polkadot_network::validation::ValidationNetwork;
|
||||
let extrinsic_store = {
|
||||
use std::path::PathBuf;
|
||||
|
||||
let mut path = PathBuf::from(service.config().database_path.clone());
|
||||
path.push("availability");
|
||||
|
||||
av_store::Store::new(::av_store::Config {
|
||||
cache_size: None,
|
||||
path,
|
||||
})?
|
||||
};
|
||||
|
||||
// collator connections and validation network both fulfilled by this
|
||||
let validation_network = ValidationNetwork::new(
|
||||
service.network(),
|
||||
@@ -283,63 +262,150 @@ service::construct_service_factory! {
|
||||
service.client(),
|
||||
polkadot_network::validation::WrappedExecutor(service.spawn_task_handle()),
|
||||
);
|
||||
let proposer_factory = consensus::ProposerFactory::new(
|
||||
let proposer = consensus::ProposerFactory::new(
|
||||
client.clone(),
|
||||
select_chain.clone(),
|
||||
validation_network.clone(),
|
||||
validation_network,
|
||||
service.transaction_pool(),
|
||||
Arc::new(service.spawn_task_handle()),
|
||||
aura_key.clone(),
|
||||
service.keystore(),
|
||||
extrinsic_store,
|
||||
SlotDuration::get_or_compute(&*client)?,
|
||||
service.config.custom.max_block_data_size,
|
||||
polkadot_runtime::constants::time::SLOT_DURATION,
|
||||
service.config().custom.max_block_data_size,
|
||||
);
|
||||
|
||||
info!("Using authority key {}", aura_key.public());
|
||||
let task = start_aura(
|
||||
SlotDuration::get_or_compute(&*client)?,
|
||||
aura_key,
|
||||
client.clone(),
|
||||
let client = service.client();
|
||||
let select_chain = service.select_chain().ok_or(ServiceError::SelectChainRequired)?;
|
||||
|
||||
let babe_config = babe::BabeParams {
|
||||
config: Config::get_or_compute(&*client)?,
|
||||
keystore: service.keystore(),
|
||||
client,
|
||||
select_chain,
|
||||
block_import,
|
||||
Arc::new(proposer_factory),
|
||||
service.network(),
|
||||
service.config.custom.inherent_data_providers.clone(),
|
||||
service.config.force_authoring,
|
||||
)?;
|
||||
env: proposer,
|
||||
sync_oracle: service.network(),
|
||||
inherent_data_providers: service.config().custom.inherent_data_providers.clone(),
|
||||
force_authoring: service.config().force_authoring,
|
||||
time_source: babe_link,
|
||||
};
|
||||
|
||||
let babe = start_babe(babe_config)?;
|
||||
let select = babe.select(service.on_exit()).then(|_| Ok(()));
|
||||
service.spawn_task(Box::new(select));
|
||||
|
||||
let config = grandpa::Config {
|
||||
// FIXME substrate#1578 make this available through chainspec
|
||||
gossip_duration: Duration::from_millis(333),
|
||||
justification_period: 4096,
|
||||
name: Some(service.config().name.clone()),
|
||||
keystore: Some(service.keystore()),
|
||||
};
|
||||
|
||||
match (service.config().roles.is_authority(), service.config().disable_grandpa) {
|
||||
(false, false) => {
|
||||
// start the lightweight GRANDPA observer
|
||||
service.spawn_task(Box::new(grandpa::run_grandpa_observer(
|
||||
config,
|
||||
link_half,
|
||||
service.network(),
|
||||
service.on_exit(),
|
||||
)?));
|
||||
},
|
||||
(true, false) => {
|
||||
// start the full GRANDPA voter
|
||||
let telemetry_on_connect = TelemetryOnConnect {
|
||||
telemetry_connection_sinks: service.telemetry_on_connect_stream(),
|
||||
};
|
||||
let grandpa_config = grandpa::GrandpaParams {
|
||||
config: config,
|
||||
link: link_half,
|
||||
network: service.network(),
|
||||
inherent_data_providers: service.config().custom.inherent_data_providers.clone(),
|
||||
on_exit: service.on_exit(),
|
||||
telemetry_on_connect: Some(telemetry_on_connect),
|
||||
};
|
||||
service.spawn_task(Box::new(grandpa::run_grandpa_voter(grandpa_config)?));
|
||||
},
|
||||
(_, true) => {
|
||||
grandpa::setup_disabled_grandpa(
|
||||
service.client(),
|
||||
&service.config().custom.inherent_data_providers,
|
||||
service.network(),
|
||||
)?;
|
||||
},
|
||||
}
|
||||
// let config = grandpa::Config {
|
||||
// // FIXME #1578 make this available through chainspec
|
||||
// gossip_duration: Duration::from_millis(333),
|
||||
// justification_period: 4096,
|
||||
// name: Some(service.config().name.clone()),
|
||||
// keystore: Some(service.keystore()),
|
||||
// };
|
||||
|
||||
// if !service.config().disable_grandpa {
|
||||
// if service.config().roles.is_authority() {
|
||||
// let telemetry_on_connect = TelemetryOnConnect {
|
||||
// telemetry_connection_sinks: service.telemetry_on_connect_stream(),
|
||||
// };
|
||||
// let grandpa_config = grandpa::GrandpaParams {
|
||||
// config: config,
|
||||
// link: link_half,
|
||||
// network: service.network(),
|
||||
// inherent_data_providers: service.config().custom.inherent_data_providers.clone(),
|
||||
// on_exit: service.on_exit(),
|
||||
// telemetry_on_connect: Some(telemetry_on_connect),
|
||||
// };
|
||||
// service.spawn_task(Box::new(grandpa::run_grandpa_voter(grandpa_config)?));
|
||||
// } else {
|
||||
// service.spawn_task(Box::new(grandpa::run_grandpa_observer(
|
||||
// config,
|
||||
// link_half,
|
||||
// service.network(),
|
||||
// service.on_exit(),
|
||||
// )?));
|
||||
// }
|
||||
// }
|
||||
|
||||
// // regardless of whether grandpa is started or not, when
|
||||
// // authoring blocks we expect inherent data regarding what our
|
||||
// // last finalized block is, to be available.
|
||||
// grandpa::register_finality_tracker_inherent_data_provider(
|
||||
// service.client(),
|
||||
// &service.config().custom.inherent_data_providers,
|
||||
// )?;
|
||||
|
||||
service.spawn_task(task);
|
||||
Ok(service)
|
||||
}},
|
||||
}
|
||||
},
|
||||
LightService = LightComponents<Self>
|
||||
{ |config| <LightComponents<Factory>>::new(config) },
|
||||
FullImportQueue = AuraImportQueue<
|
||||
Self::Block,
|
||||
>
|
||||
FullImportQueue = BabeImportQueue<Self::Block>
|
||||
{ |config: &mut FactoryFullConfiguration<Self>, client: Arc<FullClient<Self>>, select_chain: Self::SelectChain| {
|
||||
let slot_duration = SlotDuration::get_or_compute(&*client)?;
|
||||
|
||||
let (block_import, link_half) =
|
||||
grandpa::block_import::<_, _, _, RuntimeApi, FullClient<Self>, _>(
|
||||
client.clone(), client.clone(), select_chain
|
||||
)?;
|
||||
let justification_import = block_import.clone();
|
||||
|
||||
config.custom.grandpa_import_setup = Some((block_import.clone(), link_half));
|
||||
import_queue::<_, _, ed25519::Pair>(
|
||||
slot_duration,
|
||||
Box::new(block_import),
|
||||
let (import_queue, babe_link, babe_block_import, pruning_task) = import_queue(
|
||||
Config::get_or_compute(&*client)?,
|
||||
block_import,
|
||||
Some(Box::new(justification_import)),
|
||||
None,
|
||||
client.clone(),
|
||||
client,
|
||||
config.custom.inherent_data_providers.clone(),
|
||||
).map_err(Into::into)
|
||||
)?;
|
||||
|
||||
config.custom.import_setup = Some((babe_block_import.clone(), link_half, babe_link));
|
||||
config.custom.tasks_to_spawn = Some(vec![Box::new(pruning_task)]);
|
||||
|
||||
Ok(import_queue)
|
||||
}},
|
||||
LightImportQueue = AuraImportQueue<
|
||||
Self::Block,
|
||||
>
|
||||
{ |config: &mut FactoryFullConfiguration<Self>, client: Arc<LightClient<Self>>| {
|
||||
LightImportQueue = BabeImportQueue<Self::Block>
|
||||
{ |config: &FactoryFullConfiguration<Self>, client: Arc<LightClient<Self>>| {
|
||||
#[allow(deprecated)]
|
||||
let fetch_checker = client.backend().blockchain().fetcher()
|
||||
.upgrade()
|
||||
@@ -348,17 +414,22 @@ service::construct_service_factory! {
|
||||
let block_import = grandpa::light_block_import::<_, _, _, RuntimeApi, LightClient<Self>>(
|
||||
client.clone(), Arc::new(fetch_checker), client.clone()
|
||||
)?;
|
||||
|
||||
let finality_proof_import = block_import.clone();
|
||||
let finality_proof_request_builder = finality_proof_import.create_finality_proof_request_builder();
|
||||
|
||||
import_queue::<_, _, ed25519::Pair>(
|
||||
SlotDuration::get_or_compute(&*client)?,
|
||||
Box::new(block_import),
|
||||
// FIXME: pruning task isn't started since light client doesn't do `AuthoritySetup`.
|
||||
let (import_queue, ..) = import_queue(
|
||||
Config::get_or_compute(&*client)?,
|
||||
block_import,
|
||||
None,
|
||||
Some(Box::new(finality_proof_import)),
|
||||
client.clone(),
|
||||
client,
|
||||
config.custom.inherent_data_providers.clone(),
|
||||
).map_err(Into::into).map(|q| (q, finality_proof_request_builder))
|
||||
)?;
|
||||
|
||||
Ok((import_queue, finality_proof_request_builder))
|
||||
}},
|
||||
SelectChain = LongestChain<FullBackend<Self>, Self::Block>
|
||||
{ |config: &FactoryFullConfiguration<Self>, client: Arc<FullClient<Self>>| {
|
||||
@@ -367,7 +438,7 @@ service::construct_service_factory! {
|
||||
}
|
||||
},
|
||||
FinalityProofProvider = { |client: Arc<FullClient<Self>>| {
|
||||
Ok(Some(Arc::new(grandpa::FinalityProofProvider::new(client.clone(), client)) as _))
|
||||
Ok(Some(Arc::new(GrandpaFinalityProofProvider::new(client.clone(), client)) as _))
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user