mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 08:11:03 +00:00
Implement basic upward & downward messages (#118)
* Start by replacing branch names and set `DownwardMessage` * Add the upward-message crate * Add Kusama & Polkadot * More work on getting the upward messages working * Fix build * Begin to integrate it into the test Parachain * Update * Make everything compile again * Switch to westend and print parachain account on startup * Use MultiSignature etc * Fix validate block * Some downward messages work * Update git reference * More downward messages integration * Update test runtime for downward messages * Enable downward message handler and withdraw send tokens * Add some docs * Begin to implement simple XCMP * More work * Fixes and make parachain id configurable * Make parachain ID be part of the genesis * Finishing the XCMP message demo * Update and fixes tests * Update branch
This commit is contained in:
@@ -19,6 +19,7 @@ use crate::cli::{Cli, PolkadotCli, Subcommand};
|
||||
use codec::Encode;
|
||||
use log::info;
|
||||
use parachain_runtime::Block;
|
||||
use polkadot_parachain::primitives::AccountIdConversion;
|
||||
use sc_cli::{
|
||||
CliConfiguration, Error, ImportParams, KeystoreParams, NetworkParams, Result, SharedParams,
|
||||
SubstrateCli,
|
||||
@@ -30,8 +31,8 @@ use sp_runtime::{
|
||||
traits::{Block as BlockT, Hash as HashT, Header as HeaderT, Zero},
|
||||
BuildStorage,
|
||||
};
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use std::{net::SocketAddr, sync::Arc};
|
||||
use cumulus_primitives::ParaId;
|
||||
|
||||
impl SubstrateCli for Cli {
|
||||
fn impl_name() -> &'static str {
|
||||
@@ -66,7 +67,8 @@ impl SubstrateCli for Cli {
|
||||
}
|
||||
|
||||
fn load_spec(&self, _id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
|
||||
Ok(Box::new(chain_spec::get_chain_spec()))
|
||||
// Such a hack :(
|
||||
Ok(Box::new(chain_spec::get_chain_spec(self.run.parachain_id.into())))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,23 +116,21 @@ impl SubstrateCli for PolkadotCli {
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_genesis_state() -> Result<Block> {
|
||||
let storage = (&chain_spec::get_chain_spec()).build_storage()?;
|
||||
fn generate_genesis_state(para_id: ParaId) -> Result<Block> {
|
||||
let storage = (&chain_spec::get_chain_spec(para_id)).build_storage()?;
|
||||
|
||||
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
|
||||
let state_root =
|
||||
<<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
child_content.data.clone().into_iter().collect(),
|
||||
);
|
||||
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
child_content.data.clone().into_iter().collect(),
|
||||
);
|
||||
(sk.clone(), state_root.encode())
|
||||
});
|
||||
let state_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
storage.top.clone().into_iter().chain(child_roots).collect(),
|
||||
);
|
||||
|
||||
let extrinsics_root = <<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
|
||||
Vec::new(),
|
||||
);
|
||||
let extrinsics_root =
|
||||
<<<Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(Vec::new());
|
||||
|
||||
Ok(Block::new(
|
||||
<<Block as BlockT>::Header as HeaderT>::new(
|
||||
@@ -157,7 +157,7 @@ pub fn run() -> Result<()> {
|
||||
Some(Subcommand::ExportGenesisState(params)) => {
|
||||
sc_cli::init_logger("");
|
||||
|
||||
let block = generate_genesis_state()?;
|
||||
let block = generate_genesis_state(params.parachain_id.into())?;
|
||||
let header_hex = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
|
||||
|
||||
if let Some(output) = ¶ms.output {
|
||||
@@ -174,13 +174,14 @@ pub fn run() -> Result<()> {
|
||||
let grandpa_pause = if polkadot_cli.run.grandpa_pause.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some((polkadot_cli.run.grandpa_pause[0], polkadot_cli.run.grandpa_pause[1]))
|
||||
Some((
|
||||
polkadot_cli.run.grandpa_pause[0],
|
||||
polkadot_cli.run.grandpa_pause[1],
|
||||
))
|
||||
};
|
||||
|
||||
runner.run_node(
|
||||
|config| {
|
||||
polkadot_service::polkadot_new_light(config)
|
||||
},
|
||||
|config| polkadot_service::polkadot_new_light(config),
|
||||
|config| {
|
||||
polkadot_service::polkadot_new_full(
|
||||
config,
|
||||
@@ -190,22 +191,23 @@ pub fn run() -> Result<()> {
|
||||
6000,
|
||||
grandpa_pause,
|
||||
None,
|
||||
).map(|(s, _, _)| s)
|
||||
)
|
||||
.map(|(s, _, _)| s)
|
||||
},
|
||||
polkadot_service::PolkadotExecutor::native_version().runtime_version
|
||||
polkadot_service::PolkadotExecutor::native_version().runtime_version,
|
||||
)
|
||||
},
|
||||
}
|
||||
Some(Subcommand::PolkadotValidationWorker(cmd)) => {
|
||||
sc_cli::init_logger("");
|
||||
polkadot_service::run_validation_worker(&cmd.mem_id)?;
|
||||
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
None => {
|
||||
let runner = cli.create_runner(&cli.run)?;
|
||||
let runner = cli.create_runner(&*cli.run)?;
|
||||
|
||||
// TODO
|
||||
let key = Arc::new(sp_core::Pair::from_seed(&[10; 32]));
|
||||
let key = Arc::new(sp_core::Pair::generate().0);
|
||||
|
||||
let mut polkadot_cli = PolkadotCli::from_iter(
|
||||
[PolkadotCli::executable_name().to_string()]
|
||||
@@ -213,6 +215,14 @@ pub fn run() -> Result<()> {
|
||||
.chain(cli.relaychain_args.iter()),
|
||||
);
|
||||
|
||||
let id = ParaId::from(cli.run.parachain_id);
|
||||
|
||||
let parachain_account =
|
||||
AccountIdConversion::<polkadot_primitives::AccountId>::into_account(&id);
|
||||
|
||||
let block = generate_genesis_state(id)?;
|
||||
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
|
||||
|
||||
runner.run_full_node(
|
||||
|config| {
|
||||
polkadot_cli.base_path =
|
||||
@@ -226,9 +236,11 @@ pub fn run() -> Result<()> {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
info!("Parachain id: {:?}", crate::PARA_ID);
|
||||
info!("Parachain id: {:?}", id);
|
||||
info!("Parachain Account: {}", parachain_account);
|
||||
info!("Parachain genesis state: {}", genesis_state);
|
||||
|
||||
crate::service::run_collator(config, key, polkadot_config)
|
||||
crate::service::run_collator(config, key, polkadot_config, id)
|
||||
},
|
||||
parachain_runtime::VERSION,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user