mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +00:00
Add Statemint (#452)
* Add Statemint * Versioning. * Fixes * Fixes * Fixes * Fixes * Fixes * Benchmarking * kick patch (paritytech/statemin#88) * Westmint Chain Spec (paritytech/statemint#90) * Tidy the common .toml * Update weights * add westmint sudo key comment * Port consensus stuff * fix typo * fix typo ... again * Recognise Westmint Co-authored-by: Alexander Popiak <alexander.popiak@parity.io> Co-authored-by: Bastian Köcher <info@kchr.de>
This commit is contained in:
@@ -56,8 +56,7 @@ impl Extensions {
|
||||
type AccountPublic = <Signature as Verify>::Signer;
|
||||
|
||||
/// Helper function to generate an account ID from seed
|
||||
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
|
||||
where
|
||||
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId where
|
||||
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
|
||||
{
|
||||
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
|
||||
@@ -193,3 +192,535 @@ fn shell_testnet_genesis(parachain_id: ParaId) -> shell_runtime::GenesisConfig {
|
||||
parachain_info: shell_runtime::ParachainInfoConfig { parachain_id },
|
||||
}
|
||||
}
|
||||
|
||||
use statemint_common::Balance as StatemintBalance;
|
||||
|
||||
/// Specialized `ChainSpec` for the normal parachain runtime.
|
||||
pub type StatemintChainSpec = sc_service::GenericChainSpec<statemint_runtime::GenesisConfig, Extensions>;
|
||||
pub type StatemineChainSpec = sc_service::GenericChainSpec<statemine_runtime::GenesisConfig, Extensions>;
|
||||
pub type WestmintChainSpec = sc_service::GenericChainSpec<westmint_runtime::GenesisConfig, Extensions>;
|
||||
|
||||
const STATEMINT_ED: StatemintBalance = statemint_runtime::constants::currency::EXISTENTIAL_DEPOSIT;
|
||||
const STATEMINE_ED: StatemintBalance = statemine_runtime::constants::currency::EXISTENTIAL_DEPOSIT;
|
||||
const WESTMINT_ED: StatemintBalance = westmint_runtime::constants::currency::EXISTENTIAL_DEPOSIT;
|
||||
|
||||
/// Helper function to generate a crypto pair from seed
|
||||
pub fn get_pair_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()
|
||||
}
|
||||
|
||||
/// Generate collator keys from seed.
|
||||
///
|
||||
/// This function's return type must always match the session keys of the chain in tuple format.
|
||||
pub fn get_collator_keys_from_seed(seed: &str) -> AuraId {
|
||||
get_pair_from_seed::<AuraId>(seed)
|
||||
}
|
||||
|
||||
/// Generate the session keys from individual elements.
|
||||
///
|
||||
/// The input must be a tuple of individual keys (a single arg for now since we have just one key).
|
||||
pub fn statemint_session_keys(keys: AuraId) -> statemint_runtime::opaque::SessionKeys {
|
||||
statemint_runtime::opaque::SessionKeys { aura: keys }
|
||||
}
|
||||
|
||||
/// Generate the session keys from individual elements.
|
||||
///
|
||||
/// The input must be a tuple of individual keys (a single arg for now since we have just one key).
|
||||
pub fn statemine_session_keys(keys: AuraId) -> statemine_runtime::opaque::SessionKeys {
|
||||
statemine_runtime::opaque::SessionKeys { aura: keys }
|
||||
}
|
||||
|
||||
/// Generate the session keys from individual elements.
|
||||
///
|
||||
/// The input must be a tuple of individual keys (a single arg for now since we have just one key).
|
||||
pub fn westmint_session_keys(keys: AuraId) -> westmint_runtime::opaque::SessionKeys {
|
||||
westmint_runtime::opaque::SessionKeys { aura: keys }
|
||||
}
|
||||
|
||||
pub fn statemint_development_config(id: ParaId) -> StatemintChainSpec {
|
||||
let mut properties = sc_chain_spec::Properties::new();
|
||||
properties.insert("tokenSymbol".into(), "DOT".into());
|
||||
properties.insert("tokenDecimals".into(), 10.into());
|
||||
|
||||
StatemintChainSpec::from_genesis(
|
||||
// Name
|
||||
"Statemint Development",
|
||||
// ID
|
||||
"statemint_dev",
|
||||
ChainType::Local,
|
||||
move || {
|
||||
statemint_genesis(
|
||||
// initial collators.
|
||||
vec![
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice"),
|
||||
)
|
||||
],
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
|
||||
],
|
||||
id,
|
||||
)
|
||||
},
|
||||
vec![],
|
||||
None,
|
||||
None,
|
||||
Some(properties),
|
||||
Extensions {
|
||||
relay_chain: "polkadot-dev".into(),
|
||||
para_id: id.into(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn statemint_local_config(id: ParaId) -> StatemintChainSpec {
|
||||
let mut properties = sc_chain_spec::Properties::new();
|
||||
properties.insert("tokenSymbol".into(), "DOT".into());
|
||||
properties.insert("tokenDecimals".into(), 10.into());
|
||||
|
||||
StatemintChainSpec::from_genesis(
|
||||
// Name
|
||||
"Statemint Local",
|
||||
// ID
|
||||
"statemint_local",
|
||||
ChainType::Local,
|
||||
move || {
|
||||
statemint_genesis(
|
||||
// initial collators.
|
||||
vec![(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice")
|
||||
),
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_collator_keys_from_seed("Bob")
|
||||
),
|
||||
],
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Charlie"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Dave"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Eve"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
|
||||
],
|
||||
id,
|
||||
)
|
||||
},
|
||||
vec![],
|
||||
None,
|
||||
None,
|
||||
Some(properties),
|
||||
Extensions {
|
||||
relay_chain: "polkadot-local".into(),
|
||||
para_id: id.into(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn statemint_genesis(
|
||||
invulnerables: Vec<(AccountId, AuraId)>,
|
||||
endowed_accounts: Vec<AccountId>,
|
||||
id: ParaId,
|
||||
) -> statemint_runtime::GenesisConfig {
|
||||
statemint_runtime::GenesisConfig {
|
||||
frame_system: statemint_runtime::SystemConfig {
|
||||
code: statemint_runtime::WASM_BINARY
|
||||
.expect("WASM binary was not build, please build it!")
|
||||
.to_vec(),
|
||||
changes_trie_config: Default::default(),
|
||||
},
|
||||
pallet_balances: statemint_runtime::BalancesConfig {
|
||||
balances: endowed_accounts
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|k| (k, STATEMINT_ED * 4096))
|
||||
.collect(),
|
||||
},
|
||||
parachain_info: statemint_runtime::ParachainInfoConfig { parachain_id: id },
|
||||
pallet_collator_selection: statemint_runtime::CollatorSelectionConfig {
|
||||
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
|
||||
candidacy_bond: STATEMINT_ED * 16,
|
||||
..Default::default()
|
||||
},
|
||||
pallet_session: statemint_runtime::SessionConfig {
|
||||
keys: invulnerables.iter().cloned().map(|(acc, aura)| (
|
||||
acc.clone(), // account id
|
||||
acc.clone(), // validator id
|
||||
statemint_session_keys(aura), // session keys
|
||||
)).collect()
|
||||
},
|
||||
// no need to pass anything to aura, in fact it will panic if we do. Session will take care
|
||||
// of this.
|
||||
pallet_aura: Default::default(),
|
||||
cumulus_pallet_aura_ext: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn statemine_development_config(id: ParaId) -> StatemineChainSpec {
|
||||
let mut properties = sc_chain_spec::Properties::new();
|
||||
properties.insert("tokenSymbol".into(), "KSM".into());
|
||||
properties.insert("tokenDecimals".into(), 12.into());
|
||||
|
||||
StatemineChainSpec::from_genesis(
|
||||
// Name
|
||||
"Statemine Development",
|
||||
// ID
|
||||
"statemine_dev",
|
||||
ChainType::Local,
|
||||
move || {
|
||||
statemine_genesis(
|
||||
// initial collators.
|
||||
vec![
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice"),
|
||||
)
|
||||
],
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
|
||||
],
|
||||
id,
|
||||
)
|
||||
},
|
||||
vec![],
|
||||
None,
|
||||
None,
|
||||
Some(properties),
|
||||
Extensions {
|
||||
relay_chain: "kusama-dev".into(),
|
||||
para_id: id.into(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn statemine_local_config(id: ParaId) -> StatemineChainSpec {
|
||||
let mut properties = sc_chain_spec::Properties::new();
|
||||
properties.insert("tokenSymbol".into(), "KSM".into());
|
||||
properties.insert("tokenDecimals".into(), 12.into());
|
||||
|
||||
StatemineChainSpec::from_genesis(
|
||||
// Name
|
||||
"Statemine Local",
|
||||
// ID
|
||||
"statemine_local",
|
||||
ChainType::Local,
|
||||
move || {
|
||||
statemine_genesis(
|
||||
// initial collators.
|
||||
vec![(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice")
|
||||
),
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_collator_keys_from_seed("Bob")
|
||||
),
|
||||
],
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Charlie"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Dave"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Eve"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
|
||||
],
|
||||
id,
|
||||
)
|
||||
},
|
||||
vec![],
|
||||
None,
|
||||
None,
|
||||
Some(properties),
|
||||
Extensions {
|
||||
relay_chain: "kusama-local".into(),
|
||||
para_id: id.into(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn statemine_config(id: ParaId) -> StatemineChainSpec {
|
||||
let mut properties = sc_chain_spec::Properties::new();
|
||||
properties.insert("tokenSymbol".into(), "KSM".into());
|
||||
properties.insert("tokenDecimals".into(), 12.into());
|
||||
|
||||
StatemineChainSpec::from_genesis(
|
||||
// Name
|
||||
"Statemine",
|
||||
// ID
|
||||
"statemine",
|
||||
ChainType::Live,
|
||||
move || {
|
||||
statemine_genesis(
|
||||
// initial collators.
|
||||
vec![(
|
||||
hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730").into(),
|
||||
hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730").unchecked_into()
|
||||
),
|
||||
(
|
||||
hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a").into(),
|
||||
hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a").unchecked_into()
|
||||
),
|
||||
(
|
||||
hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a").into(),
|
||||
hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a").unchecked_into()
|
||||
),
|
||||
(
|
||||
hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415").into(),
|
||||
hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415").unchecked_into()
|
||||
),
|
||||
],
|
||||
vec![],
|
||||
id,
|
||||
)
|
||||
},
|
||||
vec![],
|
||||
None,
|
||||
None,
|
||||
Some(properties),
|
||||
Extensions {
|
||||
relay_chain: "kusama".into(),
|
||||
para_id: id.into(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn statemine_genesis(
|
||||
invulnerables: Vec<(AccountId, AuraId)>,
|
||||
endowed_accounts: Vec<AccountId>,
|
||||
id: ParaId,
|
||||
) -> statemine_runtime::GenesisConfig {
|
||||
statemine_runtime::GenesisConfig {
|
||||
frame_system: statemine_runtime::SystemConfig {
|
||||
code: statemine_runtime::WASM_BINARY
|
||||
.expect("WASM binary was not build, please build it!")
|
||||
.to_vec(),
|
||||
changes_trie_config: Default::default(),
|
||||
},
|
||||
pallet_balances: statemine_runtime::BalancesConfig {
|
||||
balances: endowed_accounts
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|k| (k, STATEMINE_ED * 4096))
|
||||
.collect(),
|
||||
},
|
||||
parachain_info: statemine_runtime::ParachainInfoConfig { parachain_id: id },
|
||||
pallet_collator_selection: statemine_runtime::CollatorSelectionConfig {
|
||||
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
|
||||
candidacy_bond: STATEMINE_ED * 16,
|
||||
..Default::default()
|
||||
},
|
||||
pallet_session: statemine_runtime::SessionConfig {
|
||||
keys: invulnerables.iter().cloned().map(|(acc, aura)| (
|
||||
acc.clone(), // account id
|
||||
acc.clone(), // validator id
|
||||
statemine_session_keys(aura), // session keys
|
||||
)).collect()
|
||||
},
|
||||
pallet_aura: Default::default(),
|
||||
cumulus_pallet_aura_ext: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn westmint_development_config(id: ParaId) -> WestmintChainSpec {
|
||||
let mut properties = sc_chain_spec::Properties::new();
|
||||
properties.insert("tokenSymbol".into(), "WND".into());
|
||||
properties.insert("tokenDecimals".into(), 12.into());
|
||||
|
||||
WestmintChainSpec::from_genesis(
|
||||
// Name
|
||||
"Westmint Development",
|
||||
// ID
|
||||
"westmint_dev",
|
||||
ChainType::Local,
|
||||
move || {
|
||||
westmint_genesis(
|
||||
// initial collators.
|
||||
vec![
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice"),
|
||||
)
|
||||
],
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
|
||||
],
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
id,
|
||||
)
|
||||
},
|
||||
vec![],
|
||||
None,
|
||||
None,
|
||||
Some(properties),
|
||||
Extensions {
|
||||
relay_chain: "westend-dev".into(),
|
||||
para_id: id.into(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn westmint_local_config(id: ParaId) -> WestmintChainSpec {
|
||||
let mut properties = sc_chain_spec::Properties::new();
|
||||
properties.insert("tokenSymbol".into(), "WND".into());
|
||||
properties.insert("tokenDecimals".into(), 12.into());
|
||||
|
||||
WestmintChainSpec::from_genesis(
|
||||
// Name
|
||||
"Westmint Local",
|
||||
// ID
|
||||
"westmint_local",
|
||||
ChainType::Local,
|
||||
move || {
|
||||
westmint_genesis(
|
||||
// initial collators.
|
||||
vec![(
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_collator_keys_from_seed("Alice")
|
||||
),
|
||||
(
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_collator_keys_from_seed("Bob")
|
||||
),
|
||||
],
|
||||
vec![
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Charlie"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Dave"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Eve"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
|
||||
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
|
||||
],
|
||||
get_account_id_from_seed::<sr25519::Public>("Alice"),
|
||||
id,
|
||||
)
|
||||
},
|
||||
vec![],
|
||||
None,
|
||||
None,
|
||||
Some(properties),
|
||||
Extensions {
|
||||
relay_chain: "westend-local".into(),
|
||||
para_id: id.into(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn westmint_config(id: ParaId) -> WestmintChainSpec {
|
||||
let mut properties = sc_chain_spec::Properties::new();
|
||||
properties.insert("tokenSymbol".into(), "WND".into());
|
||||
properties.insert("tokenDecimals".into(), 12.into());
|
||||
|
||||
WestmintChainSpec::from_genesis(
|
||||
// Name
|
||||
"Westmint",
|
||||
// ID
|
||||
"westmint",
|
||||
ChainType::Live,
|
||||
move || {
|
||||
westmint_genesis(
|
||||
// initial collators.
|
||||
vec![(
|
||||
hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325").into(),
|
||||
hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325").unchecked_into()
|
||||
),
|
||||
(
|
||||
hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876").into(),
|
||||
hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876").unchecked_into()
|
||||
),
|
||||
(
|
||||
hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f").into(),
|
||||
hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f").unchecked_into()
|
||||
),
|
||||
(
|
||||
hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322").into(),
|
||||
hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322").unchecked_into()
|
||||
),
|
||||
],
|
||||
vec![],
|
||||
// re-use the Westend sudo key
|
||||
hex!("6648d7f3382690650c681aba1b993cd11e54deb4df21a3a18c3e2177de9f7342").into(),
|
||||
id,
|
||||
)
|
||||
},
|
||||
vec![],
|
||||
None,
|
||||
None,
|
||||
Some(properties),
|
||||
Extensions {
|
||||
relay_chain: "westend".into(),
|
||||
para_id: id.into(),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn westmint_genesis(
|
||||
invulnerables: Vec<(AccountId, AuraId)>,
|
||||
endowed_accounts: Vec<AccountId>,
|
||||
root_key: AccountId,
|
||||
id: ParaId,
|
||||
) -> westmint_runtime::GenesisConfig {
|
||||
westmint_runtime::GenesisConfig {
|
||||
frame_system: westmint_runtime::SystemConfig {
|
||||
code: westmint_runtime::WASM_BINARY
|
||||
.expect("WASM binary was not build, please build it!")
|
||||
.to_vec(),
|
||||
changes_trie_config: Default::default(),
|
||||
},
|
||||
pallet_balances: westmint_runtime::BalancesConfig {
|
||||
balances: endowed_accounts
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(|k| (k, WESTMINT_ED * 4096))
|
||||
.collect(),
|
||||
},
|
||||
pallet_sudo: westmint_runtime::SudoConfig { key: root_key },
|
||||
parachain_info: westmint_runtime::ParachainInfoConfig { parachain_id: id },
|
||||
pallet_collator_selection: westmint_runtime::CollatorSelectionConfig {
|
||||
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
|
||||
candidacy_bond: WESTMINT_ED * 16,
|
||||
..Default::default()
|
||||
},
|
||||
pallet_session: westmint_runtime::SessionConfig {
|
||||
keys: invulnerables.iter().cloned().map(|(acc, aura)| (
|
||||
acc.clone(), // account id
|
||||
acc.clone(), // validator id
|
||||
westmint_session_keys(aura), // session keys
|
||||
)).collect()
|
||||
},
|
||||
// no need to pass anything to aura, in fact it will panic if we do. Session will take care
|
||||
// of this.
|
||||
pallet_aura: Default::default(),
|
||||
cumulus_pallet_aura_ext: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,10 @@ pub enum Subcommand {
|
||||
|
||||
/// Revert the chain to a previous state.
|
||||
Revert(sc_cli::RevertCmd),
|
||||
|
||||
/// The custom benchmark subcommmand benchmarking runtime pallets.
|
||||
#[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]
|
||||
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
|
||||
}
|
||||
|
||||
/// Command for exporting the genesis state of the parachain
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
use crate::{
|
||||
chain_spec,
|
||||
cli::{Cli, RelayChainCli, Subcommand},
|
||||
service::{
|
||||
StatemineRuntimeExecutor, StatemintRuntimeExecutor, WestmintRuntimeExecutor, new_partial,
|
||||
RococoParachainRuntimeExecutor, ShellRuntimeExecutor, Block,
|
||||
},
|
||||
};
|
||||
use codec::Encode;
|
||||
use cumulus_client_service::genesis::generate_genesis_block;
|
||||
@@ -32,35 +36,83 @@ use sp_core::hexdisplay::HexDisplay;
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use std::{io::Write, net::SocketAddr};
|
||||
|
||||
trait IdentifyChain {
|
||||
fn is_shell(&self) -> bool;
|
||||
fn is_statemint(&self) -> bool;
|
||||
fn is_statemine(&self) -> bool;
|
||||
fn is_westmint(&self) -> bool;
|
||||
}
|
||||
|
||||
impl IdentifyChain for dyn sc_service::ChainSpec {
|
||||
fn is_shell(&self) -> bool {
|
||||
self.id().starts_with("shell")
|
||||
}
|
||||
fn is_statemint(&self) -> bool {
|
||||
self.id().starts_with("statemint")
|
||||
}
|
||||
fn is_statemine(&self) -> bool {
|
||||
self.id().starts_with("statemine")
|
||||
}
|
||||
fn is_westmint(&self) -> bool {
|
||||
self.id().starts_with("westmint")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: sc_service::ChainSpec + 'static> IdentifyChain for T {
|
||||
fn is_shell(&self) -> bool {
|
||||
<dyn sc_service::ChainSpec>::is_shell(self)
|
||||
}
|
||||
fn is_statemint(&self) -> bool {
|
||||
<dyn sc_service::ChainSpec>::is_statemint(self)
|
||||
}
|
||||
fn is_statemine(&self) -> bool {
|
||||
<dyn sc_service::ChainSpec>::is_statemine(self)
|
||||
}
|
||||
fn is_westmint(&self) -> bool {
|
||||
<dyn sc_service::ChainSpec>::is_westmint(self)
|
||||
}
|
||||
}
|
||||
|
||||
fn load_spec(
|
||||
id: &str,
|
||||
para_id: ParaId,
|
||||
) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
|
||||
match id {
|
||||
"staging" => Ok(Box::new(chain_spec::staging_test_net(para_id))),
|
||||
"tick" => Ok(Box::new(chain_spec::ChainSpec::from_json_bytes(
|
||||
Ok(match id {
|
||||
"staging" => Box::new(chain_spec::staging_test_net(para_id)),
|
||||
"tick" => Box::new(chain_spec::ChainSpec::from_json_bytes(
|
||||
&include_bytes!("../res/tick.json")[..],
|
||||
)?)),
|
||||
"trick" => Ok(Box::new(chain_spec::ChainSpec::from_json_bytes(
|
||||
)?),
|
||||
"trick" => Box::new(chain_spec::ChainSpec::from_json_bytes(
|
||||
&include_bytes!("../res/trick.json")[..],
|
||||
)?)),
|
||||
"track" => Ok(Box::new(chain_spec::ChainSpec::from_json_bytes(
|
||||
)?),
|
||||
"track" => Box::new(chain_spec::ChainSpec::from_json_bytes(
|
||||
&include_bytes!("../res/track.json")[..],
|
||||
)?)),
|
||||
"shell" => Ok(Box::new(chain_spec::get_shell_chain_spec(para_id))),
|
||||
"" => Ok(Box::new(chain_spec::get_chain_spec(para_id))),
|
||||
path => Ok({
|
||||
let chain_spec = chain_spec::ChainSpec::from_json_file(
|
||||
path.into(),
|
||||
)?;
|
||||
|
||||
if use_shell_runtime(&chain_spec) {
|
||||
)?),
|
||||
"shell" => Box::new(chain_spec::get_shell_chain_spec(para_id)),
|
||||
"statemint-dev" => Box::new(chain_spec::statemint_development_config(para_id)),
|
||||
"statemint-local" => Box::new(chain_spec::statemint_local_config(para_id)),
|
||||
"statemine-dev" => Box::new(chain_spec::statemine_development_config(para_id)),
|
||||
"statemine-local" => Box::new(chain_spec::statemine_local_config(para_id)),
|
||||
"statemine" => Box::new(chain_spec::statemine_config(para_id)),
|
||||
"westmint-dev" => Box::new(chain_spec::westmint_development_config(para_id)),
|
||||
"westmint-local" => Box::new(chain_spec::westmint_local_config(para_id)),
|
||||
"westmint" => Box::new(chain_spec::westmint_config(para_id)),
|
||||
"" => Box::new(chain_spec::get_chain_spec(para_id)),
|
||||
path => {
|
||||
let chain_spec = chain_spec::ChainSpec::from_json_file(path.into())?;
|
||||
if chain_spec.is_statemint() {
|
||||
Box::new(chain_spec::StatemintChainSpec::from_json_file(path.into())?)
|
||||
} else if chain_spec.is_statemine() {
|
||||
Box::new(chain_spec::StatemineChainSpec::from_json_file(path.into())?)
|
||||
} else if chain_spec.is_westmint() {
|
||||
Box::new(chain_spec::WestmintChainSpec::from_json_file(path.into())?)
|
||||
} else if chain_spec.is_shell() {
|
||||
Box::new(chain_spec::ShellChainSpec::from_json_file(path.into())?)
|
||||
} else {
|
||||
Box::new(chain_spec)
|
||||
}
|
||||
}),
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
impl SubstrateCli for Cli {
|
||||
@@ -99,7 +151,13 @@ impl SubstrateCli for Cli {
|
||||
}
|
||||
|
||||
fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
|
||||
if use_shell_runtime(&**chain_spec) {
|
||||
if chain_spec.is_statemint() {
|
||||
&statemint_runtime::VERSION
|
||||
} else if chain_spec.is_statemine() {
|
||||
&statemine_runtime::VERSION
|
||||
} else if chain_spec.is_westmint() {
|
||||
&westmint_runtime::VERSION
|
||||
} else if chain_spec.is_shell() {
|
||||
&shell_runtime::VERSION
|
||||
} else {
|
||||
&rococo_parachain_runtime::VERSION
|
||||
@@ -157,16 +215,37 @@ fn extract_genesis_wasm(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<V
|
||||
.ok_or_else(|| "Could not find wasm file in genesis state!".into())
|
||||
}
|
||||
|
||||
fn use_shell_runtime(chain_spec: &dyn ChainSpec) -> bool {
|
||||
chain_spec.id().starts_with("shell")
|
||||
}
|
||||
|
||||
use crate::service::{new_partial, RococoParachainRuntimeExecutor, ShellRuntimeExecutor};
|
||||
|
||||
macro_rules! construct_async_run {
|
||||
(|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{
|
||||
let runner = $cli.create_runner($cmd)?;
|
||||
if use_shell_runtime(&*runner.config().chain_spec) {
|
||||
if runner.config().chain_spec.is_westmint() {
|
||||
runner.async_run(|$config| {
|
||||
let $components = new_partial::<westmint_runtime::RuntimeApi, WestmintRuntimeExecutor, _>(
|
||||
&$config,
|
||||
crate::service::statemint_build_import_queue,
|
||||
)?;
|
||||
let task_manager = $components.task_manager;
|
||||
{ $( $code )* }.map(|v| (v, task_manager))
|
||||
})
|
||||
} else if runner.config().chain_spec.is_statemine() {
|
||||
runner.async_run(|$config| {
|
||||
let $components = new_partial::<statemine_runtime::RuntimeApi, StatemineRuntimeExecutor, _>(
|
||||
&$config,
|
||||
crate::service::statemint_build_import_queue,
|
||||
)?;
|
||||
let task_manager = $components.task_manager;
|
||||
{ $( $code )* }.map(|v| (v, task_manager))
|
||||
})
|
||||
} else if runner.config().chain_spec.is_statemint() {
|
||||
runner.async_run(|$config| {
|
||||
let $components = new_partial::<statemint_runtime::RuntimeApi, StatemintRuntimeExecutor, _>(
|
||||
&$config,
|
||||
crate::service::statemint_build_import_queue,
|
||||
)?;
|
||||
let task_manager = $components.task_manager;
|
||||
{ $( $code )* }.map(|v| (v, task_manager))
|
||||
})
|
||||
} else if runner.config().chain_spec.is_shell() {
|
||||
runner.async_run(|$config| {
|
||||
let $components = new_partial::<shell_runtime::RuntimeApi, ShellRuntimeExecutor, _>(
|
||||
&$config,
|
||||
@@ -290,9 +369,26 @@ pub fn run() -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Some(Subcommand::Benchmark(cmd)) => {
|
||||
if cfg!(feature = "runtime-benchmarks") {
|
||||
let runner = cli.create_runner(cmd)?;
|
||||
if runner.config().chain_spec.is_statemine() {
|
||||
runner.sync_run(|config| cmd.run::<Block, StatemineRuntimeExecutor>(config))
|
||||
} else if runner.config().chain_spec.is_westmint() {
|
||||
runner.sync_run(|config| cmd.run::<Block, WestmintRuntimeExecutor>(config))
|
||||
} else if runner.config().chain_spec.is_statemint() {
|
||||
runner.sync_run(|config| cmd.run::<Block, StatemintRuntimeExecutor>(config))
|
||||
} else {
|
||||
Err("Chain doesn't support benchmarking".into())
|
||||
}
|
||||
} else {
|
||||
Err("Benchmarking wasn't enabled when building the node. \
|
||||
You can enable it with `--features runtime-benchmarks`."
|
||||
.into())
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let runner = cli.create_runner(&cli.run.normalize())?;
|
||||
let use_shell = use_shell_runtime(&*runner.config().chain_spec);
|
||||
|
||||
runner.run_node_until_exit(|config| async move {
|
||||
// TODO
|
||||
@@ -334,7 +430,37 @@ pub fn run() -> Result<()> {
|
||||
}
|
||||
);
|
||||
|
||||
if use_shell {
|
||||
if config.chain_spec.is_statemint() {
|
||||
crate::service::start_statemint_node::<statemint_runtime::RuntimeApi, StatemintRuntimeExecutor>(
|
||||
config,
|
||||
key,
|
||||
polkadot_config,
|
||||
id,
|
||||
)
|
||||
.await
|
||||
.map(|r| r.0)
|
||||
.map_err(Into::into)
|
||||
} else if config.chain_spec.is_statemine() {
|
||||
crate::service::start_statemint_node::<statemine_runtime::RuntimeApi, StatemineRuntimeExecutor>(
|
||||
config,
|
||||
key,
|
||||
polkadot_config,
|
||||
id,
|
||||
)
|
||||
.await
|
||||
.map(|r| r.0)
|
||||
.map_err(Into::into)
|
||||
} else if config.chain_spec.is_westmint() {
|
||||
crate::service::start_statemint_node::<westmint_runtime::RuntimeApi, WestmintRuntimeExecutor>(
|
||||
config,
|
||||
key,
|
||||
polkadot_config,
|
||||
id,
|
||||
)
|
||||
.await
|
||||
.map(|r| r.0)
|
||||
.map_err(Into::into)
|
||||
} else if config.chain_spec.is_shell() {
|
||||
crate::service::start_shell_node(config, key, polkadot_config, id)
|
||||
.await
|
||||
.map(|r| r.0)
|
||||
|
||||
@@ -17,12 +17,16 @@
|
||||
use cumulus_client_consensus_aura::{
|
||||
build_aura_consensus, BuildAuraConsensusParams, SlotProportion,
|
||||
};
|
||||
use cumulus_client_consensus_common::ParachainConsensus;
|
||||
use cumulus_client_consensus_common::{
|
||||
ParachainConsensus, ParachainCandidate, ParachainBlockImport,
|
||||
};
|
||||
use cumulus_client_network::build_block_announce_validator;
|
||||
use cumulus_client_service::{
|
||||
prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,
|
||||
};
|
||||
use cumulus_primitives_core::ParaId;
|
||||
use cumulus_primitives_core::{
|
||||
ParaId, relay_chain::v1::{Hash as PHash, PersistedValidationData},
|
||||
};
|
||||
use polkadot_primitives::v1::CollatorPair;
|
||||
|
||||
use sc_client_api::ExecutorProvider;
|
||||
@@ -30,12 +34,18 @@ use sc_executor::native_executor_instance;
|
||||
use sc_network::NetworkService;
|
||||
use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClient, TaskManager};
|
||||
use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};
|
||||
use sp_api::ConstructRuntimeApi;
|
||||
use sp_consensus::SlotData;
|
||||
use sp_api::{ConstructRuntimeApi, ApiExt};
|
||||
use sp_consensus::{
|
||||
BlockImportParams, BlockOrigin, SlotData,
|
||||
import_queue::{BasicQueue, CacheKeyId, Verifier as VerifierT},
|
||||
};
|
||||
use sp_consensus_aura::{sr25519::AuthorityId as AuraId, AuraApi};
|
||||
use sp_keystore::SyncCryptoStorePtr;
|
||||
use sp_runtime::traits::BlakeTwo256;
|
||||
use sp_runtime::{traits::{BlakeTwo256, Header as HeaderT}, generic::BlockId};
|
||||
use std::sync::Arc;
|
||||
use substrate_prometheus_endpoint::Registry;
|
||||
use futures::lock::Mutex;
|
||||
use cumulus_client_consensus_relay_chain::Verifier as RelayChainVerifier;
|
||||
|
||||
pub use sc_executor::NativeExecutor;
|
||||
|
||||
@@ -58,6 +68,30 @@ native_executor_instance!(
|
||||
shell_runtime::native_version,
|
||||
);
|
||||
|
||||
// Native Statemint executor instance.
|
||||
native_executor_instance!(
|
||||
pub StatemintRuntimeExecutor,
|
||||
statemint_runtime::api::dispatch,
|
||||
statemint_runtime::native_version,
|
||||
frame_benchmarking::benchmarking::HostFunctions,
|
||||
);
|
||||
|
||||
// Native Statemine executor instance.
|
||||
native_executor_instance!(
|
||||
pub StatemineRuntimeExecutor,
|
||||
statemine_runtime::api::dispatch,
|
||||
statemine_runtime::native_version,
|
||||
frame_benchmarking::benchmarking::HostFunctions,
|
||||
);
|
||||
|
||||
// Native Westmint executor instance.
|
||||
native_executor_instance!(
|
||||
pub WestmintRuntimeExecutor,
|
||||
westmint_runtime::api::dispatch,
|
||||
westmint_runtime::native_version,
|
||||
frame_benchmarking::benchmarking::HostFunctions,
|
||||
);
|
||||
|
||||
/// Starts a `ServiceBuilder` for a full service.
|
||||
///
|
||||
/// Use this macro if you don't actually need the full service, but just the builder in order to
|
||||
@@ -326,7 +360,9 @@ where
|
||||
|
||||
/// Build the import queue for the rococo parachain runtime.
|
||||
pub fn rococo_parachain_build_import_queue(
|
||||
client: Arc<TFullClient<Block, rococo_parachain_runtime::RuntimeApi, RococoParachainRuntimeExecutor>>,
|
||||
client: Arc<
|
||||
TFullClient<Block, rococo_parachain_runtime::RuntimeApi, RococoParachainRuntimeExecutor>,
|
||||
>,
|
||||
config: &Configuration,
|
||||
telemetry: Option<TelemetryHandle>,
|
||||
task_manager: &TaskManager,
|
||||
@@ -339,33 +375,29 @@ pub fn rococo_parachain_build_import_queue(
|
||||
> {
|
||||
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
|
||||
|
||||
cumulus_client_consensus_aura::import_queue::<
|
||||
sp_consensus_aura::sr25519::AuthorityPair,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
>(cumulus_client_consensus_aura::ImportQueueParams {
|
||||
block_import: client.clone(),
|
||||
client: client.clone(),
|
||||
create_inherent_data_providers: move |_, _| async move {
|
||||
let time = sp_timestamp::InherentDataProvider::from_system_time();
|
||||
cumulus_client_consensus_aura::import_queue::<sp_consensus_aura::sr25519::AuthorityPair, _, _, _, _, _, _>(
|
||||
cumulus_client_consensus_aura::ImportQueueParams {
|
||||
block_import: client.clone(),
|
||||
client: client.clone(),
|
||||
create_inherent_data_providers: move |_, _| async move {
|
||||
let time = sp_timestamp::InherentDataProvider::from_system_time();
|
||||
|
||||
let slot =
|
||||
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration(
|
||||
*time,
|
||||
slot_duration.slot_duration(),
|
||||
);
|
||||
let slot =
|
||||
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration(
|
||||
*time,
|
||||
slot_duration.slot_duration(),
|
||||
);
|
||||
|
||||
Ok((time, slot))
|
||||
Ok((time, slot))
|
||||
},
|
||||
registry: config.prometheus_registry().clone(),
|
||||
can_author_with: sp_consensus::CanAuthorWithNativeVersion::new(
|
||||
client.executor().clone(),
|
||||
),
|
||||
spawner: &task_manager.spawn_essential_handle(),
|
||||
telemetry,
|
||||
},
|
||||
registry: config.prometheus_registry().clone(),
|
||||
can_author_with: sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()),
|
||||
spawner: &task_manager.spawn_essential_handle(),
|
||||
telemetry,
|
||||
})
|
||||
)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
@@ -375,9 +407,10 @@ pub async fn start_rococo_parachain_node(
|
||||
collator_key: CollatorPair,
|
||||
polkadot_config: Configuration,
|
||||
id: ParaId,
|
||||
) -> sc_service::error::Result<
|
||||
(TaskManager, Arc<TFullClient<Block, rococo_parachain_runtime::RuntimeApi, RococoParachainRuntimeExecutor>>)
|
||||
> {
|
||||
) -> sc_service::error::Result<(
|
||||
TaskManager,
|
||||
Arc<TFullClient<Block, rococo_parachain_runtime::RuntimeApi, RococoParachainRuntimeExecutor>>,
|
||||
)> {
|
||||
start_node_impl::<rococo_parachain_runtime::RuntimeApi, RococoParachainRuntimeExecutor, _, _, _>(
|
||||
parachain_config,
|
||||
collator_key,
|
||||
@@ -486,15 +519,16 @@ pub fn shell_build_import_queue(
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Start a rococo-shell parachain node.
|
||||
/// Start a polkadot-shell parachain node.
|
||||
pub async fn start_shell_node(
|
||||
parachain_config: Configuration,
|
||||
collator_key: CollatorPair,
|
||||
polkadot_config: Configuration,
|
||||
id: ParaId,
|
||||
) -> sc_service::error::Result<
|
||||
(TaskManager, Arc<TFullClient<Block, shell_runtime::RuntimeApi, ShellRuntimeExecutor>>)
|
||||
> {
|
||||
) -> sc_service::error::Result<(
|
||||
TaskManager,
|
||||
Arc<TFullClient<Block, shell_runtime::RuntimeApi, ShellRuntimeExecutor>>,
|
||||
)> {
|
||||
start_node_impl::<shell_runtime::RuntimeApi, ShellRuntimeExecutor, _, _, _>(
|
||||
parachain_config,
|
||||
collator_key,
|
||||
@@ -557,3 +591,379 @@ pub async fn start_shell_node(
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
enum BuildOnAccess<R> {
|
||||
Uninitialized(Option<Box<dyn FnOnce() -> R + Send + Sync>>),
|
||||
Initialized(R),
|
||||
}
|
||||
|
||||
impl<R> BuildOnAccess<R> {
|
||||
fn get_mut(&mut self) -> &mut R {
|
||||
loop {
|
||||
match self {
|
||||
Self::Uninitialized(f) => {
|
||||
*self = Self::Initialized((f.take().unwrap())());
|
||||
}
|
||||
Self::Initialized(ref mut r) => return r,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Special [`ParachainConsensus`] implementation that waits for the upgrade from
|
||||
/// shell to a parachain runtime that implements Aura.
|
||||
struct WaitForAuraConsensus<Client> {
|
||||
client: Arc<Client>,
|
||||
aura_consensus: Arc<Mutex<BuildOnAccess<Box<dyn ParachainConsensus<Block>>>>>,
|
||||
relay_chain_consensus: Arc<Mutex<Box<dyn ParachainConsensus<Block>>>>,
|
||||
}
|
||||
|
||||
impl<Client> Clone for WaitForAuraConsensus<Client> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
client: self.client.clone(),
|
||||
aura_consensus: self.aura_consensus.clone(),
|
||||
relay_chain_consensus: self.relay_chain_consensus.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<Client> ParachainConsensus<Block> for WaitForAuraConsensus<Client>
|
||||
where
|
||||
Client: sp_api::ProvideRuntimeApi<Block> + Send + Sync,
|
||||
Client::Api: AuraApi<Block, AuraId>,
|
||||
{
|
||||
async fn produce_candidate(
|
||||
&mut self,
|
||||
parent: &Header,
|
||||
relay_parent: PHash,
|
||||
validation_data: &PersistedValidationData,
|
||||
) -> Option<ParachainCandidate<Block>> {
|
||||
let block_id = BlockId::hash(parent.hash());
|
||||
if self
|
||||
.client
|
||||
.runtime_api()
|
||||
.has_api::<dyn AuraApi<Block, AuraId>>(&block_id)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
self.aura_consensus
|
||||
.lock()
|
||||
.await
|
||||
.get_mut()
|
||||
.produce_candidate(parent, relay_parent, validation_data)
|
||||
.await
|
||||
} else {
|
||||
self.relay_chain_consensus
|
||||
.lock()
|
||||
.await
|
||||
.produce_candidate(parent, relay_parent, validation_data)
|
||||
.await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Verifier<Client> {
|
||||
client: Arc<Client>,
|
||||
aura_verifier: BuildOnAccess<Box<dyn VerifierT<Block>>>,
|
||||
relay_chain_verifier: Box<dyn VerifierT<Block>>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl<Client> VerifierT<Block> for Verifier<Client>
|
||||
where
|
||||
Client: sp_api::ProvideRuntimeApi<Block> + Send + Sync,
|
||||
Client::Api: AuraApi<Block, AuraId>,
|
||||
{
|
||||
async fn verify(
|
||||
&mut self,
|
||||
origin: BlockOrigin,
|
||||
header: Header,
|
||||
justifications: Option<sp_runtime::Justifications>,
|
||||
body: Option<Vec<<Block as sp_runtime::traits::Block>::Extrinsic>>,
|
||||
) -> Result<
|
||||
(
|
||||
BlockImportParams<Block, ()>,
|
||||
Option<Vec<(CacheKeyId, Vec<u8>)>>,
|
||||
),
|
||||
String,
|
||||
> {
|
||||
let block_id = BlockId::hash(*header.parent_hash());
|
||||
|
||||
if self
|
||||
.client
|
||||
.runtime_api()
|
||||
.has_api::<dyn AuraApi<Block, AuraId>>(&block_id)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
self.aura_verifier
|
||||
.get_mut()
|
||||
.verify(origin, header, justifications, body)
|
||||
.await
|
||||
} else {
|
||||
self.relay_chain_verifier
|
||||
.verify(origin, header, justifications, body)
|
||||
.await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Build the import queue for the statemint/statemine/westmine runtime.
|
||||
pub fn statemint_build_import_queue<RuntimeApi, Executor>(
|
||||
client: Arc<TFullClient<Block, RuntimeApi, Executor>>,
|
||||
config: &Configuration,
|
||||
telemetry_handle: Option<TelemetryHandle>,
|
||||
task_manager: &TaskManager,
|
||||
) -> Result<
|
||||
sp_consensus::DefaultImportQueue<Block, TFullClient<Block, RuntimeApi, Executor>>,
|
||||
sc_service::Error,
|
||||
>
|
||||
where
|
||||
RuntimeApi: ConstructRuntimeApi<Block, TFullClient<Block, RuntimeApi, Executor>>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
|
||||
+ sp_api::Metadata<Block>
|
||||
+ sp_session::SessionKeys<Block>
|
||||
+ sp_api::ApiExt<
|
||||
Block,
|
||||
StateBackend = sc_client_api::StateBackendFor<TFullBackend<Block>, Block>,
|
||||
> + sp_offchain::OffchainWorkerApi<Block>
|
||||
+ sp_block_builder::BlockBuilder<Block>
|
||||
+ sp_consensus_aura::AuraApi<Block, AuraId>,
|
||||
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
|
||||
Executor: sc_executor::NativeExecutionDispatch + 'static,
|
||||
{
|
||||
let client2 = client.clone();
|
||||
|
||||
let aura_verifier = move || {
|
||||
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client2).unwrap();
|
||||
|
||||
Box::new(cumulus_client_consensus_aura::build_verifier::<
|
||||
sp_consensus_aura::sr25519::AuthorityPair,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
>(cumulus_client_consensus_aura::BuildVerifierParams {
|
||||
client: client2.clone(),
|
||||
create_inherent_data_providers: move |_, _| async move {
|
||||
let time = sp_timestamp::InherentDataProvider::from_system_time();
|
||||
|
||||
let slot =
|
||||
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration(
|
||||
*time,
|
||||
slot_duration.slot_duration(),
|
||||
);
|
||||
|
||||
Ok((time, slot))
|
||||
},
|
||||
can_author_with: sp_consensus::CanAuthorWithNativeVersion::new(
|
||||
client2.executor().clone(),
|
||||
),
|
||||
telemetry: telemetry_handle,
|
||||
})) as Box<_>
|
||||
};
|
||||
|
||||
let relay_chain_verifier = Box::new(RelayChainVerifier::new(client.clone(), |_, _| async {
|
||||
Ok(())
|
||||
})) as Box<_>;
|
||||
|
||||
let verifier = Verifier {
|
||||
client: client.clone(),
|
||||
relay_chain_verifier,
|
||||
aura_verifier: BuildOnAccess::Uninitialized(Some(Box::new(aura_verifier))),
|
||||
};
|
||||
|
||||
let registry = config.prometheus_registry().clone();
|
||||
let spawner = task_manager.spawn_essential_handle();
|
||||
|
||||
Ok(BasicQueue::new(
|
||||
verifier,
|
||||
Box::new(ParachainBlockImport::new(client.clone())),
|
||||
None,
|
||||
&spawner,
|
||||
registry,
|
||||
))
|
||||
}
|
||||
|
||||
/// Start a statemint/statemine/westmint parachain node.
|
||||
pub async fn start_statemint_node<RuntimeApi, Executor>(
|
||||
parachain_config: Configuration,
|
||||
collator_key: CollatorPair,
|
||||
polkadot_config: Configuration,
|
||||
id: ParaId,
|
||||
) -> sc_service::error::Result<(
|
||||
TaskManager,
|
||||
Arc<TFullClient<Block, RuntimeApi, Executor>>,
|
||||
)>
|
||||
where
|
||||
RuntimeApi: ConstructRuntimeApi<Block, TFullClient<Block, RuntimeApi, Executor>>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
RuntimeApi::RuntimeApi: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>
|
||||
+ sp_api::Metadata<Block>
|
||||
+ sp_session::SessionKeys<Block>
|
||||
+ sp_api::ApiExt<
|
||||
Block,
|
||||
StateBackend = sc_client_api::StateBackendFor<TFullBackend<Block>, Block>,
|
||||
> + sp_offchain::OffchainWorkerApi<Block>
|
||||
+ sp_block_builder::BlockBuilder<Block>
|
||||
+ cumulus_primitives_core::CollectCollationInfo<Block>
|
||||
+ sp_consensus_aura::AuraApi<Block, AuraId>,
|
||||
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
|
||||
Executor: sc_executor::NativeExecutionDispatch + 'static,
|
||||
{
|
||||
start_node_impl::<RuntimeApi, Executor, _, _, _>(
|
||||
parachain_config,
|
||||
collator_key,
|
||||
polkadot_config,
|
||||
id,
|
||||
|_| Default::default(),
|
||||
statemint_build_import_queue,
|
||||
|client,
|
||||
prometheus_registry,
|
||||
telemetry,
|
||||
task_manager,
|
||||
relay_chain_node,
|
||||
transaction_pool,
|
||||
sync_oracle,
|
||||
keystore,
|
||||
force_authoring| {
|
||||
let client2 = client.clone();
|
||||
let relay_chain_backend = relay_chain_node.backend.clone();
|
||||
let relay_chain_client = relay_chain_node.client.clone();
|
||||
let spawn_handle = task_manager.spawn_handle();
|
||||
let transaction_pool2 = transaction_pool.clone();
|
||||
let telemetry2 = telemetry.clone();
|
||||
let prometheus_registry2 = prometheus_registry.map(|r| (*r).clone());
|
||||
|
||||
let aura_consensus = BuildOnAccess::Uninitialized(Some(
|
||||
Box::new(move || {
|
||||
let slot_duration =
|
||||
cumulus_client_consensus_aura::slot_duration(&*client2).unwrap();
|
||||
|
||||
let proposer_factory =
|
||||
sc_basic_authorship::ProposerFactory::with_proof_recording(
|
||||
spawn_handle,
|
||||
client2.clone(),
|
||||
transaction_pool2,
|
||||
prometheus_registry2.as_ref(),
|
||||
telemetry2.clone(),
|
||||
);
|
||||
|
||||
let relay_chain_backend2 = relay_chain_backend.clone();
|
||||
let relay_chain_client2 = relay_chain_client.clone();
|
||||
|
||||
build_aura_consensus::<
|
||||
sp_consensus_aura::sr25519::AuthorityPair,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
>(BuildAuraConsensusParams {
|
||||
proposer_factory,
|
||||
create_inherent_data_providers:
|
||||
move |_, (relay_parent, validation_data)| {
|
||||
let parachain_inherent =
|
||||
cumulus_primitives_parachain_inherent::ParachainInherentData::create_at_with_client(
|
||||
relay_parent,
|
||||
&relay_chain_client,
|
||||
&*relay_chain_backend,
|
||||
&validation_data,
|
||||
id,
|
||||
);
|
||||
async move {
|
||||
let time =
|
||||
sp_timestamp::InherentDataProvider::from_system_time();
|
||||
|
||||
let slot =
|
||||
sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration(
|
||||
*time,
|
||||
slot_duration.slot_duration(),
|
||||
);
|
||||
|
||||
let parachain_inherent =
|
||||
parachain_inherent.ok_or_else(|| {
|
||||
Box::<dyn std::error::Error + Send + Sync>::from(
|
||||
"Failed to create parachain inherent",
|
||||
)
|
||||
})?;
|
||||
Ok((time, slot, parachain_inherent))
|
||||
}
|
||||
},
|
||||
block_import: client2.clone(),
|
||||
relay_chain_client: relay_chain_client2,
|
||||
relay_chain_backend: relay_chain_backend2,
|
||||
para_client: client2.clone(),
|
||||
backoff_authoring_blocks: Option::<()>::None,
|
||||
sync_oracle,
|
||||
keystore,
|
||||
force_authoring,
|
||||
slot_duration,
|
||||
// We got around 500ms for proposing
|
||||
block_proposal_slot_portion: SlotProportion::new(1f32 / 24f32),
|
||||
telemetry: telemetry2,
|
||||
})
|
||||
}),
|
||||
));
|
||||
|
||||
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
|
||||
task_manager.spawn_handle(),
|
||||
client.clone(),
|
||||
transaction_pool,
|
||||
prometheus_registry.clone(),
|
||||
telemetry.clone(),
|
||||
);
|
||||
|
||||
let relay_chain_backend = relay_chain_node.backend.clone();
|
||||
let relay_chain_client = relay_chain_node.client.clone();
|
||||
|
||||
let relay_chain_consensus =
|
||||
cumulus_client_consensus_relay_chain::build_relay_chain_consensus(
|
||||
cumulus_client_consensus_relay_chain::BuildRelayChainConsensusParams {
|
||||
para_id: id,
|
||||
proposer_factory,
|
||||
block_import: client.clone(),
|
||||
relay_chain_client: relay_chain_node.client.clone(),
|
||||
relay_chain_backend: relay_chain_node.backend.clone(),
|
||||
create_inherent_data_providers:
|
||||
move |_, (relay_parent, validation_data)| {
|
||||
let parachain_inherent =
|
||||
cumulus_primitives_parachain_inherent::ParachainInherentData::create_at_with_client(
|
||||
relay_parent,
|
||||
&relay_chain_client,
|
||||
&*relay_chain_backend,
|
||||
&validation_data,
|
||||
id,
|
||||
);
|
||||
async move {
|
||||
let parachain_inherent =
|
||||
parachain_inherent.ok_or_else(|| {
|
||||
Box::<dyn std::error::Error + Send + Sync>::from(
|
||||
"Failed to create parachain inherent",
|
||||
)
|
||||
})?;
|
||||
Ok(parachain_inherent)
|
||||
}
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
let parachain_consensus = Box::new(WaitForAuraConsensus {
|
||||
client: client.clone(),
|
||||
aura_consensus: Arc::new(Mutex::new(aura_consensus)),
|
||||
relay_chain_consensus: Arc::new(Mutex::new(relay_chain_consensus)),
|
||||
});
|
||||
|
||||
Ok(parachain_consensus)
|
||||
},
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user