log on reorganization (#1356)

This commit is contained in:
Robert Habermeier
2019-01-07 15:32:04 +01:00
committed by Gav Wood
parent 409d495b42
commit eb0ff291d6
4 changed files with 33 additions and 5 deletions
-1
View File
@@ -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",
+33 -2
View File
@@ -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<C>(service: &Service<C>, 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(())
});
-1
View File
@@ -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" }
-1
View File
@@ -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;