From 0ab57c48c3c3948e68d2b4443a99fc7497d859cd Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 24 Mar 2016 13:51:51 +0000 Subject: [PATCH] Add tracing. --- miner/src/miner.rs | 33 ++++++++++++++++++++------------- rpc/src/v1/impls/eth.rs | 3 ++- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/miner/src/miner.rs b/miner/src/miner.rs index d4f6c8a00..4e0f4a5c5 100644 --- a/miner/src/miner.rs +++ b/miner/src/miner.rs @@ -166,28 +166,35 @@ impl MinerService for Miner { } fn update_sealing(&self, chain: &BlockChainClient) { - let should_disable_sealing = { - let current_no = chain.chain_info().best_block_number; - let last_request = self.sealing_block_last_request.lock().unwrap(); - let is_greater = current_no > *last_request; - is_greater && current_no - *last_request > SEALING_TIMEOUT_IN_BLOCKS - }; + if self.sealing_enabled.load(atomic::Ordering::Relaxed) { + let should_disable_sealing = { + let current_no = chain.chain_info().best_block_number; + let last_request = self.sealing_block_last_request.lock().unwrap(); + let is_greater = current_no > *last_request; + is_greater && current_no - *last_request > SEALING_TIMEOUT_IN_BLOCKS + }; - if should_disable_sealing { - self.sealing_enabled.store(false, atomic::Ordering::Relaxed); - *self.sealing_block.lock().unwrap() = None; - } else if self.sealing_enabled.load(atomic::Ordering::Relaxed) { - self.prepare_sealing(chain); + if should_disable_sealing { + trace!(target: "miner", "Miner sleeping (current {}, last {})", current_no, last_request); + self.sealing_enabled.store(false, atomic::Ordering::Relaxed); + *self.sealing_block.lock().unwrap() = None; + } else { + self.prepare_sealing(chain); + } } } fn sealing_block(&self, chain: &BlockChainClient) -> &Mutex> { if self.sealing_block.lock().unwrap().is_none() { self.sealing_enabled.store(true, atomic::Ordering::Relaxed); - self.prepare_sealing(chain); } - *self.sealing_block_last_request.lock().unwrap() = chain.chain_info().best_block_number; + let sealing_block_last_request = self.sealing_block_last_request.lock().unwrap(); + let best_number = chain.chain_info().best_block_number; + if *sealing_block_last_request != best_number { + trace!(target: "miner", "Miner received request (was {}, now {}) - waking up.", sealing_block_last_request, best_number); + *sealing_block_last_request = best_number; + } &self.sealing_block } diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index a065392d5..638403c7d 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -398,10 +398,11 @@ impl Eth for EthClient match params { Params::None => { let client = take_weak!(self.client); - // check if we're still syncing and return empty strings int that case + // check if we're still syncing and return empty strings in that case { let sync = take_weak!(self.sync); if sync.status().state != SyncState::Idle && client.queue_info().is_empty() { + trace!(target: "miner", "Syncing. Cannot give any work."); return to_value(&(String::new(), String::new(), String::new())); } }