Switch out .X().unwrap() for .unwrapped_X
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
use std::fmt;
|
||||
use std::sync::RwLock;
|
||||
use std::collections::HashMap;
|
||||
use util::{Address as H160, H256, H520};
|
||||
use util::{Address as H160, H256, H520, RwLockable};
|
||||
use ethstore::{SecretStore, Error as SSError, SafeAccount, EthStore};
|
||||
use ethstore::dir::{KeyDirectory};
|
||||
use ethstore::ethkey::{Address as SSAddress, Message as SSMessage, Secret as SSSecret, Random, Generator};
|
||||
@@ -177,7 +177,7 @@ impl AccountProvider {
|
||||
|
||||
// check if account is already unlocked pernamently, if it is, do nothing
|
||||
{
|
||||
let unlocked = self.unlocked.read().unwrap();
|
||||
let unlocked = self.unlocked.unwrapped_read();
|
||||
if let Some(data) = unlocked.get(&account) {
|
||||
if let Unlock::Perm = data.unlock {
|
||||
return Ok(())
|
||||
@@ -190,7 +190,7 @@ impl AccountProvider {
|
||||
password: password,
|
||||
};
|
||||
|
||||
let mut unlocked = self.unlocked.write().unwrap();
|
||||
let mut unlocked = self.unlocked.unwrapped_write();
|
||||
unlocked.insert(account, data);
|
||||
Ok(())
|
||||
}
|
||||
@@ -208,7 +208,7 @@ impl AccountProvider {
|
||||
/// Checks if given account is unlocked
|
||||
pub fn is_unlocked<A>(&self, account: A) -> bool where Address: From<A> {
|
||||
let account = Address::from(account).into();
|
||||
let unlocked = self.unlocked.read().unwrap();
|
||||
let unlocked = self.unlocked.unwrapped_read();
|
||||
unlocked.get(&account).is_some()
|
||||
}
|
||||
|
||||
@@ -218,12 +218,12 @@ impl AccountProvider {
|
||||
let message = Message::from(message).into();
|
||||
|
||||
let data = {
|
||||
let unlocked = self.unlocked.read().unwrap();
|
||||
let unlocked = self.unlocked.unwrapped_read();
|
||||
try!(unlocked.get(&account).ok_or(Error::NotUnlocked)).clone()
|
||||
};
|
||||
|
||||
if let Unlock::Temp = data.unlock {
|
||||
let mut unlocked = self.unlocked.write().unwrap();
|
||||
let mut unlocked = self.unlocked.unwrapped_write();
|
||||
unlocked.remove(&account).expect("data exists: so key must exist: qed");
|
||||
}
|
||||
|
||||
|
||||
@@ -285,7 +285,7 @@ impl BlockQueue {
|
||||
unverified.clear();
|
||||
verifying.clear();
|
||||
verified.clear();
|
||||
self.processing.write().unwrap().clear();
|
||||
self.processing.unwrapped_write().clear();
|
||||
}
|
||||
|
||||
/// Wait for unverified queue to be empty
|
||||
@@ -298,7 +298,7 @@ impl BlockQueue {
|
||||
|
||||
/// Check if the block is currently in the queue
|
||||
pub fn block_status(&self, hash: &H256) -> BlockStatus {
|
||||
if self.processing.read().unwrap().contains(&hash) {
|
||||
if self.processing.unwrapped_read().contains(&hash) {
|
||||
return BlockStatus::Queued;
|
||||
}
|
||||
if self.verification.bad.locked().contains(&hash) {
|
||||
@@ -312,7 +312,7 @@ impl BlockQueue {
|
||||
let header = BlockView::new(&bytes).header();
|
||||
let h = header.hash();
|
||||
{
|
||||
if self.processing.read().unwrap().contains(&h) {
|
||||
if self.processing.unwrapped_read().contains(&h) {
|
||||
return Err(ImportError::AlreadyQueued.into());
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ impl BlockQueue {
|
||||
|
||||
match verify_block_basic(&header, &bytes, self.engine.deref().deref()) {
|
||||
Ok(()) => {
|
||||
self.processing.write().unwrap().insert(h.clone());
|
||||
self.processing.unwrapped_write().insert(h.clone());
|
||||
self.verification.unverified.locked().push_back(UnverifiedBlock { header: header, bytes: bytes });
|
||||
self.more_to_verify.notify_all();
|
||||
Ok(h)
|
||||
@@ -350,7 +350,7 @@ impl BlockQueue {
|
||||
let mut verified_lock = self.verification.verified.locked();
|
||||
let mut verified = verified_lock.deref_mut();
|
||||
let mut bad = self.verification.bad.locked();
|
||||
let mut processing = self.processing.write().unwrap();
|
||||
let mut processing = self.processing.unwrapped_write();
|
||||
bad.reserve(block_hashes.len());
|
||||
for hash in block_hashes {
|
||||
bad.insert(hash.clone());
|
||||
@@ -374,7 +374,7 @@ impl BlockQueue {
|
||||
if block_hashes.is_empty() {
|
||||
return;
|
||||
}
|
||||
let mut processing = self.processing.write().unwrap();
|
||||
let mut processing = self.processing.unwrapped_write();
|
||||
for hash in block_hashes {
|
||||
processing.remove(&hash);
|
||||
}
|
||||
@@ -421,7 +421,7 @@ impl BlockQueue {
|
||||
+ verifying_bytes
|
||||
+ verified_bytes
|
||||
// TODO: https://github.com/servo/heapsize/pull/50
|
||||
//+ self.processing.read().unwrap().heap_size_of_children(),
|
||||
//+ self.processing.unwrapped_read().heap_size_of_children(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -432,7 +432,7 @@ impl BlockQueue {
|
||||
self.verification.verifying.locked().shrink_to_fit();
|
||||
self.verification.verified.locked().shrink_to_fit();
|
||||
}
|
||||
self.processing.write().unwrap().shrink_to_fit();
|
||||
self.processing.unwrapped_write().shrink_to_fit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ impl BlockProvider for BlockChain {
|
||||
/// Get raw block data
|
||||
fn block(&self, hash: &H256) -> Option<Bytes> {
|
||||
{
|
||||
let read = self.blocks.read().unwrap();
|
||||
let read = self.blocks.unwrapped_read();
|
||||
if let Some(v) = read.get(hash) {
|
||||
return Some(v.clone());
|
||||
}
|
||||
@@ -184,7 +184,7 @@ impl BlockProvider for BlockChain {
|
||||
match opt {
|
||||
Some(b) => {
|
||||
let bytes: Bytes = b.to_vec();
|
||||
let mut write = self.blocks.write().unwrap();
|
||||
let mut write = self.blocks.unwrapped_write();
|
||||
write.insert(hash.clone(), bytes.clone());
|
||||
Some(bytes)
|
||||
},
|
||||
@@ -338,7 +338,7 @@ impl BlockChain {
|
||||
};
|
||||
|
||||
{
|
||||
let mut best_block = bc.best_block.write().unwrap();
|
||||
let mut best_block = bc.best_block.unwrapped_write();
|
||||
best_block.number = bc.block_number(&best_block_hash).unwrap();
|
||||
best_block.total_difficulty = bc.block_details(&best_block_hash).unwrap().total_difficulty;
|
||||
best_block.hash = best_block_hash;
|
||||
@@ -483,25 +483,25 @@ impl BlockChain {
|
||||
self.note_used(CacheID::BlockDetails(hash));
|
||||
}
|
||||
|
||||
let mut write_details = self.block_details.write().unwrap();
|
||||
let mut write_details = self.block_details.unwrapped_write();
|
||||
batch.extend_with_cache(write_details.deref_mut(), update.block_details, CacheUpdatePolicy::Overwrite);
|
||||
}
|
||||
|
||||
{
|
||||
let mut write_receipts = self.block_receipts.write().unwrap();
|
||||
let mut write_receipts = self.block_receipts.unwrapped_write();
|
||||
batch.extend_with_cache(write_receipts.deref_mut(), update.block_receipts, CacheUpdatePolicy::Remove);
|
||||
}
|
||||
|
||||
{
|
||||
let mut write_blocks_blooms = self.blocks_blooms.write().unwrap();
|
||||
let mut write_blocks_blooms = self.blocks_blooms.unwrapped_write();
|
||||
batch.extend_with_cache(write_blocks_blooms.deref_mut(), update.blocks_blooms, CacheUpdatePolicy::Remove);
|
||||
}
|
||||
|
||||
// These cached values must be updated last and togeterh
|
||||
{
|
||||
let mut best_block = self.best_block.write().unwrap();
|
||||
let mut write_hashes = self.block_hashes.write().unwrap();
|
||||
let mut write_txs = self.transaction_addresses.write().unwrap();
|
||||
let mut best_block = self.best_block.unwrapped_write();
|
||||
let mut write_hashes = self.block_hashes.unwrapped_write();
|
||||
let mut write_txs = self.transaction_addresses.unwrapped_write();
|
||||
|
||||
// update best block
|
||||
match update.info.location {
|
||||
@@ -728,33 +728,33 @@ impl BlockChain {
|
||||
|
||||
/// Get best block hash.
|
||||
pub fn best_block_hash(&self) -> H256 {
|
||||
self.best_block.read().unwrap().hash.clone()
|
||||
self.best_block.unwrapped_read().hash.clone()
|
||||
}
|
||||
|
||||
/// Get best block number.
|
||||
pub fn best_block_number(&self) -> BlockNumber {
|
||||
self.best_block.read().unwrap().number
|
||||
self.best_block.unwrapped_read().number
|
||||
}
|
||||
|
||||
/// Get best block total difficulty.
|
||||
pub fn best_block_total_difficulty(&self) -> U256 {
|
||||
self.best_block.read().unwrap().total_difficulty
|
||||
self.best_block.unwrapped_read().total_difficulty
|
||||
}
|
||||
|
||||
/// Get current cache size.
|
||||
pub fn cache_size(&self) -> CacheSize {
|
||||
CacheSize {
|
||||
blocks: self.blocks.read().unwrap().heap_size_of_children(),
|
||||
block_details: self.block_details.read().unwrap().heap_size_of_children(),
|
||||
transaction_addresses: self.transaction_addresses.read().unwrap().heap_size_of_children(),
|
||||
blocks_blooms: self.blocks_blooms.read().unwrap().heap_size_of_children(),
|
||||
block_receipts: self.block_receipts.read().unwrap().heap_size_of_children(),
|
||||
blocks: self.blocks.unwrapped_read().heap_size_of_children(),
|
||||
block_details: self.block_details.unwrapped_read().heap_size_of_children(),
|
||||
transaction_addresses: self.transaction_addresses.unwrapped_read().heap_size_of_children(),
|
||||
blocks_blooms: self.blocks_blooms.unwrapped_read().heap_size_of_children(),
|
||||
block_receipts: self.block_receipts.unwrapped_read().heap_size_of_children(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Let the cache system know that a cacheable item has been used.
|
||||
fn note_used(&self, id: CacheID) {
|
||||
let mut cache_man = self.cache_man.write().unwrap();
|
||||
let mut cache_man = self.cache_man.unwrapped_write();
|
||||
if !cache_man.cache_usage[0].contains(&id) {
|
||||
cache_man.cache_usage[0].insert(id.clone());
|
||||
if cache_man.in_use.contains(&id) {
|
||||
@@ -773,13 +773,13 @@ impl BlockChain {
|
||||
|
||||
for _ in 0..COLLECTION_QUEUE_SIZE {
|
||||
{
|
||||
let mut blocks = self.blocks.write().unwrap();
|
||||
let mut block_details = self.block_details.write().unwrap();
|
||||
let mut block_hashes = self.block_hashes.write().unwrap();
|
||||
let mut transaction_addresses = self.transaction_addresses.write().unwrap();
|
||||
let mut blocks_blooms = self.blocks_blooms.write().unwrap();
|
||||
let mut block_receipts = self.block_receipts.write().unwrap();
|
||||
let mut cache_man = self.cache_man.write().unwrap();
|
||||
let mut blocks = self.blocks.unwrapped_write();
|
||||
let mut block_details = self.block_details.unwrapped_write();
|
||||
let mut block_hashes = self.block_hashes.unwrapped_write();
|
||||
let mut transaction_addresses = self.transaction_addresses.unwrapped_write();
|
||||
let mut blocks_blooms = self.blocks_blooms.unwrapped_write();
|
||||
let mut block_receipts = self.block_receipts.unwrapped_write();
|
||||
let mut cache_man = self.cache_man.unwrapped_write();
|
||||
|
||||
for id in cache_man.cache_usage.pop_back().unwrap().into_iter() {
|
||||
cache_man.in_use.remove(&id);
|
||||
|
||||
@@ -334,7 +334,7 @@ impl Client {
|
||||
let route = self.commit_block(closed_block, &header.hash(), &block.bytes);
|
||||
import_results.push(route);
|
||||
|
||||
self.report.write().unwrap().accrue_block(&block);
|
||||
self.report.unwrapped_write().accrue_block(&block);
|
||||
trace!(target: "client", "Imported #{} ({})", header.number(), header.hash());
|
||||
}
|
||||
|
||||
@@ -462,7 +462,7 @@ impl Client {
|
||||
|
||||
/// Get the report.
|
||||
pub fn report(&self) -> ClientReport {
|
||||
let mut report = self.report.read().unwrap().clone();
|
||||
let mut report = self.report.unwrapped_read().clone();
|
||||
report.state_db_mem = self.state_db.locked().mem_used();
|
||||
report
|
||||
}
|
||||
|
||||
@@ -108,38 +108,38 @@ impl TestBlockChainClient {
|
||||
miner: Arc::new(Miner::with_spec(Spec::new_test())),
|
||||
};
|
||||
client.add_blocks(1, EachBlockWith::Nothing); // add genesis block
|
||||
client.genesis_hash = client.last_hash.read().unwrap().clone();
|
||||
client.genesis_hash = client.last_hash.unwrapped_read().clone();
|
||||
client
|
||||
}
|
||||
|
||||
/// Set the transaction receipt result
|
||||
pub fn set_transaction_receipt(&self, id: TransactionID, receipt: LocalizedReceipt) {
|
||||
self.receipts.write().unwrap().insert(id, receipt);
|
||||
self.receipts.unwrapped_write().insert(id, receipt);
|
||||
}
|
||||
|
||||
/// Set the execution result.
|
||||
pub fn set_execution_result(&self, result: Executed) {
|
||||
*self.execution_result.write().unwrap() = Some(result);
|
||||
*self.execution_result.unwrapped_write() = Some(result);
|
||||
}
|
||||
|
||||
/// Set the balance of account `address` to `balance`.
|
||||
pub fn set_balance(&self, address: Address, balance: U256) {
|
||||
self.balances.write().unwrap().insert(address, balance);
|
||||
self.balances.unwrapped_write().insert(address, balance);
|
||||
}
|
||||
|
||||
/// Set nonce of account `address` to `nonce`.
|
||||
pub fn set_nonce(&self, address: Address, nonce: U256) {
|
||||
self.nonces.write().unwrap().insert(address, nonce);
|
||||
self.nonces.unwrapped_write().insert(address, nonce);
|
||||
}
|
||||
|
||||
/// Set `code` at `address`.
|
||||
pub fn set_code(&self, address: Address, code: Bytes) {
|
||||
self.code.write().unwrap().insert(address, code);
|
||||
self.code.unwrapped_write().insert(address, code);
|
||||
}
|
||||
|
||||
/// Set storage `position` to `value` for account `address`.
|
||||
pub fn set_storage(&self, address: Address, position: H256, value: H256) {
|
||||
self.storage.write().unwrap().insert((address, position), value);
|
||||
self.storage.unwrapped_write().insert((address, position), value);
|
||||
}
|
||||
|
||||
/// Set block queue size for testing
|
||||
@@ -149,11 +149,11 @@ impl TestBlockChainClient {
|
||||
|
||||
/// Add blocks to test client.
|
||||
pub fn add_blocks(&self, count: usize, with: EachBlockWith) {
|
||||
let len = self.numbers.read().unwrap().len();
|
||||
let len = self.numbers.unwrapped_read().len();
|
||||
for n in len..(len + count) {
|
||||
let mut header = BlockHeader::new();
|
||||
header.difficulty = From::from(n);
|
||||
header.parent_hash = self.last_hash.read().unwrap().clone();
|
||||
header.parent_hash = self.last_hash.unwrapped_read().clone();
|
||||
header.number = n as BlockNumber;
|
||||
header.gas_limit = U256::from(1_000_000);
|
||||
let uncles = match with {
|
||||
@@ -161,7 +161,7 @@ impl TestBlockChainClient {
|
||||
let mut uncles = RlpStream::new_list(1);
|
||||
let mut uncle_header = BlockHeader::new();
|
||||
uncle_header.difficulty = From::from(n);
|
||||
uncle_header.parent_hash = self.last_hash.read().unwrap().clone();
|
||||
uncle_header.parent_hash = self.last_hash.unwrapped_read().clone();
|
||||
uncle_header.number = n as BlockNumber;
|
||||
uncles.append(&uncle_header);
|
||||
header.uncles_hash = uncles.as_raw().sha3();
|
||||
@@ -174,7 +174,7 @@ impl TestBlockChainClient {
|
||||
let mut txs = RlpStream::new_list(1);
|
||||
let keypair = KeyPair::create().unwrap();
|
||||
// Update nonces value
|
||||
self.nonces.write().unwrap().insert(keypair.address(), U256::one());
|
||||
self.nonces.unwrapped_write().insert(keypair.address(), U256::one());
|
||||
let tx = Transaction {
|
||||
action: Action::Create,
|
||||
value: U256::from(100),
|
||||
@@ -207,7 +207,7 @@ impl TestBlockChainClient {
|
||||
rlp.append(&header);
|
||||
rlp.append_raw(&rlp::NULL_RLP, 1);
|
||||
rlp.append_raw(&rlp::NULL_RLP, 1);
|
||||
self.blocks.write().unwrap().insert(hash, rlp.out());
|
||||
self.blocks.unwrapped_write().insert(hash, rlp.out());
|
||||
}
|
||||
|
||||
/// Make a bad block by setting invalid parent hash.
|
||||
@@ -219,12 +219,12 @@ impl TestBlockChainClient {
|
||||
rlp.append(&header);
|
||||
rlp.append_raw(&rlp::NULL_RLP, 1);
|
||||
rlp.append_raw(&rlp::NULL_RLP, 1);
|
||||
self.blocks.write().unwrap().insert(hash, rlp.out());
|
||||
self.blocks.unwrapped_write().insert(hash, rlp.out());
|
||||
}
|
||||
|
||||
/// TODO:
|
||||
pub fn block_hash_delta_minus(&mut self, delta: usize) -> H256 {
|
||||
let blocks_read = self.numbers.read().unwrap();
|
||||
let blocks_read = self.numbers.unwrapped_read();
|
||||
let index = blocks_read.len() - delta;
|
||||
blocks_read[&index].clone()
|
||||
}
|
||||
@@ -232,9 +232,9 @@ impl TestBlockChainClient {
|
||||
fn block_hash(&self, id: BlockID) -> Option<H256> {
|
||||
match id {
|
||||
BlockID::Hash(hash) => Some(hash),
|
||||
BlockID::Number(n) => self.numbers.read().unwrap().get(&(n as usize)).cloned(),
|
||||
BlockID::Earliest => self.numbers.read().unwrap().get(&0).cloned(),
|
||||
BlockID::Latest => self.numbers.read().unwrap().get(&(self.numbers.read().unwrap().len() - 1)).cloned()
|
||||
BlockID::Number(n) => self.numbers.unwrapped_read().get(&(n as usize)).cloned(),
|
||||
BlockID::Earliest => self.numbers.unwrapped_read().get(&0).cloned(),
|
||||
BlockID::Latest => self.numbers.unwrapped_read().get(&(self.numbers.unwrapped_read().len() - 1)).cloned()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -255,7 +255,7 @@ impl MiningBlockChainClient for TestBlockChainClient {
|
||||
|
||||
impl BlockChainClient for TestBlockChainClient {
|
||||
fn call(&self, _t: &SignedTransaction, _analytics: CallAnalytics) -> Result<Executed, ExecutionError> {
|
||||
Ok(self.execution_result.read().unwrap().clone().unwrap())
|
||||
Ok(self.execution_result.unwrapped_read().clone().unwrap())
|
||||
}
|
||||
|
||||
fn block_total_difficulty(&self, _id: BlockID) -> Option<U256> {
|
||||
@@ -268,7 +268,7 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
|
||||
fn nonce(&self, address: &Address, id: BlockID) -> Option<U256> {
|
||||
match id {
|
||||
BlockID::Latest => Some(self.nonces.read().unwrap().get(address).cloned().unwrap_or_else(U256::zero)),
|
||||
BlockID::Latest => Some(self.nonces.unwrapped_read().get(address).cloned().unwrap_or_else(U256::zero)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -278,12 +278,12 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
}
|
||||
|
||||
fn code(&self, address: &Address) -> Option<Bytes> {
|
||||
self.code.read().unwrap().get(address).cloned()
|
||||
self.code.unwrapped_read().get(address).cloned()
|
||||
}
|
||||
|
||||
fn balance(&self, address: &Address, id: BlockID) -> Option<U256> {
|
||||
if let BlockID::Latest = id {
|
||||
Some(self.balances.read().unwrap().get(address).cloned().unwrap_or_else(U256::zero))
|
||||
Some(self.balances.unwrapped_read().get(address).cloned().unwrap_or_else(U256::zero))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -295,7 +295,7 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
|
||||
fn storage_at(&self, address: &Address, position: &H256, id: BlockID) -> Option<H256> {
|
||||
if let BlockID::Latest = id {
|
||||
Some(self.storage.read().unwrap().get(&(address.clone(), position.clone())).cloned().unwrap_or_else(H256::new))
|
||||
Some(self.storage.unwrapped_read().get(&(address.clone(), position.clone())).cloned().unwrap_or_else(H256::new))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -310,7 +310,7 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
}
|
||||
|
||||
fn transaction_receipt(&self, id: TransactionID) -> Option<LocalizedReceipt> {
|
||||
self.receipts.read().unwrap().get(&id).cloned()
|
||||
self.receipts.unwrapped_read().get(&id).cloned()
|
||||
}
|
||||
|
||||
fn blocks_with_bloom(&self, _bloom: &H2048, _from_block: BlockID, _to_block: BlockID) -> Option<Vec<BlockNumber>> {
|
||||
@@ -326,11 +326,11 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
}
|
||||
|
||||
fn block_header(&self, id: BlockID) -> Option<Bytes> {
|
||||
self.block_hash(id).and_then(|hash| self.blocks.read().unwrap().get(&hash).map(|r| Rlp::new(r).at(0).as_raw().to_vec()))
|
||||
self.block_hash(id).and_then(|hash| self.blocks.unwrapped_read().get(&hash).map(|r| Rlp::new(r).at(0).as_raw().to_vec()))
|
||||
}
|
||||
|
||||
fn block_body(&self, id: BlockID) -> Option<Bytes> {
|
||||
self.block_hash(id).and_then(|hash| self.blocks.read().unwrap().get(&hash).map(|r| {
|
||||
self.block_hash(id).and_then(|hash| self.blocks.unwrapped_read().get(&hash).map(|r| {
|
||||
let mut stream = RlpStream::new_list(2);
|
||||
stream.append_raw(Rlp::new(&r).at(1).as_raw(), 1);
|
||||
stream.append_raw(Rlp::new(&r).at(2).as_raw(), 1);
|
||||
@@ -339,13 +339,13 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
}
|
||||
|
||||
fn block(&self, id: BlockID) -> Option<Bytes> {
|
||||
self.block_hash(id).and_then(|hash| self.blocks.read().unwrap().get(&hash).cloned())
|
||||
self.block_hash(id).and_then(|hash| self.blocks.unwrapped_read().get(&hash).cloned())
|
||||
}
|
||||
|
||||
fn block_status(&self, id: BlockID) -> BlockStatus {
|
||||
match id {
|
||||
BlockID::Number(number) if (number as usize) < self.blocks.read().unwrap().len() => BlockStatus::InChain,
|
||||
BlockID::Hash(ref hash) if self.blocks.read().unwrap().get(hash).is_some() => BlockStatus::InChain,
|
||||
BlockID::Number(number) if (number as usize) < self.blocks.unwrapped_read().len() => BlockStatus::InChain,
|
||||
BlockID::Hash(ref hash) if self.blocks.unwrapped_read().get(hash).is_some() => BlockStatus::InChain,
|
||||
_ => BlockStatus::Unknown
|
||||
}
|
||||
}
|
||||
@@ -356,7 +356,7 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
ancestor: H256::new(),
|
||||
index: 0,
|
||||
blocks: {
|
||||
let numbers_read = self.numbers.read().unwrap();
|
||||
let numbers_read = self.numbers.unwrapped_read();
|
||||
let mut adding = false;
|
||||
|
||||
let mut blocks = Vec::new();
|
||||
@@ -413,11 +413,11 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
let header = Rlp::new(&b).val_at::<BlockHeader>(0);
|
||||
let h = header.hash();
|
||||
let number: usize = header.number as usize;
|
||||
if number > self.blocks.read().unwrap().len() {
|
||||
panic!("Unexpected block number. Expected {}, got {}", self.blocks.read().unwrap().len(), number);
|
||||
if number > self.blocks.unwrapped_read().len() {
|
||||
panic!("Unexpected block number. Expected {}, got {}", self.blocks.unwrapped_read().len(), number);
|
||||
}
|
||||
if number > 0 {
|
||||
match self.blocks.read().unwrap().get(&header.parent_hash) {
|
||||
match self.blocks.unwrapped_read().get(&header.parent_hash) {
|
||||
Some(parent) => {
|
||||
let parent = Rlp::new(parent).val_at::<BlockHeader>(0);
|
||||
if parent.number != (header.number - 1) {
|
||||
@@ -429,27 +429,27 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
}
|
||||
}
|
||||
}
|
||||
let len = self.numbers.read().unwrap().len();
|
||||
let len = self.numbers.unwrapped_read().len();
|
||||
if number == len {
|
||||
{
|
||||
let mut difficulty = self.difficulty.write().unwrap();
|
||||
let mut difficulty = self.difficulty.unwrapped_write();
|
||||
*difficulty.deref_mut() = *difficulty.deref() + header.difficulty;
|
||||
}
|
||||
mem::replace(self.last_hash.write().unwrap().deref_mut(), h.clone());
|
||||
self.blocks.write().unwrap().insert(h.clone(), b);
|
||||
self.numbers.write().unwrap().insert(number, h.clone());
|
||||
mem::replace(self.last_hash.unwrapped_write().deref_mut(), h.clone());
|
||||
self.blocks.unwrapped_write().insert(h.clone(), b);
|
||||
self.numbers.unwrapped_write().insert(number, h.clone());
|
||||
let mut parent_hash = header.parent_hash;
|
||||
if number > 0 {
|
||||
let mut n = number - 1;
|
||||
while n > 0 && self.numbers.read().unwrap()[&n] != parent_hash {
|
||||
*self.numbers.write().unwrap().get_mut(&n).unwrap() = parent_hash.clone();
|
||||
while n > 0 && self.numbers.unwrapped_read()[&n] != parent_hash {
|
||||
*self.numbers.unwrapped_write().get_mut(&n).unwrap() = parent_hash.clone();
|
||||
n -= 1;
|
||||
parent_hash = Rlp::new(&self.blocks.read().unwrap()[&parent_hash]).val_at::<BlockHeader>(0).parent_hash;
|
||||
parent_hash = Rlp::new(&self.blocks.unwrapped_read()[&parent_hash]).val_at::<BlockHeader>(0).parent_hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
self.blocks.write().unwrap().insert(h.clone(), b.to_vec());
|
||||
self.blocks.unwrapped_write().insert(h.clone(), b.to_vec());
|
||||
}
|
||||
Ok(h)
|
||||
}
|
||||
@@ -470,11 +470,11 @@ impl BlockChainClient for TestBlockChainClient {
|
||||
|
||||
fn chain_info(&self) -> BlockChainInfo {
|
||||
BlockChainInfo {
|
||||
total_difficulty: *self.difficulty.read().unwrap(),
|
||||
pending_total_difficulty: *self.difficulty.read().unwrap(),
|
||||
total_difficulty: *self.difficulty.unwrapped_read(),
|
||||
pending_total_difficulty: *self.difficulty.unwrapped_read(),
|
||||
genesis_hash: self.genesis_hash.clone(),
|
||||
best_block_hash: self.last_hash.read().unwrap().clone(),
|
||||
best_block_number: self.blocks.read().unwrap().len() as BlockNumber - 1,
|
||||
best_block_hash: self.last_hash.unwrapped_read().clone(),
|
||||
best_block_number: self.blocks.unwrapped_read().len() as BlockNumber - 1,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ use std::ops::Deref;
|
||||
use std::hash::Hash;
|
||||
use std::sync::RwLock;
|
||||
use std::collections::HashMap;
|
||||
use util::{DBTransaction, Database};
|
||||
use util::{DBTransaction, Database, RwLockable};
|
||||
use util::rlp::{encode, Encodable, decode, Decodable};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -115,14 +115,14 @@ pub trait Readable {
|
||||
T: Clone + Decodable,
|
||||
C: Cache<K, T> {
|
||||
{
|
||||
let read = cache.read().unwrap();
|
||||
let read = cache.unwrapped_read();
|
||||
if let Some(v) = read.get(key) {
|
||||
return Some(v.clone());
|
||||
}
|
||||
}
|
||||
|
||||
self.read(key).map(|value: T|{
|
||||
let mut write = cache.write().unwrap();
|
||||
let mut write = cache.unwrapped_write();
|
||||
write.insert(key.clone(), value.clone());
|
||||
value
|
||||
})
|
||||
@@ -137,7 +137,7 @@ pub trait Readable {
|
||||
R: Deref<Target = [u8]>,
|
||||
C: Cache<K, T> {
|
||||
{
|
||||
let read = cache.read().unwrap();
|
||||
let read = cache.unwrapped_read();
|
||||
if read.get(key).is_some() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use util::numbers::U256;
|
||||
use util::hash::H256;
|
||||
use util::{RwLockable, U256, H256};
|
||||
|
||||
/// External miner interface.
|
||||
pub trait ExternalMinerService: Send + Sync {
|
||||
@@ -55,15 +54,15 @@ impl ExternalMiner {
|
||||
|
||||
impl ExternalMinerService for ExternalMiner {
|
||||
fn submit_hashrate(&self, hashrate: U256, id: H256) {
|
||||
self.hashrates.write().unwrap().insert(id, hashrate);
|
||||
self.hashrates.unwrapped_write().insert(id, hashrate);
|
||||
}
|
||||
|
||||
fn hashrate(&self) -> U256 {
|
||||
self.hashrates.read().unwrap().iter().fold(U256::from(0), |sum, (_, v)| sum + *v)
|
||||
self.hashrates.unwrapped_read().iter().fold(U256::from(0), |sum, (_, v)| sum + *v)
|
||||
}
|
||||
|
||||
fn is_mining(&self) -> bool {
|
||||
!self.hashrates.read().unwrap().is_empty()
|
||||
!self.hashrates.unwrapped_read().is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -425,20 +425,20 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn set_author(&self, author: Address) {
|
||||
*self.author.write().unwrap() = author;
|
||||
*self.author.unwrapped_write() = author;
|
||||
}
|
||||
|
||||
fn set_extra_data(&self, extra_data: Bytes) {
|
||||
*self.extra_data.write().unwrap() = extra_data;
|
||||
*self.extra_data.unwrapped_write() = extra_data;
|
||||
}
|
||||
|
||||
/// Set the gas limit we wish to target when sealing a new block.
|
||||
fn set_gas_floor_target(&self, target: U256) {
|
||||
self.gas_range_target.write().unwrap().0 = target;
|
||||
self.gas_range_target.unwrapped_write().0 = target;
|
||||
}
|
||||
|
||||
fn set_gas_ceil_target(&self, target: U256) {
|
||||
self.gas_range_target.write().unwrap().1 = target;
|
||||
self.gas_range_target.unwrapped_write().1 = target;
|
||||
}
|
||||
|
||||
fn set_minimal_gas_price(&self, min_gas_price: U256) {
|
||||
@@ -455,7 +455,7 @@ impl MinerService for Miner {
|
||||
}
|
||||
|
||||
fn sensible_gas_limit(&self) -> U256 {
|
||||
self.gas_range_target.read().unwrap().0 / 5.into()
|
||||
self.gas_range_target.unwrapped_read().0 / 5.into()
|
||||
}
|
||||
|
||||
fn transactions_limit(&self) -> usize {
|
||||
@@ -472,22 +472,22 @@ impl MinerService for Miner {
|
||||
|
||||
/// Get the author that we will seal blocks as.
|
||||
fn author(&self) -> Address {
|
||||
*self.author.read().unwrap()
|
||||
*self.author.unwrapped_read()
|
||||
}
|
||||
|
||||
/// Get the extra_data that we will seal blocks with.
|
||||
fn extra_data(&self) -> Bytes {
|
||||
self.extra_data.read().unwrap().clone()
|
||||
self.extra_data.unwrapped_read().clone()
|
||||
}
|
||||
|
||||
/// Get the gas limit we wish to target when sealing a new block.
|
||||
fn gas_floor_target(&self) -> U256 {
|
||||
self.gas_range_target.read().unwrap().0
|
||||
self.gas_range_target.unwrapped_read().0
|
||||
}
|
||||
|
||||
/// Get the gas limit we wish to target when sealing a new block.
|
||||
fn gas_ceil_target(&self) -> U256 {
|
||||
self.gas_range_target.read().unwrap().1
|
||||
self.gas_range_target.unwrapped_read().1
|
||||
}
|
||||
|
||||
fn import_external_transactions(&self, chain: &MiningBlockChainClient, transactions: Vec<SignedTransaction>) ->
|
||||
|
||||
@@ -136,10 +136,10 @@ impl Spec {
|
||||
|
||||
/// Return the state root for the genesis state, memoising accordingly.
|
||||
pub fn state_root(&self) -> H256 {
|
||||
if self.state_root_memo.read().unwrap().is_none() {
|
||||
*self.state_root_memo.write().unwrap() = Some(self.genesis_state.root());
|
||||
if self.state_root_memo.unwrapped_read().is_none() {
|
||||
*self.state_root_memo.unwrapped_write() = Some(self.genesis_state.root());
|
||||
}
|
||||
self.state_root_memo.read().unwrap().as_ref().unwrap().clone()
|
||||
self.state_root_memo.unwrapped_read().as_ref().unwrap().clone()
|
||||
}
|
||||
|
||||
/// Get the known knodes of the network in enode format.
|
||||
@@ -209,12 +209,12 @@ impl Spec {
|
||||
/// Alter the value of the genesis state.
|
||||
pub fn set_genesis_state(&mut self, s: PodState) {
|
||||
self.genesis_state = s;
|
||||
*self.state_root_memo.write().unwrap() = None;
|
||||
*self.state_root_memo.unwrapped_write() = None;
|
||||
}
|
||||
|
||||
/// Returns `false` if the memoized state root is invalid. `true` otherwise.
|
||||
pub fn is_state_root_valid(&self) -> bool {
|
||||
self.state_root_memo.read().unwrap().clone().map_or(true, |sr| sr == self.genesis_state.root())
|
||||
self.state_root_memo.unwrapped_read().clone().map_or(true, |sr| sr == self.genesis_state.root())
|
||||
}
|
||||
|
||||
/// Ensure that the given state DB has the trie nodes in for the genesis state.
|
||||
|
||||
@@ -22,10 +22,9 @@ use std::sync::{RwLock, Arc};
|
||||
use std::path::Path;
|
||||
use bloomchain::{Number, Config as BloomConfig};
|
||||
use bloomchain::group::{BloomGroupDatabase, BloomGroupChain, GroupPosition, BloomGroup};
|
||||
use util::{H256, H264, Database, DatabaseConfig, DBTransaction};
|
||||
use util::{H256, H264, Database, DatabaseConfig, DBTransaction, RwLockable};
|
||||
use header::BlockNumber;
|
||||
use trace::{BlockTraces, LocalizedTrace, Config, Switch, Filter, Database as TraceDatabase, ImportRequest,
|
||||
DatabaseExtras, Error};
|
||||
use trace::{BlockTraces, LocalizedTrace, Config, Switch, Filter, Database as TraceDatabase, ImportRequest, DatabaseExtras, Error};
|
||||
use db::{Key, Writable, Readable, CacheUpdatePolicy};
|
||||
use blooms;
|
||||
use super::flat::{FlatTrace, FlatBlockTraces, FlatTransactionTraces};
|
||||
@@ -232,7 +231,7 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
|
||||
|
||||
// at first, let's insert new block traces
|
||||
{
|
||||
let mut traces = self.traces.write().unwrap();
|
||||
let mut traces = self.traces.unwrapped_write();
|
||||
// it's important to use overwrite here,
|
||||
// cause this value might be queried by hash later
|
||||
batch.write_with_cache(traces.deref_mut(), request.block_hash, request.traces, CacheUpdatePolicy::Overwrite);
|
||||
@@ -260,7 +259,7 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
|
||||
.map(|p| (From::from(p.0), From::from(p.1)))
|
||||
.collect::<HashMap<TraceGroupPosition, blooms::BloomGroup>>();
|
||||
|
||||
let mut blooms = self.blooms.write().unwrap();
|
||||
let mut blooms = self.blooms.unwrapped_write();
|
||||
batch.extend_with_cache(blooms.deref_mut(), blooms_to_insert, CacheUpdatePolicy::Remove);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user