From 4d3a39e043cad79e3e8491e2455d9f71110ea59e Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Thu, 19 Sep 2024 22:42:23 +0800 Subject: [PATCH] Cargo clippy: apply suggestions for ckb-sync and ckb-shared --- chain/src/verify.rs | 2 +- ckb-bin/src/lib.rs | 2 +- freezer/src/freezer.rs | 1 + freezer/src/freezer_files.rs | 1 + miner/src/worker/mod.rs | 4 ++-- pow/src/tests.rs | 2 +- rpc/src/error.rs | 2 +- rpc/src/server.rs | 6 ++---- shared/src/shared_builder.rs | 2 +- shared/src/types/header_map/backend.rs | 1 + spec/src/tests/mod.rs | 2 +- src/main.rs | 1 + store/src/store.rs | 15 +++++---------- sync/src/synchronizer/headers_process.rs | 1 + sync/src/tests/synchronizer/functions.rs | 2 +- 15 files changed, 21 insertions(+), 23 deletions(-) diff --git a/chain/src/verify.rs b/chain/src/verify.rs index 3b6fb4eea9..2da6aa6d5b 100644 --- a/chain/src/verify.rs +++ b/chain/src/verify.rs @@ -203,7 +203,7 @@ impl ConsumeUnverifiedBlockProcessor { match *assume_valid_target { Some(ref target) => { // if the target has been reached, delete it - if target == &Into::::into(&BlockView::hash(block)) { + if target == &Into::::into(BlockView::hash(block)) { assume_valid_target.take(); Switch::NONE } else { diff --git a/ckb-bin/src/lib.rs b/ckb-bin/src/lib.rs index 23c09d238b..cb2a5b07c0 100644 --- a/ckb-bin/src/lib.rs +++ b/ckb-bin/src/lib.rs @@ -30,7 +30,7 @@ pub(crate) const LOG_TARGET_SENTRY: &str = "sentry"; /// ## Parameters /// /// * `version` - The version is passed in so the bin crate can collect the version without trigger -/// re-linking. +/// re-linking. pub fn run_app(version: Version) -> Result<(), ExitCode> { // Always print backtrace on panic. ::std::env::set_var("RUST_BACKTRACE", "full"); diff --git a/freezer/src/freezer.rs b/freezer/src/freezer.rs index 6812e7620a..c45dadc592 100644 --- a/freezer/src/freezer.rs +++ b/freezer/src/freezer.rs @@ -43,6 +43,7 @@ impl Freezer { let lock = OpenOptions::new() .write(true) .create(true) + .truncate(false) .open(lock_path) .map_err(internal_error)?; lock.try_lock_exclusive().map_err(internal_error)?; diff --git a/freezer/src/freezer_files.rs b/freezer/src/freezer_files.rs index 03325d84f1..5b4845721e 100644 --- a/freezer/src/freezer_files.rs +++ b/freezer/src/freezer_files.rs @@ -496,6 +496,7 @@ impl FreezerFilesBuilder { fn open_append>(&self, path: P) -> Result<(File, u64), IoError> { let mut file = fs::OpenOptions::new() .create(true) + .truncate(false) .read(true) .write(true) .open(path)?; diff --git a/miner/src/worker/mod.rs b/miner/src/worker/mod.rs index 86d5e028d6..ac27e72519 100644 --- a/miner/src/worker/mod.rs +++ b/miner/src/worker/mod.rs @@ -45,11 +45,11 @@ impl WorkerController { } fn partition_nonce(id: u128, total: u128) -> Range { - let span = u128::max_value() / total; + let span = u128::MAX / total; let start = span * id; let end = match id { x if x < total - 1 => start + span, - x if x == total - 1 => u128::max_value(), + x if x == total - 1 => u128::MAX, _ => unreachable!(), }; Range { start, end } diff --git a/pow/src/tests.rs b/pow/src/tests.rs index fafeabd3dd..3a35d7d98a 100644 --- a/pow/src/tests.rs +++ b/pow/src/tests.rs @@ -4,7 +4,7 @@ use ckb_hash::blake2b_256; #[test] fn test_pow_message() { let zero_hash = blake2b_256([]).into(); - let nonce = u128::max_value(); + let nonce = u128::MAX; let message = pow_message(&zero_hash, nonce); assert_eq!( message.to_vec(), diff --git a/rpc/src/error.rs b/rpc/src/error.rs index 8f8bd43e99..753f747dbe 100644 --- a/rpc/src/error.rs +++ b/rpc/src/error.rs @@ -25,7 +25,7 @@ use std::fmt::{Debug, Display}; /// /// * -1 ~ -999 are general errors /// * -1000 ~ -2999 are module-specific errors. Each module generally gets 100 reserved error -/// codes. +/// codes. /// /// Unless otherwise noted, all the errors return optional detailed information as `string` in the error /// object `data` field. diff --git a/rpc/src/server.rs b/rpc/src/server.rs index 4835cd6765..3d9b97a3b9 100644 --- a/rpc/src/server.rs +++ b/rpc/src/server.rs @@ -62,16 +62,14 @@ impl RpcServer { handler.clone(), false, ) - .map(|local_addr| { + .inspect(|&local_addr| { info!("Listen HTTP RPCServer on address: {}", local_addr); - local_addr }) .unwrap(); let ws_address = if let Some(addr) = config.ws_listen_address { - let local_addr = Self::start_server(&rpc, addr, handler.clone(), true).map(|addr| { + let local_addr = Self::start_server(&rpc, addr, handler.clone(), true).inspect(|&addr| { info!("Listen WebSocket RPCServer on address: {}", addr); - addr }); local_addr.ok() } else { diff --git a/shared/src/shared_builder.rs b/shared/src/shared_builder.rs index 1bb7537d31..60f932f061 100644 --- a/shared/src/shared_builder.rs +++ b/shared/src/shared_builder.rs @@ -171,7 +171,7 @@ impl SharedBuilder { thread_local! { // NOTICE:we can't put the runtime directly into thread_local here, // on windows the runtime in thread_local will get stuck when dropping - static RUNTIME_HANDLE: unsync::OnceCell = unsync::OnceCell::new(); + static RUNTIME_HANDLE: unsync::OnceCell = const { unsync::OnceCell::new() }; } static DB_COUNT: AtomicUsize = AtomicUsize::new(0); diff --git a/shared/src/types/header_map/backend.rs b/shared/src/types/header_map/backend.rs index 9724e89aa9..41ebcd33b9 100644 --- a/shared/src/types/header_map/backend.rs +++ b/shared/src/types/header_map/backend.rs @@ -4,6 +4,7 @@ use ckb_types::packed::Byte32; use crate::types::HeaderIndexView; +#[allow(dead_code)] pub(crate) trait KeyValueBackend { fn new

(tmpdir: Option

) -> Self where diff --git a/spec/src/tests/mod.rs b/spec/src/tests/mod.rs index e5f23bb5b7..d0c038ded6 100644 --- a/spec/src/tests/mod.rs +++ b/spec/src/tests/mod.rs @@ -110,7 +110,7 @@ fn test_bundled_specs() { let outputs_capacity = dep_group_tx .outputs() .into_iter() - .map(|output| Into::::into(&output.capacity())) + .map(|output| Into::::into(output.capacity())) .try_fold(Capacity::zero(), Capacity::safe_add) .unwrap(); // capacity for input and outputs should be same diff --git a/src/main.rs b/src/main.rs index 55c5dfa74d..8a55ba4f95 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ fn main() { } } +#[allow(unexpected_cfgs)] fn get_version() -> Version { let major = env!("CARGO_PKG_VERSION_MAJOR") .parse::() diff --git a/store/src/store.rs b/store/src/store.rs index 90657c5017..376c5a7805 100644 --- a/store/src/store.rs +++ b/store/src/store.rs @@ -79,9 +79,8 @@ pub trait ChainStore: Send + Sync + Sized { }); if let Some(cache) = self.cache() { - ret.map(|header| { + ret.inspect(|header| { cache.headers.lock().put(hash.clone(), header.clone()); - header }) } else { ret @@ -191,9 +190,8 @@ pub trait ChainStore: Send + Sync + Sized { }); if let Some(cache) = self.cache() { - ret.map(|data| { + ret.inspect(|data| { cache.block_proposals.lock().put(hash.clone(), data.clone()); - data }) } else { ret @@ -214,9 +212,8 @@ pub trait ChainStore: Send + Sync + Sized { }); if let Some(cache) = self.cache() { - ret.map(|uncles| { + ret.inspect(|uncles| { cache.block_uncles.lock().put(hash.clone(), uncles.clone()); - uncles }) } else { ret @@ -374,9 +371,8 @@ pub trait ChainStore: Send + Sync + Sized { }); if let Some(cache) = self.cache() { - ret.map(|cached| { + ret.inspect(|cached| { cache.cell_data.lock().put(key, cached.clone()); - cached }) } else { ret @@ -401,9 +397,8 @@ pub trait ChainStore: Send + Sync + Sized { }); if let Some(cache) = self.cache() { - ret.map(|cached| { + ret.inspect(|cached| { cache.cell_data_hash.lock().put(key, cached.clone()); - cached }) } else { ret diff --git a/sync/src/synchronizer/headers_process.rs b/sync/src/synchronizer/headers_process.rs index c2ae0f7665..9fdeeb94bc 100644 --- a/sync/src/synchronizer/headers_process.rs +++ b/sync/src/synchronizer/headers_process.rs @@ -353,6 +353,7 @@ pub enum ValidationState { Invalid, } +#[allow(dead_code)] #[derive(Debug)] pub enum ValidationError { Verify(Error), diff --git a/sync/src/tests/synchronizer/functions.rs b/sync/src/tests/synchronizer/functions.rs index 45892f1663..0e1f435fea 100644 --- a/sync/src/tests/synchronizer/functions.rs +++ b/sync/src/tests/synchronizer/functions.rs @@ -688,7 +688,7 @@ fn test_sync_process() { // Construct a better tip, to trigger fixing last_common_header inside `get_blocks_to_fetch` insert_block(&synchronizer2.chain, &shared2, 201u128, 201); - let headers = vec![synchronizer2.shared.active_chain().tip_header()]; + let headers = [synchronizer2.shared.active_chain().tip_header()]; let sendheaders = SendHeadersBuilder::default() .headers( headers