Skip to content

Commit

Permalink
fix stable clippy::needless_borrow (#1236)
Browse files Browse the repository at this point in the history
* clippy: remove borrowed references dereferenced by the compiler (`#needless_borrow`)

* blockchain: run cargo fmt

* ci: remove fixed warnings from clippy exceptions
  • Loading branch information
q9f authored Oct 18, 2021
1 parent 5006e62 commit 4eb74f9
Show file tree
Hide file tree
Showing 55 changed files with 163 additions and 165 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ jobs:
command: make license
- run:
name: cargo clippy
command: cargo clippy -- -D warnings -A clippy::upper_case_acronyms -A clippy::needless_collect -A clippy::enum_variant_names -A clippy::needless_borrow
command: cargo clippy -- -D warnings -A clippy::needless_collect
- run:
name: cargo fmt
command: cargo fmt --all -- --check
Expand Down
2 changes: 1 addition & 1 deletion blockchain/blocks/src/election_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn poly_val(poly: &[BigInt], x: &BigInt) -> BigInt {
/// computes lambda in Q.256
#[inline]
fn lambda(power: &BigInt, total_power: &BigInt) -> BigInt {
((power * BLOCKS_PER_EPOCH) << PRECISION).div_floor(&total_power)
((power * BLOCKS_PER_EPOCH) << PRECISION).div_floor(total_power)
}

/// Poisson inverted CDF
Expand Down
6 changes: 3 additions & 3 deletions blockchain/blocks/src/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ impl BlockHeader {
.ok_or_else(|| Error::InvalidSignature("Signature is nil in header".to_owned()))?;

signature
.verify(&self.to_signing_bytes(), &addr)
.verify(&self.to_signing_bytes(), addr)
.map_err(|e| Error::InvalidSignature(format!("Block signature invalid: {}", e)))?;

// Set validated cache to true
Expand Down Expand Up @@ -420,7 +420,7 @@ impl BlockHeader {
let mut prev = prev_entry;
for curr in &self.beacon_entries {
if !curr_beacon
.verify_entry(&curr, &prev)
.verify_entry(curr, prev)
.await
.map_err(|e| Error::Validation(e.to_string()))?
{
Expand All @@ -429,7 +429,7 @@ impl BlockHeader {
curr, prev
)));
}
prev = &curr;
prev = curr;
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion blockchain/chain/src/store/base_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ where

// Add all unique messages' gas limit to get the total for the Tipset.
for b in ts.blocks() {
let (msg1, msg2) = crate::block_messages(db, &b)?;
let (msg1, msg2) = crate::block_messages(db, b)?;
for m in msg1 {
let m_cid = m.cid()?;
if !seen.contains(&m_cid) {
Expand Down
2 changes: 1 addition & 1 deletion blockchain/chain/src/store/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ where

for message in unsigned_box.chain(signed_box) {
let from_address = message.from();
if applied.contains_key(&from_address) {
if applied.contains_key(from_address) {
let actor_state = state
.get_actor(from_address)
.map_err(|e| Error::Other(e.to_string()))?
Expand Down
2 changes: 1 addition & 1 deletion blockchain/chain/src/store/tipset_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<DB: BlockStore> TipsetTracker<DB> {
// TODO: maybe cache the parents tipset keys to avoid having to do a blockstore lookup here
let h = self
.db
.get::<BlockHeader>(&cid)
.get::<BlockHeader>(cid)
.ok()
.flatten()
.ok_or_else(|| {
Expand Down
2 changes: 1 addition & 1 deletion blockchain/chain_sync/src/chain_muxer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ where
let ts = chain_store.tipset_from_keys(&tipset_keys).await?;
for header in ts.blocks() {
// Retrieve bls and secp messages from specified BlockHeader
let (bls_msgs, secp_msgs) = chain::block_messages(chain_store.blockstore(), &header)?;
let (bls_msgs, secp_msgs) = chain::block_messages(chain_store.blockstore(), header)?;
// Construct a full block
blocks.push(Block {
header: header.clone(),
Expand Down
22 changes: 10 additions & 12 deletions blockchain/chain_sync/src/tipset_syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl TipsetGroup {
if !self.epoch.eq(&tipset.epoch()) || !self.parents.eq(tipset.parents()) {
return Some(tipset);
}
if self.tipsets.iter().any(|ts| tipset.key().eq(&ts.key())) {
if self.tipsets.iter().any(|ts| tipset.key().eq(ts.key())) {
return Some(tipset);
}
self.tipsets.push(tipset);
Expand Down Expand Up @@ -434,7 +434,7 @@ where
if ns.is_mergeable(&heaviest_tipset_group) {
// Both tipsets groups have the same epoch & parents, so merge them
ns.merge(heaviest_tipset_group);
} else if heaviest_tipset_group.is_heavier_than(&ns) {
} else if heaviest_tipset_group.is_heavier_than(ns) {
// The tipset group received is heavier than the one saved, replace it.
*next_sync = Some(heaviest_tipset_group);
}
Expand Down Expand Up @@ -481,7 +481,7 @@ where
if ns.is_mergeable(&heaviest_tipset_group) {
// Both tipsets groups have the same epoch & parents, so merge them
ns.merge(heaviest_tipset_group);
} else if heaviest_tipset_group.is_heavier_than(&ns) {
} else if heaviest_tipset_group.is_heavier_than(ns) {
// The tipset group received is heavier than the one saved, replace it.
*next_sync = Some(heaviest_tipset_group);
} else {
Expand Down Expand Up @@ -881,7 +881,7 @@ async fn sync_headers_in_reverse<DB: BlockStore + Sync + Send + 'static>(
if tipset.epoch() < current_head.epoch() {
break 'sync;
}
validate_tipset_against_cache(bad_block_cache.clone(), &tipset.key(), &parent_blocks)
validate_tipset_against_cache(bad_block_cache.clone(), tipset.key(), &parent_blocks)
.await?;
parent_blocks.extend_from_slice(tipset.cids());
tracker.write().await.set_epoch(tipset.epoch());
Expand Down Expand Up @@ -1196,7 +1196,7 @@ async fn validate_block<
let header = block.header();

// Check to ensure all optional values exist
block_sanity_checks(&header).map_err(|e| (*block_cid, e))?;
block_sanity_checks(header).map_err(|e| (*block_cid, e))?;

let base_tipset = chain_store
.tipset_from_keys(header.parents())
Expand Down Expand Up @@ -1385,9 +1385,7 @@ async fn validate_block<
.map_err(|e| TipsetRangeSyncerError::DrawingChainRandomness(e.to_string()))?;
verify_election_post_vrf(&work_addr, &vrf_base, election_proof.vrfproof.as_bytes())?;

if v_state_manager
.is_miner_slashed(header.miner_address(), &v_base_tipset.parent_state())?
{
if v_state_manager.is_miner_slashed(header.miner_address(), v_base_tipset.parent_state())? {
return Err(TipsetRangeSyncerError::InvalidOrSlashedMiner);
}
let (mpow, tpow) = v_state_manager
Expand Down Expand Up @@ -1577,9 +1575,9 @@ fn verify_winning_post_proof<DB: BlockStore + Send + Sync + 'static, V: ProofVer
})?;
let sectors = state_manager
.get_sectors_for_winning_post::<V>(
&lookback_state,
lookback_state,
network_version,
&header.miner_address(),
header.miner_address(),
Randomness(rand.to_vec()),
)
.map_err(|e| {
Expand Down Expand Up @@ -1638,7 +1636,7 @@ fn check_block_messages<
.map(|x| &x[..])
.collect::<Vec<&[u8]>>()
.as_slice(),
&sig,
sig,
) {
return Err(TipsetRangeSyncerError::BlsAggregateSignatureInvalid(
format!("{:?}", sig),
Expand Down Expand Up @@ -1695,7 +1693,7 @@ fn check_block_messages<
let mut account_sequences: HashMap<Address, u64> = HashMap::default();
let block_store = state_manager.blockstore();
let (state_root, _) =
task::block_on(state_manager.tipset_state::<V>(&base_tipset)).map_err(|e| {
task::block_on(state_manager.tipset_state::<V>(base_tipset)).map_err(|e| {
TipsetRangeSyncerError::Calculation(format!("Could not update state: {}", e))
})?;
let tree = StateTree::new_from_root(block_store, &state_root).map_err(|e| {
Expand Down
10 changes: 5 additions & 5 deletions blockchain/message_pool/src/msg_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ impl Chains {
let a = self.map.get(*a).unwrap();
let b = self.map.get(*b).unwrap();
if rev {
b.compare(&a)
b.compare(a)
} else {
a.compare(&b)
a.compare(b)
}
});
let _ = mem::replace(&mut self.key_vec, chains);
Expand All @@ -81,7 +81,7 @@ impl Chains {
self.map
.get(*a)
.unwrap()
.cmp_effective(&self.map.get(*b).unwrap())
.cmp_effective(self.map.get(*b).unwrap())
});
let _ = mem::replace(&mut self.key_vec, chains);
}
Expand Down Expand Up @@ -356,7 +356,7 @@ where
// cannot exceed the block limit; drop all messages that exceed the limit
// - the total gasReward cannot exceed the actor's balance; drop all messages that exceed
// the balance
let actor_state = api.read().await.get_actor_after(&actor, &ts)?;
let actor_state = api.read().await.get_actor_after(actor, ts)?;
let mut cur_seq = actor_state.sequence;
let mut balance = actor_state.balance;

Expand Down Expand Up @@ -405,7 +405,7 @@ where
let value = m.value();
balance -= value;

let gas_reward = get_gas_reward(&m, base_fee);
let gas_reward = get_gas_reward(m, base_fee);
rewards.push(gas_reward);
i += 1;
}
Expand Down
8 changes: 4 additions & 4 deletions blockchain/message_pool/src/msgpool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async fn get_state_sequence<T>(
where
T: Provider,
{
let actor = api.read().await.get_actor_after(&addr, cur_ts)?;
let actor = api.read().await.get_actor_after(addr, cur_ts)?;
let base_sequence = actor.sequence;

Ok(base_sequence)
Expand Down Expand Up @@ -94,7 +94,7 @@ where

let mut chains = Chains::new();
for (actor, mset) in pending_map.iter() {
create_message_chains(&api, actor, mset, &base_fee_lower_bound, &ts, &mut chains).await?;
create_message_chains(api, actor, mset, &base_fee_lower_bound, &ts, &mut chains).await?;
}

if chains.is_empty() {
Expand Down Expand Up @@ -198,7 +198,7 @@ where

let mut msgs: Vec<SignedMessage> = Vec::new();
for block in ts.blocks() {
let (umsg, smsgs) = api.read().await.messages_for_block(&block)?;
let (umsg, smsgs) = api.read().await.messages_for_block(block)?;
msgs.extend(smsgs);
for msg in umsg {
let mut bls_sig_cache = bls_sig_cache.write().await;
Expand Down Expand Up @@ -242,7 +242,7 @@ where
for (_, hm) in rmsgs {
for (_, msg) in hm {
let sequence =
get_state_sequence(api, &msg.from(), &cur_tipset.read().await.clone()).await?;
get_state_sequence(api, msg.from(), &cur_tipset.read().await.clone()).await?;
if let Err(e) = add_helper(api, bls_sig_cache, pending, msg, sequence).await {
error!("Failed to readd message from reorg to mpool: {}", e);
}
Expand Down
24 changes: 12 additions & 12 deletions blockchain/message_pool/src/msgpool/msg_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ where
repub_trigger.clone(),
republished.as_ref(),
pending.as_ref(),
&cur.as_ref(),
cur.as_ref(),
rev,
app,
)
Expand Down Expand Up @@ -374,7 +374,7 @@ where
return Err(Error::SequenceTooLow);
}

let publish = verify_msg_before_add(&msg, &cur_ts, local)?;
let publish = verify_msg_before_add(&msg, cur_ts, local)?;

let balance = self.get_state_balance(msg.from(), cur_ts).await?;

Expand Down Expand Up @@ -425,14 +425,14 @@ where

/// Get the state of the sequence for a given address in cur_ts.
async fn get_state_sequence(&self, addr: &Address, cur_ts: &Tipset) -> Result<u64, Error> {
let actor = self.api.read().await.get_actor_after(&addr, cur_ts)?;
let actor = self.api.read().await.get_actor_after(addr, cur_ts)?;
Ok(actor.sequence)
}

/// Get the state balance for the actor that corresponds to the supplied address and tipset,
/// if this actor does not exist, return an error.
async fn get_state_balance(&self, addr: &Address, ts: &Tipset) -> Result<BigInt, Error> {
let actor = self.api.read().await.get_actor_after(&addr, &ts)?;
let actor = self.api.read().await.get_actor_after(addr, ts)?;
Ok(actor.balance)
}

Expand All @@ -447,20 +447,20 @@ where
Protocol::ID => {
let api = self.api.read().await;

api.state_account_key::<V>(&addr, &self.cur_tipset.read().await.clone())
api.state_account_key::<V>(addr, &self.cur_tipset.read().await.clone())
.await?
}
_ => *addr,
};

let sequence = self.get_sequence(&addr).await?;
let sequence = self.get_sequence(addr).await?;
let msg = cb(from_key, sequence)?;
self.check_message(&msg).await?;
if *self.cur_tipset.read().await != cur_ts {
return Err(Error::TryAgain);
}

if self.get_sequence(&addr).await? != sequence {
if self.get_sequence(addr).await? != sequence {
return Err(Error::TryAgain);
}

Expand All @@ -483,7 +483,7 @@ where
}

async fn check_balance(&self, m: &SignedMessage, cur_ts: &Tipset) -> Result<(), Error> {
let bal = self.get_state_balance(m.from(), &cur_ts).await?;
let bal = self.get_state_balance(m.from(), cur_ts).await?;
let mut required_funds = m.required_funds();
if bal < required_funds {
return Err(Error::NotEnoughFunds);
Expand Down Expand Up @@ -555,7 +555,7 @@ where
let mut msg_vec: Vec<SignedMessage> = Vec::new();

for block in blks {
let (umsg, mut smsgs) = self.api.read().await.messages_for_block(&block)?;
let (umsg, mut smsgs) = self.api.read().await.messages_for_block(block)?;

msg_vec.append(smsgs.as_mut());
for msg in umsg {
Expand Down Expand Up @@ -607,9 +607,9 @@ where
if local {
let local_addrs = self.local_addrs.read().await;
for a in local_addrs.iter() {
if let Some(mset) = self.pending.read().await.get(&a) {
if let Some(mset) = self.pending.read().await.get(a) {
for m in mset.msgs.values() {
if !self.local_msgs.write().await.remove(&m) {
if !self.local_msgs.write().await.remove(m) {
warn!("error deleting local message");
}
}
Expand All @@ -620,7 +620,7 @@ where
} else {
let mut pending = self.pending.write().await;
let local_addrs = self.local_addrs.read().await;
pending.retain(|a, _| local_addrs.contains(&a));
pending.retain(|a, _| local_addrs.contains(a));
}
}
pub fn get_config(&self) -> &MpoolConfig {
Expand Down
Loading

0 comments on commit 4eb74f9

Please sign in to comment.