From f39d7b82327d7d1f32e903146b7906de5d5caf0f Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Wed, 7 Feb 2024 20:55:04 +0800 Subject: [PATCH] Fix cargo clippy warnings Signed-off-by: Eval EXEC --- Cargo.lock | 3 --- chain/Cargo.toml | 1 - chain/src/consume_orphan.rs | 12 +++++++----- chain/src/consume_unverified.rs | 13 ++++--------- chain/src/lib.rs | 2 ++ chain/src/tests/orphan_block_pool.rs | 12 ++++++------ shared/Cargo.toml | 1 - shared/src/types/header_map/kernel_lru.rs | 20 ++++++++++++-------- shared/src/types/header_map/memory.rs | 12 +++++++++--- sync/src/relayer/mod.rs | 2 +- sync/src/synchronizer/block_fetcher.rs | 4 ++-- sync/src/synchronizer/block_process.rs | 3 +-- sync/src/tests/sync_shared.rs | 2 +- sync/src/types/mod.rs | 4 ++-- util/launcher/Cargo.toml | 1 - 15 files changed, 47 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8b15f4fd3b5..e2c26275e43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -719,7 +719,6 @@ dependencies = [ "lazy_static", "minstant", "tempfile", - "tokio", ] [[package]] @@ -984,7 +983,6 @@ dependencies = [ "ckb-types", "ckb-verification", "ckb-verification-traits", - "tokio", ] [[package]] @@ -1454,7 +1452,6 @@ dependencies = [ "ckb-logger", "ckb-metrics", "ckb-migrate", - "ckb-network", "ckb-notify", "ckb-proposal-table", "ckb-snapshot", diff --git a/chain/Cargo.toml b/chain/Cargo.toml index 91ac5ccceab..6ac25957fc0 100644 --- a/chain/Cargo.toml +++ b/chain/Cargo.toml @@ -33,7 +33,6 @@ ckb-constant = { path = "../util/constant", version = "= 0.114.0-pre" } ckb-util = { path = "../util", version = "= 0.114.0-pre" } crossbeam = "0.8.2" ckb-network = { path = "../network", version = "= 0.114.0-pre" } -tokio = { version = "1", features = ["sync"] } ckb-tx-pool = { path = "../tx-pool", version = "= 0.114.0-pre"} minstant = "0.1.4" diff --git a/chain/src/consume_orphan.rs b/chain/src/consume_orphan.rs index 4f9bbb30d32..82e10b7388f 100644 --- a/chain/src/consume_orphan.rs +++ b/chain/src/consume_orphan.rs @@ -1,3 +1,5 @@ +#![allow(missing_docs)] + use crate::utils::orphan_block_pool::OrphanBlockPool; use crate::{LonelyBlock, LonelyBlockHash}; use ckb_channel::{select, Receiver, Sender}; @@ -93,11 +95,11 @@ impl ConsumeDescendantProcessor { fn send_unverified_block(&self, lonely_block: LonelyBlockHash, total_difficulty: U256) { let block_number = lonely_block.block_number_and_hash.number(); let block_hash = lonely_block.block_number_and_hash.hash(); - ckb_metrics::handle().map(|metrics| { + if let Some(metrics) = ckb_metrics::handle() { metrics .ckb_chain_unverified_block_ch_len .set(self.unverified_blocks_tx.len() as i64) - }); + }; match self.unverified_blocks_tx.send(lonely_block) { Ok(_) => { @@ -298,10 +300,10 @@ impl ConsumeOrphan { } self.search_orphan_pool(); - ckb_metrics::handle().map(|handle| { - handle + if let Some(metrics) = ckb_metrics::handle() { + metrics .ckb_chain_orphan_count .set(self.orphan_blocks_broker.len() as i64) - }); + }; } } diff --git a/chain/src/consume_unverified.rs b/chain/src/consume_unverified.rs index 1e643c8a6f0..2fb0be60880 100644 --- a/chain/src/consume_unverified.rs +++ b/chain/src/consume_unverified.rs @@ -1,8 +1,5 @@ use crate::LonelyBlockHash; -use crate::{ - utils::forkchanges::ForkChanges, GlobalIndex, TruncateRequest, - VerifyResult, -}; +use crate::{utils::forkchanges::ForkChanges, GlobalIndex, TruncateRequest, VerifyResult}; use ckb_channel::{select, Receiver}; use ckb_error::{Error, InternalErrorKind}; use ckb_logger::internal::{log_enabled, trace}; @@ -291,7 +288,7 @@ impl ConsumeUnverifiedBlockProcessor { &cannon_total_difficulty - ¤t_total_difficulty, self.shared.get_unverified_tip().number(), ); - self.find_fork(&mut fork, current_tip_header.number(), &block, ext); + self.find_fork(&mut fork, current_tip_header.number(), block, ext); self.rollback(&fork, &db_txn)?; // update and verify chain root @@ -347,10 +344,9 @@ impl ConsumeUnverifiedBlockProcessor { } } - let block_ref: &BlockView = █ self.shared .notify_controller() - .notify_new_block(block_ref.clone()); + .notify_new_block(block.to_owned()); if log_enabled!(ckb_logger::Level::Trace) { self.print_chain(10); } @@ -370,8 +366,7 @@ impl ConsumeUnverifiedBlockProcessor { let tx_pool_controller = self.shared.tx_pool_controller(); if tx_pool_controller.service_started() { - let block_ref: &BlockView = █ - if let Err(e) = tx_pool_controller.notify_new_uncle(block_ref.as_uncle()) { + if let Err(e) = tx_pool_controller.notify_new_uncle(block.as_uncle()) { error!("[verify block] notify new_uncle error {}", e); } } diff --git a/chain/src/lib.rs b/chain/src/lib.rs index a35a12ff4dd..d656a1ba1d2 100644 --- a/chain/src/lib.rs +++ b/chain/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(missing_docs)] + //! CKB chain service. //! //! [`ChainService`] background base on database, handle block importing, diff --git a/chain/src/tests/orphan_block_pool.rs b/chain/src/tests/orphan_block_pool.rs index db094e478d7..3c14890fbac 100644 --- a/chain/src/tests/orphan_block_pool.rs +++ b/chain/src/tests/orphan_block_pool.rs @@ -74,9 +74,9 @@ fn test_remove_blocks_by_parent() { let pool = OrphanBlockPool::with_capacity(200); for _ in 1..block_number { let lonely_block = gen_lonely_block(&parent); - let new_block_clone = lonely_block.block().clone(); + let new_block_clone = Arc::clone(lonely_block.block()); let new_block = LonelyBlock { - block: new_block_clone.clone(), + block: Arc::clone(&new_block_clone), switch: None, verify_callback: None, }; @@ -157,7 +157,7 @@ fn test_leaders() { assert_eq!(pool.leaders_len(), 4); pool.insert(LonelyBlock { - block: blocks[5].block().clone(), + block: Arc::clone(blocks[5].block()), switch: None, verify_callback: None, }); @@ -166,7 +166,7 @@ fn test_leaders() { assert_eq!(pool.leaders_len(), 3); pool.insert(LonelyBlock { - block: blocks[10].block().clone(), + block: Arc::clone(blocks[10].block()), switch: None, verify_callback: None, }); @@ -181,7 +181,7 @@ fn test_leaders() { assert_eq!(pool.leaders_len(), 2); pool.insert(LonelyBlock { - block: blocks[0].block().clone(), + block: Arc::clone(blocks[0].block()), switch: None, verify_callback: None, }); @@ -194,7 +194,7 @@ fn test_leaders() { assert_eq!(pool.leaders_len(), 1); pool.insert(LonelyBlock { - block: blocks[15].block().clone(), + block: Arc::clone(blocks[15].block()), switch: None, verify_callback: None, }); diff --git a/shared/Cargo.toml b/shared/Cargo.toml index c81e3051a8d..e30690a4488 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -30,7 +30,6 @@ ckb-channel = { path = "../util/channel", version = "= 0.114.0-pre" } ckb-app-config = {path = "../util/app-config", version = "= 0.114.0-pre"} ckb-migrate = { path = "../util/migrate", version = "= 0.114.0-pre" } once_cell = "1.8.0" -ckb-network = { path = "../network", version = "= 0.114.0-pre" } ckb-util = { path = "../util", version = "= 0.114.0-pre" } ckb-metrics = { path = "../util/metrics", version = "= 0.114.0-pre" } bitflags = "1.0" diff --git a/shared/src/types/header_map/kernel_lru.rs b/shared/src/types/header_map/kernel_lru.rs index 07dbb3d4400..46dba8eb359 100644 --- a/shared/src/types/header_map/kernel_lru.rs +++ b/shared/src/types/header_map/kernel_lru.rs @@ -87,12 +87,14 @@ where self.stats().tick_primary_contain(); } if self.memory.contains_key(hash) { - ckb_metrics::handle() - .map(|metrics| metrics.ckb_header_map_memory_hit_miss_count.hit.inc()); + if let Some(metrics) = ckb_metrics::handle() { + metrics.ckb_header_map_memory_hit_miss_count.hit.inc() + } return true; } - ckb_metrics::handle() - .map(|metrics| metrics.ckb_header_map_memory_hit_miss_count.miss.inc()); + if let Some(metrics) = ckb_metrics::handle() { + metrics.ckb_header_map_memory_hit_miss_count.miss.inc(); + } if self.backend.is_empty() { return false; @@ -110,13 +112,15 @@ where self.stats().tick_primary_select(); } if let Some(view) = self.memory.get_refresh(hash) { - ckb_metrics::handle() - .map(|metrics| metrics.ckb_header_map_memory_hit_miss_count.hit.inc()); + if let Some(metrics) = ckb_metrics::handle() { + metrics.ckb_header_map_memory_hit_miss_count.hit.inc(); + } return Some(view); } - ckb_metrics::handle() - .map(|metrics| metrics.ckb_header_map_memory_hit_miss_count.miss.inc()); + if let Some(metrics) = ckb_metrics::handle() { + metrics.ckb_header_map_memory_hit_miss_count.miss.inc(); + } if self.backend.is_empty() { return None; diff --git a/shared/src/types/header_map/memory.rs b/shared/src/types/header_map/memory.rs index b88a5042566..7a01b83891b 100644 --- a/shared/src/types/header_map/memory.rs +++ b/shared/src/types/header_map/memory.rs @@ -97,7 +97,9 @@ impl MemoryMap { let (key, value) = header.into(); let ret = guard.insert(key, value); if ret.is_none() { - ckb_metrics::handle().map(|metrics| metrics.ckb_header_map_memory_count.inc()); + if let Some(metrics) = ckb_metrics::handle() { + metrics.ckb_header_map_memory_count.inc(); + } } ret.map(|_| ()) } @@ -110,7 +112,9 @@ impl MemoryMap { shrink_to_fit!(guard, SHRINK_THRESHOLD); } ret.map(|inner| { - ckb_metrics::handle().map(|metrics| metrics.ckb_header_map_memory_count.dec()); + if let Some(metrics) = ckb_metrics::handle() { + metrics.ckb_header_map_memory_count.dec(); + } (key.clone(), inner).into() }) @@ -142,7 +146,9 @@ impl MemoryMap { } } - ckb_metrics::handle().map(|metrics| metrics.ckb_header_map_memory_count.sub(keys_count)); + if let Some(metrics) = ckb_metrics::handle() { + metrics.ckb_header_map_memory_count.sub(keys_count) + } if shrink_to_fit { shrink_to_fit!(guard, SHRINK_THRESHOLD); diff --git a/sync/src/relayer/mod.rs b/sync/src/relayer/mod.rs index 4597c837227..bd139f7c865 100644 --- a/sync/src/relayer/mod.rs +++ b/sync/src/relayer/mod.rs @@ -340,7 +340,7 @@ impl Relayer { StatusCode::BlockIsInvalid.with_context(format!( "block {} is invalid, reason: {}", block.hash(), - err.to_string() + err )), ); } diff --git a/sync/src/synchronizer/block_fetcher.rs b/sync/src/synchronizer/block_fetcher.rs index d4ca821dd65..c2c4ce0eb00 100644 --- a/sync/src/synchronizer/block_fetcher.rs +++ b/sync/src/synchronizer/block_fetcher.rs @@ -278,11 +278,11 @@ impl BlockFetcher { } let inflight_total_count = state.read_inflight_blocks().total_inflight_count(); - ckb_metrics::handle().map(|metrics| { + if let Some(metrics) = ckb_metrics::handle() { metrics .ckb_inflight_blocks_count .set(inflight_total_count as i64); - }); + } if fetch.is_empty() { debug!( diff --git a/sync/src/synchronizer/block_process.rs b/sync/src/synchronizer/block_process.rs index 3be0e42221b..074f0ac4d94 100644 --- a/sync/src/synchronizer/block_process.rs +++ b/sync/src/synchronizer/block_process.rs @@ -61,8 +61,7 @@ impl<'a> BlockProcess<'a> { "SendBlock", StatusCode::BlockIsInvalid.with_context(format!( "block {} is invalid, reason: {}", - block_hash, - err.to_string() + block_hash, err )), ); } diff --git a/sync/src/tests/sync_shared.rs b/sync/src/tests/sync_shared.rs index 04d79e700d0..875a2dfa39a 100644 --- a/sync/src/tests/sync_shared.rs +++ b/sync/src/tests/sync_shared.rs @@ -29,7 +29,7 @@ fn wait_for_expected_block_status( } std::thread::sleep(std::time::Duration::from_micros(100)); } - return false; + false } #[test] diff --git a/sync/src/types/mod.rs b/sync/src/types/mod.rs index f38e5458240..eb8625726f9 100644 --- a/sync/src/types/mod.rs +++ b/sync/src/types/mod.rs @@ -677,9 +677,9 @@ impl InflightBlocks { key.number, key.hash, value.peer ); - ckb_metrics::handle().map(|metrics| { + if let Some(metrics) = ckb_metrics::handle() { metrics.ckb_inflight_timeout_count.inc(); - }); + } } } diff --git a/util/launcher/Cargo.toml b/util/launcher/Cargo.toml index 7bc96c3b94b..44223eb004a 100644 --- a/util/launcher/Cargo.toml +++ b/util/launcher/Cargo.toml @@ -31,7 +31,6 @@ ckb-channel = { path = "../channel", version = "= 0.114.0-pre" } ckb-tx-pool = { path = "../../tx-pool", version = "= 0.114.0-pre" } ckb-light-client-protocol-server = { path = "../light-client-protocol-server", version = "= 0.114.0-pre" } ckb-block-filter = { path = "../../block-filter", version = "= 0.114.0-pre" } -tokio = { version = "1", features = ["sync"] } [features] with_sentry = [ "ckb-sync/with_sentry", "ckb-network/with_sentry", "ckb-app-config/with_sentry" ]