Add tracing.

This commit is contained in:
Gav Wood 2016-03-24 13:51:51 +00:00
parent 038b67cbd4
commit 0ab57c48c3
2 changed files with 22 additions and 14 deletions

View File

@ -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<Option<ClosedBlock>> {
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
}

View File

@ -398,10 +398,11 @@ impl<C, S, A, M, EM> Eth for EthClient<C, S, A, M, EM>
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()));
}
}