Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Fix a deadlock (#9952)
Browse files Browse the repository at this point in the history
* Update informant:
  - decimal in Mgas/s
  - print every 5s (not randomly between 5s and 10s)

* Fix dead-lock in `blockchain.rs`

* Update locks ordering
  • Loading branch information
ngotchac authored and 5chdn committed Nov 27, 2018
1 parent 87ccdae commit 41141c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ethcore/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,8 +1187,8 @@ impl BlockChain {
let mut pending_block_details = self.pending_block_details.write();
let mut pending_write_txs = self.pending_transaction_addresses.write();

let mut best_ancient_block = self.best_ancient_block.write();
let mut best_block = self.best_block.write();
let mut best_ancient_block = self.best_ancient_block.write();
let mut write_block_details = self.block_details.write();
let mut write_hashes = self.block_hashes.write();
let mut write_txs = self.transaction_addresses.write();
Expand Down
12 changes: 5 additions & 7 deletions parity/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,13 @@ impl<T: InformantData> Informant<T> {
}

pub fn tick(&self) {
let elapsed = self.last_tick.read().elapsed();
if elapsed < Duration::from_secs(5) {
return;
}
let now = Instant::now();
let elapsed = now.duration_since(*self.last_tick.read());

let (client_report, full_report) = {
let mut last_report = self.last_report.lock();
let full_report = self.target.report();
let diffed = full_report.client_report.clone() - &*last_report;
*last_report = full_report.client_report.clone();
(diffed, full_report)
};

Expand All @@ -289,7 +286,8 @@ impl<T: InformantData> Informant<T> {
return;
}

*self.last_tick.write() = Instant::now();
*self.last_tick.write() = now;
*self.last_report.lock() = full_report.client_report.clone();

let paint = |c: Style, t: String| match self.with_color && atty::is(atty::Stream::Stdout) {
true => format!("{}", c.paint(t)),
Expand All @@ -306,7 +304,7 @@ impl<T: InformantData> Informant<T> {
format!("{} blk/s {} tx/s {} Mgas/s",
paint(Yellow.bold(), format!("{:7.2}", (client_report.blocks_imported * 1000) as f64 / elapsed.as_milliseconds() as f64)),
paint(Yellow.bold(), format!("{:6.1}", (client_report.transactions_applied * 1000) as f64 / elapsed.as_milliseconds() as f64)),
paint(Yellow.bold(), format!("{:4}", (client_report.gas_processed / (elapsed.as_milliseconds() * 1000)).low_u64()))
paint(Yellow.bold(), format!("{:6.1}", (client_report.gas_processed / 1000).low_u64() as f64 / elapsed.as_milliseconds() as f64))
)
} else {
format!("{} hdr/s",
Expand Down

0 comments on commit 41141c2

Please sign in to comment.