Fix up informant. (#2865)
Just ensure as many transactions/blocks are reported as possible.
This commit is contained in:
parent
5b978be034
commit
c9298981f8
@ -43,6 +43,7 @@ pub struct Informant {
|
|||||||
net: Option<Arc<ManageNetwork>>,
|
net: Option<Arc<ManageNetwork>>,
|
||||||
last_import: Mutex<Instant>,
|
last_import: Mutex<Instant>,
|
||||||
skipped: AtomicUsize,
|
skipped: AtomicUsize,
|
||||||
|
skipped_txs: AtomicUsize,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format byte counts to standard denominations.
|
/// Format byte counts to standard denominations.
|
||||||
@ -80,6 +81,7 @@ impl Informant {
|
|||||||
net: net,
|
net: net,
|
||||||
last_import: Mutex::new(Instant::now()),
|
last_import: Mutex::new(Instant::now()),
|
||||||
skipped: AtomicUsize::new(0),
|
skipped: AtomicUsize::new(0),
|
||||||
|
skipped_txs: AtomicUsize::new(0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,13 +180,21 @@ impl ChainNotify for Informant {
|
|||||||
let mut last_import = self.last_import.lock();
|
let mut last_import = self.last_import.lock();
|
||||||
let sync_state = self.sync.as_ref().map(|s| s.status().state);
|
let sync_state = self.sync.as_ref().map(|s| s.status().state);
|
||||||
let importing = is_major_importing(sync_state, self.client.queue_info());
|
let importing = is_major_importing(sync_state, self.client.queue_info());
|
||||||
if Instant::now() > *last_import + Duration::from_secs(1) && !importing {
|
|
||||||
|
let ripe = Instant::now() > *last_import + Duration::from_secs(1) && !importing;
|
||||||
|
let txs_imported = imported.iter()
|
||||||
|
.take(imported.len() - if ripe {1} else {0})
|
||||||
|
.filter_map(|h| self.client.block(BlockID::Hash(h.clone())))
|
||||||
|
.map(|b| BlockView::new(&b).transactions_count())
|
||||||
|
.sum();
|
||||||
|
|
||||||
|
if ripe {
|
||||||
if let Some(block) = imported.last().and_then(|h| self.client.block(BlockID::Hash(*h))) {
|
if let Some(block) = imported.last().and_then(|h| self.client.block(BlockID::Hash(*h))) {
|
||||||
let view = BlockView::new(&block);
|
let view = BlockView::new(&block);
|
||||||
let header = view.header();
|
let header = view.header();
|
||||||
let tx_count = view.transactions_count();
|
let tx_count = view.transactions_count();
|
||||||
let size = block.len();
|
let size = block.len();
|
||||||
let skipped = self.skipped.load(AtomicOrdering::Relaxed);
|
let (skipped, skipped_txs) = (self.skipped.load(AtomicOrdering::Relaxed) + imported.len() - 1, self.skipped.load(AtomicOrdering::Relaxed) + txs_imported);
|
||||||
info!(target: "import", "Imported {} {} ({} txs, {} Mgas, {} ms, {} KiB){}",
|
info!(target: "import", "Imported {} {} ({} txs, {} Mgas, {} ms, {} KiB){}",
|
||||||
Colour::White.bold().paint(format!("#{}", header.number())),
|
Colour::White.bold().paint(format!("#{}", header.number())),
|
||||||
Colour::White.bold().paint(format!("{}", header.hash())),
|
Colour::White.bold().paint(format!("{}", header.hash())),
|
||||||
@ -192,13 +202,22 @@ impl ChainNotify for Informant {
|
|||||||
Colour::Yellow.bold().paint(format!("{:.2}", header.gas_used().low_u64() as f32 / 1000000f32)),
|
Colour::Yellow.bold().paint(format!("{:.2}", header.gas_used().low_u64() as f32 / 1000000f32)),
|
||||||
Colour::Purple.bold().paint(format!("{:.2}", duration as f32 / 1000000f32)),
|
Colour::Purple.bold().paint(format!("{:.2}", duration as f32 / 1000000f32)),
|
||||||
Colour::Blue.bold().paint(format!("{:.2}", size as f32 / 1024f32)),
|
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() }
|
if skipped > 0 {
|
||||||
|
format!(" + another {} block(s) containing {} tx(s)",
|
||||||
|
Colour::Red.bold().paint(format!("{}", skipped)),
|
||||||
|
Colour::Red.bold().paint(format!("{}", skipped_txs))
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
self.skipped.store(0, AtomicOrdering::Relaxed);
|
||||||
|
self.skipped_txs.store(0, AtomicOrdering::Relaxed);
|
||||||
*last_import = Instant::now();
|
*last_import = Instant::now();
|
||||||
}
|
}
|
||||||
self.skipped.store(0, AtomicOrdering::Relaxed);
|
|
||||||
} else {
|
} else {
|
||||||
self.skipped.fetch_add(imported.len(), AtomicOrdering::Relaxed);
|
self.skipped.fetch_add(imported.len(), AtomicOrdering::Relaxed);
|
||||||
|
self.skipped_txs.fetch_add(txs_imported, AtomicOrdering::Relaxed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user