-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #276 from AurevoirXavier/canary
Boot From Configuration File
- Loading branch information
Showing
12 changed files
with
2,842 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]>"] | ||
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", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
= Substrate CLI | ||
|
||
Substrate CLI library | ||
|
||
include::doc/shell-completion.adoc[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(|_| ()) | ||
} |
Oops, something went wrong.