Skip to content

Commit

Permalink
Fix cargo clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Eval EXEC <[email protected]>
  • Loading branch information
eval-exec committed Feb 20, 2024
1 parent abaede4 commit f39d7b8
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 45 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
12 changes: 7 additions & 5 deletions chain/src/consume_orphan.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(missing_docs)]

use crate::utils::orphan_block_pool::OrphanBlockPool;
use crate::{LonelyBlock, LonelyBlockHash};
use ckb_channel::{select, Receiver, Sender};
Expand Down Expand Up @@ -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(_) => {
Expand Down Expand Up @@ -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)
});
};
}
}
13 changes: 4 additions & 9 deletions chain/src/consume_unverified.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -291,7 +288,7 @@ impl ConsumeUnverifiedBlockProcessor {
&cannon_total_difficulty - &current_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
Expand Down Expand Up @@ -347,10 +344,9 @@ impl ConsumeUnverifiedBlockProcessor {
}
}

let block_ref: &BlockView = &block;
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);
}
Expand All @@ -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 = &block;
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);
}
}
Expand Down
2 changes: 2 additions & 0 deletions chain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(missing_docs)]

//! CKB chain service.
//!
//! [`ChainService`] background base on database, handle block importing,
Expand Down
12 changes: 6 additions & 6 deletions chain/src/tests/orphan_block_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
});
Expand All @@ -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,
});
Expand All @@ -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,
});
Expand All @@ -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,
});
Expand Down
1 change: 0 additions & 1 deletion shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 12 additions & 8 deletions shared/src/types/header_map/kernel_lru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions shared/src/types/header_map/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|_| ())
}
Expand All @@ -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()
})
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion sync/src/relayer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl Relayer {
StatusCode::BlockIsInvalid.with_context(format!(
"block {} is invalid, reason: {}",
block.hash(),
err.to_string()
err
)),
);
}
Expand Down
4 changes: 2 additions & 2 deletions sync/src/synchronizer/block_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
3 changes: 1 addition & 2 deletions sync/src/synchronizer/block_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)),
);
}
Expand Down
2 changes: 1 addition & 1 deletion sync/src/tests/sync_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn wait_for_expected_block_status(
}
std::thread::sleep(std::time::Duration::from_micros(100));
}
return false;
false
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions sync/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
}
}

Expand Down
1 change: 0 additions & 1 deletion util/launcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down

0 comments on commit f39d7b8

Please sign in to comment.