Multi-mode logging. (#1643)
* Multi-mode logging. Better for miners (they get immediate notification of new block). Better for general use (less superfluous information shown). * Remove comment. [ci:skip] * Minor string change [ci:skip] * Minor message tweak. * Minor tweaks and indentation fix.
This commit is contained in:
@@ -22,21 +22,18 @@ use std::sync::{Arc, Weak};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::fmt;
|
||||
use std::sync::atomic::{AtomicUsize, AtomicBool, Ordering as AtomicOrdering};
|
||||
use std::time::Instant;
|
||||
use std::time::{Instant, Duration};
|
||||
use time::precise_time_ns;
|
||||
|
||||
// util
|
||||
use util::{journaldb, rlp, Bytes, Stream, View, PerfTimer, Itertools, Mutex, RwLock, Colour};
|
||||
use util::journaldb::JournalDB;
|
||||
use util::rlp::{RlpStream, Rlp, UntrustedRlp};
|
||||
use util::numbers::*;
|
||||
use util::panics::*;
|
||||
use util::io::*;
|
||||
use util::rlp;
|
||||
use util::sha3::*;
|
||||
use util::Bytes;
|
||||
use util::rlp::{RlpStream, Rlp, UntrustedRlp};
|
||||
use util::journaldb;
|
||||
use util::journaldb::JournalDB;
|
||||
use util::kvdb::*;
|
||||
use util::{Stream, View, PerfTimer, Itertools};
|
||||
use util::{Mutex, RwLock};
|
||||
|
||||
// other
|
||||
use views::BlockView;
|
||||
@@ -145,6 +142,8 @@ pub struct Client {
|
||||
notify: RwLock<Option<Weak<ChainNotify>>>,
|
||||
queue_transactions: AtomicUsize,
|
||||
previous_enode: Mutex<Option<String>>,
|
||||
skipped: AtomicUsize,
|
||||
last_import: Mutex<Instant>,
|
||||
last_hashes: RwLock<VecDeque<H256>>,
|
||||
}
|
||||
|
||||
@@ -233,6 +232,8 @@ impl Client {
|
||||
notify: RwLock::new(None),
|
||||
queue_transactions: AtomicUsize::new(0),
|
||||
previous_enode: Mutex::new(None),
|
||||
skipped: AtomicUsize::new(0),
|
||||
last_import: Mutex::new(Instant::now()),
|
||||
last_hashes: RwLock::new(VecDeque::new()),
|
||||
};
|
||||
Ok(Arc::new(client))
|
||||
@@ -367,16 +368,21 @@ impl Client {
|
||||
|
||||
for block in blocks {
|
||||
let header = &block.header;
|
||||
let start = precise_time_ns();
|
||||
|
||||
if invalid_blocks.contains(&header.parent_hash) {
|
||||
invalid_blocks.insert(header.hash());
|
||||
continue;
|
||||
}
|
||||
let tx_count = block.transactions.len();
|
||||
let size = block.bytes.len();
|
||||
|
||||
let closed_block = self.check_and_close_block(&block);
|
||||
if let Err(_) = closed_block {
|
||||
invalid_blocks.insert(header.hash());
|
||||
continue;
|
||||
}
|
||||
|
||||
let closed_block = closed_block.unwrap();
|
||||
imported_blocks.push(header.hash());
|
||||
|
||||
@@ -384,7 +390,30 @@ impl Client {
|
||||
import_results.push(route);
|
||||
|
||||
self.report.write().accrue_block(&block);
|
||||
trace!(target: "client", "Imported #{} ({})", header.number(), header.hash());
|
||||
|
||||
let duration_ns = precise_time_ns() - start;
|
||||
|
||||
let mut last_import = self.last_import.lock();
|
||||
if Instant::now() > *last_import + Duration::from_secs(1) {
|
||||
let queue_info = self.queue_info();
|
||||
let importing = queue_info.unverified_queue_size + queue_info.verified_queue_size > 3;
|
||||
if !importing {
|
||||
let skipped = self.skipped.load(AtomicOrdering::Relaxed);
|
||||
info!(target: "import", "Imported {} {} ({} txs, {} Mgas, {} ms, {} KiB){}",
|
||||
Colour::White.bold().paint(format!("#{}", header.number())),
|
||||
Colour::White.bold().paint(format!("{}", header.hash())),
|
||||
Colour::Yellow.bold().paint(format!("{}", tx_count)),
|
||||
Colour::Yellow.bold().paint(format!("{:.2}", header.gas_used.low_u64() as f32 / 1000000f32)),
|
||||
Colour::Purple.bold().paint(format!("{:.2}", duration_ns as f32 / 1000000f32)),
|
||||
Colour::Blue.bold().paint(format!("{:.2}", size as f32 / 1024f32)),
|
||||
if skipped > 0 { format!(" + another {} block(s)", Colour::Red.bold().paint(format!("{}", skipped))) } else { String::new() }
|
||||
);
|
||||
*last_import = Instant::now();
|
||||
}
|
||||
self.skipped.store(0, AtomicOrdering::Relaxed);
|
||||
} else {
|
||||
self.skipped.fetch_add(1, AtomicOrdering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
let imported = imported_blocks.len();
|
||||
|
||||
Reference in New Issue
Block a user