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

Commit

Permalink
Merge branch 'fixmining' of github.com:ethcore/parity into work-notify
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar committed Jun 30, 2016
2 parents 5a7fd62 + 1d780f4 commit 4e8fb0c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions ethcore/src/miner/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Miner {
fn prepare_sealing(&self, chain: &MiningBlockChainClient) {
trace!(target: "miner", "prepare_sealing: entering");

let (transactions, mut open_block, last_work_hash) = {
let (transactions, mut open_block, original_work_hash) = {
let transactions = {self.transaction_queue.lock().unwrap().top_transactions()};
let mut sealing_work = self.sealing_work.lock().unwrap();
let last_work_hash = sealing_work.peek_last_ref().map(|pb| pb.block().fields().header.hash());
Expand Down Expand Up @@ -254,27 +254,31 @@ impl Miner {
}
}

let work = {
let (work, is_new) = {
let mut sealing_work = self.sealing_work.lock().unwrap();
trace!(target: "miner", "Checking whether we need to reseal: last={:?}, this={:?}", last_work_hash, block.block().fields().header.hash());
let work = if last_work_hash.map_or(true, |h| h != block.block().fields().header.hash()) {
let last_work_hash = sealing_work.peek_last_ref().map(|pb| pb.block().fields().header.hash());
trace!(target: "miner", "Checking whether we need to reseal: orig={:?} last={:?}, this={:?}", original_work_hash, last_work_hash, block.block().fields().header.hash());
let (work, is_new) = if last_work_hash.map_or(true, |h| h != block.block().fields().header.hash()) {
trace!(target: "miner", "Pushing a new, refreshed or borrowed pending {}...", block.block().fields().header.hash());
let pow_hash = block.block().fields().header.hash();
let number = block.block().fields().header.number();
let difficulty = *block.block().fields().header.difficulty();
let is_new = original_work_hash.map_or(true, |h| block.block().fields().header.hash() != h);
sealing_work.push(block);
// If push notifications are enabled we assume all work items are used.
if self.work_poster.is_some() {
if self.work_poster.is_some() && is_new {
sealing_work.use_last_ref();
}
Some((pow_hash, difficulty, number))
(Some((pow_hash, difficulty, number)), is_new)
} else {
None
(None, false)
};
trace!(target: "miner", "prepare_sealing: leaving (last={:?})", sealing_work.peek_last_ref().map(|b| b.block().fields().header.hash()));
work
(work, is_new)
};
work.map(|(pow_hash, difficulty, number)| self.work_poster.as_ref().map(|ref p| p.notify(pow_hash, difficulty, number)));
if is_new {
work.map(|(pow_hash, difficulty, number)| self.work_poster.as_ref().map(|ref p| p.notify(pow_hash, difficulty, number)));
}
}

fn update_gas_limit(&self, chain: &MiningBlockChainClient) {
Expand Down

0 comments on commit 4e8fb0c

Please sign in to comment.