Skip to content

Commit

Permalink
Cargo clippy: apply suggestions for ckb-sync and ckb-shared
Browse files Browse the repository at this point in the history
  • Loading branch information
eval-exec committed Sep 19, 2024
1 parent df342ca commit 4d3a39e
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion chain/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl ConsumeUnverifiedBlockProcessor {
match *assume_valid_target {
Some(ref target) => {
// if the target has been reached, delete it
if target == &Into::<H256>::into(&BlockView::hash(block)) {
if target == &Into::<H256>::into(BlockView::hash(block)) {
assume_valid_target.take();
Switch::NONE
} else {
Expand Down
2 changes: 1 addition & 1 deletion ckb-bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions freezer/src/freezer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
1 change: 1 addition & 0 deletions freezer/src/freezer_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ impl FreezerFilesBuilder {
fn open_append<P: AsRef<Path>>(&self, path: P) -> Result<(File, u64), IoError> {
let mut file = fs::OpenOptions::new()
.create(true)
.truncate(false)
.read(true)
.write(true)
.open(path)?;
Expand Down
4 changes: 2 additions & 2 deletions miner/src/worker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ impl WorkerController {
}

fn partition_nonce(id: u128, total: u128) -> Range<u128> {
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 }
Expand Down
2 changes: 1 addition & 1 deletion pow/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions rpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion shared/src/shared_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Handle> = unsync::OnceCell::new();
static RUNTIME_HANDLE: unsync::OnceCell<Handle> = const { unsync::OnceCell::new() };
}

static DB_COUNT: AtomicUsize = AtomicUsize::new(0);
Expand Down
1 change: 1 addition & 0 deletions shared/src/types/header_map/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ckb_types::packed::Byte32;

use crate::types::HeaderIndexView;

#[allow(dead_code)]
pub(crate) trait KeyValueBackend {
fn new<P>(tmpdir: Option<P>) -> Self
where
Expand Down
2 changes: 1 addition & 1 deletion spec/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn test_bundled_specs() {
let outputs_capacity = dep_group_tx
.outputs()
.into_iter()
.map(|output| Into::<Capacity>::into(&output.capacity()))
.map(|output| Into::<Capacity>::into(output.capacity()))
.try_fold(Capacity::zero(), Capacity::safe_add)
.unwrap();
// capacity for input and outputs should be same
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fn main() {
}
}

#[allow(unexpected_cfgs)]
fn get_version() -> Version {
let major = env!("CARGO_PKG_VERSION_MAJOR")
.parse::<u8>()
Expand Down
15 changes: 5 additions & 10 deletions store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions sync/src/synchronizer/headers_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ pub enum ValidationState {
Invalid,
}

#[allow(dead_code)]
#[derive(Debug)]
pub enum ValidationError {
Verify(Error),
Expand Down
2 changes: 1 addition & 1 deletion sync/src/tests/synchronizer/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4d3a39e

Please sign in to comment.