Merge branch 'master' into kvdb_split

This commit is contained in:
debris 2017-10-15 16:40:20 +02:00
commit db3ff67182
18 changed files with 34 additions and 34 deletions

View File

@ -64,7 +64,7 @@ impl AddressBook {
/// Sets new name for given address.
pub fn set_name(&mut self, a: Address, name: String) {
{
let mut x = self.cache.entry(a)
let x = self.cache.entry(a)
.or_insert_with(|| AccountMeta {name: Default::default(), meta: "{}".to_owned(), uuid: None});
x.name = name;
}
@ -74,7 +74,7 @@ impl AddressBook {
/// Sets new meta for given address.
pub fn set_meta(&mut self, a: Address, meta: String) {
{
let mut x = self.cache.entry(a)
let x = self.cache.entry(a)
.or_insert_with(|| AccountMeta {name: "Anonymous".to_owned(), meta: Default::default(), uuid: None});
x.meta = meta;
}
@ -253,7 +253,7 @@ impl DappsSettingsStore {
/// Marks recent dapp as used
pub fn mark_dapp_used(&mut self, dapp: DappId) {
{
let mut entry = self.history.entry(dapp).or_insert_with(|| Default::default());
let entry = self.history.entry(dapp).or_insert_with(|| Default::default());
entry.last_accessed = self.time.get();
}
// Clear extraneous entries
@ -280,7 +280,7 @@ impl DappsSettingsStore {
/// Sets accounts for specific dapp.
pub fn set_accounts(&mut self, id: DappId, accounts: Option<Vec<Address>>) {
{
let mut settings = self.settings.entry(id).or_insert_with(DappsSettings::default);
let settings = self.settings.entry(id).or_insert_with(DappsSettings::default);
settings.accounts = accounts;
}
self.settings.save(JsonSettings::write);
@ -289,7 +289,7 @@ impl DappsSettingsStore {
/// Sets a default account for specific dapp.
pub fn set_default(&mut self, id: DappId, default: Address) {
{
let mut settings = self.settings.entry(id).or_insert_with(DappsSettings::default);
let settings = self.settings.entry(id).or_insert_with(DappsSettings::default);
settings.default = Some(default);
}
self.settings.save(JsonSettings::write);

View File

@ -421,7 +421,7 @@ pub mod common {
.and_then(|_| fields.state.commit());
let block_author = fields.header.author().clone();
fields.traces.as_mut().map(move |mut traces| {
fields.traces.as_mut().map(move |traces| {
let mut tracer = ExecutiveTracer::default();
tracer.trace_reward(block_author, reward, RewardType::Block);
traces.push(tracer.drain())

View File

@ -433,7 +433,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
// trace only top level calls to builtins to avoid DDoS attacks
if self.depth == 0 {
let mut trace_output = tracer.prepare_trace_output();
if let Some(mut out) = trace_output.as_mut() {
if let Some(out) = trace_output.as_mut() {
*out = output.to_owned();
}

View File

@ -149,7 +149,7 @@ impl BanningTransactionQueue {
/// queue.
fn ban_sender(&mut self, address: Address) -> bool {
let count = {
let mut count = self.senders_bans.entry(address).or_insert_with(|| 0);
let count = self.senders_bans.entry(address).or_insert_with(|| 0);
*count = count.saturating_add(1);
*count
};
@ -169,7 +169,7 @@ impl BanningTransactionQueue {
/// Returns true if bans threshold has been reached.
fn ban_recipient(&mut self, address: Address) -> bool {
let count = {
let mut count = self.recipients_bans.entry(address).or_insert_with(|| 0);
let count = self.recipients_bans.entry(address).or_insert_with(|| 0);
*count = count.saturating_add(1);
*count
};
@ -185,7 +185,7 @@ impl BanningTransactionQueue {
/// If bans threshold is reached all subsequent transactions to contracts with this codehash will be rejected.
/// Returns true if bans threshold has been reached.
fn ban_codehash(&mut self, code_hash: H256) -> bool {
let mut count = self.codes_bans.entry(code_hash).or_insert_with(|| 0);
let count = self.codes_bans.entry(code_hash).or_insert_with(|| 0);
*count = count.saturating_add(1);
match self.ban_threshold {

View File

@ -341,7 +341,7 @@ impl GasPriceQueue {
/// Remove an item from a BTreeMap/HashSet "multimap".
/// Returns true if the item was removed successfully.
pub fn remove(&mut self, gas_price: &U256, hash: &H256) -> bool {
if let Some(mut hashes) = self.backing.get_mut(gas_price) {
if let Some(hashes) = self.backing.get_mut(gas_price) {
let only_one_left = hashes.len() == 1;
if !only_one_left {
// Operation may be ok: only if hash is in gas-price's Set.
@ -1225,7 +1225,7 @@ impl TransactionQueue {
if by_nonce.is_none() {
return;
}
let mut by_nonce = by_nonce.expect("None is tested in early-exit condition above; qed");
let by_nonce = by_nonce.expect("None is tested in early-exit condition above; qed");
while let Some(order) = by_nonce.remove(&current_nonce) {
// remove also from priority and gas_price
self.future.by_priority.remove(&order);

View File

@ -962,7 +962,7 @@ impl<B: Backend> State<B> {
// at this point the entry is guaranteed to be in the cache.
Ok(RefMut::map(self.cache.borrow_mut(), |c| {
let mut entry = c.get_mut(a).expect("entry known to exist in the cache; qed");
let entry = c.get_mut(a).expect("entry known to exist in the cache; qed");
match &mut entry.account {
&mut Some(ref mut acc) => not_default(acc),

View File

@ -211,7 +211,7 @@ impl StateDB {
pub fn sync_cache(&mut self, enacted: &[H256], retracted: &[H256], is_best: bool) {
trace!("sync_cache id = (#{:?}, {:?}), parent={:?}, best={}", self.commit_number, self.commit_hash, self.parent_hash, is_best);
let mut cache = self.account_cache.lock();
let mut cache = &mut *cache;
let cache = &mut *cache;
// Purge changes from re-enacted and retracted blocks.
// Filter out commiting block if any.

View File

@ -522,7 +522,7 @@ impl<K: Kind> VerificationQueue<K> {
return;
}
let mut verified_lock = self.verification.verified.lock();
let mut verified = &mut *verified_lock;
let verified = &mut *verified_lock;
let mut bad = self.verification.bad.lock();
let mut processing = self.processing.write();
bad.reserve(hashes.len());

View File

@ -35,7 +35,7 @@ impl KeyDirectory for MemoryDirectory {
fn update(&self, account: SafeAccount) -> Result<SafeAccount, Error> {
let mut lock = self.accounts.write();
let mut accounts = lock.entry(account.address.clone()).or_insert_with(Vec::new);
let accounts = lock.entry(account.address.clone()).or_insert_with(Vec::new);
// If the filename is the same we just need to replace the entry
accounts.retain(|acc| acc.filename != account.filename);
accounts.push(account.clone());
@ -44,14 +44,14 @@ impl KeyDirectory for MemoryDirectory {
fn insert(&self, account: SafeAccount) -> Result<SafeAccount, Error> {
let mut lock = self.accounts.write();
let mut accounts = lock.entry(account.address.clone()).or_insert_with(Vec::new);
let accounts = lock.entry(account.address.clone()).or_insert_with(Vec::new);
accounts.push(account.clone());
Ok(account)
}
fn remove(&self, account: &SafeAccount) -> Result<(), Error> {
let mut accounts = self.accounts.write();
let is_empty = if let Some(mut accounts) = accounts.get_mut(&account.address) {
let is_empty = if let Some(accounts) = accounts.get_mut(&account.address) {
if let Some(position) = accounts.iter().position(|acc| acc == account) {
accounts.remove(position);
}

View File

@ -358,7 +358,7 @@ impl EthMultiStore {
// update cache
let mut cache = self.cache.write();
let mut accounts = cache.entry(account_ref.clone()).or_insert_with(Vec::new);
let accounts = cache.entry(account_ref.clone()).or_insert_with(Vec::new);
// Remove old account
accounts.retain(|acc| acc != &old);
// And push updated to the end

View File

@ -255,7 +255,7 @@ impl Manager {
let mut chunk_size = if chunk_index == 0 { 12 } else { 5 };
let size = min(64 - chunk_size, data.len() - offset);
{
let mut chunk = &mut hid_chunk[HID_PREFIX_ZERO..];
let chunk = &mut hid_chunk[HID_PREFIX_ZERO..];
&mut chunk[0..5].copy_from_slice(&[0x01, 0x01, APDU_TAG, (chunk_index >> 8) as u8, (chunk_index & 0xff) as u8 ]);
if chunk_index == 0 {

View File

@ -176,7 +176,7 @@ impl<T: TimeProvider> AuthCodes<T> {
}
// look for code
for mut code in &mut self.codes {
for code in &mut self.codes {
if &as_token(&code.code) == hash {
code.last_used_at = Some(time::Duration::from_secs(now));
return true;

View File

@ -136,7 +136,7 @@ impl ws::RequestMiddleware for WsExtractor {
}
fn add_security_headers(res: &mut ws::ws::Response) {
let mut headers = res.headers_mut();
let headers = res.headers_mut();
headers.push(("X-Frame-Options".into(), b"SAMEORIGIN".to_vec()));
headers.push(("X-XSS-Protection".into(), b"1; mode=block".to_vec()));
headers.push(("X-Content-Type-Options".into(), b"nosniff".to_vec()));

View File

@ -459,7 +459,7 @@ impl ChainSync {
/// Updates transactions were received by a peer
pub fn transactions_received(&mut self, hashes: Vec<H256>, peer_id: PeerId) {
if let Some(mut peer_info) = self.peers.get_mut(&peer_id) {
if let Some(peer_info) = self.peers.get_mut(&peer_id) {
peer_info.last_sent_transactions.extend(&hashes);
}
}
@ -730,7 +730,7 @@ impl ChainSync {
}
let result = {
let mut downloader = match block_set {
let downloader = match block_set {
BlockSet::NewBlocks => &mut self.new_blocks,
BlockSet::OldBlocks => {
match self.old_blocks {
@ -795,7 +795,7 @@ impl ChainSync {
else
{
let result = {
let mut downloader = match block_set {
let downloader = match block_set {
BlockSet::NewBlocks => &mut self.new_blocks,
BlockSet::OldBlocks => match self.old_blocks {
None => {
@ -849,7 +849,7 @@ impl ChainSync {
else
{
let result = {
let mut downloader = match block_set {
let downloader = match block_set {
BlockSet::NewBlocks => &mut self.new_blocks,
BlockSet::OldBlocks => match self.old_blocks {
None => {
@ -2186,7 +2186,7 @@ impl ChainSync {
// Select random peer to re-broadcast transactions to.
let peer = random::new().gen_range(0, self.peers.len());
trace!(target: "sync", "Re-broadcasting transactions to a random peer.");
self.peers.values_mut().nth(peer).map(|mut peer_info|
self.peers.values_mut().nth(peer).map(|peer_info|
peer_info.last_sent_transactions.clear()
);
}

View File

@ -57,8 +57,8 @@ impl TransactionsStats {
/// Increases number of propagations to given `enodeid`.
pub fn propagated(&mut self, hash: &H256, enode_id: Option<NodeId>, current_block_num: BlockNumber) {
let enode_id = enode_id.unwrap_or_default();
let mut stats = self.pending_transactions.entry(*hash).or_insert_with(|| Stats::new(current_block_num));
let mut count = stats.propagated_to.entry(enode_id).or_insert(0);
let stats = self.pending_transactions.entry(*hash).or_insert_with(|| Stats::new(current_block_num));
let count = stats.propagated_to.entry(enode_id).or_insert(0);
*count = count.saturating_add(1);
}

View File

@ -156,7 +156,7 @@ impl Discovery {
trace!(target: "discovery", "Inserting {:?}", &e);
let id_hash = keccak(e.id);
let ping = {
let mut bucket = &mut self.node_buckets[Discovery::distance(&self.id_hash, &id_hash) as usize];
let bucket = &mut self.node_buckets[Discovery::distance(&self.id_hash, &id_hash) as usize];
let updated = if let Some(node) = bucket.nodes.iter_mut().find(|n| n.address.id == e.id) {
node.address = e.clone();
node.timeout = None;
@ -169,7 +169,7 @@ impl Discovery {
if bucket.nodes.len() > BUCKET_SIZE {
//ping least active node
let mut last = bucket.nodes.back_mut().expect("Last item is always present when len() > 0");
let last = bucket.nodes.back_mut().expect("Last item is always present when len() > 0");
last.timeout = Some(time::precise_time_ns());
Some(last.address.endpoint.clone())
} else { None }
@ -180,7 +180,7 @@ impl Discovery {
}
fn clear_ping(&mut self, id: &NodeId) {
let mut bucket = &mut self.node_buckets[Discovery::distance(&self.id_hash, &keccak(id)) as usize];
let bucket = &mut self.node_buckets[Discovery::distance(&self.id_hash, &keccak(id)) as usize];
if let Some(node) = bucket.nodes.iter_mut().find(|n| &n.address.id == id) {
node.timeout = None;
}

View File

@ -253,7 +253,7 @@ impl NodeTable {
/// Apply table changes coming from discovery
pub fn update(&mut self, mut update: TableUpdates, reserved: &HashSet<NodeId>) {
for (_, node) in update.added.drain() {
let mut entry = self.nodes.entry(node.id.clone()).or_insert_with(|| Node::new(node.id.clone(), node.endpoint.clone()));
let entry = self.nodes.entry(node.id.clone()).or_insert_with(|| Node::new(node.id.clone(), node.endpoint.clone()));
entry.endpoint = node.endpoint;
}
for r in update.removed {

View File

@ -91,7 +91,7 @@ impl<Row, Col, Val> Table<Row, Col, Val>
if let None = row_map {
return None;
}
let mut row_map = row_map.unwrap();
let row_map = row_map.unwrap();
let val = row_map.remove(col);
(val, row_map.is_empty())
};