diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index ae0492f52f..dfab26f9a2 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -3711,7 +3711,6 @@ dependencies = [ "sr-primitives 0.1.0", "substrate-client 0.1.0", "substrate-client-db 0.1.0", - "substrate-consensus-aura-primitives 0.1.0", "substrate-consensus-common 0.1.0", "substrate-executor 0.1.0", "substrate-keystore 0.1.0", diff --git a/substrate/core/cli/src/informant.rs b/substrate/core/cli/src/informant.rs index 5912da8126..e9dab4ae8b 100644 --- a/substrate/core/cli/src/informant.rs +++ b/substrate/core/cli/src/informant.rs @@ -24,7 +24,9 @@ use tokio::runtime::TaskExecutor; use tokio::timer::Interval; use sysinfo::{get_current_pid, ProcessExt, System, SystemExt}; use network::{SyncState, SyncProvider}; -use client::BlockchainEvents; +use client::{backend::Backend, BlockchainEvents}; + +use runtime_primitives::generic::BlockId; use runtime_primitives::traits::{Header, As}; const TIMER_INTERVAL_MS: u64 = 5000; @@ -92,7 +94,36 @@ pub fn start(service: &Service, exit: ::exit_future::Exit, handle: TaskExe }); let client = service.client(); - let display_block_import = client.import_notification_stream().for_each(|n| { + let mut last = match client.info() { + Ok(info) => Some((info.chain.best_number, info.chain.best_hash)), + Err(e) => { warn!("Error getting best block information: {:?}", e); None } + }; + + 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 { + if n.header.parent_hash() != last_hash { + let tree_route = ::client::blockchain::tree_route( + client.backend().blockchain(), + BlockId::Hash(last_hash.clone()), + BlockId::Hash(n.hash), + ); + + match tree_route { + Ok(ref t) if !t.retracted().is_empty() => info!( + "Reorg from #{},{} to #{},{}, common ancestor #{},{}", + last_num, last_hash, + n.header.number(), n.hash, + t.common_block().number, t.common_block().hash, + ), + Ok(_) => {}, + Err(e) => warn!("Error computing tree route: {}", e), + } + } + } + + last = Some((n.header.number().clone(), n.hash.clone())); + info!(target: "substrate", "Imported #{} ({})", n.header.number(), n.hash); Ok(()) }); diff --git a/substrate/core/service/Cargo.toml b/substrate/core/service/Cargo.toml index e9f165ed9d..f950a77341 100644 --- a/substrate/core/service/Cargo.toml +++ b/substrate/core/service/Cargo.toml @@ -21,7 +21,6 @@ sr-io = { path = "../../core/sr-io" } sr-primitives = { path = "../../core/sr-primitives" } substrate-primitives = { path = "../../core/primitives" } substrate-consensus-common = { path = "../../core/consensus/common" } -substrate-consensus-aura-primitives = { path = "../../core/consensus/aura/primitives" } substrate-network = { path = "../../core/network" } substrate-client = { path = "../../core/client" } substrate-client-db = { path = "../../core/client/db" } diff --git a/substrate/core/service/src/lib.rs b/substrate/core/service/src/lib.rs index f782f917ed..dec78575c8 100644 --- a/substrate/core/service/src/lib.rs +++ b/substrate/core/service/src/lib.rs @@ -34,7 +34,6 @@ extern crate substrate_client as client; extern crate substrate_client_db as client_db; extern crate parity_codec as codec; extern crate substrate_transaction_pool as transaction_pool; -extern crate substrate_consensus_aura_primitives as aura_primitives; extern crate substrate_rpc_servers as rpc; extern crate target_info; extern crate tokio;