Show imported messages for light client (#8517)
This commit is contained in:
parent
44c68221a8
commit
2a829b1f1a
@ -30,7 +30,7 @@ use kvdb::KeyValueDB;
|
|||||||
use cache::Cache;
|
use cache::Cache;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
|
||||||
use super::{ChainDataFetcher, Client, Config as ClientConfig};
|
use super::{ChainDataFetcher, LightChainNotify, Client, Config as ClientConfig};
|
||||||
|
|
||||||
/// Errors on service initialization.
|
/// Errors on service initialization.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -86,6 +86,11 @@ impl<T: ChainDataFetcher> Service<T> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the actor to be notified on certain chain events
|
||||||
|
pub fn add_notify(&self, notify: Arc<LightChainNotify>) {
|
||||||
|
self.client.add_listener(Arc::downgrade(¬ify));
|
||||||
|
}
|
||||||
|
|
||||||
/// Register an I/O handler on the service.
|
/// Register an I/O handler on the service.
|
||||||
pub fn register_handler(&self, handler: Arc<IoHandler<ClientIoMessage> + Send>) -> Result<(), IoError> {
|
pub fn register_handler(&self, handler: Arc<IoHandler<ClientIoMessage> + Send>) -> Result<(), IoError> {
|
||||||
self.io_service.register_handler(handler)
|
self.io_service.register_handler(handler)
|
||||||
|
@ -33,7 +33,7 @@ use ethcore::snapshot::service::Service as SnapshotService;
|
|||||||
use sync::{LightSyncProvider, LightSync, SyncProvider, ManageNetwork};
|
use sync::{LightSyncProvider, LightSync, SyncProvider, ManageNetwork};
|
||||||
use io::{TimerToken, IoContext, IoHandler};
|
use io::{TimerToken, IoContext, IoHandler};
|
||||||
use light::Cache as LightDataCache;
|
use light::Cache as LightDataCache;
|
||||||
use light::client::LightChainClient;
|
use light::client::{LightChainClient, LightChainNotify};
|
||||||
use number_prefix::{binary_prefix, Standalone, Prefixed};
|
use number_prefix::{binary_prefix, Standalone, Prefixed};
|
||||||
use parity_rpc::{is_major_importing};
|
use parity_rpc::{is_major_importing};
|
||||||
use parity_rpc::informant::RpcStats;
|
use parity_rpc::informant::RpcStats;
|
||||||
@ -395,6 +395,33 @@ impl ChainNotify for Informant<FullNodeInformantData> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl LightChainNotify for Informant<LightNodeInformantData> {
|
||||||
|
fn new_headers(&self, good: &[H256]) {
|
||||||
|
let mut last_import = self.last_import.lock();
|
||||||
|
let client = &self.target.client;
|
||||||
|
|
||||||
|
let importing = self.target.is_major_importing();
|
||||||
|
let ripe = Instant::now() > *last_import + Duration::from_secs(1) && !importing;
|
||||||
|
|
||||||
|
if ripe {
|
||||||
|
if let Some(header) = good.last().and_then(|h| client.block_header(BlockId::Hash(*h))) {
|
||||||
|
info!(target: "import", "Imported {} {} ({} Mgas){}",
|
||||||
|
Colour::White.bold().paint(format!("#{}", header.number())),
|
||||||
|
Colour::White.bold().paint(format!("{}", header.hash())),
|
||||||
|
Colour::Yellow.bold().paint(format!("{:.2}", header.gas_used().low_u64() as f32 / 1000000f32)),
|
||||||
|
if good.len() > 1 {
|
||||||
|
format!(" + another {} header(s)",
|
||||||
|
Colour::Red.bold().paint(format!("{}", good.len() - 1)))
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
*last_import = Instant::now();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const INFO_TIMER: TimerToken = 0;
|
const INFO_TIMER: TimerToken = 0;
|
||||||
|
|
||||||
impl<T: InformantData> IoHandler<ClientIoMessage> for Informant<T> {
|
impl<T: InformantData> IoHandler<ClientIoMessage> for Informant<T> {
|
||||||
|
@ -412,7 +412,7 @@ fn execute_light_impl(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<Runnin
|
|||||||
Some(rpc_stats),
|
Some(rpc_stats),
|
||||||
cmd.logger_config.color,
|
cmd.logger_config.color,
|
||||||
));
|
));
|
||||||
|
service.add_notify(informant.clone());
|
||||||
service.register_handler(informant.clone()).map_err(|_| "Unable to register informant handler".to_owned())?;
|
service.register_handler(informant.clone()).map_err(|_| "Unable to register informant handler".to_owned())?;
|
||||||
|
|
||||||
Ok(RunningClient::Light {
|
Ok(RunningClient::Light {
|
||||||
|
Loading…
Reference in New Issue
Block a user