Seedling Runtime + Node (#824)

* before adding seedling client side

* seedling runtime compiles

* create seedling spec script added

* seedling node & BaseCallFilter fixes

* update AllPalets

* formatting

* CallFilter + SignedExtra + AccountData fix

* XCM removed

* cleanup
This commit is contained in:
Ignacio Palacios
2021-12-08 12:54:59 +01:00
committed by GitHub
parent 58a425667e
commit fff94ff24c
9 changed files with 880 additions and 276 deletions
@@ -30,6 +30,10 @@ pub type ChainSpec =
/// Specialized `ChainSpec` for the shell parachain runtime.
pub type ShellChainSpec = sc_service::GenericChainSpec<shell_runtime::GenesisConfig, Extensions>;
/// Specialized `ChainSpec` for the seedling parachain runtime.
pub type SeedlingChainSpec =
sc_service::GenericChainSpec<seedling_runtime::GenesisConfig, Extensions>;
/// 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)
@@ -112,6 +116,25 @@ pub fn get_shell_chain_spec() -> ShellChainSpec {
)
}
pub fn get_seedling_chain_spec() -> SeedlingChainSpec {
SeedlingChainSpec::from_genesis(
"Seedling Local Testnet",
"seedling_local_testnet",
ChainType::Local,
move || {
seedling_testnet_genesis(
get_account_id_from_seed::<sr25519::Public>("Alice"),
2000.into(),
)
},
Vec::new(),
None,
None,
None,
Extensions { relay_chain: "westend".into(), para_id: 2000 },
)
}
pub fn staging_test_net() -> ChainSpec {
ChainSpec::from_genesis(
"Staging Testnet",
@@ -177,6 +200,22 @@ fn shell_testnet_genesis(parachain_id: ParaId) -> shell_runtime::GenesisConfig {
}
}
fn seedling_testnet_genesis(
root_key: AccountId,
parachain_id: ParaId,
) -> seedling_runtime::GenesisConfig {
seedling_runtime::GenesisConfig {
system: seedling_runtime::SystemConfig {
code: seedling_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
},
sudo: seedling_runtime::SudoConfig { key: root_key },
parachain_info: seedling_runtime::ParachainInfoConfig { parachain_id },
parachain_system: Default::default(),
}
}
use parachains_common::Balance as StatemintBalance;
/// Specialized `ChainSpec` for the normal parachain runtime.
+39 -6
View File
@@ -18,8 +18,9 @@ use crate::{
chain_spec,
cli::{Cli, RelayChainCli, Subcommand},
service::{
new_partial, Block, RococoParachainRuntimeExecutor, ShellRuntimeExecutor,
StatemineRuntimeExecutor, StatemintRuntimeExecutor, WestmintRuntimeExecutor,
new_partial, Block, RococoParachainRuntimeExecutor, SeedlingRuntimeExecutor,
ShellRuntimeExecutor, StatemineRuntimeExecutor, StatemintRuntimeExecutor,
WestmintRuntimeExecutor,
},
};
use codec::Encode;
@@ -41,6 +42,7 @@ use std::{io::Write, net::SocketAddr};
trait IdentifyChain {
fn is_shell(&self) -> bool;
fn is_seedling(&self) -> bool;
fn is_statemint(&self) -> bool;
fn is_statemine(&self) -> bool;
fn is_westmint(&self) -> bool;
@@ -50,6 +52,9 @@ impl IdentifyChain for dyn sc_service::ChainSpec {
fn is_shell(&self) -> bool {
self.id().starts_with("shell")
}
fn is_seedling(&self) -> bool {
self.id().starts_with("seedling")
}
fn is_statemint(&self) -> bool {
self.id().starts_with("statemint")
}
@@ -65,6 +70,9 @@ impl<T: sc_service::ChainSpec + 'static> IdentifyChain for T {
fn is_shell(&self) -> bool {
<dyn sc_service::ChainSpec>::is_shell(self)
}
fn is_seedling(&self) -> bool {
<dyn sc_service::ChainSpec>::is_seedling(self)
}
fn is_statemint(&self) -> bool {
<dyn sc_service::ChainSpec>::is_statemint(self)
}
@@ -89,6 +97,7 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, St
&include_bytes!("../res/track.json")[..],
)?),
"shell" => Box::new(chain_spec::get_shell_chain_spec()),
"seedling" => Box::new(chain_spec::get_seedling_chain_spec()),
"statemint-dev" => Box::new(chain_spec::statemint_development_config()),
"statemint-local" => Box::new(chain_spec::statemint_local_config()),
"statemine-dev" => Box::new(chain_spec::statemine_development_config()),
@@ -118,6 +127,8 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, St
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 if chain_spec.is_seedling() {
Box::new(chain_spec::SeedlingChainSpec::from_json_file(path.into())?)
} else {
Box::new(chain_spec)
}
@@ -169,6 +180,8 @@ impl SubstrateCli for Cli {
&westmint_runtime::VERSION
} else if chain_spec.is_shell() {
&shell_runtime::VERSION
} else if chain_spec.is_seedling() {
&seedling_runtime::VERSION
} else {
&rococo_parachain_runtime::VERSION
}
@@ -264,6 +277,15 @@ macro_rules! construct_async_run {
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
} else if runner.config().chain_spec.is_seedling() {
runner.async_run(|$config| {
let $components = new_partial::<seedling_runtime::RuntimeApi, SeedlingRuntimeExecutor, _>(
&$config,
crate::service::shell_build_import_queue,
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
} else {
runner.async_run(|$config| {
let $components = new_partial::<
@@ -485,10 +507,21 @@ pub fn run() -> Result<()> {
.map(|r| r.0)
.map_err(Into::into)
} else if config.chain_spec.is_shell() {
crate::service::start_shell_node(config, polkadot_config, id)
.await
.map(|r| r.0)
.map_err(Into::into)
crate::service::start_shell_node::<
shell_runtime::RuntimeApi,
ShellRuntimeExecutor,
>(config, polkadot_config, id)
.await
.map(|r| r.0)
.map_err(Into::into)
} else if config.chain_spec.is_seedling() {
crate::service::start_shell_node::<
seedling_runtime::RuntimeApi,
SeedlingRuntimeExecutor,
>(config, polkadot_config, id)
.await
.map(|r| r.0)
.map_err(Into::into)
} else {
crate::service::start_rococo_parachain_node(config, polkadot_config, id)
.await
+56 -12
View File
@@ -84,6 +84,21 @@ impl sc_executor::NativeExecutionDispatch for ShellRuntimeExecutor {
}
}
/// Native executor instance.
pub struct SeedlingRuntimeExecutor;
impl sc_executor::NativeExecutionDispatch for SeedlingRuntimeExecutor {
type ExtendHostFunctions = ();
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
seedling_runtime::api::dispatch(method, data)
}
fn native_version() -> sc_executor::NativeVersion {
seedling_runtime::native_version()
}
}
// Native Statemint executor instance.
pub struct StatemintRuntimeExecutor;
@@ -759,20 +774,34 @@ pub async fn start_rococo_parachain_node(
}
/// Build the import queue for the shell runtime.
pub fn shell_build_import_queue(
client: Arc<
TFullClient<Block, shell_runtime::RuntimeApi, NativeElseWasmExecutor<ShellRuntimeExecutor>>,
>,
pub fn shell_build_import_queue<RuntimeApi, Executor>(
client: Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>,
config: &Configuration,
_: Option<TelemetryHandle>,
task_manager: &TaskManager,
) -> Result<
sc_consensus::DefaultImportQueue<
Block,
TFullClient<Block, shell_runtime::RuntimeApi, NativeElseWasmExecutor<ShellRuntimeExecutor>>,
TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>,
>,
sc_service::Error,
> {
>
where
RuntimeApi: ConstructRuntimeApi<Block, TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<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>,
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
Executor: sc_executor::NativeExecutionDispatch + 'static,
{
cumulus_client_consensus_relay_chain::import_queue(
client.clone(),
client,
@@ -784,17 +813,32 @@ pub fn shell_build_import_queue(
}
/// Start a polkadot-shell parachain node.
pub async fn start_shell_node(
pub async fn start_shell_node<RuntimeApi, Executor>(
parachain_config: Configuration,
polkadot_config: Configuration,
id: ParaId,
) -> sc_service::error::Result<(
TaskManager,
Arc<
TFullClient<Block, shell_runtime::RuntimeApi, NativeElseWasmExecutor<ShellRuntimeExecutor>>,
>,
)> {
start_shell_node_impl::<shell_runtime::RuntimeApi, ShellRuntimeExecutor, _, _, _>(
Arc<TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<Executor>>>,
)>
where
RuntimeApi: ConstructRuntimeApi<Block, TFullClient<Block, RuntimeApi, NativeElseWasmExecutor<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>,
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
Executor: sc_executor::NativeExecutionDispatch + 'static,
{
start_shell_node_impl::<RuntimeApi, Executor, _, _, _>(
parachain_config,
polkadot_config,
id,