Remove .lock().unwrap() idiom into locked().
This commit is contained in:
@@ -161,8 +161,8 @@ impl Miner {
|
||||
trace!(target: "miner", "prepare_sealing: entering");
|
||||
|
||||
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 transactions = {self.transaction_queue.locked().top_transactions()};
|
||||
let mut sealing_work = self.sealing_work.locked();
|
||||
let last_work_hash = sealing_work.peek_last_ref().map(|pb| pb.block().fields().header.hash());
|
||||
let best_hash = chain.best_block_header().sha3();
|
||||
/*
|
||||
@@ -232,7 +232,7 @@ impl Miner {
|
||||
};
|
||||
|
||||
{
|
||||
let mut queue = self.transaction_queue.lock().unwrap();
|
||||
let mut queue = self.transaction_queue.locked();
|
||||
for hash in invalid_transactions.into_iter() {
|
||||
queue.remove_invalid(&hash, &fetch_account);
|
||||
}
|
||||
@@ -263,7 +263,7 @@ impl Miner {
|
||||
}
|
||||
|
||||
let (work, is_new) = {
|
||||
let mut sealing_work = self.sealing_work.lock().unwrap();
|
||||
let mut sealing_work = self.sealing_work.locked();
|
||||
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()) {
|
||||
@@ -291,20 +291,20 @@ impl Miner {
|
||||
|
||||
fn update_gas_limit(&self, chain: &MiningBlockChainClient) {
|
||||
let gas_limit = HeaderView::new(&chain.best_block_header()).gas_limit();
|
||||
let mut queue = self.transaction_queue.lock().unwrap();
|
||||
let mut queue = self.transaction_queue.locked();
|
||||
queue.set_gas_limit(gas_limit);
|
||||
}
|
||||
|
||||
/// Returns true if we had to prepare new pending block
|
||||
fn enable_and_prepare_sealing(&self, chain: &MiningBlockChainClient) -> bool {
|
||||
trace!(target: "miner", "enable_and_prepare_sealing: entering");
|
||||
let have_work = self.sealing_work.lock().unwrap().peek_last_ref().is_some();
|
||||
let have_work = self.sealing_work.locked().peek_last_ref().is_some();
|
||||
trace!(target: "miner", "enable_and_prepare_sealing: have_work={}", have_work);
|
||||
if !have_work {
|
||||
self.sealing_enabled.store(true, atomic::Ordering::Relaxed);
|
||||
self.prepare_sealing(chain);
|
||||
}
|
||||
let mut sealing_block_last_request = self.sealing_block_last_request.lock().unwrap();
|
||||
let mut sealing_block_last_request = self.sealing_block_last_request.locked();
|
||||
let best_number = chain.chain_info().best_block_number;
|
||||
if *sealing_block_last_request != best_number {
|
||||
trace!(target: "miner", "enable_and_prepare_sealing: Miner received request (was {}, now {}) - waking up.", *sealing_block_last_request, best_number);
|
||||
@@ -329,7 +329,7 @@ impl Miner {
|
||||
}
|
||||
|
||||
/// Are we allowed to do a non-mandatory reseal?
|
||||
fn tx_reseal_allowed(&self) -> bool { Instant::now() > *self.next_allowed_reseal.lock().unwrap() }
|
||||
fn tx_reseal_allowed(&self) -> bool { Instant::now() > *self.next_allowed_reseal.locked() }
|
||||
}
|
||||
|
||||
const SEALING_TIMEOUT_IN_BLOCKS : u64 = 5;
|
||||
@@ -337,13 +337,13 @@ const SEALING_TIMEOUT_IN_BLOCKS : u64 = 5;
|
||||
impl MinerService for Miner {
|
||||
|
||||
fn clear_and_reset(&self, chain: &MiningBlockChainClient) {
|
||||
self.transaction_queue.lock().unwrap().clear();
|
||||
self.transaction_queue.locked().clear();
|
||||
self.update_sealing(chain);
|
||||
}
|
||||
|
||||
fn status(&self) -> MinerStatus {
|
||||
let status = self.transaction_queue.lock().unwrap().status();
|
||||
let sealing_work = self.sealing_work.lock().unwrap();
|
||||
let status = self.transaction_queue.locked().status();
|
||||
let sealing_work = self.sealing_work.locked();
|
||||
MinerStatus {
|
||||
transactions_in_pending_queue: status.pending,
|
||||
transactions_in_future_queue: status.future,
|
||||
@@ -352,7 +352,7 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn call(&self, chain: &MiningBlockChainClient, t: &SignedTransaction, analytics: CallAnalytics) -> Result<Executed, ExecutionError> {
|
||||
let sealing_work = self.sealing_work.lock().unwrap();
|
||||
let sealing_work = self.sealing_work.locked();
|
||||
match sealing_work.peek_last_ref() {
|
||||
Some(work) => {
|
||||
let block = work.block();
|
||||
@@ -399,7 +399,7 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn balance(&self, chain: &MiningBlockChainClient, address: &Address) -> U256 {
|
||||
let sealing_work = self.sealing_work.lock().unwrap();
|
||||
let sealing_work = self.sealing_work.locked();
|
||||
sealing_work.peek_last_ref().map_or_else(
|
||||
|| chain.latest_balance(address),
|
||||
|b| b.block().fields().state.balance(address)
|
||||
@@ -407,7 +407,7 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn storage_at(&self, chain: &MiningBlockChainClient, address: &Address, position: &H256) -> H256 {
|
||||
let sealing_work = self.sealing_work.lock().unwrap();
|
||||
let sealing_work = self.sealing_work.locked();
|
||||
sealing_work.peek_last_ref().map_or_else(
|
||||
|| chain.latest_storage_at(address, position),
|
||||
|b| b.block().fields().state.storage_at(address, position)
|
||||
@@ -415,12 +415,12 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn nonce(&self, chain: &MiningBlockChainClient, address: &Address) -> U256 {
|
||||
let sealing_work = self.sealing_work.lock().unwrap();
|
||||
let sealing_work = self.sealing_work.locked();
|
||||
sealing_work.peek_last_ref().map_or_else(|| chain.latest_nonce(address), |b| b.block().fields().state.nonce(address))
|
||||
}
|
||||
|
||||
fn code(&self, chain: &MiningBlockChainClient, address: &Address) -> Option<Bytes> {
|
||||
let sealing_work = self.sealing_work.lock().unwrap();
|
||||
let sealing_work = self.sealing_work.locked();
|
||||
sealing_work.peek_last_ref().map_or_else(|| chain.code(address), |b| b.block().fields().state.code(address))
|
||||
}
|
||||
|
||||
@@ -442,16 +442,16 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn set_minimal_gas_price(&self, min_gas_price: U256) {
|
||||
self.transaction_queue.lock().unwrap().set_minimal_gas_price(min_gas_price);
|
||||
self.transaction_queue.locked().set_minimal_gas_price(min_gas_price);
|
||||
}
|
||||
|
||||
fn minimal_gas_price(&self) -> U256 {
|
||||
*self.transaction_queue.lock().unwrap().minimal_gas_price()
|
||||
*self.transaction_queue.locked().minimal_gas_price()
|
||||
}
|
||||
|
||||
fn sensible_gas_price(&self) -> U256 {
|
||||
// 10% above our minimum.
|
||||
*self.transaction_queue.lock().unwrap().minimal_gas_price() * 110.into() / 100.into()
|
||||
*self.transaction_queue.locked().minimal_gas_price() * 110.into() / 100.into()
|
||||
}
|
||||
|
||||
fn sensible_gas_limit(&self) -> U256 {
|
||||
@@ -459,15 +459,15 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn transactions_limit(&self) -> usize {
|
||||
self.transaction_queue.lock().unwrap().limit()
|
||||
self.transaction_queue.locked().limit()
|
||||
}
|
||||
|
||||
fn set_transactions_limit(&self, limit: usize) {
|
||||
self.transaction_queue.lock().unwrap().set_limit(limit)
|
||||
self.transaction_queue.locked().set_limit(limit)
|
||||
}
|
||||
|
||||
fn set_tx_gas_limit(&self, limit: U256) {
|
||||
self.transaction_queue.lock().unwrap().set_tx_gas_limit(limit)
|
||||
self.transaction_queue.locked().set_tx_gas_limit(limit)
|
||||
}
|
||||
|
||||
/// Get the author that we will seal blocks as.
|
||||
@@ -493,7 +493,7 @@ impl MinerService for Miner {
|
||||
fn import_external_transactions(&self, chain: &MiningBlockChainClient, transactions: Vec<SignedTransaction>) ->
|
||||
Vec<Result<TransactionImportResult, Error>> {
|
||||
|
||||
let mut transaction_queue = self.transaction_queue.lock().unwrap();
|
||||
let mut transaction_queue = self.transaction_queue.locked();
|
||||
let results = self.add_transactions_to_queue(chain, transactions, TransactionOrigin::External,
|
||||
&mut transaction_queue);
|
||||
|
||||
@@ -514,7 +514,7 @@ impl MinerService for Miner {
|
||||
|
||||
let imported = {
|
||||
// Be sure to release the lock before we call enable_and_prepare_sealing
|
||||
let mut transaction_queue = self.transaction_queue.lock().unwrap();
|
||||
let mut transaction_queue = self.transaction_queue.locked();
|
||||
let import = self.add_transactions_to_queue(chain, vec![transaction], TransactionOrigin::Local, &mut transaction_queue).pop().unwrap();
|
||||
|
||||
match import {
|
||||
@@ -546,13 +546,13 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn all_transactions(&self) -> Vec<SignedTransaction> {
|
||||
let queue = self.transaction_queue.lock().unwrap();
|
||||
let queue = self.transaction_queue.locked();
|
||||
queue.top_transactions()
|
||||
}
|
||||
|
||||
fn pending_transactions(&self) -> Vec<SignedTransaction> {
|
||||
let queue = self.transaction_queue.lock().unwrap();
|
||||
let sw = self.sealing_work.lock().unwrap();
|
||||
let queue = self.transaction_queue.locked();
|
||||
let sw = self.sealing_work.locked();
|
||||
// TODO: should only use the sealing_work when it's current (it could be an old block)
|
||||
let sealing_set = match self.sealing_enabled.load(atomic::Ordering::Relaxed) {
|
||||
true => sw.peek_last_ref(),
|
||||
@@ -565,8 +565,8 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn pending_transactions_hashes(&self) -> Vec<H256> {
|
||||
let queue = self.transaction_queue.lock().unwrap();
|
||||
let sw = self.sealing_work.lock().unwrap();
|
||||
let queue = self.transaction_queue.locked();
|
||||
let sw = self.sealing_work.locked();
|
||||
let sealing_set = match self.sealing_enabled.load(atomic::Ordering::Relaxed) {
|
||||
true => sw.peek_last_ref(),
|
||||
false => None,
|
||||
@@ -578,8 +578,8 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn transaction(&self, hash: &H256) -> Option<SignedTransaction> {
|
||||
let queue = self.transaction_queue.lock().unwrap();
|
||||
let sw = self.sealing_work.lock().unwrap();
|
||||
let queue = self.transaction_queue.locked();
|
||||
let sw = self.sealing_work.locked();
|
||||
let sealing_set = match self.sealing_enabled.load(atomic::Ordering::Relaxed) {
|
||||
true => sw.peek_last_ref(),
|
||||
false => None,
|
||||
@@ -591,7 +591,7 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn pending_receipts(&self) -> BTreeMap<H256, Receipt> {
|
||||
match (self.sealing_enabled.load(atomic::Ordering::Relaxed), self.sealing_work.lock().unwrap().peek_last_ref()) {
|
||||
match (self.sealing_enabled.load(atomic::Ordering::Relaxed), self.sealing_work.locked().peek_last_ref()) {
|
||||
(true, Some(pending)) => {
|
||||
let hashes = pending.transactions()
|
||||
.iter()
|
||||
@@ -606,14 +606,14 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn last_nonce(&self, address: &Address) -> Option<U256> {
|
||||
self.transaction_queue.lock().unwrap().last_nonce(address)
|
||||
self.transaction_queue.locked().last_nonce(address)
|
||||
}
|
||||
|
||||
fn update_sealing(&self, chain: &MiningBlockChainClient) {
|
||||
if self.sealing_enabled.load(atomic::Ordering::Relaxed) {
|
||||
let current_no = chain.chain_info().best_block_number;
|
||||
let has_local_transactions = self.transaction_queue.lock().unwrap().has_local_pending_transactions();
|
||||
let last_request = *self.sealing_block_last_request.lock().unwrap();
|
||||
let has_local_transactions = self.transaction_queue.locked().has_local_pending_transactions();
|
||||
let last_request = *self.sealing_block_last_request.locked();
|
||||
let should_disable_sealing = !self.forced_sealing()
|
||||
&& !has_local_transactions
|
||||
&& current_no > last_request
|
||||
@@ -622,9 +622,9 @@ impl MinerService for Miner {
|
||||
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_work.lock().unwrap().reset();
|
||||
self.sealing_work.locked().reset();
|
||||
} else {
|
||||
*self.next_allowed_reseal.lock().unwrap() = Instant::now() + self.options.reseal_min_period;
|
||||
*self.next_allowed_reseal.locked() = Instant::now() + self.options.reseal_min_period;
|
||||
self.prepare_sealing(chain);
|
||||
}
|
||||
}
|
||||
@@ -634,14 +634,14 @@ impl MinerService for Miner {
|
||||
trace!(target: "miner", "map_sealing_work: entering");
|
||||
self.enable_and_prepare_sealing(chain);
|
||||
trace!(target: "miner", "map_sealing_work: sealing prepared");
|
||||
let mut sealing_work = self.sealing_work.lock().unwrap();
|
||||
let mut sealing_work = self.sealing_work.locked();
|
||||
let ret = sealing_work.use_last_ref();
|
||||
trace!(target: "miner", "map_sealing_work: leaving use_last_ref={:?}", ret.as_ref().map(|b| b.block().fields().header.hash()));
|
||||
ret.map(f)
|
||||
}
|
||||
|
||||
fn submit_seal(&self, chain: &MiningBlockChainClient, pow_hash: H256, seal: Vec<Bytes>) -> Result<(), Error> {
|
||||
let result = if let Some(b) = self.sealing_work.lock().unwrap().get_used_if(if self.options.enable_resubmission { GetAction::Clone } else { GetAction::Take }, |b| &b.hash() == &pow_hash) {
|
||||
let result = if let Some(b) = self.sealing_work.locked().get_used_if(if self.options.enable_resubmission { GetAction::Clone } else { GetAction::Take }, |b| &b.hash() == &pow_hash) {
|
||||
b.lock().try_seal(self.engine(), seal).or_else(|_| {
|
||||
warn!(target: "miner", "Mined solution rejected: Invalid.");
|
||||
Err(Error::PowInvalid)
|
||||
@@ -688,7 +688,7 @@ impl MinerService for Miner {
|
||||
.par_iter()
|
||||
.map(|h| fetch_transactions(chain, h));
|
||||
out_of_chain.for_each(|txs| {
|
||||
let mut transaction_queue = self.transaction_queue.lock().unwrap();
|
||||
let mut transaction_queue = self.transaction_queue.locked();
|
||||
let _ = self.add_transactions_to_queue(
|
||||
chain, txs, TransactionOrigin::External, &mut transaction_queue
|
||||
);
|
||||
@@ -702,7 +702,7 @@ impl MinerService for Miner {
|
||||
.map(|h: &H256| fetch_transactions(chain, h));
|
||||
|
||||
in_chain.for_each(|mut txs| {
|
||||
let mut transaction_queue = self.transaction_queue.lock().unwrap();
|
||||
let mut transaction_queue = self.transaction_queue.locked();
|
||||
|
||||
let to_remove = txs.drain(..)
|
||||
.map(|tx| {
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
//! assert_eq!(miner.status().transactions_in_pending_queue, 0);
|
||||
//!
|
||||
//! // Check block for sealing
|
||||
//! //assert!(miner.sealing_block(client.deref()).lock().unwrap().is_some());
|
||||
//! //assert!(miner.sealing_block(client.deref()).locked().is_some());
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
|
||||
@@ -61,13 +61,13 @@ impl WorkPoster {
|
||||
pub fn notify(&self, pow_hash: H256, difficulty: U256, number: u64) {
|
||||
// TODO: move this to engine
|
||||
let target = Ethash::difficulty_to_boundary(&difficulty);
|
||||
let seed_hash = &self.seed_compute.lock().unwrap().get_seedhash(number);
|
||||
let seed_hash = &self.seed_compute.locked().get_seedhash(number);
|
||||
let seed_hash = H256::from_slice(&seed_hash[..]);
|
||||
let body = format!(
|
||||
r#"{{ "result": ["0x{}","0x{}","0x{}","0x{:x}"] }}"#,
|
||||
pow_hash.hex(), seed_hash.hex(), target.hex(), number
|
||||
);
|
||||
let mut client = self.client.lock().unwrap();
|
||||
let mut client = self.client.locked();
|
||||
for u in &self.urls {
|
||||
if let Err(e) = client.request(u.clone(), PostHandler { body: body.clone() }) {
|
||||
warn!("Error sending HTTP notification to {} : {}, retrying", u, e);
|
||||
|
||||
Reference in New Issue
Block a user