Skip to content

Commit

Permalink
chore: re-enable some clippy hint
Browse files Browse the repository at this point in the history
  • Loading branch information
quake committed Apr 12, 2019
1 parent 884bfa1 commit 7662ee0
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 25 deletions.
3 changes: 1 addition & 2 deletions chain/src/chain.rs
Expand Up @@ -12,8 +12,7 @@ use ckb_shared::cell_set::CellSetDiff;
use ckb_shared::chain_state::ChainState;
use ckb_shared::error::SharedError;
use ckb_shared::shared::Shared;
use ckb_shared::store::ChainStore;
use ckb_shared::store::StoreBatch;
use ckb_shared::store::{ChainStore, StoreBatch};
use ckb_traits::{BlockMedianTimeContext, ChainProvider};
use ckb_verification::{BlockVerifier, TransactionsVerifier, Verifier};
use crossbeam_channel::{self, select, Receiver, Sender};
Expand Down
12 changes: 6 additions & 6 deletions core/src/difficulty.rs
@@ -1,23 +1,23 @@
#![allow(clippy::op_ref)]

use numext_fixed_hash::H256;
use numext_fixed_uint::U256;

const ONE: U256 = U256::one();

/// f(x) = 2^256 / x
pub fn boundary_to_difficulty(boundary: &H256) -> U256 {
let d: U256 = boundary.into();
if d <= U256::one() {
if d.le(&ONE) {
U256::max_value()
} else {
((U256::one() << 255) / d) << 1
((ONE << 255) / d) << 1
}
}

pub fn difficulty_to_boundary(difficulty: &U256) -> H256 {
if difficulty <= &U256::one() {
if difficulty.le(&ONE) {
U256::max_value().into()
} else {
let t = U256::one() << 255;
let t = ONE << 255;
let boundary = (&t / difficulty) << 1u8;
boundary.into()
}
Expand Down
3 changes: 1 addition & 2 deletions miner/src/block_assembler.rs
Expand Up @@ -432,8 +432,7 @@ mod tests {
use ckb_pow::Pow;
use ckb_shared::shared::Shared;
use ckb_shared::shared::SharedBuilder;
use ckb_shared::store::ChainKVStore;
use ckb_shared::store::ChainStore;
use ckb_shared::store::{ChainKVStore, ChainStore};
use ckb_traits::ChainProvider;
use ckb_verification::{BlockVerifier, HeaderResolverWrapper, HeaderVerifier, Verifier};
use jsonrpc_types::{BlockTemplate, CellbaseTemplate};
Expand Down
3 changes: 1 addition & 2 deletions pow/src/lib.rs
Expand Up @@ -38,10 +38,9 @@ fn pow_message(pow_hash: &[u8], nonce: u64) -> [u8; 40] {
pub trait PowEngine: Send + Sync {
fn init(&self, number: BlockNumber);

#[allow(clippy::op_ref)]
fn verify_header(&self, header: &Header) -> bool {
let proof_hash: H256 = blake2b_256(&header.proof()).into();
if &boundary_to_difficulty(&proof_hash) < header.difficulty() {
if boundary_to_difficulty(&proof_hash).lt(header.difficulty()) {
return false;
}

Expand Down
5 changes: 2 additions & 3 deletions shared/src/shared.rs
Expand Up @@ -178,7 +178,6 @@ impl<CS: ChainStore> ChainProvider for Shared<CS> {
// T_interval = L / C_m
// HR_m = HR_last/ (1 + o)
// Diff= HR_m * T_interval / H = Diff_last * o_last / o
#[allow(clippy::op_ref)]
fn calculate_difficulty(&self, last: &Header) -> Option<U256> {
let last_hash = last.hash();
let last_number = last.number();
Expand Down Expand Up @@ -209,11 +208,11 @@ impl<CS: ChainStore> ChainProvider for Shared<CS> {

let min_difficulty = self.consensus.min_difficulty();
let max_difficulty = last_difficulty * 2u32;
if &difficulty > &max_difficulty {
if difficulty > max_difficulty {
return Some(max_difficulty);
}

if &difficulty < min_difficulty {
if difficulty.lt(min_difficulty) {
return Some(min_difficulty.clone());
}
return Some(difficulty);
Expand Down
1 change: 0 additions & 1 deletion shared/src/tx_pool/trace.rs
Expand Up @@ -73,7 +73,6 @@ impl TxTraceMap {
}
}

#[allow(clippy::needless_pass_by_value)]
pub fn add_pending<S: ToString>(&mut self, hash: &H256, info: S) {
self.inner
.entry(hash.clone())
Expand Down
2 changes: 0 additions & 2 deletions sync/src/relayer/mod.rs
@@ -1,5 +1,3 @@
#![allow(clippy::needless_pass_by_value)]

mod block_proposal_process;
mod block_transactions_process;
pub mod compact_block;
Expand Down
3 changes: 1 addition & 2 deletions sync/src/synchronizer/headers_process.rs
Expand Up @@ -91,7 +91,6 @@ impl<'a, CS: ChainStore> HeaderResolver for VerifierResolver<'a, CS> {
self.parent
}

#[allow(clippy::op_ref)]
fn calculate_difficulty(&self) -> Option<U256> {
self.parent().and_then(|parent| {
let parent_hash = parent.hash();
Expand Down Expand Up @@ -133,7 +132,7 @@ impl<'a, CS: ChainStore> HeaderResolver for VerifierResolver<'a, CS> {
return Some(max_difficulty);
}

if &difficulty < min_difficulty {
if difficulty.lt(min_difficulty) {
return Some(min_difficulty.clone());
}
return Some(difficulty);
Expand Down
7 changes: 2 additions & 5 deletions sync/src/synchronizer/mod.rs
Expand Up @@ -380,7 +380,6 @@ impl<CS: ChainStore> Synchronizer<CS> {
.collect()
}

#[allow(clippy::op_ref)]
pub fn insert_header_view(&self, header: &Header, peer: PeerIndex) {
if let Some(parent_view) = self.get_header_view(&header.parent_hash()) {
let total_difficulty = parent_view.total_difficulty() + header.difficulty();
Expand All @@ -391,7 +390,7 @@ impl<CS: ChainStore> Synchronizer<CS> {
let header_view =
HeaderView::new(header.clone(), total_difficulty.clone(), total_uncles_count);

if &total_difficulty > best_known_header.total_difficulty()
if total_difficulty.gt(best_known_header.total_difficulty())
|| (&total_difficulty == best_known_header.total_difficulty()
&& header.hash() < best_known_header.hash())
{
Expand Down Expand Up @@ -434,7 +433,6 @@ impl<CS: ChainStore> Synchronizer<CS> {
}

//TODO: process block which we don't request
#[allow(clippy::single_match)]
pub fn process_new_block(&self, peer: PeerIndex, block: Block) {
match self.get_block_status(&block.header().hash()) {
BlockStatus::VALID_MASK => {
Expand Down Expand Up @@ -786,8 +784,7 @@ mod tests {
use ckb_notify::{NotifyController, NotifyService};
use ckb_protocol::{Block as FbsBlock, Headers as FbsHeaders};
use ckb_shared::shared::SharedBuilder;
use ckb_shared::store::ChainKVStore;
use ckb_shared::store::ChainStore;
use ckb_shared::store::{ChainKVStore, ChainStore};
use ckb_util::Mutex;
#[cfg(not(disable_faketime))]
use faketime;
Expand Down

0 comments on commit 7662ee0

Please sign in to comment.