From 29b6ba4a87579423019cdcaa76e842a9a2097170 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 30 Jun 2016 22:35:59 +0200 Subject: [PATCH 1/2] Fix the reseal mechanism. --- ethcore/src/miner/miner.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 7b101afc7..35c9998c7 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -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()); @@ -254,23 +254,27 @@ 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(false, |h| block.block().fields().header.hash() == h); sealing_work.push(block); - 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) { From 1d780f456ac7d7bf09af7df366478289788d4d72 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 30 Jun 2016 23:14:54 +0200 Subject: [PATCH 2/2] Fix is_new. --- ethcore/src/miner/miner.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 35c9998c7..d3e32c797 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -263,7 +263,7 @@ impl Miner { 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(false, |h| block.block().fields().header.hash() == h); + let is_new = original_work_hash.map_or(true, |h| block.block().fields().header.hash() != h); sealing_work.push(block); (Some((pow_hash, difficulty, number)), is_new) } else {