mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-08 20:38:04 +00:00
Update substrate and polkadot (#50)
* Update Cargo.lock * Fix for substrate update * Update Cargo.lock * Fix for substrate update * Fix for substrate update * Fix for substrate update * Fix for substrate update * Update Cargo.lock * Fix for substrate update * Fix for substrate update * Fix for substrate update * Fix for substrate update * Fix for substrate update * WIP * Temporary fix until polkadot is fixed * WIP * WIP
This commit is contained in:
Generated
+545
-393
File diff suppressed because it is too large
Load Diff
+9
-6
@@ -24,6 +24,7 @@ use sp_consensus::{
|
||||
};
|
||||
use sp_inherents::InherentDataProviders;
|
||||
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
|
||||
use sc_cli;
|
||||
|
||||
use polkadot_collator::{
|
||||
BuildParachainContext, InvalidHead, Network as CollatorNetwork, ParachainContext,
|
||||
@@ -43,7 +44,9 @@ use log::{error, trace};
|
||||
|
||||
use futures::{task::Spawn, Future, future};
|
||||
|
||||
use std::{fmt::Debug, marker::PhantomData, sync::Arc, time::Duration, pin::Pin};
|
||||
use std::{
|
||||
fmt::Debug, marker::PhantomData, sync::Arc, time::Duration, pin::Pin, collections::HashMap,
|
||||
};
|
||||
|
||||
use parking_lot::Mutex;
|
||||
|
||||
@@ -207,11 +210,12 @@ where
|
||||
post_digests: vec![],
|
||||
body: Some(b.extrinsics().to_vec()),
|
||||
finalized: false,
|
||||
intermediates: HashMap::new(),
|
||||
auxiliary: vec![], // block-weight is written in block import.
|
||||
// TODO: block-import handles fork choice and this shouldn't even have the
|
||||
// option to specify one.
|
||||
// https://github.com/paritytech/substrate/issues/3623
|
||||
fork_choice: ForkChoiceStrategy::LongestChain,
|
||||
fork_choice: Some(ForkChoiceStrategy::LongestChain),
|
||||
allow_missing_state: false,
|
||||
import_existing: false,
|
||||
storage_changes: Some(storage_changes),
|
||||
@@ -342,10 +346,9 @@ pub trait SetupParachain<Block: BlockT>: Send {
|
||||
}
|
||||
|
||||
/// Run a collator with the given proposer factory.
|
||||
pub fn run_collator<Block, SP, E>(
|
||||
pub fn run_collator<Block, SP>(
|
||||
setup_parachain: SP,
|
||||
para_id: ParaId,
|
||||
exit: E,
|
||||
key: Arc<CollatorPair>,
|
||||
configuration: polkadot_collator::Configuration,
|
||||
) -> Result<(), sc_cli::error::Error>
|
||||
@@ -353,9 +356,9 @@ where
|
||||
Block: BlockT,
|
||||
SP: SetupParachain<Block> + Send + 'static,
|
||||
<<SP as SetupParachain<Block>>::ProposerFactory as Environment<Block>>::Proposer: Send,
|
||||
E: Future<Output = ()> + Unpin + Send + Clone + Sync + 'static,
|
||||
{
|
||||
let builder = CollatorBuilder::new(setup_parachain);
|
||||
let exit = future::pending(); // TODO to delete
|
||||
polkadot_collator::run_collator(builder, para_id, exit, key, configuration)
|
||||
}
|
||||
|
||||
@@ -518,7 +521,7 @@ mod tests {
|
||||
let context = builder
|
||||
.build::<_, _, polkadot_service::polkadot_runtime::RuntimeApi, _, _>(
|
||||
Arc::new(
|
||||
substrate_test_client::TestClientBuilder::<_, _, ()>::default()
|
||||
substrate_test_client::TestClientBuilder::<_, _, _, ()>::default()
|
||||
.build_with_native_executor(Some(NativeExecutor::<
|
||||
polkadot_service::PolkadotExecutor,
|
||||
>::new(Interpreted, None)))
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use sc_client::Client;
|
||||
use sc_client_api::{Backend, CallExecutor, TransactionFor};
|
||||
@@ -95,9 +96,10 @@ where
|
||||
post_digests: Vec::new(),
|
||||
body,
|
||||
finalized: false,
|
||||
intermediates: HashMap::new(),
|
||||
justification,
|
||||
auxiliary: Vec::new(),
|
||||
fork_choice: ForkChoiceStrategy::LongestChain,
|
||||
fork_choice: Some(ForkChoiceStrategy::LongestChain),
|
||||
allow_missing_state: false,
|
||||
import_existing: false,
|
||||
storage_changes: None,
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ edition = "2018"
|
||||
codec = { package = "parity-scale-codec", version = "1.0.5", default-features = false, features = [ "derive" ] }
|
||||
memory-db = { version = "0.18.0", default-features = false }
|
||||
hash-db = { version = "0.15.2", default-features = false }
|
||||
trie-db = { version = "0.18.0", default-features = false }
|
||||
trie-db = { version = "0.19.2", default-features = false }
|
||||
hashbrown = "0.6.1"
|
||||
|
||||
# Substrate dependencies
|
||||
|
||||
@@ -47,7 +47,6 @@ fn call_validate_block(
|
||||
.encode();
|
||||
|
||||
call_in_wasm::<
|
||||
_,
|
||||
(
|
||||
sp_io::SubstrateHostFunctions,
|
||||
sc_executor::deprecated_host_interface::SubstrateExternals,
|
||||
|
||||
@@ -11,4 +11,4 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "cumulu
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
codec = { package = "parity-scale-codec", version = "1.0.5", default-features = false, features = [ "derive" ] }
|
||||
|
||||
sp-test-primitives = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
|
||||
+10
-5
@@ -21,7 +21,7 @@ use runtime::{
|
||||
genesismap::{additional_storage_with_genesis, GenesisConfig},
|
||||
Block,
|
||||
};
|
||||
use sp_core::{sr25519, storage::Storage};
|
||||
use sp_core::{sr25519, storage::Storage, ChangesTrieConfiguration};
|
||||
use sp_keyring::{AccountKeyring, Sr25519Keyring};
|
||||
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT};
|
||||
pub use test_client::*;
|
||||
@@ -46,7 +46,7 @@ pub type Executor =
|
||||
sc_client::LocalCallExecutor<Backend, sc_executor::NativeExecutor<LocalExecutor>>;
|
||||
|
||||
/// Test client builder for Cumulus
|
||||
pub type TestClientBuilder = test_client::TestClientBuilder<Executor, Backend, GenesisParameters>;
|
||||
pub type TestClientBuilder = test_client::TestClientBuilder<Block, Executor, Backend, GenesisParameters>;
|
||||
|
||||
/// LongestChain type for the test runtime/client.
|
||||
pub type LongestChain = test_client::sc_client::LongestChain<Backend, Block>;
|
||||
@@ -64,7 +64,12 @@ impl test_client::GenesisInit for GenesisParameters {
|
||||
fn genesis_storage(&self) -> Storage {
|
||||
use codec::Encode;
|
||||
|
||||
let mut storage = genesis_config(self.support_changes_trie).genesis_map();
|
||||
let changes_trie_config: Option<ChangesTrieConfiguration> = if self.support_changes_trie {
|
||||
Some(sp_test_primitives::changes_trie_config())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut storage = genesis_config(changes_trie_config).genesis_map();
|
||||
|
||||
let child_roots = storage.children.iter().map(|(sk, child_content)| {
|
||||
let state_root =
|
||||
@@ -121,9 +126,9 @@ impl DefaultTestClientBuilderExt for TestClientBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
fn genesis_config(support_changes_trie: bool) -> GenesisConfig {
|
||||
fn genesis_config(changes_trie_config: Option<ChangesTrieConfiguration>) -> GenesisConfig {
|
||||
GenesisConfig::new(
|
||||
support_changes_trie,
|
||||
changes_trie_config,
|
||||
vec![
|
||||
sr25519::Public::from(Sr25519Keyring::Alice).into(),
|
||||
sr25519::Public::from(Sr25519Keyring::Bob).into(),
|
||||
|
||||
@@ -38,7 +38,7 @@ sc-transaction-pool = { git = "https://github.com/paritytech/substrate", branch
|
||||
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-network = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-client = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-basic-authority = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sc-basic-authorship = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "cumulus-branch" }
|
||||
|
||||
# Cumulus dependencies
|
||||
@@ -49,6 +49,7 @@ cumulus-collator = { path = "../../collator" }
|
||||
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-collator = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "cumulus-branch" }
|
||||
|
||||
[build-dependencies]
|
||||
vergen = '3.0.4'
|
||||
|
||||
@@ -338,6 +338,12 @@ impl_runtime_apis! {
|
||||
}
|
||||
|
||||
impl sp_session::SessionKeys<Block> for Runtime {
|
||||
fn decode_session_keys(
|
||||
encoded: Vec<u8>,
|
||||
) -> Option<Vec<(Vec<u8>, sp_core::crypto::KeyTypeId)>> {
|
||||
opaque::SessionKeys::decode_into_raw_public_keys(&encoded)
|
||||
}
|
||||
|
||||
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
|
||||
opaque::SessionKeys::generate(seed)
|
||||
}
|
||||
|
||||
+16
-184
@@ -14,207 +14,39 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::chain_spec;
|
||||
|
||||
use parachain_runtime::Block;
|
||||
|
||||
pub use sc_cli::{
|
||||
error::{self, Result},
|
||||
IntoExit, VersionInfo,
|
||||
};
|
||||
use sc_cli::{parse_and_prepare, NoCustom, ParseAndPrepare};
|
||||
use sc_client::genesis;
|
||||
use sc_service::{Configuration, Roles as ServiceRoles};
|
||||
use sp_core::hexdisplay::HexDisplay;
|
||||
use sp_runtime::{
|
||||
traits::{Block as BlockT, Hash as HashT, Header as HeaderT},
|
||||
BuildStorage,
|
||||
};
|
||||
use polkadot_service::ChainSpec as ChainSpecPolkadot;
|
||||
use polkadot_service::CustomConfiguration as CustomConfigurationPolkadot;
|
||||
|
||||
use futures::{channel::oneshot, future::Map, FutureExt};
|
||||
|
||||
use codec::Encode;
|
||||
|
||||
use log::info;
|
||||
|
||||
use std::{cell::RefCell, path::PathBuf, sync::Arc};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use sc_cli;
|
||||
pub use polkadot_cli::Cli as PolkadotCli;
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// Sub-commands supported by the collator.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
enum SubCommands {
|
||||
pub enum Subcommand {
|
||||
#[structopt(flatten)]
|
||||
Base(sc_cli::Subcommand),
|
||||
/// Export the genesis state of the parachain.
|
||||
#[structopt(name = "export-genesis-state")]
|
||||
ExportGenesisState(ExportGenesisStateCommand),
|
||||
}
|
||||
|
||||
impl sc_cli::GetSharedParams for SubCommands {
|
||||
fn shared_params(&self) -> Option<&sc_cli::SharedParams> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Command for exporting the genesis state of the parachain
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
struct ExportGenesisStateCommand {
|
||||
pub struct ExportGenesisStateCommand {
|
||||
/// Output file name or stdout if unspecified.
|
||||
#[structopt(parse(from_os_str))]
|
||||
pub output: Option<PathBuf>,
|
||||
}
|
||||
|
||||
/// Parse command line arguments into service configuration.
|
||||
pub fn run<I, T, E>(args_parachain: I, args_relaychain: I, exit: E, version: VersionInfo) -> error::Result<()>
|
||||
where
|
||||
I: IntoIterator<Item = T>,
|
||||
T: Into<std::ffi::OsString> + Clone,
|
||||
E: IntoExit + Send + 'static,
|
||||
{
|
||||
type Config<T> = Configuration<(), T>;
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
pub struct Cli {
|
||||
#[structopt(subcommand)]
|
||||
pub subcommand: Option<Subcommand>,
|
||||
|
||||
match parse_and_prepare::<SubCommands, NoCustom, _>(
|
||||
&version,
|
||||
"cumulus-test-parachain-collator",
|
||||
args_parachain,
|
||||
) {
|
||||
ParseAndPrepare::Run(cmd) => cmd.run(
|
||||
load_spec,
|
||||
exit,
|
||||
|exit, _cli_args, _custom_args, mut config: Config<_>| {
|
||||
info!("{}", version.name);
|
||||
info!(" version {}", config.full_version());
|
||||
info!(" by {}, 2019", version.author);
|
||||
info!("Chain specification: {}", config.chain_spec.name());
|
||||
info!("Node name: {}", config.name);
|
||||
info!("Roles: {:?}", config.roles);
|
||||
info!("Parachain id: {:?}", crate::PARA_ID);
|
||||
#[structopt(flatten)]
|
||||
pub run: sc_cli::RunCmd,
|
||||
|
||||
// TODO
|
||||
let key = Arc::new(sp_core::Pair::from_seed(&[10; 32]));
|
||||
|
||||
// TODO
|
||||
config.network.listen_addresses = Vec::new();
|
||||
|
||||
let mut polkadot_config = parse_and_prepare::<NoCustom, NoCustom, _>(
|
||||
&version,
|
||||
"cumulus-test-parachain-collator",
|
||||
args_relaychain,
|
||||
).into_configuration::<CustomConfigurationPolkadot, _, _, _>(
|
||||
load_spec_polkadot,
|
||||
config.in_chain_config_dir("polkadot"),
|
||||
)
|
||||
.map_err(|e| e.to_string())?
|
||||
.expect(
|
||||
"can only fail when this is a CustomCommand. Running parse_and_prepare with \
|
||||
NoCustom can never return a CustomCommand; therefore this will never fail; qed"
|
||||
);
|
||||
polkadot_config.network.boot_nodes = config.network.boot_nodes.clone();
|
||||
|
||||
if let Some(ref config_dir) = polkadot_config.config_dir {
|
||||
polkadot_config.database = sc_service::config::DatabaseConfig::Path {
|
||||
cache_size: Default::default(),
|
||||
path: config_dir.join("db"),
|
||||
};
|
||||
|
||||
polkadot_config.keystore = sc_service::config::KeystoreConfig::Path {
|
||||
path: config_dir.join("keystore"),
|
||||
password: None,
|
||||
};
|
||||
}
|
||||
|
||||
match config.roles {
|
||||
ServiceRoles::LIGHT => unimplemented!("Light client not supported!"),
|
||||
_ => crate::service::run_collator(config, exit, key, polkadot_config),
|
||||
}
|
||||
.map_err(|e| format!("{:?}", e))
|
||||
},
|
||||
),
|
||||
ParseAndPrepare::BuildSpec(cmd) => cmd.run::<NoCustom, _, _, _>(load_spec),
|
||||
ParseAndPrepare::ExportBlocks(cmd) => cmd.run_with_builder(
|
||||
|config: Config<_>| Ok(new_full_start!(config).0),
|
||||
load_spec,
|
||||
exit,
|
||||
),
|
||||
ParseAndPrepare::ImportBlocks(cmd) => cmd.run_with_builder(
|
||||
|config: Config<_>| Ok(new_full_start!(config).0),
|
||||
load_spec,
|
||||
exit,
|
||||
),
|
||||
ParseAndPrepare::CheckBlock(cmd) => cmd.run_with_builder(
|
||||
|config: Config<_>| Ok(new_full_start!(config).0),
|
||||
load_spec,
|
||||
exit,
|
||||
),
|
||||
ParseAndPrepare::PurgeChain(cmd) => cmd.run(load_spec),
|
||||
ParseAndPrepare::RevertChain(cmd) => {
|
||||
cmd.run_with_builder(|config: Config<_>| Ok(new_full_start!(config).0), load_spec)
|
||||
}
|
||||
ParseAndPrepare::CustomCommand(SubCommands::ExportGenesisState(cmd)) => {
|
||||
export_genesis_state(cmd.output)
|
||||
}
|
||||
}?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn load_spec(_: &str) -> std::result::Result<Option<chain_spec::ChainSpec>, String> {
|
||||
Ok(Some(chain_spec::get_chain_spec()))
|
||||
}
|
||||
|
||||
fn load_spec_polkadot(_: &str) -> std::result::Result<Option<ChainSpecPolkadot>, String> {
|
||||
Some(polkadot_service::ChainSpec::from_json_bytes(
|
||||
&include_bytes!("../res/polkadot_chainspec.json")[..],
|
||||
)).transpose()
|
||||
}
|
||||
|
||||
/// Export the genesis state of the parachain.
|
||||
fn export_genesis_state(output: Option<PathBuf>) -> error::Result<()> {
|
||||
let storage = (&chain_spec::get_chain_spec()).build_storage()?;
|
||||
|
||||
let child_roots = storage.children.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(),
|
||||
);
|
||||
(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 block: Block = genesis::construct_genesis_block(state_root);
|
||||
|
||||
let header_hex = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
|
||||
|
||||
if let Some(output) = output {
|
||||
std::fs::write(output, header_hex)?;
|
||||
} else {
|
||||
println!("{}", header_hex);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// handles ctrl-c
|
||||
pub struct Exit;
|
||||
impl IntoExit for Exit {
|
||||
type Exit = Map<oneshot::Receiver<()>, fn(std::result::Result<(), oneshot::Canceled>) -> ()>;
|
||||
fn into_exit(self) -> Self::Exit {
|
||||
// can't use signal directly here because CtrlC takes only `Fn`.
|
||||
let (exit_send, exit) = oneshot::channel();
|
||||
|
||||
let exit_send_cell = RefCell::new(Some(exit_send));
|
||||
ctrlc::set_handler(move || {
|
||||
let exit_send = exit_send_cell
|
||||
.try_borrow_mut()
|
||||
.expect("signal handler not reentrant; qed")
|
||||
.take();
|
||||
if let Some(exit_send) = exit_send {
|
||||
exit_send.send(()).expect("Error sending exit notification");
|
||||
}
|
||||
})
|
||||
.expect("Error setting Ctrl-C handler");
|
||||
|
||||
exit.map(drop)
|
||||
}
|
||||
/// Relaychain arguments
|
||||
#[structopt(raw = true)]
|
||||
pub relaychain_args: Vec<String>,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
// Copyright 2019 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Cumulus.
|
||||
|
||||
// Cumulus is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Cumulus is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Cumulus. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::chain_spec;
|
||||
use crate::cli::{Cli, PolkadotCli, Subcommand};
|
||||
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
use futures::{future::Map, FutureExt};
|
||||
|
||||
use parachain_runtime::Block;
|
||||
|
||||
use sc_cli::{error::{self, Result}, VersionInfo};
|
||||
use sc_client::genesis;
|
||||
use sc_service::{Configuration, Roles as ServiceRoles};
|
||||
use sp_core::hexdisplay::HexDisplay;
|
||||
use sp_runtime::{
|
||||
traits::{Block as BlockT, Hash as HashT, Header as HeaderT},
|
||||
BuildStorage,
|
||||
};
|
||||
use polkadot_service::ChainSpec as ChainSpecPolkadot;
|
||||
|
||||
use codec::Encode;
|
||||
use log::info;
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// Parse command line arguments into service configuration.
|
||||
pub fn run(version: VersionInfo) -> error::Result<()> {
|
||||
let opt: Cli = sc_cli::from_args(&version);
|
||||
|
||||
let mut config = sc_service::Configuration::default();
|
||||
config.impl_name = "cumulus-test-parachain-collator";
|
||||
|
||||
match opt.subcommand {
|
||||
Some(Subcommand::Base(subcommand)) => sc_cli::run_subcommand(
|
||||
config,
|
||||
subcommand,
|
||||
load_spec,
|
||||
|config: Configuration<_, _>| Ok(new_full_start!(config).0),
|
||||
&version,
|
||||
),
|
||||
Some(Subcommand::ExportGenesisState(params)) => {
|
||||
sc_cli::init_logger("");
|
||||
|
||||
let storage = (&chain_spec::get_chain_spec()).build_storage()?;
|
||||
|
||||
let child_roots = storage.children.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(),
|
||||
);
|
||||
(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 block: Block = genesis::construct_genesis_block(state_root);
|
||||
|
||||
let header_hex = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
|
||||
|
||||
if let Some(output) = params.output {
|
||||
std::fs::write(output, header_hex)?;
|
||||
} else {
|
||||
println!("{}", header_hex);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
},
|
||||
None => {
|
||||
sc_cli::init(&mut config, load_spec, &opt.run.shared_params, &version)?;
|
||||
|
||||
info!("{}", version.name);
|
||||
info!(" version {}", config.full_version());
|
||||
info!(" by {}, 2019", version.author);
|
||||
info!("Chain specification: {}", config.expect_chain_spec().name());
|
||||
info!("Node name: {}", config.name);
|
||||
info!("Roles: {:?}", config.roles);
|
||||
info!("Parachain id: {:?}", crate::PARA_ID);
|
||||
|
||||
// TODO
|
||||
let key = Arc::new(sp_core::Pair::from_seed(&[10; 32]));
|
||||
|
||||
let mut polkadot_config = Configuration::default();
|
||||
polkadot_config.impl_name = "cumulus-test-parachain-collator";
|
||||
polkadot_config.config_dir = config.in_chain_config_dir("polkadot");
|
||||
|
||||
// TODO: parse_address is private
|
||||
/*
|
||||
let rpc_interface: &str = interface_str(opt.run.rpc_external, opt.run.unsafe_rpc_external, opt.run.validator)?;
|
||||
config.rpc_http = Some(parse_address(&format!("{}:{}", rpc_interface, 9934), opt.run.rpc_port)?);
|
||||
let ws_interface: &str = interface_str(opt.run.ws_external, opt.run.unsafe_ws_external, opt.run.validator)?;
|
||||
config.rpc_ws = Some(parse_address(&format!("{}:{}", ws_interface, 9945), opt.run.ws_port)?);
|
||||
let grafana_interface: &str = if opt.run.grafana_external { "0.0.0.0" } else { "127.0.0.1" };
|
||||
config.grafana_port = Some(
|
||||
parse_address(&format!("{}:{}", grafana_interface, 9956), opt.run.grafana_port)?
|
||||
);
|
||||
*/
|
||||
|
||||
let polkadot_opt: PolkadotCli = sc_cli::from_iter(opt.relaychain_args, &version);
|
||||
|
||||
// TODO
|
||||
polkadot_config.chain_spec = Some(sc_cli::load_spec(&polkadot_opt.run.shared_params, load_spec_polkadot)?);
|
||||
// TODO: base_path is private
|
||||
//polkadot_config.config_dir = Some(sc_cli::base_path(&polkadot_opt.run.shared_params, &version));
|
||||
polkadot_config.impl_commit = version.commit;
|
||||
polkadot_config.impl_version = version.version;
|
||||
|
||||
// TODO
|
||||
if let Some(ref config_dir) = polkadot_config.config_dir {
|
||||
polkadot_config.database = sc_service::config::DatabaseConfig::Path {
|
||||
cache_size: Default::default(),
|
||||
path: config_dir.join("db"),
|
||||
};
|
||||
}
|
||||
// TODO
|
||||
polkadot_config.network.boot_nodes = polkadot_config.network.boot_nodes.clone();
|
||||
polkadot_config.telemetry_endpoints = polkadot_config.expect_chain_spec().telemetry_endpoints().clone();
|
||||
|
||||
sc_cli::update_config_for_running_node(&mut polkadot_config, polkadot_opt.run);
|
||||
|
||||
match config.roles {
|
||||
ServiceRoles::LIGHT => unimplemented!("Light client not supported!"),
|
||||
_ => crate::service::run_collator(config, key, polkadot_config),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn load_spec(_: &str) -> std::result::Result<Option<chain_spec::ChainSpec>, String> {
|
||||
Ok(Some(chain_spec::get_chain_spec()))
|
||||
}
|
||||
|
||||
fn load_spec_polkadot(_: &str) -> std::result::Result<Option<ChainSpecPolkadot>, String> {
|
||||
Some(polkadot_service::ChainSpec::from_json_bytes(
|
||||
&include_bytes!("../res/polkadot_chainspec.json")[..],
|
||||
)).transpose()
|
||||
}
|
||||
@@ -26,8 +26,9 @@ mod chain_spec;
|
||||
#[macro_use]
|
||||
mod service;
|
||||
mod cli;
|
||||
mod command;
|
||||
|
||||
pub use sc_cli::{error, IntoExit, VersionInfo};
|
||||
pub use sc_cli::{error, VersionInfo};
|
||||
|
||||
/// The parachain id of this parachain.
|
||||
pub const PARA_ID: ParaId = ParaId::new(100);
|
||||
@@ -38,7 +39,7 @@ const DESCRIPTION: &'static str =
|
||||
to the relaychain node.\n\n\
|
||||
cumulus-test-parachain-collator [parachain-args] -- [relaychain-args]";
|
||||
|
||||
fn main() -> Result<(), cli::error::Error> {
|
||||
fn main() -> Result<(), error::Error> {
|
||||
let version = VersionInfo {
|
||||
name: "Cumulus Test Parachain Collator",
|
||||
commit: env!("VERGEN_SHA_SHORT"),
|
||||
@@ -47,12 +48,8 @@ fn main() -> Result<(), cli::error::Error> {
|
||||
description: DESCRIPTION,
|
||||
executable_name: EXECUTABLE_NAME,
|
||||
support_url: "https://github.com/paritytech/cumulus/issues/new",
|
||||
copyright_start_year: 2017,
|
||||
};
|
||||
|
||||
let args = std::env::args().collect::<Vec<String>>();
|
||||
let mut iter = args.iter();
|
||||
let parachain_args: Vec<_> = iter.take_while_ref(|&x| x != &"--").collect();
|
||||
let relaychain_args: Vec<_> = iter.collect();
|
||||
|
||||
cli::run(parachain_args, relaychain_args, cli::Exit, version)
|
||||
command::run(version)
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ use sc_network::construct_simple_protocol;
|
||||
use sc_service::{AbstractService, Configuration};
|
||||
use sp_consensus::{BlockImport, Environment, Proposer};
|
||||
use sp_inherents::InherentDataProviders;
|
||||
use sc_cli;
|
||||
|
||||
use futures::{future, task::Spawn, FutureExt, TryFutureExt};
|
||||
|
||||
@@ -57,13 +58,9 @@ macro_rules! new_full_start {
|
||||
>($config)?
|
||||
.with_select_chain(|_config, backend| Ok(sc_client::LongestChain::new(backend.clone())))?
|
||||
.with_transaction_pool(|config, client, _| {
|
||||
let pool_api = sc_transaction_pool::FullChainApi::new(client.clone());
|
||||
let pool_api = Arc::new(sc_transaction_pool::FullChainApi::new(client.clone()));
|
||||
let pool = sc_transaction_pool::BasicPool::new(config, pool_api);
|
||||
let maintainer =
|
||||
sc_transaction_pool::FullBasicPoolMaintainer::new(pool.pool().clone(), client);
|
||||
let maintainable_pool =
|
||||
sp_transaction_pool::MaintainableTransactionPool::new(pool, maintainer);
|
||||
Ok(maintainable_pool)
|
||||
Ok(pool)
|
||||
})?
|
||||
.with_import_queue(|_config, client, _, _| {
|
||||
let import_queue = cumulus_consensus::import_queue::import_queue(
|
||||
@@ -80,12 +77,11 @@ macro_rules! new_full_start {
|
||||
}
|
||||
|
||||
/// Run the collator with the given `config`.
|
||||
pub fn run_collator<C: Send + Default + 'static, E: crate::cli::IntoExit + Send + 'static>(
|
||||
config: Configuration<C, GenesisConfig>,
|
||||
exit: E,
|
||||
pub fn run_collator<E: sc_service::ChainSpecExtension>(
|
||||
config: Configuration<GenesisConfig, E>,
|
||||
key: Arc<polkadot_primitives::parachain::CollatorPair>,
|
||||
polkadot_config: polkadot_collator::Configuration,
|
||||
) -> crate::cli::Result<()> {
|
||||
) -> Result<(), sc_cli::error::Error> {
|
||||
let (builder, inherent_data_providers) = new_full_start!(config);
|
||||
inherent_data_providers
|
||||
.register_provider(sp_timestamp::InherentDataProvider)
|
||||
@@ -94,35 +90,31 @@ pub fn run_collator<C: Send + Default + 'static, E: crate::cli::IntoExit + Send
|
||||
let service = builder
|
||||
.with_network_protocol(|_| Ok(NodeProtocol::new()))?
|
||||
.build()?;
|
||||
let proposer_factory = sc_basic_authority::ProposerFactory {
|
||||
let proposer_factory = sc_basic_authorship::ProposerFactory {
|
||||
client: service.client(),
|
||||
transaction_pool: service.transaction_pool(),
|
||||
};
|
||||
|
||||
let on_exit = service.on_exit();
|
||||
let block_import = service.client();
|
||||
|
||||
let setup_parachain = SetupParachain {
|
||||
service,
|
||||
inherent_data_providers,
|
||||
proposer_factory,
|
||||
exit,
|
||||
block_import,
|
||||
};
|
||||
|
||||
cumulus_collator::run_collator(
|
||||
setup_parachain,
|
||||
crate::PARA_ID,
|
||||
on_exit,
|
||||
key,
|
||||
polkadot_config,
|
||||
)
|
||||
}
|
||||
|
||||
struct SetupParachain<S, PF, E, BI> {
|
||||
struct SetupParachain<S, PF, BI> {
|
||||
service: S,
|
||||
proposer_factory: PF,
|
||||
exit: E,
|
||||
inherent_data_providers: InherentDataProviders,
|
||||
block_import: BI,
|
||||
}
|
||||
@@ -130,10 +122,9 @@ struct SetupParachain<S, PF, E, BI> {
|
||||
type TransactionFor<E, Block> =
|
||||
<<E as Environment<Block>>::Proposer as Proposer<Block>>::Transaction;
|
||||
|
||||
impl<S, PF, E, BI> cumulus_collator::SetupParachain<Block> for SetupParachain<S, PF, E, BI>
|
||||
impl<S, PF, BI> cumulus_collator::SetupParachain<Block> for SetupParachain<S, PF, BI>
|
||||
where
|
||||
S: AbstractService,
|
||||
E: Send + crate::cli::IntoExit,
|
||||
PF: Environment<Block> + Send + 'static,
|
||||
BI: BlockImport<Block, Error = sp_consensus::Error, Transaction = TransactionFor<PF, Block>>
|
||||
+ Send
|
||||
@@ -174,7 +165,7 @@ where
|
||||
future::select(
|
||||
self.service
|
||||
.map_err(|e| error!("Parachain service error: {:?}", e)),
|
||||
future::select(follow, self.exit.into_exit()),
|
||||
follow,
|
||||
)
|
||||
.map(|_| ()),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user