diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index ec232d238..ef59de1ec 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -31,13 +31,14 @@ use miner::{MinerService, MinerStatus, TransactionQueue, AccountDetails, Transac /// Keeps track of transactions using priority queue and holds currently mined block. pub struct Miner { + // NOTE [ToDr] When locking always lock in this order! transaction_queue: Mutex, + sealing_work: Mutex>, // for sealing... force_sealing: bool, sealing_enabled: AtomicBool, sealing_block_last_request: Mutex, - sealing_work: Mutex>, gas_floor_target: RwLock, author: RwLock
, extra_data: RwLock, @@ -424,20 +425,20 @@ impl MinerService for Miner { } fn pending_transactions_hashes(&self) -> Vec { + let queue = self.transaction_queue.lock().unwrap(); match (self.sealing_enabled.load(atomic::Ordering::Relaxed), self.sealing_work.lock().unwrap().peek_last_ref()) { (true, Some(pending)) => pending.transactions().iter().map(|t| t.hash()).collect(), _ => { - let queue = self.transaction_queue.lock().unwrap(); queue.pending_hashes() } } } fn transaction(&self, hash: &H256) -> Option { + let queue = self.transaction_queue.lock().unwrap(); match (self.sealing_enabled.load(atomic::Ordering::Relaxed), self.sealing_work.lock().unwrap().peek_last_ref()) { (true, Some(pending)) => pending.transactions().iter().find(|t| &t.hash() == hash).cloned(), _ => { - let queue = self.transaction_queue.lock().unwrap(); queue.find(hash) } } @@ -449,11 +450,11 @@ impl MinerService for Miner { } fn pending_transactions(&self) -> Vec { + let queue = self.transaction_queue.lock().unwrap(); // TODO: should only use the sealing_work when it's current (it could be an old block) match (self.sealing_enabled.load(atomic::Ordering::Relaxed), self.sealing_work.lock().unwrap().peek_last_ref()) { (true, Some(pending)) => pending.transactions().clone(), _ => { - let queue = self.transaction_queue.lock().unwrap(); queue.top_transactions() } }