mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-01 20:37:25 +00:00
Minimal switch of substrate-node to GRANDPA /Aura (#1128)
* add beginnings of SRML grandpa library * get srml-grandpa compiling * tests for srml-grandpa * add optional session integration to grandpa SRML * start integration into node runtime * Allow extracting pending change from header digest * Make it compile on wasm * make tests compile again * Move Authority Key fetching into service, simplify service factory construction * Generalize Authority Consensus Setup system * Add Authority Setup Docs * Allow CLI params to be extensible - move params to structopts - split parsing and default command execution - add custom config to node - extended parsing of custom config - extending params via structop's flatten * Minor fixes on cli extension params: - added docs - re-add actual app name, rather than node-name - make strategy and subcommand optional * better cli params * synchronize GRANDPA and normal node authorities * Implement grandpa::network for gossip consensus * run_grandpa in Node * Fix missed merge error * Integrate grandpa import queue * more specific type def * link up linkhalf and import block * make grandpa future send * get compiling * Fix new params convention and license header * get it running * rebuild node runtime WASM * change logging level * Update node/cli/src/params.rs Co-Authored-By: rphmeier <rphmeier@gmail.com> * Update node/cli/src/params.rs Co-Authored-By: rphmeier <rphmeier@gmail.com> * Update node/cli/src/lib.rs Co-Authored-By: rphmeier <rphmeier@gmail.com> * Update node/runtime/src/lib.rs Co-Authored-By: rphmeier <rphmeier@gmail.com> * Update node/cli/src/lib.rs Co-Authored-By: rphmeier <rphmeier@gmail.com> * Clean up and Fixme for mutable config * Move GrandpaService Integration into grandpa, feature gated but on per default * Fixing grandpa runtime module test * Update wasm runtime hashes for tests * GRANDPA: use post-header hash when logging scheduled changes * add an extra bit of logging to authorities * fixing missing constrain * remove old code * move `NewAuthorities` to an event in srml-grandpa * fix node-executor tests to use grandpa log * Remove GossipConsensus from tests, use newly provided sync-feature, fixes tests * Update to latest wasm runtimes * address grumbles * address grumbles * only derive deserialize when using std * Clean up use of Deserialize
This commit is contained in:
committed by
GitHub
parent
84da9d4a02
commit
11fe84a742
@@ -50,7 +50,10 @@ extern crate clap;
|
||||
extern crate error_chain;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use]
|
||||
extern crate structopt;
|
||||
|
||||
mod params;
|
||||
pub mod error;
|
||||
pub mod informant;
|
||||
mod panic_hook;
|
||||
@@ -72,6 +75,8 @@ use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use names::{Generator, Name};
|
||||
use regex::Regex;
|
||||
use structopt::StructOpt;
|
||||
pub use params::{CoreParams, CoreCommands, ExecutionStrategy};
|
||||
|
||||
use futures::Future;
|
||||
|
||||
@@ -90,11 +95,11 @@ pub struct VersionInfo {
|
||||
}
|
||||
|
||||
/// CLI Action
|
||||
pub enum Action<F: ServiceFactory, E: IntoExit> {
|
||||
pub enum Action<E> {
|
||||
/// Substrate handled the command. No need to do anything.
|
||||
ExecutedInternally,
|
||||
/// Service mode requested. Caller should start the service.
|
||||
RunService((FactoryFullConfiguration<F>, E)),
|
||||
RunService(E),
|
||||
}
|
||||
|
||||
/// Something that can be converted into an exit signal.
|
||||
@@ -117,7 +122,7 @@ fn load_spec<F, G>(matches: &clap::ArgMatches, factory: F) -> Result<ChainSpec<G
|
||||
}
|
||||
|
||||
fn base_path(matches: &clap::ArgMatches) -> PathBuf {
|
||||
matches.value_of("base-path")
|
||||
matches.value_of("base_path")
|
||||
.map(|x| Path::new(x).to_owned())
|
||||
.unwrap_or_else(default_base_path)
|
||||
}
|
||||
@@ -145,84 +150,42 @@ fn is_node_name_valid(_name: &str) -> Result<(), &str> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Parse command line arguments and execute commands or return service configuration.
|
||||
///
|
||||
/// IANA unassigned port ranges that we could use:
|
||||
/// 6717-6766 Unassigned
|
||||
/// 8504-8553 Unassigned
|
||||
/// 9556-9591 Unassigned
|
||||
/// 9803-9874 Unassigned
|
||||
/// 9926-9949 Unassigned
|
||||
pub fn prepare_execution<F, I, T, E, S>(
|
||||
args: I,
|
||||
exit: E,
|
||||
version: VersionInfo,
|
||||
spec_factory: S,
|
||||
impl_name: &'static str,
|
||||
) -> error::Result<Action<F, E>>
|
||||
/// Parse command line arguments
|
||||
pub fn parse_args_default<'a, I, T>(args: I, version: VersionInfo) -> clap::ArgMatches<'a>
|
||||
where
|
||||
I: IntoIterator<Item = T>,
|
||||
T: Into<std::ffi::OsString> + Clone,
|
||||
E: IntoExit,
|
||||
F: ServiceFactory,
|
||||
S: FnOnce(&str) -> Result<Option<ChainSpec<FactoryGenesis<F>>>, String>,
|
||||
{
|
||||
panic_hook::set();
|
||||
|
||||
let full_version = service::config::full_version_from_strs(
|
||||
version.version,
|
||||
version.commit
|
||||
);
|
||||
let yaml = format!(include_str!("./cli.yml"),
|
||||
name = version.executable_name,
|
||||
description = version.description,
|
||||
author = version.author,
|
||||
);
|
||||
let yaml = &clap::YamlLoader::load_from_str(&yaml).expect("Invalid yml file")[0];
|
||||
let matches = match clap::App::from_yaml(yaml)
|
||||
|
||||
match CoreParams::clap()
|
||||
.name(version.executable_name)
|
||||
.author(version.author)
|
||||
.about(version.description)
|
||||
.version(&(full_version + "\n")[..])
|
||||
.get_matches_from_safe(args) {
|
||||
Ok(m) => m,
|
||||
Err(e) => e.exit(),
|
||||
};
|
||||
|
||||
// TODO [ToDr] Split parameters parsing from actual execution.
|
||||
let log_pattern = matches.value_of("log").unwrap_or("");
|
||||
init_logger(log_pattern);
|
||||
fdlimit::raise_fd_limit();
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("build-spec") {
|
||||
let spec = load_spec(&matches, spec_factory)?;
|
||||
build_spec::<F>(matches, spec)?;
|
||||
return Ok(Action::ExecutedInternally);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("export-blocks") {
|
||||
let spec = load_spec(&matches, spec_factory)?;
|
||||
export_blocks::<F, _>(matches, spec, exit.into_exit())?;
|
||||
return Ok(Action::ExecutedInternally);
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("import-blocks") {
|
||||
let spec = load_spec(&matches, spec_factory)?;
|
||||
import_blocks::<F, _>(matches, spec, exit.into_exit())?;
|
||||
return Ok(Action::ExecutedInternally);
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("revert") {
|
||||
let spec = load_spec(&matches, spec_factory)?;
|
||||
revert_chain::<F>(matches, spec)?;
|
||||
return Ok(Action::ExecutedInternally);
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("purge-chain") {
|
||||
let spec = load_spec(&matches, spec_factory)?;
|
||||
purge_chain::<F>(matches, spec)?;
|
||||
return Ok(Action::ExecutedInternally);
|
||||
}
|
||||
/// Parse clap::Matches into config and chain specification
|
||||
pub fn parse_matches<'a, F, S>(
|
||||
spec_factory: S,
|
||||
version: VersionInfo,
|
||||
impl_name: &'static str,
|
||||
matches: &clap::ArgMatches<'a>
|
||||
) -> error::Result<(ChainSpec<<F as service::ServiceFactory>::Genesis>, FactoryFullConfiguration<F>)>
|
||||
where
|
||||
F: ServiceFactory,
|
||||
S: FnOnce(&str) -> Result<Option<ChainSpec<FactoryGenesis<F>>>, String>,
|
||||
|
||||
{
|
||||
let spec = load_spec(&matches, spec_factory)?;
|
||||
let mut config = service::Configuration::default_with_spec(spec);
|
||||
let mut config = service::Configuration::default_with_spec(spec.clone());
|
||||
|
||||
config.impl_name = impl_name;
|
||||
config.impl_commit = version.commit;
|
||||
@@ -284,14 +247,14 @@ where
|
||||
config.network.config_path = Some(network_path(&base_path, config.chain_spec.id()).to_string_lossy().into());
|
||||
config.network.net_config_path = config.network.config_path.clone();
|
||||
config.network.reserved_nodes.extend(matches
|
||||
.values_of("reserved-nodes")
|
||||
.values_of("reserved_nodes")
|
||||
.map_or(Default::default(), |v| v.map(|n| n.to_owned()).collect::<Vec<_>>()));
|
||||
if !config.network.reserved_nodes.is_empty() {
|
||||
config.network.non_reserved_mode = NonReservedPeerMode::Deny;
|
||||
}
|
||||
|
||||
config.network.listen_addresses = Vec::new();
|
||||
for addr in matches.values_of("listen-addr").unwrap_or_default() {
|
||||
for addr in matches.values_of("listen_addr").unwrap_or_default() {
|
||||
let addr = addr.parse().map_err(|_| "Invalid listen multiaddress")?;
|
||||
config.network.listen_addresses.push(addr);
|
||||
}
|
||||
@@ -310,17 +273,17 @@ where
|
||||
config.network.public_addresses = Vec::new();
|
||||
|
||||
config.network.client_version = config.client_id();
|
||||
config.network.use_secret = match matches.value_of("node-key").map(H256::from_str) {
|
||||
config.network.use_secret = match matches.value_of("node_key").map(H256::from_str) {
|
||||
Some(Ok(secret)) => Some(secret.into()),
|
||||
Some(Err(err)) => return Err(format!("Error parsing node key: {}", err).into()),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let in_peers = match matches.value_of("in-peers") {
|
||||
let in_peers = match matches.value_of("in_peers") {
|
||||
Some(in_peers) => in_peers.parse().map_err(|_| "Invalid in-peers value specified.")?,
|
||||
None => 25,
|
||||
};
|
||||
let out_peers = match matches.value_of("out-peers") {
|
||||
let out_peers = match matches.value_of("out_peers") {
|
||||
Some(out_peers) => out_peers.parse().map_err(|_| "Invalid out-peers value specified.")?,
|
||||
None => 25,
|
||||
};
|
||||
@@ -334,20 +297,73 @@ where
|
||||
config.keys.push("Alice".into());
|
||||
}
|
||||
|
||||
let rpc_interface: &str = if matches.is_present("rpc-external") { "0.0.0.0" } else { "127.0.0.1" };
|
||||
let ws_interface: &str = if matches.is_present("ws-external") { "0.0.0.0" } else { "127.0.0.1" };
|
||||
let rpc_interface: &str = if matches.is_present("rpc_external") { "0.0.0.0" } else { "127.0.0.1" };
|
||||
let ws_interface: &str = if matches.is_present("ws_external") { "0.0.0.0" } else { "127.0.0.1" };
|
||||
|
||||
config.rpc_http = Some(parse_address(&format!("{}:{}", rpc_interface, 9933), "rpc-port", &matches)?);
|
||||
config.rpc_ws = Some(parse_address(&format!("{}:{}", ws_interface, 9944), "ws-port", &matches)?);
|
||||
config.rpc_http = Some(parse_address(&format!("{}:{}", rpc_interface, 9933), "rpc_port", &matches)?);
|
||||
config.rpc_ws = Some(parse_address(&format!("{}:{}", ws_interface, 9944), "ws_port", &matches)?);
|
||||
|
||||
// Override telemetry
|
||||
if matches.is_present("no-telemetry") {
|
||||
if matches.is_present("no_telemetry") {
|
||||
config.telemetry_url = None;
|
||||
} else if let Some(url) = matches.value_of("telemetry-url") {
|
||||
} else if let Some(url) = matches.value_of("telemetry_url") {
|
||||
config.telemetry_url = Some(url.to_owned());
|
||||
}
|
||||
|
||||
Ok(Action::RunService((config, exit)))
|
||||
Ok((spec, config))
|
||||
}
|
||||
|
||||
//
|
||||
// IANA unassigned port ranges that we could use:
|
||||
// 6717-6766 Unassigned
|
||||
// 8504-8553 Unassigned
|
||||
// 9556-9591 Unassigned
|
||||
// 9803-9874 Unassigned
|
||||
// 9926-9949 Unassigned
|
||||
|
||||
/// execute default commands or return service configuration
|
||||
pub fn execute_default<'a, F, E>(
|
||||
spec: ChainSpec<FactoryGenesis<F>>,
|
||||
exit: E,
|
||||
matches: &clap::ArgMatches<'a>
|
||||
) -> error::Result<Action<E>>
|
||||
where
|
||||
E: IntoExit,
|
||||
F: ServiceFactory,
|
||||
{
|
||||
|
||||
panic_hook::set();
|
||||
|
||||
let log_pattern = matches.value_of("log").unwrap_or("");
|
||||
init_logger(log_pattern);
|
||||
fdlimit::raise_fd_limit();
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("build_spec") {
|
||||
build_spec::<F>(matches, spec)?;
|
||||
return Ok(Action::ExecutedInternally);
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("export_blocks") {
|
||||
export_blocks::<F, _>(matches, spec, exit.into_exit())?;
|
||||
return Ok(Action::ExecutedInternally);
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("import_blocks") {
|
||||
import_blocks::<F, _>(matches, spec, exit.into_exit())?;
|
||||
return Ok(Action::ExecutedInternally);
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("revert") {
|
||||
revert_chain::<F>(matches, spec)?;
|
||||
return Ok(Action::ExecutedInternally);
|
||||
}
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("purge_chain") {
|
||||
purge_chain::<F>(matches, spec)?;
|
||||
return Ok(Action::ExecutedInternally);
|
||||
}
|
||||
|
||||
Ok(Action::RunService(exit))
|
||||
}
|
||||
|
||||
fn build_spec<F>(matches: &clap::ArgMatches, spec: ChainSpec<FactoryGenesis<F>>) -> error::Result<()>
|
||||
|
||||
Reference in New Issue
Block a user