From 8fad728e9b277899ee7895c834302c52151a1ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Sun, 19 Jun 2016 12:33:50 +0200 Subject: [PATCH] Fixing locks order (#1328) --- ethcore/src/miner/miner.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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() } }