Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boot From Configuration File #276

Merged
merged 4 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"bin/node/rpc-client",
"bin/node/rpc",
"bin/node/runtime",
"client/cli",
"frame/balances/kton",
"frame/balances/ring",
"frame/chainrelay/eth/backing",
Expand Down
15 changes: 9 additions & 6 deletions bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ edition = "2018"
default-run = "darwinia"

[badges]
travis-ci = { repository = "paritytech/substrate", branch = "master" }
travis-ci = { repository = "darwinia-network/darwinia", branch = "develop" }
maintenance = { status = "actively-developed" }
is-it-maintained-issue-resolution = { repository = "paritytech/substrate" }
is-it-maintained-open-issues = { repository = "paritytech/substrate" }
is-it-maintained-issue-resolution = { repository = "darwinia-network/darwinia" }
is-it-maintained-open-issues = { repository = "darwinia-network/darwinia" }

[[bin]]
name = "darwinia"
Expand Down Expand Up @@ -82,9 +82,10 @@ node-runtime = { path = "../runtime" }
# CLI-specific dependencies
ctrlc = { version = "3.1.3", features = ["termination"], optional = true }
node-transaction-factory = { version = "2.0.0", optional = true, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sc-cli = { version = "2.0.0", optional = true, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
tokio = { version = "0.1.22", optional = true }

sc-cli = { package = "darwinia-cli", optional = true, path = "../../../client/cli" }

# WASM-specific dependencies
clear_on_drop = { version = "0.2.3", features = ["no_cc"], optional = true } # Imported just for the `no_cc` feature
console_error_panic_hook = { version = "0.1.1", optional = true }
Expand All @@ -97,11 +98,13 @@ wasm-bindgen = { version = "0.2.45", optional = true }
wasm-bindgen-futures = { version = "0.3.22", optional = true }

[build-dependencies]
build-script-utils = { version = "2.0.0", package = "substrate-build-script-utils", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sc-cli = { version = "2.0.0", package = "sc-cli", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
structopt = "=0.3.7"
vergen = "3.0.4"

build-script-utils = { version = "2.0.0", package = "substrate-build-script-utils", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }

sc-cli = { package = "darwinia-cli", path = "../../../client/cli" }

[features]
default = ["cli"]
browser = [
Expand Down
50 changes: 50 additions & 0 deletions client/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[package]
name = "darwinia-cli"
version = "2.0.0"
authors = ["Darwinia Network <hello@darwinia.network>"]
description = "Darwinia CLI interface."
edition = "2018"

[dependencies]
# crates.io
ansi_term = "0.12.1"
app_dirs = "1.2.1"
atty = "0.2.13"
clap = "2.33.0"
derive_more = "0.99.2"
env_logger = "0.7.0"
fdlimit = "0.1.1"
futures = { version = "0.3.1", features = ["compat"] }
lazy_static = "1.4.0"
log = "0.4.8"
names = "0.11.0"
regex = "1.3.1"
serde = "1.0.102"
serde_json = "1.0.41"
structopt = "=0.3.7"
time = "0.1.42"
tokio = "0.2.1"

# github.com
sc-client-api = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sc-network = { version = "0.8", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sc-service = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sc-tracing = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sp-blockchain = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sp-core = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sp-keyring = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sp-panic-handler = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sp-runtime = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sp-state-machine = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }
sc-telemetry = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", tag = "pre-v2.0-3e65111" }

[target.'cfg(not(target_os = "unknown"))'.dependencies]
rpassword = "4.0.1"

[dev-dependencies]
tempfile = "3.1.0"

[features]
wasmtime = [
"sc-service/wasmtime",
]
6 changes: 6 additions & 0 deletions client/cli/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

= Substrate CLI

Substrate CLI library

include::doc/shell-completion.adoc[]
64 changes: 64 additions & 0 deletions client/cli/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2017-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.

// Substrate 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.

// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Initialization errors.

/// Result type alias for the CLI.
pub type Result<T> = std::result::Result<T, Error>;

/// Error type for the CLI.
#[derive(Debug, derive_more::Display, derive_more::From)]
pub enum Error {
/// Io error
Io(std::io::Error),
/// Cli error
Cli(clap::Error),
/// Service error
Service(sc_service::Error),
/// Client error
Client(sp_blockchain::Error),
/// Input error
#[from(ignore)]
Input(String),
/// Invalid listen multiaddress
#[display(fmt = "Invalid listen multiaddress")]
InvalidListenMultiaddress,
/// Other uncategorized error.
#[from(ignore)]
Other(String),
}

/// Must be implemented explicitly because `derive_more` won't generate this
/// case due to conflicting derive for `Other(String)`.
impl std::convert::From<String> for Error {
fn from(s: String) -> Error {
Error::Input(s)
}
}

impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Io(ref err) => Some(err),
Error::Cli(ref err) => Some(err),
Error::Service(ref err) => Some(err),
Error::Client(ref err) => Some(err),
Error::Input(_) => None,
Error::InvalidListenMultiaddress => None,
Error::Other(_) => None,
}
}
}
35 changes: 35 additions & 0 deletions client/cli/src/execution_strategy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2018-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.

// Substrate 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.

// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>.

#![allow(missing_docs)]

use serde::Deserialize;
use structopt::clap::arg_enum;

arg_enum! {
/// How to execute blocks
#[derive(Clone, Copy, Debug, Deserialize)]
pub enum ExecutionStrategy {
// Execute with native build (if available, WebAssembly otherwise).
Native,
// Only execute with the WebAssembly build.
Wasm,
// Execute with both native (where available) and WebAssembly builds.
Both,
// Execute with the native build if possible; if it fails, then execute with WebAssembly.
NativeElseWasm,
}
}
80 changes: 80 additions & 0 deletions client/cli/src/informant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2017-2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.

// Substrate 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.

// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Console informant. Prints sync progress and block events. Runs on the calling thread.

use futures::{compat::Stream01CompatExt, future, FutureExt, StreamExt, TryStreamExt};
use log::{info, warn};
use sc_client_api::BlockchainEvents;
use sc_service::AbstractService;
use sp_runtime::traits::Header;
use std::time::Duration;

mod display;

/// Creates an informant in the form of a `Future` that must be polled regularly.
pub fn build(service: &impl AbstractService) -> impl futures::Future<Output = ()> {
let client = service.client();

let mut display = display::InformantDisplay::new();

let display_notifications = service
.network_status(Duration::from_millis(5000))
.compat()
.try_for_each(move |(net_status, _)| {
let info = client.usage_info();
display.display(&info, net_status);
future::ok(())
});

let client = service.client();
let mut last_best = {
let info = client.usage_info();
Some((info.chain.best_number, info.chain.best_hash))
};

let display_block_import = client.import_notification_stream().for_each(move |n| {
// detect and log reorganizations.
if let Some((ref last_num, ref last_hash)) = last_best {
if n.header.parent_hash() != last_hash && n.is_new_best {
let maybe_ancestor = sp_blockchain::lowest_common_ancestor(&*client, last_hash.clone(), n.hash);

match maybe_ancestor {
Ok(ref ancestor) if ancestor.hash != *last_hash => info!(
"Reorg from #{},{} to #{},{}, common ancestor #{},{}",
last_num,
last_hash,
n.header.number(),
n.hash,
ancestor.number,
ancestor.hash,
),
Ok(_) => {}
Err(e) => warn!("Error computing tree route: {}", e),
}
}
}

if n.is_new_best {
last_best = Some((n.header.number().clone(), n.hash.clone()));
}

info!(target: "substrate", "Imported #{} ({})", n.header.number(), n.hash);
future::ready(())
});

future::join(display_notifications, display_block_import).map(|_| ())
}
Loading