Remove .lock().unwrap() idiom into locked().
This commit is contained in:
@@ -41,6 +41,7 @@ use rpc::v1::tests::helpers::{TestSyncProvider, Config as SyncConfig, TestMinerS
|
||||
use rpc::v1::{Eth, EthClient, EthFilter, EthFilterClient};
|
||||
use util::panics::MayPanic;
|
||||
use util::hash::Address;
|
||||
use util::Lockable;
|
||||
|
||||
const USAGE: &'static str = r#"
|
||||
Parity rpctest client.
|
||||
@@ -137,7 +138,7 @@ impl Configuration {
|
||||
panic_handler.on_panic(move |_reason| { e.notify_all(); });
|
||||
|
||||
let mutex = Mutex::new(());
|
||||
let _ = exit.wait(mutex.lock().unwrap()).unwrap();
|
||||
let _ = exit.wait(mutex.locked()).unwrap();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ use std::time::{Instant, Duration};
|
||||
use std::sync::{mpsc, Mutex, RwLock, Arc};
|
||||
use std::collections::HashMap;
|
||||
use jsonrpc_core;
|
||||
use util::U256;
|
||||
use util::{U256, Lockable};
|
||||
use v1::helpers::{TransactionRequest, TransactionConfirmation};
|
||||
|
||||
/// Result that can be returned from JSON RPC.
|
||||
@@ -110,7 +110,7 @@ pub struct ConfirmationPromise {
|
||||
impl ConfirmationToken {
|
||||
/// Submit solution to all listeners
|
||||
fn resolve(&self, result: Option<RpcResult>) {
|
||||
let mut res = self.result.lock().unwrap();
|
||||
let mut res = self.result.locked();
|
||||
*res = result.map_or(ConfirmationResult::Rejected, |h| ConfirmationResult::Confirmed(h));
|
||||
// Notify listener
|
||||
self.handle.unpark();
|
||||
@@ -142,7 +142,7 @@ impl ConfirmationPromise {
|
||||
// Park thread (may wake up spuriously)
|
||||
thread::park_timeout(deadline - now);
|
||||
// Take confirmation result
|
||||
let res = self.result.lock().unwrap();
|
||||
let res = self.result.locked();
|
||||
// Check the result
|
||||
match *res {
|
||||
ConfirmationResult::Rejected => return None,
|
||||
@@ -183,7 +183,7 @@ impl ConfirmationsQueue {
|
||||
/// This method can be used only once (only single consumer of events can exist).
|
||||
pub fn start_listening<F>(&self, listener: F) -> Result<(), QueueError>
|
||||
where F: Fn(QueueEvent) -> () {
|
||||
let recv = self.receiver.lock().unwrap().take();
|
||||
let recv = self.receiver.locked().take();
|
||||
if let None = recv {
|
||||
return Err(QueueError::AlreadyUsed);
|
||||
}
|
||||
@@ -208,7 +208,7 @@ impl ConfirmationsQueue {
|
||||
/// Notifies receiver about the event happening in this queue.
|
||||
fn notify(&self, message: QueueEvent) {
|
||||
// We don't really care about the result
|
||||
let _ = self.sender.lock().unwrap().send(message);
|
||||
let _ = self.sender.locked().send(message);
|
||||
}
|
||||
|
||||
/// Removes transaction from this queue and notifies `ConfirmationPromise` holders about the result.
|
||||
@@ -241,7 +241,7 @@ impl SigningQueue for ConfirmationsQueue {
|
||||
fn add_request(&self, transaction: TransactionRequest) -> ConfirmationPromise {
|
||||
// Increment id
|
||||
let id = {
|
||||
let mut last_id = self.id.lock().unwrap();
|
||||
let mut last_id = self.id.locked();
|
||||
*last_id = *last_id + U256::from(1);
|
||||
*last_id
|
||||
};
|
||||
@@ -354,7 +354,7 @@ mod test {
|
||||
let r = received.clone();
|
||||
let handle = thread::spawn(move || {
|
||||
q.start_listening(move |notification| {
|
||||
let mut v = r.lock().unwrap();
|
||||
let mut v = r.locked();
|
||||
*v = Some(notification);
|
||||
}).expect("Should be closed nicely.")
|
||||
});
|
||||
@@ -363,7 +363,7 @@ mod test {
|
||||
|
||||
// then
|
||||
handle.join().expect("Thread should finish nicely");
|
||||
let r = received.lock().unwrap().take();
|
||||
let r = received.locked().take();
|
||||
assert_eq!(r, Some(QueueEvent::NewRequest(U256::from(1))));
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ use jsonrpc_core::*;
|
||||
use util::numbers::*;
|
||||
use util::sha3::*;
|
||||
use util::rlp::{encode, decode, UntrustedRlp, View};
|
||||
use util::Lockable;
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use ethcore::client::{MiningBlockChainClient, BlockID, TransactionID, UncleID};
|
||||
use ethcore::block::IsBlock;
|
||||
@@ -561,7 +562,7 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
|
||||
miner.map_sealing_work(client.deref(), |b| {
|
||||
let pow_hash = b.hash();
|
||||
let target = Ethash::difficulty_to_boundary(b.block().header().difficulty());
|
||||
let seed_hash = self.seed_compute.lock().unwrap().get_seedhash(b.block().header().number());
|
||||
let seed_hash = self.seed_compute.locked().get_seedhash(b.block().header().number());
|
||||
let block_number = RpcU256::from(b.block().header().number());
|
||||
to_value(&(RpcH256::from(pow_hash), RpcH256::from(seed_hash), RpcH256::from(target), block_number))
|
||||
}).unwrap_or(Err(Error::internal_error())) // no work found.
|
||||
|
||||
@@ -20,6 +20,7 @@ use std::ops::Deref;
|
||||
use std::sync::{Arc, Weak, Mutex};
|
||||
use std::collections::HashSet;
|
||||
use jsonrpc_core::*;
|
||||
use util::Lockable;
|
||||
use util::numbers::*;
|
||||
use ethcore::miner::MinerService;
|
||||
use ethcore::filter::Filter as EthcoreFilter;
|
||||
@@ -68,7 +69,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
|
||||
try!(self.active());
|
||||
from_params::<(Filter,)>(params)
|
||||
.and_then(|(filter,)| {
|
||||
let mut polls = self.polls.lock().unwrap();
|
||||
let mut polls = self.polls.locked();
|
||||
let block_number = take_weak!(self.client).chain_info().best_block_number;
|
||||
let id = polls.create_poll(PollFilter::Logs(block_number, Default::default(), filter));
|
||||
to_value(&RpcU256::from(id))
|
||||
@@ -79,7 +80,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
|
||||
try!(self.active());
|
||||
match params {
|
||||
Params::None => {
|
||||
let mut polls = self.polls.lock().unwrap();
|
||||
let mut polls = self.polls.locked();
|
||||
let id = polls.create_poll(PollFilter::Block(take_weak!(self.client).chain_info().best_block_number));
|
||||
to_value(&RpcU256::from(id))
|
||||
},
|
||||
@@ -91,7 +92,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
|
||||
try!(self.active());
|
||||
match params {
|
||||
Params::None => {
|
||||
let mut polls = self.polls.lock().unwrap();
|
||||
let mut polls = self.polls.locked();
|
||||
let pending_transactions = take_weak!(self.miner).pending_transactions_hashes();
|
||||
let id = polls.create_poll(PollFilter::PendingTransaction(pending_transactions));
|
||||
|
||||
@@ -106,7 +107,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
|
||||
let client = take_weak!(self.client);
|
||||
from_params::<(Index,)>(params)
|
||||
.and_then(|(index,)| {
|
||||
let mut polls = self.polls.lock().unwrap();
|
||||
let mut polls = self.polls.locked();
|
||||
match polls.poll_mut(&index.value()) {
|
||||
None => Ok(Value::Array(vec![] as Vec<Value>)),
|
||||
Some(filter) => match *filter {
|
||||
@@ -196,7 +197,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
|
||||
try!(self.active());
|
||||
from_params::<(Index,)>(params)
|
||||
.and_then(|(index,)| {
|
||||
let mut polls = self.polls.lock().unwrap();
|
||||
let mut polls = self.polls.locked();
|
||||
match polls.poll(&index.value()) {
|
||||
Some(&PollFilter::Logs(ref _block_number, ref _previous_log, ref filter)) => {
|
||||
let include_pending = filter.to_block == Some(BlockNumber::Pending);
|
||||
@@ -222,7 +223,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
|
||||
try!(self.active());
|
||||
from_params::<(Index,)>(params)
|
||||
.and_then(|(index,)| {
|
||||
self.polls.lock().unwrap().remove_poll(&index.value());
|
||||
self.polls.locked().remove_poll(&index.value());
|
||||
to_value(&true)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Test implementation of miner service.
|
||||
|
||||
use util::{Address, H256, Bytes, U256, FixedHash, Uint};
|
||||
use util::{Address, H256, Bytes, U256, FixedHash, Uint, Lockable};
|
||||
use util::standard::*;
|
||||
use ethcore::error::{Error, ExecutionError};
|
||||
use ethcore::client::{MiningBlockChainClient, Executed, CallAnalytics};
|
||||
@@ -133,7 +133,7 @@ impl MinerService for TestMinerService {
|
||||
fn import_external_transactions(&self, _chain: &MiningBlockChainClient, transactions: Vec<SignedTransaction>) ->
|
||||
Vec<Result<TransactionImportResult, Error>> {
|
||||
// lets assume that all txs are valid
|
||||
self.imported_transactions.lock().unwrap().extend_from_slice(&transactions);
|
||||
self.imported_transactions.locked().extend_from_slice(&transactions);
|
||||
|
||||
for sender in transactions.iter().filter_map(|t| t.sender().ok()) {
|
||||
let nonce = self.last_nonce(&sender).expect("last_nonce must be populated in tests");
|
||||
@@ -156,7 +156,7 @@ impl MinerService for TestMinerService {
|
||||
}
|
||||
|
||||
// lets assume that all txs are valid
|
||||
self.imported_transactions.lock().unwrap().push(transaction);
|
||||
self.imported_transactions.locked().push(transaction);
|
||||
|
||||
Ok(TransactionImportResult::Current)
|
||||
}
|
||||
@@ -186,19 +186,19 @@ impl MinerService for TestMinerService {
|
||||
}
|
||||
|
||||
fn transaction(&self, hash: &H256) -> Option<SignedTransaction> {
|
||||
self.pending_transactions.lock().unwrap().get(hash).cloned()
|
||||
self.pending_transactions.locked().get(hash).cloned()
|
||||
}
|
||||
|
||||
fn all_transactions(&self) -> Vec<SignedTransaction> {
|
||||
self.pending_transactions.lock().unwrap().values().cloned().collect()
|
||||
self.pending_transactions.locked().values().cloned().collect()
|
||||
}
|
||||
|
||||
fn pending_transactions(&self) -> Vec<SignedTransaction> {
|
||||
self.pending_transactions.lock().unwrap().values().cloned().collect()
|
||||
self.pending_transactions.locked().values().cloned().collect()
|
||||
}
|
||||
|
||||
fn pending_receipts(&self) -> BTreeMap<H256, Receipt> {
|
||||
self.pending_receipts.lock().unwrap().clone()
|
||||
self.pending_receipts.locked().clone()
|
||||
}
|
||||
|
||||
fn last_nonce(&self, address: &Address) -> Option<U256> {
|
||||
@@ -212,7 +212,7 @@ impl MinerService for TestMinerService {
|
||||
}
|
||||
|
||||
fn balance(&self, _chain: &MiningBlockChainClient, address: &Address) -> U256 {
|
||||
self.latest_closed_block.lock().unwrap().as_ref().map_or_else(U256::zero, |b| b.block().fields().state.balance(address).clone())
|
||||
self.latest_closed_block.locked().as_ref().map_or_else(U256::zero, |b| b.block().fields().state.balance(address).clone())
|
||||
}
|
||||
|
||||
fn call(&self, _chain: &MiningBlockChainClient, _t: &SignedTransaction, _analytics: CallAnalytics) -> Result<Executed, ExecutionError> {
|
||||
@@ -220,7 +220,7 @@ impl MinerService for TestMinerService {
|
||||
}
|
||||
|
||||
fn storage_at(&self, _chain: &MiningBlockChainClient, address: &Address, position: &H256) -> H256 {
|
||||
self.latest_closed_block.lock().unwrap().as_ref().map_or_else(H256::default, |b| b.block().fields().state.storage_at(address, position).clone())
|
||||
self.latest_closed_block.locked().as_ref().map_or_else(H256::default, |b| b.block().fields().state.storage_at(address, position).clone())
|
||||
}
|
||||
|
||||
fn nonce(&self, _chain: &MiningBlockChainClient, address: &Address) -> U256 {
|
||||
@@ -230,7 +230,7 @@ impl MinerService for TestMinerService {
|
||||
}
|
||||
|
||||
fn code(&self, _chain: &MiningBlockChainClient, address: &Address) -> Option<Bytes> {
|
||||
self.latest_closed_block.lock().unwrap().as_ref().map_or(None, |b| b.block().fields().state.code(address).clone())
|
||||
self.latest_closed_block.locked().as_ref().map_or(None, |b| b.block().fields().state.code(address).clone())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ use std::str::FromStr;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use jsonrpc_core::IoHandler;
|
||||
use util::Lockable;
|
||||
use util::hash::{Address, H256, FixedHash};
|
||||
use util::numbers::{Uint, U256};
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
@@ -363,7 +364,7 @@ fn rpc_eth_pending_transaction_by_hash() {
|
||||
let tester = EthTester::default();
|
||||
{
|
||||
let tx: SignedTransaction = decode(&FromHex::from_hex("f85f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804").unwrap());
|
||||
tester.miner.pending_transactions.lock().unwrap().insert(H256::zero(), tx);
|
||||
tester.miner.pending_transactions.locked().insert(H256::zero(), tx);
|
||||
}
|
||||
|
||||
let response = r#"{"jsonrpc":"2.0","result":{"blockHash":null,"blockNumber":null,"creates":null,"from":"0x0f65fe9276bc9a24ae7083ae28e2660ef72df99e","gas":"0x5208","gasPrice":"0x01","hash":"0x41df922fd0d4766fcc02e161f8295ec28522f329ae487f14d811e4b64c8d6e31","input":"0x","nonce":"0x00","to":"0x095e7baea6a6c7c4c2dfeb977efac326af552d87","transactionIndex":null,"value":"0x0a"},"id":1}"#;
|
||||
|
||||
@@ -18,6 +18,7 @@ use std::sync::Arc;
|
||||
use std::str::FromStr;
|
||||
use jsonrpc_core::IoHandler;
|
||||
use util::numbers::*;
|
||||
use util::Lockable;
|
||||
use ethcore::account_provider::AccountProvider;
|
||||
use ethcore::client::TestBlockChainClient;
|
||||
use ethcore::transaction::{Transaction, Action};
|
||||
@@ -112,7 +113,7 @@ fn should_reject_transaction_from_queue_without_dispatching() {
|
||||
// then
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.queue.requests().len(), 0);
|
||||
assert_eq!(tester.miner.imported_transactions.lock().unwrap().len(), 0);
|
||||
assert_eq!(tester.miner.imported_transactions.locked().len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -181,6 +182,6 @@ fn should_confirm_transaction_and_dispatch() {
|
||||
// then
|
||||
assert_eq!(tester.io.handle_request(&request), Some(response.to_owned()));
|
||||
assert_eq!(tester.queue.requests().len(), 0);
|
||||
assert_eq!(tester.miner.imported_transactions.lock().unwrap().len(), 1);
|
||||
assert_eq!(tester.miner.imported_transactions.locked().len(), 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user