Statemint: Support running statemint only with ed25519 (#923)

* Statemint: Support running statemint only with ed25519

* FMT

* Update polkadot-parachains/parachains-common/src/lib.rs

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>

Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
This commit is contained in:
Bastian Köcher
2022-01-21 09:17:02 +01:00
committed by GitHub
parent ec751f8fca
commit 0760c6804f
5 changed files with 72 additions and 47 deletions
@@ -52,6 +52,13 @@ mod types {
// Aura consensus authority. // Aura consensus authority.
pub type AuraId = sp_consensus_aura::sr25519::AuthorityId; pub type AuraId = sp_consensus_aura::sr25519::AuthorityId;
// Aura consensus authority used by Statemint.
//
// Because of registering the authorities with an ed25519 key before switching from Shell
// to Statemint, we were required to deploy a hotfix that changed Statemint to ed22519.
// In the future that may change again.
pub type StatemintAuraId = sp_consensus_aura::ed25519::AuthorityId;
// Id used for identifying assets. // Id used for identifying assets.
pub type AssetId = u32; pub type AssetId = u32;
} }
+13 -13
View File
@@ -220,7 +220,7 @@ fn seedling_testnet_genesis(
} }
} }
use parachains_common::Balance as StatemintBalance; use parachains_common::{Balance as StatemintBalance, StatemintAuraId};
/// Specialized `ChainSpec` for the normal parachain runtime. /// Specialized `ChainSpec` for the normal parachain runtime.
pub type StatemintChainSpec = pub type StatemintChainSpec =
@@ -244,14 +244,14 @@ pub fn get_public_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pa
/// Generate collator keys from seed. /// Generate collator keys from seed.
/// ///
/// This function's return type must always match the session keys of the chain in tuple format. /// 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 { pub fn get_collator_keys_from_seed<AuraId: Public>(seed: &str) -> <AuraId::Pair as Pair>::Public {
get_public_from_seed::<AuraId>(seed) get_public_from_seed::<AuraId>(seed)
} }
/// Generate the session keys from individual elements. /// 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). /// 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::SessionKeys { pub fn statemint_session_keys(keys: StatemintAuraId) -> statemint_runtime::SessionKeys {
statemint_runtime::SessionKeys { aura: keys } statemint_runtime::SessionKeys { aura: keys }
} }
@@ -286,7 +286,7 @@ pub fn statemint_development_config() -> StatemintChainSpec {
// initial collators. // initial collators.
vec![( vec![(
get_account_id_from_seed::<sr25519::Public>("Alice"), get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed("Alice"), get_collator_keys_from_seed::<StatemintAuraId>("Alice"),
)], )],
vec![ vec![
get_account_id_from_seed::<sr25519::Public>("Alice"), get_account_id_from_seed::<sr25519::Public>("Alice"),
@@ -324,11 +324,11 @@ pub fn statemint_local_config() -> StatemintChainSpec {
vec![ vec![
( (
get_account_id_from_seed::<sr25519::Public>("Alice"), get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed("Alice"), get_collator_keys_from_seed::<StatemintAuraId>("Alice"),
), ),
( (
get_account_id_from_seed::<sr25519::Public>("Bob"), get_account_id_from_seed::<sr25519::Public>("Bob"),
get_collator_keys_from_seed("Bob"), get_collator_keys_from_seed::<StatemintAuraId>("Bob"),
), ),
], ],
vec![ vec![
@@ -418,7 +418,7 @@ pub fn statemint_config() -> StatemintChainSpec {
} }
fn statemint_genesis( fn statemint_genesis(
invulnerables: Vec<(AccountId, AuraId)>, invulnerables: Vec<(AccountId, StatemintAuraId)>,
endowed_accounts: Vec<AccountId>, endowed_accounts: Vec<AccountId>,
id: ParaId, id: ParaId,
) -> statemint_runtime::GenesisConfig { ) -> statemint_runtime::GenesisConfig {
@@ -474,7 +474,7 @@ pub fn statemine_development_config() -> StatemineChainSpec {
// initial collators. // initial collators.
vec![( vec![(
get_account_id_from_seed::<sr25519::Public>("Alice"), get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed("Alice"), get_collator_keys_from_seed::<AuraId>("Alice"),
)], )],
vec![ vec![
get_account_id_from_seed::<sr25519::Public>("Alice"), get_account_id_from_seed::<sr25519::Public>("Alice"),
@@ -512,11 +512,11 @@ pub fn statemine_local_config() -> StatemineChainSpec {
vec![ vec![
( (
get_account_id_from_seed::<sr25519::Public>("Alice"), get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed("Alice"), get_collator_keys_from_seed::<AuraId>("Alice"),
), ),
( (
get_account_id_from_seed::<sr25519::Public>("Bob"), get_account_id_from_seed::<sr25519::Public>("Bob"),
get_collator_keys_from_seed("Bob"), get_collator_keys_from_seed::<AuraId>("Bob"),
), ),
], ],
vec![ vec![
@@ -657,7 +657,7 @@ pub fn westmint_development_config() -> WestmintChainSpec {
// initial collators. // initial collators.
vec![( vec![(
get_account_id_from_seed::<sr25519::Public>("Alice"), get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed("Alice"), get_collator_keys_from_seed::<AuraId>("Alice"),
)], )],
vec![ vec![
get_account_id_from_seed::<sr25519::Public>("Alice"), get_account_id_from_seed::<sr25519::Public>("Alice"),
@@ -694,11 +694,11 @@ pub fn westmint_local_config() -> WestmintChainSpec {
vec![ vec![
( (
get_account_id_from_seed::<sr25519::Public>("Alice"), get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed("Alice"), get_collator_keys_from_seed::<AuraId>("Alice"),
), ),
( (
get_account_id_from_seed::<sr25519::Public>("Bob"), get_account_id_from_seed::<sr25519::Public>("Bob"),
get_collator_keys_from_seed("Bob"), get_collator_keys_from_seed::<AuraId>("Bob"),
), ),
], ],
vec![ vec![
+7 -3
View File
@@ -27,6 +27,7 @@ use codec::Encode;
use cumulus_client_service::genesis::generate_genesis_block; use cumulus_client_service::genesis::generate_genesis_block;
use cumulus_primitives_core::ParaId; use cumulus_primitives_core::ParaId;
use log::info; use log::info;
use parachains_common::{AuraId, StatemintAuraId};
use polkadot_parachain::primitives::AccountIdConversion; use polkadot_parachain::primitives::AccountIdConversion;
use sc_cli::{ use sc_cli::{
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
@@ -254,7 +255,7 @@ macro_rules! construct_async_run {
runner.async_run(|$config| { runner.async_run(|$config| {
let $components = new_partial::<westmint_runtime::RuntimeApi, WestmintRuntimeExecutor, _>( let $components = new_partial::<westmint_runtime::RuntimeApi, WestmintRuntimeExecutor, _>(
&$config, &$config,
crate::service::statemint_build_import_queue, crate::service::statemint_build_import_queue::<_, _, AuraId>,
)?; )?;
let task_manager = $components.task_manager; let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager)) { $( $code )* }.map(|v| (v, task_manager))
@@ -263,7 +264,7 @@ macro_rules! construct_async_run {
runner.async_run(|$config| { runner.async_run(|$config| {
let $components = new_partial::<statemine_runtime::RuntimeApi, StatemineRuntimeExecutor, _>( let $components = new_partial::<statemine_runtime::RuntimeApi, StatemineRuntimeExecutor, _>(
&$config, &$config,
crate::service::statemint_build_import_queue, crate::service::statemint_build_import_queue::<_, _, AuraId>,
)?; )?;
let task_manager = $components.task_manager; let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager)) { $( $code )* }.map(|v| (v, task_manager))
@@ -272,7 +273,7 @@ macro_rules! construct_async_run {
runner.async_run(|$config| { runner.async_run(|$config| {
let $components = new_partial::<statemint_runtime::RuntimeApi, StatemintRuntimeExecutor, _>( let $components = new_partial::<statemint_runtime::RuntimeApi, StatemintRuntimeExecutor, _>(
&$config, &$config,
crate::service::statemint_build_import_queue, crate::service::statemint_build_import_queue::<_, _, StatemintAuraId>,
)?; )?;
let task_manager = $components.task_manager; let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager)) { $( $code )* }.map(|v| (v, task_manager))
@@ -502,6 +503,7 @@ pub fn run() -> Result<()> {
crate::service::start_statemint_node::< crate::service::start_statemint_node::<
statemint_runtime::RuntimeApi, statemint_runtime::RuntimeApi,
StatemintRuntimeExecutor, StatemintRuntimeExecutor,
StatemintAuraId,
>(config, polkadot_config, id) >(config, polkadot_config, id)
.await .await
.map(|r| r.0) .map(|r| r.0)
@@ -510,6 +512,7 @@ pub fn run() -> Result<()> {
crate::service::start_statemint_node::< crate::service::start_statemint_node::<
statemine_runtime::RuntimeApi, statemine_runtime::RuntimeApi,
StatemineRuntimeExecutor, StatemineRuntimeExecutor,
AuraId,
>(config, polkadot_config, id) >(config, polkadot_config, id)
.await .await
.map(|r| r.0) .map(|r| r.0)
@@ -518,6 +521,7 @@ pub fn run() -> Result<()> {
crate::service::start_statemint_node::< crate::service::start_statemint_node::<
westmint_runtime::RuntimeApi, westmint_runtime::RuntimeApi,
WestmintRuntimeExecutor, WestmintRuntimeExecutor,
AuraId,
>(config, polkadot_config, id) >(config, polkadot_config, id)
.await .await
.map(|r| r.0) .map(|r| r.0)
+33 -20
View File
@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>. // along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
use codec::Codec;
use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion}; use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};
use cumulus_client_consensus_common::{ use cumulus_client_consensus_common::{
ParachainBlockImport, ParachainCandidate, ParachainConsensus, ParachainBlockImport, ParachainCandidate, ParachainConsensus,
@@ -46,13 +47,15 @@ use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClie
use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle}; use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};
use sp_api::{ApiExt, ConstructRuntimeApi}; use sp_api::{ApiExt, ConstructRuntimeApi};
use sp_consensus::{CacheKeyId, SlotData}; use sp_consensus::{CacheKeyId, SlotData};
use sp_consensus_aura::{sr25519::AuthorityId as AuraId, AuraApi}; use sp_consensus_aura::AuraApi;
use sp_core::crypto::Pair;
use sp_keystore::SyncCryptoStorePtr; use sp_keystore::SyncCryptoStorePtr;
use sp_runtime::{ use sp_runtime::{
app_crypto::AppKey,
generic::BlockId, generic::BlockId,
traits::{BlakeTwo256, Header as HeaderT}, traits::{BlakeTwo256, Header as HeaderT},
}; };
use std::{sync::Arc, time::Duration}; use std::{marker::PhantomData, sync::Arc, time::Duration};
use substrate_prometheus_endpoint::Registry; use substrate_prometheus_endpoint::Registry;
/// Native executor instance. /// Native executor instance.
@@ -907,27 +910,30 @@ impl<R> BuildOnAccess<R> {
/// Special [`ParachainConsensus`] implementation that waits for the upgrade from /// Special [`ParachainConsensus`] implementation that waits for the upgrade from
/// shell to a parachain runtime that implements Aura. /// shell to a parachain runtime that implements Aura.
struct WaitForAuraConsensus<Client> { struct WaitForAuraConsensus<Client, AuraId> {
client: Arc<Client>, client: Arc<Client>,
aura_consensus: Arc<Mutex<BuildOnAccess<Box<dyn ParachainConsensus<Block>>>>>, aura_consensus: Arc<Mutex<BuildOnAccess<Box<dyn ParachainConsensus<Block>>>>>,
relay_chain_consensus: Arc<Mutex<Box<dyn ParachainConsensus<Block>>>>, relay_chain_consensus: Arc<Mutex<Box<dyn ParachainConsensus<Block>>>>,
_phantom: PhantomData<AuraId>,
} }
impl<Client> Clone for WaitForAuraConsensus<Client> { impl<Client, AuraId> Clone for WaitForAuraConsensus<Client, AuraId> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
client: self.client.clone(), client: self.client.clone(),
aura_consensus: self.aura_consensus.clone(), aura_consensus: self.aura_consensus.clone(),
relay_chain_consensus: self.relay_chain_consensus.clone(), relay_chain_consensus: self.relay_chain_consensus.clone(),
_phantom: PhantomData,
} }
} }
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<Client> ParachainConsensus<Block> for WaitForAuraConsensus<Client> impl<Client, AuraId> ParachainConsensus<Block> for WaitForAuraConsensus<Client, AuraId>
where where
Client: sp_api::ProvideRuntimeApi<Block> + Send + Sync, Client: sp_api::ProvideRuntimeApi<Block> + Send + Sync,
Client::Api: AuraApi<Block, AuraId>, Client::Api: AuraApi<Block, AuraId>,
AuraId: Send + Codec + Sync,
{ {
async fn produce_candidate( async fn produce_candidate(
&mut self, &mut self,
@@ -958,17 +964,19 @@ where
} }
} }
struct Verifier<Client> { struct Verifier<Client, AuraId> {
client: Arc<Client>, client: Arc<Client>,
aura_verifier: BuildOnAccess<Box<dyn VerifierT<Block>>>, aura_verifier: BuildOnAccess<Box<dyn VerifierT<Block>>>,
relay_chain_verifier: Box<dyn VerifierT<Block>>, relay_chain_verifier: Box<dyn VerifierT<Block>>,
_phantom: PhantomData<AuraId>,
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<Client> VerifierT<Block> for Verifier<Client> impl<Client, AuraId> VerifierT<Block> for Verifier<Client, AuraId>
where where
Client: sp_api::ProvideRuntimeApi<Block> + Send + Sync, Client: sp_api::ProvideRuntimeApi<Block> + Send + Sync,
Client::Api: AuraApi<Block, AuraId>, Client::Api: AuraApi<Block, AuraId>,
AuraId: Send + Sync + Codec,
{ {
async fn verify( async fn verify(
&mut self, &mut self,
@@ -990,7 +998,7 @@ where
} }
/// Build the import queue for the statemint/statemine/westmine runtime. /// Build the import queue for the statemint/statemine/westmine runtime.
pub fn statemint_build_import_queue<RuntimeApi, Executor>( pub fn statemint_build_import_queue<RuntimeApi, Executor, AuraId: AppKey>(
client: Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>, client: Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>,
config: &Configuration, config: &Configuration,
telemetry_handle: Option<TelemetryHandle>, telemetry_handle: Option<TelemetryHandle>,
@@ -1015,21 +1023,20 @@ where
StateBackend = sc_client_api::StateBackendFor<TFullBackend<Block>, Block>, StateBackend = sc_client_api::StateBackendFor<TFullBackend<Block>, Block>,
> + sp_offchain::OffchainWorkerApi<Block> > + sp_offchain::OffchainWorkerApi<Block>
+ sp_block_builder::BlockBuilder<Block> + sp_block_builder::BlockBuilder<Block>
+ sp_consensus_aura::AuraApi<Block, AuraId>, + sp_consensus_aura::AuraApi<Block, <<AuraId as AppKey>::Pair as Pair>::Public>,
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>, sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
Executor: sc_executor::NativeExecutionDispatch + 'static, Executor: sc_executor::NativeExecutionDispatch + 'static,
<<AuraId as AppKey>::Pair as Pair>::Signature:
TryFrom<Vec<u8>> + std::hash::Hash + sp_runtime::traits::Member + Codec,
{ {
let client2 = client.clone(); let client2 = client.clone();
let aura_verifier = move || { let aura_verifier = move || {
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client2).unwrap(); let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client2).unwrap();
Box::new(cumulus_client_consensus_aura::build_verifier::< Box::new(
sp_consensus_aura::sr25519::AuthorityPair, cumulus_client_consensus_aura::build_verifier::<<AuraId as AppKey>::Pair, _, _, _>(
_, cumulus_client_consensus_aura::BuildVerifierParams {
_,
_,
>(cumulus_client_consensus_aura::BuildVerifierParams {
client: client2.clone(), client: client2.clone(),
create_inherent_data_providers: move |_, _| async move { create_inherent_data_providers: move |_, _| async move {
let time = sp_timestamp::InherentDataProvider::from_system_time(); let time = sp_timestamp::InherentDataProvider::from_system_time();
@@ -1046,7 +1053,9 @@ where
client2.executor().clone(), client2.executor().clone(),
), ),
telemetry: telemetry_handle, telemetry: telemetry_handle,
})) as Box<_> },
),
) as Box<_>
}; };
let relay_chain_verifier = let relay_chain_verifier =
@@ -1056,6 +1065,7 @@ where
client: client.clone(), client: client.clone(),
relay_chain_verifier, relay_chain_verifier,
aura_verifier: BuildOnAccess::Uninitialized(Some(Box::new(aura_verifier))), aura_verifier: BuildOnAccess::Uninitialized(Some(Box::new(aura_verifier))),
_phantom: PhantomData,
}; };
let registry = config.prometheus_registry().clone(); let registry = config.prometheus_registry().clone();
@@ -1071,7 +1081,7 @@ where
} }
/// Start a statemint/statemine/westmint parachain node. /// Start a statemint/statemine/westmint parachain node.
pub async fn start_statemint_node<RuntimeApi, Executor>( pub async fn start_statemint_node<RuntimeApi, Executor, AuraId: AppKey>(
parachain_config: Configuration, parachain_config: Configuration,
polkadot_config: Configuration, polkadot_config: Configuration,
id: ParaId, id: ParaId,
@@ -1093,18 +1103,20 @@ where
> + sp_offchain::OffchainWorkerApi<Block> > + sp_offchain::OffchainWorkerApi<Block>
+ sp_block_builder::BlockBuilder<Block> + sp_block_builder::BlockBuilder<Block>
+ cumulus_primitives_core::CollectCollationInfo<Block> + cumulus_primitives_core::CollectCollationInfo<Block>
+ sp_consensus_aura::AuraApi<Block, AuraId> + sp_consensus_aura::AuraApi<Block, <<AuraId as AppKey>::Pair as Pair>::Public>
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance> + pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
+ frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>, + frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>, sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
Executor: sc_executor::NativeExecutionDispatch + 'static, Executor: sc_executor::NativeExecutionDispatch + 'static,
<<AuraId as AppKey>::Pair as Pair>::Signature:
TryFrom<Vec<u8>> + std::hash::Hash + sp_runtime::traits::Member + Codec,
{ {
start_node_impl::<RuntimeApi, Executor, _, _, _>( start_node_impl::<RuntimeApi, Executor, _, _, _>(
parachain_config, parachain_config,
polkadot_config, polkadot_config,
id, id,
|_| Ok(Default::default()), |_| Ok(Default::default()),
statemint_build_import_queue, statemint_build_import_queue::<_, _, AuraId>,
|client, |client,
prometheus_registry, prometheus_registry,
telemetry, telemetry,
@@ -1132,7 +1144,7 @@ where
telemetry2.clone(), telemetry2.clone(),
); );
AuraConsensus::build::<sp_consensus_aura::sr25519::AuthorityPair, _, _, _, _, _, _>( AuraConsensus::build::<<AuraId as AppKey>::Pair, _, _, _, _, _, _>(
BuildAuraConsensusParams { BuildAuraConsensusParams {
proposer_factory, proposer_factory,
create_inherent_data_providers: create_inherent_data_providers:
@@ -1220,6 +1232,7 @@ where
client: client.clone(), client: client.clone(),
aura_consensus: Arc::new(Mutex::new(aura_consensus)), aura_consensus: Arc::new(Mutex::new(aura_consensus)),
relay_chain_consensus: Arc::new(Mutex::new(relay_chain_consensus)), relay_chain_consensus: Arc::new(Mutex::new(relay_chain_consensus)),
_phantom: PhantomData,
}); });
Ok(parachain_consensus) Ok(parachain_consensus)
+3 -2
View File
@@ -57,8 +57,9 @@ use frame_system::{
pub use parachains_common as common; pub use parachains_common as common;
use parachains_common::{ use parachains_common::{
impls::{AssetsToBlockAuthor, DealWithFees, NonZeroIssuance}, impls::{AssetsToBlockAuthor, DealWithFees, NonZeroIssuance},
opaque, AccountId, AssetId, AuraId, Balance, BlockNumber, Hash, Header, Index, Signature, opaque, AccountId, AssetId, Balance, BlockNumber, Hash, Header, Index, Signature,
AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, StatemintAuraId as AuraId, AVERAGE_ON_INITIALIZE_RATIO, HOURS, MAXIMUM_BLOCK_WEIGHT,
NORMAL_DISPATCH_RATIO, SLOT_DURATION,
}; };
#[cfg(any(feature = "std", test))] #[cfg(any(feature = "std", test))]