From ece24097ca7e6929a5d1ce5c09dd190b467f955d Mon Sep 17 00:00:00 2001 From: simonjiao Date: Sat, 2 Sep 2023 20:19:41 +0800 Subject: [PATCH 1/3] upgrade rust to 1.75.0 1. silence `default-features=false` warnings 2. silence some clippy warnings 3. fix consensus test case 4. remove some unused imports 5. silence non ffi-safe warning --- Cargo.lock | 3 +- account/Cargo.toml | 2 +- account/api/Cargo.toml | 4 +-- account/api/src/provider.rs | 8 ++--- account/service/Cargo.toml | 2 +- benchmarks/Cargo.toml | 8 ++--- block-relayer/Cargo.toml | 14 ++++----- chain/Cargo.toml | 20 ++++++------ chain/api/Cargo.toml | 4 +-- chain/api/src/lib.rs | 2 +- chain/force-upgrade/Cargo.toml | 2 +- chain/mock/Cargo.toml | 16 +++++----- chain/open-block/Cargo.toml | 10 +++--- chain/service/Cargo.toml | 2 +- chain/src/chain.rs | 4 ++- chain/src/lib.rs | 2 +- cmd/airdrop/src/main.rs | 2 +- cmd/db-exporter/Cargo.toml | 6 ++-- cmd/faucet/Cargo.toml | 2 +- cmd/generator/Cargo.toml | 2 +- cmd/merkle-generator/Cargo.toml | 2 +- cmd/miner_client/Cargo.toml | 8 ++--- cmd/miner_client/src/cpu_solver.rs | 31 +++++++++++-------- cmd/miner_client/src/solver.rs | 1 + cmd/peer-watcher/Cargo.toml | 2 +- cmd/resource-exporter/Cargo.toml | 2 +- cmd/starcoin/Cargo.toml | 6 ++-- cmd/starcoin/src/account/generate_keypair.rs | 1 - cmd/starcoin/src/state/get_proof_cmd.rs | 4 +-- cmd/starcoin/src/state/get_root_cmd.rs | 4 +-- commons/accumulator/Cargo.toml | 6 ++-- commons/forkable-jellyfish-merkle/Cargo.toml | 2 +- commons/metrics/Cargo.toml | 2 +- commons/scmd/src/result.rs | 9 ++---- commons/serde-helpers/Cargo.toml | 2 +- commons/utils/src/mpsc.rs | 4 +-- config/Cargo.toml | 8 ++--- config/src/api_config.rs | 8 ++--- config/src/genesis_config.rs | 8 ++--- consensus/Cargo.toml | 10 ++---- consensus/src/argon.rs | 2 +- consensus/src/cn.rs | 2 +- consensus/src/consensus.rs | 6 ++-- consensus/src/consensus_test.rs | 7 +++-- consensus/src/difficulty.rs | 28 ++++++++++------- consensus/src/keccak.rs | 2 +- consensus/src/lib.rs | 16 ++++++---- dataformat-generator/Cargo.toml | 6 ++-- executor/Cargo.toml | 8 ++--- executor/benchmark/Cargo.toml | 8 ++--- genesis/Cargo.toml | 2 +- genesis/src/errors.rs | 2 +- miner/Cargo.toml | 18 +++++------ network-p2p/Cargo.toml | 2 +- network-p2p/core/Cargo.toml | 4 +-- network-p2p/peerset/Cargo.toml | 2 +- .../src/protocol/generic_proto/handler.rs | 2 +- .../src/protocol/generic_proto/upgrade.rs | 2 +- network-p2p/types/Cargo.toml | 4 +-- network-rpc/Cargo.toml | 24 +++++++------- network-rpc/api/Cargo.toml | 2 +- network/Cargo.toml | 2 +- network/api/Cargo.toml | 4 +-- network/api/src/lib.rs | 2 +- network/api/src/peer_provider.rs | 8 ++--- network/src/lib.rs | 2 +- network/src/network_p2p_handle.rs | 4 +-- network/types/Cargo.toml | 2 +- node/Cargo.toml | 2 +- node/src/node.rs | 3 +- rpc/api/Cargo.toml | 4 +-- rpc/api/src/types/pubsub.rs | 8 ++--- rpc/client/Cargo.toml | 4 +-- rpc/client/src/remote_state_reader.rs | 8 ++--- rpc/server/Cargo.toml | 4 +-- rpc/server/src/module/txpool_rpc.rs | 5 --- rust-toolchain.toml | 2 +- state/api/Cargo.toml | 2 +- state/state-tree/Cargo.toml | 4 +-- state/statedb/Cargo.toml | 2 +- storage/Cargo.toml | 8 ++--- stratum/Cargo.toml | 2 +- sync/Cargo.toml | 16 +++++----- sync/api/Cargo.toml | 8 ++--- sync/src/lib.rs | 2 +- sync/src/verified_rpc_client.rs | 1 - test-helper/Cargo.toml | 4 +-- testsuite/Cargo.toml | 2 +- txpool/Cargo.toml | 12 +++---- txpool/api/Cargo.toml | 4 +-- txpool/mock-service/Cargo.toml | 2 +- types/Cargo.toml | 12 +++---- types/src/lib.rs | 2 +- types/uint/Cargo.toml | 4 +-- vm/compiler/Cargo.toml | 7 ++--- vm/e2e-tests/Cargo.toml | 2 +- vm/move-coverage/Cargo.toml | 2 +- vm/move-explain/Cargo.toml | 4 +-- vm/move-package-manager/Cargo.toml | 2 +- vm/move-package-manager/src/lib.rs | 8 ++--- .../Cargo.toml | 2 +- .../src/lib.rs | 2 +- vm/stdlib/Cargo.toml | 4 +-- vm/stdlib/src/main.rs | 1 - vm/transaction-benchmarks/Cargo.toml | 2 +- vm/transaction-builder/Cargo.toml | 4 +-- vm/types/Cargo.toml | 8 ++--- vm/types/src/account_config/constants/mod.rs | 8 ++--- vm/types/src/account_config/resources/mod.rs | 10 +++--- vm/types/src/genesis_config.rs | 16 ++++------ vm/types/src/proptest_types.rs | 2 +- vm/vm-runtime/Cargo.toml | 6 ++-- vm/vm-runtime/src/move_vm_ext/mod.rs | 4 +-- vm/vm-runtime/src/starcoin_vm.rs | 4 +-- 114 files changed, 304 insertions(+), 329 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 305926dac3..27d9e27136 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7657,6 +7657,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom 0.2.8", + "serde 1.0.152", ] [[package]] @@ -9494,8 +9495,6 @@ dependencies = [ "futures 0.3.26", "hex", "once_cell", - "proptest", - "proptest-derive", "rand 0.8.5", "rand_core 0.6.4", "rust-argon2", diff --git a/account/Cargo.toml b/account/Cargo.toml index 76c29e1c5a..ce1f858c5b 100644 --- a/account/Cargo.toml +++ b/account/Cargo.toml @@ -1,7 +1,7 @@ [dependencies] anyhow = { workspace = true } async-trait = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } futures = { workspace = true } parking_lot = { workspace = true } rand = { workspace = true } diff --git a/account/api/Cargo.toml b/account/api/Cargo.toml index d9794f0a34..de4bc29100 100644 --- a/account/api/Cargo.toml +++ b/account/api/Cargo.toml @@ -1,13 +1,13 @@ [dependencies] anyhow = { workspace = true } async-trait = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } futures = { workspace = true } hex = { workspace = true } rand = { workspace = true } rand_core = { default-features = false, workspace = true } schemars = { workspace = true } -serde = { default-features = false, workspace = true } +serde = { features = ["derive"], workspace = true } serde_bytes = { workspace = true } serde_json = { workspace = true } starcoin-crypto = { workspace = true } diff --git a/account/api/src/provider.rs b/account/api/src/provider.rs index b55d54dd0f..d8ef109af2 100644 --- a/account/api/src/provider.rs +++ b/account/api/src/provider.rs @@ -6,17 +6,15 @@ use starcoin_types::sign_message::{SignedMessage, SigningMessage}; use starcoin_types::transaction::{RawUserTransaction, SignedUserTransaction}; #[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Default)] pub enum AccountProviderStrategy { + #[default] RPC, Local, PrivateKey, } -impl Default for AccountProviderStrategy { - fn default() -> Self { - AccountProviderStrategy::RPC - } -} + pub trait AccountProvider { fn create_account(&self, password: String) -> Result; diff --git a/account/service/Cargo.toml b/account/service/Cargo.toml index 98a64611c9..7e902c453c 100644 --- a/account/service/Cargo.toml +++ b/account/service/Cargo.toml @@ -1,7 +1,7 @@ [dependencies] anyhow = { workspace = true } async-trait = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } futures = { workspace = true } starcoin-account = { workspace = true } starcoin-account-api = { features = ["mock"], workspace = true } diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml index 8aadab05c6..339913399b 100644 --- a/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -13,21 +13,21 @@ rust-version = { workspace = true } [dependencies] anyhow = { workspace = true } criterion = { workspace = true } -starcoin-crypto = { package = "starcoin-crypto", workspace = true } +starcoin-crypto = { workspace = true } forkable-jellyfish-merkle = { workspace = true } futures = { workspace = true } futures-timer = { workspace = true } -starcoin-logger = { package = "starcoin-logger", workspace = true } +starcoin-logger = { workspace = true } parking_lot = { workspace = true } proptest = { workspace = true } rand = { workspace = true } rand_core = { default-features = false, workspace = true } starcoin-account-api = { workspace = true } -starcoin-accumulator = { package = "starcoin-accumulator", workspace = true } +starcoin-accumulator = { workspace = true } starcoin-chain = { workspace = true } starcoin-config = { workspace = true } starcoin-consensus = { workspace = true } -starcoin-executor = { package = "starcoin-executor", workspace = true } +starcoin-executor = { workspace = true } starcoin-genesis = { workspace = true } network-api = { workspace = true } starcoin-service-registry = { workspace = true } diff --git a/block-relayer/Cargo.toml b/block-relayer/Cargo.toml index 6e49a3b348..76b7122902 100644 --- a/block-relayer/Cargo.toml +++ b/block-relayer/Cargo.toml @@ -1,23 +1,23 @@ [dependencies] anyhow = { workspace = true } async-trait = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } -starcoin-crypto = { package = "starcoin-crypto", workspace = true } +bcs-ext = { workspace = true } +starcoin-crypto = { workspace = true } futures = { workspace = true } -starcoin-logger = { package = "starcoin-logger", workspace = true } -network-api = { package = "network-api", workspace = true } +starcoin-logger = { workspace = true } +network-api = { workspace = true } starcoin-chain = { workspace = true } starcoin-chain-api = { workspace = true } starcoin-metrics = { workspace = true } starcoin-network = { workspace = true } starcoin-network-rpc-api = { workspace = true } starcoin-service-registry = { workspace = true } -starcoin-sync = { package = "starcoin-sync", workspace = true } -starcoin-sync-api = { package = "starcoin-sync-api", workspace = true } +starcoin-sync = { workspace = true } +starcoin-sync-api = { workspace = true } starcoin-time-service = { workspace = true } starcoin-txpool = { workspace = true } starcoin-txpool-api = { workspace = true } -starcoin-types = { package = "starcoin-types", workspace = true } +starcoin-types = { workspace = true } starcoin-config = { workspace = true } [dev-dependencies] diff --git a/chain/Cargo.toml b/chain/Cargo.toml index e9213d3f35..1c7df7f35c 100644 --- a/chain/Cargo.toml +++ b/chain/Cargo.toml @@ -1,25 +1,25 @@ [dependencies] anyhow = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } clap = { features = ["derive"], workspace = true } -starcoin-crypto = { package = "starcoin-crypto", workspace = true } -starcoin-logger = { package = "starcoin-logger", workspace = true } -proptest = { default-features = false, optional = true, workspace = true } -proptest-derive = { default-features = false, optional = true, workspace = true } +starcoin-crypto = { workspace = true } +starcoin-logger = { workspace = true } +proptest = { features = ["std"], optional = true, workspace = true } +proptest-derive = { optional = true, workspace = true } rand = { workspace = true } rand_core = { default-features = false, workspace = true } sp-utils = { workspace = true } -starcoin-accumulator = { package = "starcoin-accumulator", workspace = true } +starcoin-accumulator = { workspace = true } starcoin-consensus = { workspace = true } starcoin-chain-api = { workspace = true } starcoin-config = { workspace = true } -starcoin-executor = { package = "starcoin-executor", workspace = true } +starcoin-executor = { workspace = true } starcoin-open-block = { workspace = true } starcoin-service-registry = { workspace = true } starcoin-state-api = { workspace = true } starcoin-statedb = { workspace = true } starcoin-time-service = { workspace = true } -starcoin-types = { package = "starcoin-types", workspace = true } +starcoin-types = { workspace = true } starcoin-vm-types = { workspace = true } starcoin-vm-runtime = { workspace = true } starcoin-force-upgrade = { workspace = true } @@ -36,9 +36,7 @@ starcoin-chain-mock = { workspace = true } starcoin-genesis = { workspace = true } starcoin-resource-viewer = { workspace = true } starcoin-transaction-builder = { workspace = true } -starcoin-types = { package = "starcoin-types", features = [ - "fuzzing", -], workspace = true } +starcoin-types = { features = [ "fuzzing" ], workspace = true } stdlib = { workspace = true } stest = { workspace = true } test-helper = { workspace = true } diff --git a/chain/api/Cargo.toml b/chain/api/Cargo.toml index 79c4df5a4e..9630238afd 100644 --- a/chain/api/Cargo.toml +++ b/chain/api/Cargo.toml @@ -2,10 +2,10 @@ anyhow = { workspace = true } async-trait = { workspace = true } futures = { workspace = true } -network-api = { package = "network-api", workspace = true } +network-api = { workspace = true } rand = { workspace = true } rand_core = { default-features = false, workspace = true } -serde = { default-features = false, workspace = true } +serde = { features = ["derive"], workspace = true } starcoin-accumulator = { workspace = true } starcoin-crypto = { workspace = true } starcoin-service-registry = { workspace = true } diff --git a/chain/api/src/lib.rs b/chain/api/src/lib.rs index 7d08162394..35a77dfc39 100644 --- a/chain/api/src/lib.rs +++ b/chain/api/src/lib.rs @@ -1,6 +1,6 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2 -#![deny(clippy::integer_arithmetic)] +#![deny(clippy::arithmetic_side_effects)] use anyhow::{bail, format_err, Result}; use serde::{Deserialize, Serialize}; diff --git a/chain/force-upgrade/Cargo.toml b/chain/force-upgrade/Cargo.toml index 5f6b1ef073..9a4a06fe2f 100644 --- a/chain/force-upgrade/Cargo.toml +++ b/chain/force-upgrade/Cargo.toml @@ -13,7 +13,7 @@ rust-version = { workspace = true } [dependencies] anyhow = { workspace = true } async-trait = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } starcoin-crypto = { workspace = true } futures = { workspace = true } starcoin-logger = { workspace = true } diff --git a/chain/mock/Cargo.toml b/chain/mock/Cargo.toml index 65d37a5abb..7028af8dd9 100644 --- a/chain/mock/Cargo.toml +++ b/chain/mock/Cargo.toml @@ -1,26 +1,26 @@ [dependencies] anyhow = { workspace = true } async-trait = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } -starcoin-crypto = { package = "starcoin-crypto", workspace = true } +bcs-ext = { workspace = true } +starcoin-crypto = { workspace = true } futures = { workspace = true } futures-timer = { workspace = true } -starcoin-logger = { package = "starcoin-logger", workspace = true } +starcoin-logger = { workspace = true } parking_lot = { workspace = true } -proptest = { default-features = false, optional = true, workspace = true } -proptest-derive = { default-features = false, optional = true, workspace = true } +proptest = { features = ["std"], optional = true, workspace = true } +proptest-derive = { optional = true, workspace = true } starcoin-account-api = { workspace = true } -starcoin-accumulator = { package = "starcoin-accumulator", workspace = true } +starcoin-accumulator = { workspace = true } starcoin-chain = { workspace = true } starcoin-config = { workspace = true } starcoin-consensus = { workspace = true } -starcoin-executor = { package = "starcoin-executor", workspace = true } +starcoin-executor = { workspace = true } starcoin-genesis = { workspace = true } starcoin-open-block = { workspace = true } starcoin-state-api = { workspace = true } starcoin-statedb = { workspace = true } starcoin-storage = { workspace = true } -starcoin-types = { package = "starcoin-types", workspace = true } +starcoin-types = { workspace = true } starcoin-vm-types = { workspace = true } thiserror = { workspace = true } diff --git a/chain/open-block/Cargo.toml b/chain/open-block/Cargo.toml index 7b211b4bf8..95ed7e50ab 100644 --- a/chain/open-block/Cargo.toml +++ b/chain/open-block/Cargo.toml @@ -1,14 +1,14 @@ [dependencies] anyhow = { workspace = true } async-trait = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } -starcoin-crypto = { package = "starcoin-crypto", workspace = true } +bcs-ext = { workspace = true } +starcoin-crypto = { workspace = true } futures = { workspace = true } -starcoin-logger = { package = "starcoin-logger", workspace = true } +starcoin-logger = { workspace = true } parking_lot = { workspace = true } -starcoin-accumulator = { package = "starcoin-accumulator", workspace = true } +starcoin-accumulator = { workspace = true } starcoin-chain-api = { workspace = true } -starcoin-executor = { package = "starcoin-executor", workspace = true } +starcoin-executor = { workspace = true } starcoin-state-api = { workspace = true } starcoin-statedb = { workspace = true } starcoin-storage = { workspace = true } diff --git a/chain/service/Cargo.toml b/chain/service/Cargo.toml index 68a8783c7f..54b661f7af 100644 --- a/chain/service/Cargo.toml +++ b/chain/service/Cargo.toml @@ -4,7 +4,7 @@ async-trait = { workspace = true } futures = { workspace = true } rand = { workspace = true } rand_core = { default-features = false, workspace = true } -serde = { default-features = false, workspace = true } +serde = { features = ["derive"], workspace = true } starcoin-chain = { workspace = true } starcoin-chain-api = { workspace = true } starcoin-config = { workspace = true } diff --git a/chain/src/chain.rs b/chain/src/chain.rs index 2d3162ccf6..1b85f28c88 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -992,7 +992,9 @@ impl BlockChain { .map(|status| status.total_difficulty()) .unwrap_or_default(); - let total_difficulty = pre_total_difficulty + header.difficulty(); + let total_difficulty = pre_total_difficulty + .checked_add(header.difficulty()) + .ok_or(format_err!("failed to calculate total difficulty"))?; block_accumulator.append(&[block_id])?; block_accumulator.flush()?; diff --git a/chain/src/lib.rs b/chain/src/lib.rs index 70c73faab9..44bfd09865 100644 --- a/chain/src/lib.rs +++ b/chain/src/lib.rs @@ -1,6 +1,6 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -#![deny(clippy::integer_arithmetic)] +#![deny(clippy::arithmetic_side_effects)] mod chain; pub mod verifier; pub use chain::BlockChain; diff --git a/cmd/airdrop/src/main.rs b/cmd/airdrop/src/main.rs index 4f28fb2e5c..594281f275 100644 --- a/cmd/airdrop/src/main.rs +++ b/cmd/airdrop/src/main.rs @@ -226,7 +226,7 @@ async fn main() -> Result<()> { .map(|r| r.sequence_number()) .unwrap_or_default() }; - for (i, airdrops) in airdrop_infos.chunks(batch_size).into_iter().enumerate() { + for (i, airdrops) in airdrop_infos.chunks(batch_size).enumerate() { let addresses = MoveValue::Vector( airdrops .iter() diff --git a/cmd/db-exporter/Cargo.toml b/cmd/db-exporter/Cargo.toml index 2bff6ed903..dad8cb4f36 100644 --- a/cmd/db-exporter/Cargo.toml +++ b/cmd/db-exporter/Cargo.toml @@ -5,12 +5,12 @@ path = "src/main.rs" [dependencies] anyhow = { workspace = true } atomic-counter = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } clap = { features = ["derive"], workspace = true } csv = { workspace = true } hex = { workspace = true } indicatif = { workspace = true } -starcoin-logger = { package = "starcoin-logger", workspace = true } +starcoin-logger = { workspace = true } serde = { workspace = true } serde_json = { features = ["arbitrary_precision"], workspace = true } tokio = { features = ["full"], workspace = true } @@ -18,7 +18,7 @@ move-binary-format = { workspace = true } move-bytecode-verifier = { workspace = true } starcoin-account = { workspace = true } starcoin-account-api = { workspace = true } -starcoin-accumulator = { package = "starcoin-accumulator", workspace = true } +starcoin-accumulator = { workspace = true } starcoin-chain = { workspace = true } starcoin-cmd = { workspace = true } starcoin-config = { workspace = true } diff --git a/cmd/faucet/Cargo.toml b/cmd/faucet/Cargo.toml index d758ea0449..18d0cf679f 100644 --- a/cmd/faucet/Cargo.toml +++ b/cmd/faucet/Cargo.toml @@ -8,7 +8,7 @@ ascii = { workspace = true } clap = { features = ["derive"], workspace = true } futures = { workspace = true } futures-timer = { workspace = true } -hex = { default-features = false, workspace = true } +hex = { features = ["serde"], workspace = true } once_cell = { workspace = true } rust-embed = { workspace = true } serde = { workspace = true } diff --git a/cmd/generator/Cargo.toml b/cmd/generator/Cargo.toml index 9ef6df736b..2d22d6304a 100644 --- a/cmd/generator/Cargo.toml +++ b/cmd/generator/Cargo.toml @@ -7,7 +7,7 @@ anyhow = { workspace = true } clap = { features = ["derive"], workspace = true } futures = { workspace = true } futures-timer = { workspace = true } -hex = { default-features = false, workspace = true } +hex = { features = ["serde"], workspace = true } scmd = { workspace = true } serde = { workspace = true } serde_json = { features = ["arbitrary_precision"], workspace = true } diff --git a/cmd/merkle-generator/Cargo.toml b/cmd/merkle-generator/Cargo.toml index ea393b8b48..d133e534b2 100644 --- a/cmd/merkle-generator/Cargo.toml +++ b/cmd/merkle-generator/Cargo.toml @@ -1,6 +1,6 @@ [dependencies] anyhow = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } clap = { features = ["derive"], workspace = true } csv = { workspace = true } hex = { workspace = true } diff --git a/cmd/miner_client/Cargo.toml b/cmd/miner_client/Cargo.toml index e3a39f1d93..90e1afa3c0 100644 --- a/cmd/miner_client/Cargo.toml +++ b/cmd/miner_client/Cargo.toml @@ -7,14 +7,14 @@ actix = { workspace = true } actix-rt = { workspace = true } anyhow = { workspace = true } async-std = { workspace = true } -starcoin-consensus = { package = "starcoin-consensus", workspace = true } -starcoin-crypto = { package = "starcoin-crypto", workspace = true } +starcoin-consensus = { workspace = true } +starcoin-crypto = { workspace = true } futures = { workspace = true } futures-channel = { workspace = true } jsonrpc-core = { features = ["arbitrary_precision"], workspace = true } jsonrpc-core-client = { workspace = true } jsonrpc-server-utils = { workspace = true } -starcoin-logger = { package = "starcoin-logger", workspace = true } +starcoin-logger = { workspace = true } starcoin-config = { workspace = true } starcoin-time-service = { workspace = true } starcoin-types = { workspace = true } @@ -24,7 +24,7 @@ byteorder = { workspace = true } clap = { features = ["derive"], workspace = true } dyn-clone = { workspace = true } futures-timer = { workspace = true } -hex = { default-features = false, workspace = true } +hex = { features = ["serde"], workspace = true } libloading = { workspace = true } parking_lot = { workspace = true } rand = { workspace = true } diff --git a/cmd/miner_client/src/cpu_solver.rs b/cmd/miner_client/src/cpu_solver.rs index 955fc74406..305588c667 100644 --- a/cmd/miner_client/src/cpu_solver.rs +++ b/cmd/miner_client/src/cpu_solver.rs @@ -103,20 +103,25 @@ impl Solver for CpuSolver { let nonce = Self::nonce_generator(&nonce_range); if let Ok(pow_hash) = strategy.calculate_pow_hash(&minting_blob, nonce, &extra) { let pow_hash_u256: U256 = pow_hash.into(); - let target = difficult_to_target(diff); hash_counter += 1; - if pow_hash_u256 <= target { - let elapsed_sec: f64 = start.elapsed().as_nanos() as f64 / 1_000_000_000.0; - let hash_rate = hash_counter as f64 / elapsed_sec; - info!("[miner-client-solver-{:?}] New seal found by solver, nonce {:?}, hash rate:{:>10.3}", i, nonce, hash_rate); - if let Err(e) = block_on(nonce_tx.send(SealEvent { - minting_blob, - nonce, - extra: mint_extra, - hash_result: Default::default(), - })) { - error!("[miner-client-solver] Failed to send seal: {:?}", e); - }; + if let Ok(target) = difficult_to_target(diff) { + if pow_hash_u256 <= target { + let elapsed_sec: f64 = start.elapsed().as_nanos() as f64 / 1_000_000_000.0; + let hash_rate = hash_counter as f64 / elapsed_sec; + info!("[miner-client-solver-{:?}] New seal found by solver, nonce {:?}, hash rate:{:>10.3}", i, nonce, hash_rate); + if let Err(e) = block_on(nonce_tx.send(SealEvent { + minting_blob, + nonce, + extra: mint_extra, + hash_result: Default::default(), + })) { + error!("[miner-client-solver] Failed to send seal: {:?}", e); + }; + break; + } + + } else { + error!("[miner-client-solver] Failed to calculate target: {diff}"); break; } } diff --git a/cmd/miner_client/src/solver.rs b/cmd/miner_client/src/solver.rs index 38f4dfd145..e4bafe2501 100644 --- a/cmd/miner_client/src/solver.rs +++ b/cmd/miner_client/src/solver.rs @@ -4,6 +4,7 @@ use starcoin_config::{MinerClientConfig, TimeService}; use starcoin_miner_client_api::Solver; use std::sync::Arc; +#[allow(improper_ctypes_definitions)] type CreateSolver = extern "C" fn() -> Box; const SOLVER_CREATOR: &[u8] = b"create_solver"; diff --git a/cmd/peer-watcher/Cargo.toml b/cmd/peer-watcher/Cargo.toml index 64b9ce0382..ed3560274c 100644 --- a/cmd/peer-watcher/Cargo.toml +++ b/cmd/peer-watcher/Cargo.toml @@ -17,7 +17,7 @@ starcoin-logger = { workspace = true } starcoin-network = { workspace = true } starcoin-storage = { workspace = true } starcoin-types = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } [package] authors = { workspace = true } diff --git a/cmd/resource-exporter/Cargo.toml b/cmd/resource-exporter/Cargo.toml index 8e3f624a85..836cad00c8 100644 --- a/cmd/resource-exporter/Cargo.toml +++ b/cmd/resource-exporter/Cargo.toml @@ -1,6 +1,6 @@ [dependencies] anyhow = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } clap = { features = ["derive"], workspace = true } csv = { workspace = true } hex = { workspace = true } diff --git a/cmd/starcoin/Cargo.toml b/cmd/starcoin/Cargo.toml index 3c3c92621f..912780cd3d 100644 --- a/cmd/starcoin/Cargo.toml +++ b/cmd/starcoin/Cargo.toml @@ -4,16 +4,16 @@ path = "src/main.rs" [dependencies] anyhow = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } clap = { features = ["derive"], workspace = true } crossbeam-channel = { workspace = true } forkable-jellyfish-merkle = { workspace = true } futures = { workspace = true } -hex = { default-features = false, workspace = true } +hex = { features = ["serde"], workspace = true } itertools = { workspace = true } move-command-line-common = { workspace = true } move-errmapgen = { workspace = true } -network-api = { package = "network-api", workspace = true } +network-api = { workspace = true } network-p2p-types = { workspace = true } network-types = { workspace = true } rand = { workspace = true } diff --git a/cmd/starcoin/src/account/generate_keypair.rs b/cmd/starcoin/src/account/generate_keypair.rs index 9b24f0cc0c..5e79be4c6d 100644 --- a/cmd/starcoin/src/account/generate_keypair.rs +++ b/cmd/starcoin/src/account/generate_keypair.rs @@ -59,7 +59,6 @@ impl CommandAction for GenerateKeypairCommand { KeyGen::from_os_rng() }; let keypairs = (0..opt.count.unwrap_or(1)) - .into_iter() .map(|_| { let (private_key, public_key) = key_gen.generate_keypair(); let account_public_key = AccountPublicKey::single(public_key); diff --git a/cmd/starcoin/src/state/get_proof_cmd.rs b/cmd/starcoin/src/state/get_proof_cmd.rs index c9249180bd..37d62b3583 100644 --- a/cmd/starcoin/src/state/get_proof_cmd.rs +++ b/cmd/starcoin/src/state/get_proof_cmd.rs @@ -15,7 +15,7 @@ use starcoin_types::access_path::AccessPath; /// Get state and proof with access_path, etc: 0x1/0/Account, 0x1/1/0x1::Account::Account #[derive(Debug, Parser)] #[clap(name = "get-proof", alias = "get_proof")] -pub struct GetOpt { +pub struct GetProofOpt { #[clap(name = "access_path")] /// access_path of code or resource, etc: 0x1/0/Account, 0x1/1/0x1::Account::Account access_path: AccessPath, @@ -51,7 +51,7 @@ pub struct GetProofCommand; impl CommandAction for GetProofCommand { type State = CliState; type GlobalOpt = StarcoinOpt; - type Opt = GetOpt; + type Opt = GetProofOpt; type ReturnItem = ViewOrRaw; fn run( diff --git a/cmd/starcoin/src/state/get_root_cmd.rs b/cmd/starcoin/src/state/get_root_cmd.rs index 3b6983e0ab..96c7da41d5 100644 --- a/cmd/starcoin/src/state/get_root_cmd.rs +++ b/cmd/starcoin/src/state/get_root_cmd.rs @@ -10,14 +10,14 @@ use starcoin_crypto::HashValue; #[derive(Debug, Parser)] #[clap(name = "get-root", alias = "get_root")] -pub struct GetOpt {} +pub struct GetRootOpt {} pub struct GetRootCommand; impl CommandAction for GetRootCommand { type State = CliState; type GlobalOpt = StarcoinOpt; - type Opt = GetOpt; + type Opt = GetRootOpt; type ReturnItem = HashValue; fn run( diff --git a/commons/accumulator/Cargo.toml b/commons/accumulator/Cargo.toml index 9b4d1786d1..7dac897342 100644 --- a/commons/accumulator/Cargo.toml +++ b/commons/accumulator/Cargo.toml @@ -1,9 +1,9 @@ [dependencies] anyhow = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } byteorder = { workspace = true } -itertools = { default-features = false, workspace = true } -starcoin-logger = { package = "starcoin-logger", workspace = true } +itertools = { features = ["use_alloc"], workspace = true } +starcoin-logger = { workspace = true } lru = { workspace = true } mirai-annotations = { workspace = true } once_cell = { workspace = true } diff --git a/commons/forkable-jellyfish-merkle/Cargo.toml b/commons/forkable-jellyfish-merkle/Cargo.toml index 57ded2e207..303648f87e 100644 --- a/commons/forkable-jellyfish-merkle/Cargo.toml +++ b/commons/forkable-jellyfish-merkle/Cargo.toml @@ -5,7 +5,7 @@ name = "bench_merkle_tree" [dependencies] anyhow = { workspace = true } backtrace = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } byteorder = { workspace = true } hex = { workspace = true } mirai-annotations = { workspace = true } diff --git a/commons/metrics/Cargo.toml b/commons/metrics/Cargo.toml index ef3d1ca617..f7a07f788f 100644 --- a/commons/metrics/Cargo.toml +++ b/commons/metrics/Cargo.toml @@ -1,6 +1,6 @@ [dependencies] anyhow = { workspace = true } -prometheus = { default-features = false, workspace = true } +prometheus = { features = ["push"], workspace = true } serde_json = { features = ["arbitrary_precision"], workspace = true } starcoin-logger = { workspace = true } futures = { optional = true, workspace = true } diff --git a/commons/scmd/src/result.rs b/commons/scmd/src/result.rs index daf05f50f3..9f7a010e23 100644 --- a/commons/scmd/src/result.rs +++ b/commons/scmd/src/result.rs @@ -8,9 +8,10 @@ use flatten_json::flatten; use serde_json::{json, Value}; use std::str::FromStr; -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, Default)] #[allow(clippy::upper_case_acronyms)] pub enum OutputFormat { + #[default] JSON, TABLE, } @@ -27,12 +28,6 @@ impl FromStr for OutputFormat { } } -impl Default for OutputFormat { - fn default() -> Self { - OutputFormat::JSON - } -} - impl std::fmt::Display for OutputFormat { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let s = match self { diff --git a/commons/serde-helpers/Cargo.toml b/commons/serde-helpers/Cargo.toml index 72faef70f2..6ba535491a 100644 --- a/commons/serde-helpers/Cargo.toml +++ b/commons/serde-helpers/Cargo.toml @@ -4,7 +4,7 @@ serde = { features = ["derive"], workspace = true } serde_bytes = { workspace = true } [dev-dependencies] -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } serde_json = { features = ["arbitrary_precision"], workspace = true } [package] diff --git a/commons/utils/src/mpsc.rs b/commons/utils/src/mpsc.rs index ed8d7acfe9..4a3f201db0 100644 --- a/commons/utils/src/mpsc.rs +++ b/commons/utils/src/mpsc.rs @@ -65,13 +65,13 @@ mod inner { /// Wrapper around `mpsc::unbounded` that tracks the in- and outflow via /// `UNBOUNDED_CHANNELS_COUNTER` - #[allow(clippy::clone_double_ref)] + #[allow(suspicious_double_ref_op)] pub fn tracing_unbounded( key: &'static str, ) -> (TracingUnboundedSender, TracingUnboundedReceiver) { let (s, r) = mpsc::unbounded(); ( - TracingUnboundedSender(key.clone(), s), + TracingUnboundedSender(key, s), TracingUnboundedReceiver(key, r), ) } diff --git a/config/Cargo.toml b/config/Cargo.toml index 2ccaa6c6f2..89be30d383 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -6,7 +6,7 @@ git-version = { workspace = true } hex = { workspace = true } libc = { workspace = true } names = { default-features = false, workspace = true } -network-api = { package = "network-api", workspace = true } +network-api = { workspace = true } network-p2p-types = { workspace = true } network-types = { workspace = true } num_cpus = { workspace = true } @@ -20,9 +20,9 @@ serde = { features = ["derive"], workspace = true } serde_json = { features = ["arbitrary_precision"], workspace = true } starcoin-account-api = { workspace = true } starcoin-crypto = { workspace = true } -starcoin-logger = { package = "starcoin-logger", workspace = true } +starcoin-logger = { workspace = true } starcoin-metrics = { workspace = true } -starcoin-system = { package = "starcoin-system", workspace = true } +starcoin-system = { workspace = true } starcoin-time-service = { workspace = true } starcoin-types = { workspace = true } starcoin-uint = { workspace = true } @@ -32,7 +32,7 @@ starcoin-gas = { workspace = true } stdlib = { workspace = true } tempfile = { workspace = true } thiserror = { workspace = true } -toml = { default-features = false, workspace = true } +toml = { features = ["default"], workspace = true } [package] authors = { workspace = true } diff --git a/config/src/api_config.rs b/config/src/api_config.rs index 3962298f7c..c2ff0dae6f 100644 --- a/config/src/api_config.rs +++ b/config/src/api_config.rs @@ -83,8 +83,10 @@ impl FromStr for Api { } #[derive(Debug, Clone)] +#[derive(Default)] pub enum ApiSet { // Unsafe context (like jsonrpc over http) + #[default] UnsafeContext, // All possible APIs (safe context like token-protected WS interface) All, @@ -96,11 +98,7 @@ pub enum ApiSet { List(HashSet), } -impl Default for ApiSet { - fn default() -> Self { - ApiSet::UnsafeContext - } -} + impl PartialEq for ApiSet { fn eq(&self, other: &Self) -> bool { diff --git a/config/src/genesis_config.rs b/config/src/genesis_config.rs index 4a1d23d3cf..830bd24a89 100644 --- a/config/src/genesis_config.rs +++ b/config/src/genesis_config.rs @@ -59,6 +59,7 @@ use std::sync::Arc; )] #[repr(u8)] #[allow(clippy::upper_case_acronyms)] +#[derive(Default)] pub enum BuiltinNetworkID { /// A ephemeral network just for unit test. Test = 255, @@ -76,6 +77,7 @@ pub enum BuiltinNetworkID { /// Barnard's Star is a red dwarf about six light-years away from Earth in the constellation of Ophiuchus. Barnard = 251, /// Starcoin main net. + #[default] Main = 1, } @@ -199,11 +201,7 @@ impl BuiltinNetworkID { } } -impl Default for BuiltinNetworkID { - fn default() -> Self { - BuiltinNetworkID::Main - } -} + impl From for ChainNetwork { fn from(network: BuiltinNetworkID) -> Self { diff --git a/consensus/Cargo.toml b/consensus/Cargo.toml index 9968df42be..cdae243de9 100644 --- a/consensus/Cargo.toml +++ b/consensus/Cargo.toml @@ -3,12 +3,10 @@ anyhow = { workspace = true } byteorder = { workspace = true } cryptonight-rs = { workspace = true } futures = { workspace = true } -hex = { default-features = false, workspace = true } +hex = { features = ["serde"], workspace = true } once_cell = { workspace = true } -proptest = { default-features = false, optional = true, workspace = true } -proptest-derive = { default-features = false, optional = true, workspace = true } rand = { workspace = true } -rand_core = { default-features = false, workspace = true } +rand_core = { features = ["serde"], workspace = true } rust-argon2 = { workspace = true } sha3 = { workspace = true } starcoin-chain-api = { workspace = true } @@ -21,15 +19,13 @@ starcoin-vm-types = { workspace = true } thiserror = { workspace = true } [dev-dependencies] -proptest = { workspace = true } -proptest-derive = { workspace = true } stest = { workspace = true } serde = { features = ["derive"], workspace = true } serde_json = { features = ["arbitrary_precision"], workspace = true } [features] default = [] -fuzzing = ["proptest", "proptest-derive", "starcoin-types/fuzzing"] +fuzzing = ["starcoin-types/fuzzing"] [package] authors = { workspace = true } diff --git a/consensus/src/argon.rs b/consensus/src/argon.rs index 81684a7287..4fd27cc3cb 100644 --- a/consensus/src/argon.rs +++ b/consensus/src/argon.rs @@ -22,7 +22,7 @@ impl ArgonConsensus { impl Consensus for ArgonConsensus { fn calculate_next_difficulty(&self, reader: &dyn ChainReader) -> Result { let target = difficulty::get_next_work_required(reader)?; - Ok(target_to_difficulty(target)) + target_to_difficulty(target) } fn calculate_pow_hash( diff --git a/consensus/src/cn.rs b/consensus/src/cn.rs index 09a8463f87..88ca8e7763 100644 --- a/consensus/src/cn.rs +++ b/consensus/src/cn.rs @@ -22,7 +22,7 @@ impl CryptoNightConsensus { impl Consensus for CryptoNightConsensus { fn calculate_next_difficulty(&self, reader: &dyn ChainReader) -> Result { let target = difficulty::get_next_work_required(reader)?; - Ok(target_to_difficulty(target)) + target_to_difficulty(target) } /// CryptoNight-R diff --git a/consensus/src/consensus.rs b/consensus/src/consensus.rs index 421b26bdcb..f4d6056283 100644 --- a/consensus/src/consensus.rs +++ b/consensus/src/consensus.rs @@ -46,7 +46,7 @@ pub trait Consensus { .calculate_pow_hash(mining_hash, nonce, &extra) .expect("calculate hash should work") .into(); - let target = difficult_to_target(difficulty); + let target = difficult_to_target(difficulty).expect("failed to calculate target"); if pow_hash > target { nonce = nonce.saturating_add(1); continue; @@ -102,7 +102,7 @@ pub trait Consensus { let pow_hash: U256 = self .calculate_pow_hash(&pow_header_blob, nonce, extra)? .into(); - let target = difficult_to_target(difficulty); + let target = difficult_to_target(difficulty)?; if pow_hash > target { return Err(ConsensusVerifyError::VerifyNonceError { target, @@ -124,7 +124,7 @@ pub trait Consensus { difficulty: U256, ) -> Result<()> { let pow_hash: U256 = self.calculate_pow_hash(&blob, nonce, &extra)?.into(); - let target = difficult_to_target(difficulty); + let target = difficult_to_target(difficulty)?; if pow_hash > target { return Err(ConsensusVerifyError::VerifyNonceError { target, diff --git a/consensus/src/consensus_test.rs b/consensus/src/consensus_test.rs index 0bf608fc3f..7c1997a186 100644 --- a/consensus/src/consensus_test.rs +++ b/consensus/src/consensus_test.rs @@ -124,10 +124,13 @@ fn simulate_blocks(time_plan: u64, init_difficulty: U256) -> u64 { for _ in 0..500 { let timestamp = liner_hash_pow(diff, now); now = timestamp; - blocks.push_front(BlockDiffInfo::new(timestamp, difficult_to_target(diff))); + blocks.push_front(BlockDiffInfo::new( + timestamp, + difficult_to_target(diff).unwrap(), + )); let bf: Vec<&BlockDiffInfo> = blocks.iter().collect(); let blocks = bf.iter().map(|&b| b.clone()).collect(); - diff = target_to_difficulty(get_next_target_helper(blocks, time_plan).unwrap()); + diff = target_to_difficulty(get_next_target_helper(blocks, time_plan).unwrap()).unwrap(); } blocks[0].timestamp - blocks[1].timestamp } diff --git a/consensus/src/difficulty.rs b/consensus/src/difficulty.rs index 8f67b3f0bc..53537cd0f4 100644 --- a/consensus/src/difficulty.rs +++ b/consensus/src/difficulty.rs @@ -14,7 +14,7 @@ pub fn get_next_work_required(chain: &dyn ChainReader) -> Result { let epoch = chain.epoch(); let current_header = chain.current_header(); if current_header.number() <= 1 { - return Ok(difficult_to_target(current_header.difficulty())); + return difficult_to_target(current_header.difficulty()); } let start_window_num = if current_header.number() < epoch.block_difficulty_window() { 0 @@ -35,7 +35,7 @@ pub fn get_next_work_required(chain: &dyn ChainReader) -> Result { chain .get_header_by_number(n)? .ok_or_else(|| format_err!("Can not find header by number {}", n)) - .map(|header| header.into()) + .and_then(|header| header.try_into()) }) .collect::>>()?; if start_window_num != 0 { @@ -102,14 +102,17 @@ pub fn get_next_target_helper(blocks: Vec, time_plan: u64) -> Res } // new_target = avg_target * avg_time_used/time_plan // avoid the target increase or reduce too fast. - let new_target = if let Some(new_target) = (avg_target / time_plan).checked_mul(avg_time.into()) + let new_target = if let Some(new_target) = avg_target + .checked_div(time_plan.into()) + .and_then(|r| r.checked_mul(avg_time.into())) { - if new_target / 2 > avg_target { + // the divisor is `2` and never be `0` + if new_target.checked_div(2.into()).unwrap() > avg_target { debug!("target increase too fast, limit to 2 times"); - avg_target * 2 - } else if new_target < avg_target / 2 { + avg_target.saturating_mul(2.into()) + } else if new_target < avg_target.checked_div(2.into()).unwrap() { debug!("target reduce too fast, limit to 2 times"); - avg_target / 2 + avg_target.checked_div(2.into()).unwrap() } else { new_target } @@ -136,11 +139,12 @@ impl BlockDiffInfo { } } -impl From for BlockDiffInfo { - fn from(block_header: BlockHeader) -> Self { - Self { +impl TryFrom for BlockDiffInfo { + type Error = anyhow::Error; + fn try_from(block_header: BlockHeader) -> Result { + Ok(Self { timestamp: block_header.timestamp(), - target: difficult_to_target(block_header.difficulty()), - } + target: difficult_to_target(block_header.difficulty())?, + }) } } diff --git a/consensus/src/keccak.rs b/consensus/src/keccak.rs index 328d35385d..93647c8a71 100644 --- a/consensus/src/keccak.rs +++ b/consensus/src/keccak.rs @@ -22,7 +22,7 @@ impl KeccakConsensus { impl Consensus for KeccakConsensus { fn calculate_next_difficulty(&self, reader: &dyn ChainReader) -> Result { let target = difficulty::get_next_work_required(reader)?; - Ok(target_to_difficulty(target)) + target_to_difficulty(target) } /// Double keccak256 for pow hash diff --git a/consensus/src/lib.rs b/consensus/src/lib.rs index 8b870c6d2e..35bcd524e5 100644 --- a/consensus/src/lib.rs +++ b/consensus/src/lib.rs @@ -1,12 +1,12 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -#![deny(clippy::integer_arithmetic)] +#![deny(clippy::arithmetic_side_effects)] use crate::argon::ArgonConsensus; use crate::cn::CryptoNightConsensus; use crate::dummy::DummyConsensus; use crate::keccak::KeccakConsensus; -use anyhow::Result; +use anyhow::{format_err, Result}; use byteorder::{LittleEndian, WriteBytesExt}; use once_cell::sync::Lazy; use rand::Rng; @@ -30,12 +30,16 @@ pub mod keccak; pub use consensus::{Consensus, ConsensusVerifyError}; pub use starcoin_time_service::duration_since_epoch; -pub fn target_to_difficulty(target: U256) -> U256 { - U256::max_value() / target +pub fn target_to_difficulty(target: U256) -> Result { + U256::max_value() + .checked_div(target) + .ok_or(format_err!("zero-divisor")) } -pub fn difficult_to_target(difficulty: U256) -> U256 { - U256::max_value() / difficulty +pub fn difficult_to_target(difficulty: U256) -> Result { + U256::max_value() + .checked_div(difficulty) + .ok_or(format_err!("zero-divisor")) } pub fn set_header_nonce(header: &[u8], nonce: u32, extra: &BlockHeaderExtra) -> Vec { diff --git a/dataformat-generator/Cargo.toml b/dataformat-generator/Cargo.toml index 24f1a9a1fa..a5b6f01fb0 100644 --- a/dataformat-generator/Cargo.toml +++ b/dataformat-generator/Cargo.toml @@ -1,9 +1,9 @@ [build-dependencies] serde-reflection = { workspace = true } -starcoin-crypto = { package = "starcoin-crypto", workspace = true } -starcoin-types = { package = "starcoin-types", workspace = true } +starcoin-crypto = { workspace = true } +starcoin-types = { workspace = true } anyhow = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } serde = { features = ["derive"], workspace = true } serde_yaml = { workspace = true } starcoin-vm-types = { workspace = true } diff --git a/executor/Cargo.toml b/executor/Cargo.toml index 2fb1c75a67..9638ab1268 100644 --- a/executor/Cargo.toml +++ b/executor/Cargo.toml @@ -1,7 +1,7 @@ [dependencies] anyhow = { workspace = true } log = { workspace = true } -starcoin-logger = { package = "starcoin-logger", workspace = true } +starcoin-logger = { workspace = true } starcoin-crypto = { workspace = true } starcoin-state-api = { workspace = true } starcoin-types = { workspace = true } @@ -9,11 +9,11 @@ starcoin-vm-types = { workspace = true } starcoin-vm-runtime = { workspace = true } starcoin-statedb = { workspace = true } starcoin-force-upgrade = { workspace = true } -serde = { default-features = false, workspace = true } +serde = { workspace = true } bcs-ext = { workspace = true } [dev-dependencies] -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } hex = { workspace = true } once_cell = { workspace = true } serde = { workspace = true } @@ -29,7 +29,7 @@ starcoin-state-tree = { workspace = true } starcoin-statedb = { workspace = true } starcoin-vm-runtime = { workspace = true } starcoin-force-upgrade = { workspace = true } -stdlib = { package = "stdlib", workspace = true } +stdlib = { workspace = true } stest = { workspace = true } tempfile = { workspace = true } test-helper = { workspace = true } diff --git a/executor/benchmark/Cargo.toml b/executor/benchmark/Cargo.toml index 3761cfee5a..275261ed3f 100644 --- a/executor/benchmark/Cargo.toml +++ b/executor/benchmark/Cargo.toml @@ -1,12 +1,12 @@ [dependencies] anyhow = { workspace = true } clap = { features = ["derive"], workspace = true } -itertools = { default-features = false, workspace = true } +itertools = { features = ["use_alloc"], workspace = true } rand = { workspace = true } rayon = { workspace = true } -starcoin-accumulator = { package = "starcoin-accumulator", workspace = true } -starcoin-crypto = { package = "starcoin-crypto", workspace = true } -starcoin-logger = { package = "starcoin-logger", workspace = true } +starcoin-accumulator = { workspace = true } +starcoin-crypto = { workspace = true } +starcoin-logger = { workspace = true } starcoin-config = { workspace = true } starcoin-consensus = { workspace = true } starcoin-genesis = { workspace = true } diff --git a/genesis/Cargo.toml b/genesis/Cargo.toml index 0f09b6e871..8453070b9e 100644 --- a/genesis/Cargo.toml +++ b/genesis/Cargo.toml @@ -1,6 +1,6 @@ [dependencies] anyhow = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } clap = { features = ["derive"], workspace = true } include_dir = { workspace = true } once_cell = { workspace = true } diff --git a/genesis/src/errors.rs b/genesis/src/errors.rs index 9a10c2f95f..cbb3aca072 100644 --- a/genesis/src/errors.rs +++ b/genesis/src/errors.rs @@ -1,7 +1,7 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -pub use anyhow::{anyhow, bail, format_err, Error, Result}; +pub use anyhow::Error; use starcoin_crypto::HashValue; use thiserror::Error; diff --git a/miner/Cargo.toml b/miner/Cargo.toml index 2c63ae9010..0f9454b1be 100644 --- a/miner/Cargo.toml +++ b/miner/Cargo.toml @@ -6,14 +6,14 @@ hex = { workspace = true } once_cell = { workspace = true } parking_lot = { workspace = true } thiserror = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } -starcoin-consensus = { package = "starcoin-consensus", workspace = true } -starcoin-crypto = { package = "starcoin-crypto", workspace = true } -starcoin-logger = { package = "starcoin-logger", workspace = true } +bcs-ext = { workspace = true } +starcoin-consensus = { workspace = true } +starcoin-crypto = { workspace = true } +starcoin-logger = { workspace = true } serde = { workspace = true } starcoin-account-api = { workspace = true } starcoin-account-service = { workspace = true } -starcoin-accumulator = { package = "starcoin-accumulator", workspace = true } +starcoin-accumulator = { workspace = true } starcoin-chain = { workspace = true } starcoin-config = { workspace = true } starcoin-executor = { workspace = true } @@ -26,18 +26,18 @@ starcoin-txpool = { workspace = true } starcoin-txpool-api = { workspace = true } starcoin-vm-types = { workspace = true } tokio = { features = ["full"], workspace = true } -starcoin-types = { package = "starcoin-types", workspace = true } +starcoin-types = { workspace = true } [dev-dependencies] -starcoin-network-rpc = { package = "starcoin-network-rpc", workspace = true } +starcoin-network-rpc = { workspace = true } starcoin-genesis = { workspace = true } starcoin-network-rpc-api = { workspace = true } starcoin-node = { workspace = true } starcoin-state-service = { workspace = true } -starcoin-sync-api = { package = "starcoin-sync-api", workspace = true } +starcoin-sync-api = { workspace = true } starcoin-time-service = { workspace = true } stest = { workspace = true } -starcoin-sync = { package = "starcoin-sync", workspace = true } +starcoin-sync = { workspace = true } test-helper = { workspace = true } [package] diff --git a/network-p2p/Cargo.toml b/network-p2p/Cargo.toml index 70daa9619a..6cd858528b 100644 --- a/network-p2p/Cargo.toml +++ b/network-p2p/Cargo.toml @@ -5,7 +5,7 @@ asynchronous-codec = { workspace = true } bitflags = { workspace = true } bytes = { workspace = true } once_cell = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } async-std = { workspace = true } bs58 = { workspace = true } derive_more = { workspace = true } diff --git a/network-p2p/core/Cargo.toml b/network-p2p/core/Cargo.toml index 7cd391c6b2..2bbf9f87b7 100644 --- a/network-p2p/core/Cargo.toml +++ b/network-p2p/core/Cargo.toml @@ -1,12 +1,12 @@ [dependencies] anyhow = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } futures = { workspace = true } log = { workspace = true } network-p2p-derive = { workspace = true } num_enum = { workspace = true } serde = { features = ["derive"], workspace = true } -starcoin-types = { package = "starcoin-types", workspace = true } +starcoin-types = { workspace = true } network-p2p-types = { workspace = true } [dev-dependencies] diff --git a/network-p2p/peerset/Cargo.toml b/network-p2p/peerset/Cargo.toml index 2406be10c9..eaa5078e03 100644 --- a/network-p2p/peerset/Cargo.toml +++ b/network-p2p/peerset/Cargo.toml @@ -1,6 +1,6 @@ [dependencies] futures = { workspace = true } -libp2p = { default-features = false, workspace = true } +libp2p = { workspace = true } log = { workspace = true } serde_json = { features = ["arbitrary_precision"], workspace = true } sp-utils = { workspace = true } diff --git a/network-p2p/src/protocol/generic_proto/handler.rs b/network-p2p/src/protocol/generic_proto/handler.rs index d57be898b6..cd315fd741 100644 --- a/network-p2p/src/protocol/generic_proto/handler.rs +++ b/network-p2p/src/protocol/generic_proto/handler.rs @@ -499,7 +499,7 @@ impl ConnectionHandler for NotifsHandler { >::Output, (): (), ) { - let mut protocol_info = &mut self.protocols[protocol_index]; + let protocol_info = &mut self.protocols[protocol_index]; match protocol_info.state { State::Closed { pending_opening } => { self.events_queue.push_back(ConnectionHandlerEvent::Custom( diff --git a/network-p2p/src/protocol/generic_proto/upgrade.rs b/network-p2p/src/protocol/generic_proto/upgrade.rs index 27eda9ceb6..5f6beb1a2e 100644 --- a/network-p2p/src/protocol/generic_proto/upgrade.rs +++ b/network-p2p/src/protocol/generic_proto/upgrade.rs @@ -19,7 +19,7 @@ pub use self::collec::UpgradeCollec; pub use self::notifications::{ NotificationsHandshakeError, NotificationsIn, NotificationsInSubstream, NotificationsOut, - NotificationsOutError, NotificationsOutSubstream, + NotificationsOutSubstream, }; mod collec; diff --git a/network-p2p/types/Cargo.toml b/network-p2p/types/Cargo.toml index 4712fbeafb..e6057ed9af 100644 --- a/network-p2p/types/Cargo.toml +++ b/network-p2p/types/Cargo.toml @@ -2,9 +2,7 @@ bitflags = { workspace = true } bytes = { workspace = true } derive_more = { workspace = true } -libp2p = { default-features = false, features = [ - "request-response", -], workspace = true } +libp2p = { features = [ "request-response" ], workspace = true } rand = { workspace = true } sc-peerset = { workspace = true } schemars = { workspace = true } diff --git a/network-rpc/Cargo.toml b/network-rpc/Cargo.toml index 6bf4fc7d2e..62a36b06c3 100644 --- a/network-rpc/Cargo.toml +++ b/network-rpc/Cargo.toml @@ -8,12 +8,12 @@ serde = { features = ["derive"], workspace = true } serde_json = { workspace = true } tokio = { features = ["full"], workspace = true } api-limiter = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } -starcoin-crypto = { package = "starcoin-crypto", workspace = true } +bcs-ext = { workspace = true } +starcoin-crypto = { workspace = true } network-api = { workspace = true } network-p2p-types = { workspace = true } network-p2p-core = { workspace = true } -network-p2p-derive = { package = "network-p2p-derive", workspace = true } +network-p2p-derive = { workspace = true } prometheus = { workspace = true } starcoin-accumulator = { workspace = true } starcoin-chain-service = { workspace = true } @@ -25,24 +25,24 @@ starcoin-state-api = { workspace = true } starcoin-state-service = { workspace = true } starcoin-txpool = { workspace = true } starcoin-txpool-api = { workspace = true } -starcoin-storage = { package = "starcoin-storage", workspace = true } -starcoin-types = { package = "starcoin-types", workspace = true } +starcoin-storage = { workspace = true } +starcoin-types = { workspace = true } starcoin-state-tree = { workspace = true } starcoin-vm-types = { workspace = true } [dev-dependencies] -starcoin-account-api = { package = "starcoin-account-api", workspace = true } -starcoin-block-relayer = { package = "starcoin-block-relayer", workspace = true } -starcoin-consensus = { package = "starcoin-consensus", workspace = true } +starcoin-account-api = { workspace = true } +starcoin-block-relayer = { workspace = true } +starcoin-consensus = { workspace = true } futures-timer = { workspace = true } -starcoin-miner = { package = "starcoin-miner", workspace = true } -starcoin-network = { package = "starcoin-network", workspace = true } +starcoin-miner = { workspace = true } +starcoin-network = { workspace = true } starcoin-node = { workspace = true } -starcoin-statedb = { package = "starcoin-statedb", workspace = true } +starcoin-statedb = { workspace = true } starcoin-txpool = { workspace = true } starcoin-txpool-api = { workspace = true } starcoin-vm-types = { workspace = true } -starcoin-storage = { package = "starcoin-storage", workspace = true } +starcoin-storage = { workspace = true } stest = { workspace = true } test-helper = { workspace = true } diff --git a/network-rpc/api/Cargo.toml b/network-rpc/api/Cargo.toml index 66e8a3441f..40d86f26ed 100644 --- a/network-rpc/api/Cargo.toml +++ b/network-rpc/api/Cargo.toml @@ -1,7 +1,7 @@ [dependencies] once_cell = { workspace = true } anyhow = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } futures = { workspace = true } network-p2p-core = { workspace = true } network-p2p-derive = { workspace = true } diff --git a/network/Cargo.toml b/network/Cargo.toml index 662468cd85..5067d01df5 100644 --- a/network/Cargo.toml +++ b/network/Cargo.toml @@ -11,7 +11,7 @@ starcoin-config = { workspace = true } starcoin-logger = { workspace = true } starcoin-txpool-api = { workspace = true } starcoin-types = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } starcoin-crypto = { workspace = true } bitflags = { workspace = true } fnv = { workspace = true } diff --git a/network/api/Cargo.toml b/network/api/Cargo.toml index 7471089dae..7559ebcf45 100644 --- a/network/api/Cargo.toml +++ b/network/api/Cargo.toml @@ -6,8 +6,8 @@ hex = { workspace = true } itertools = { workspace = true } parking_lot = { workspace = true } rand = { workspace = true } -serde = { default-features = false, workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +serde = { features = ["derive"], workspace = true } +bcs-ext = { workspace = true } network-p2p-types = { workspace = true } network-types = { workspace = true } schemars = { workspace = true } diff --git a/network/api/src/lib.rs b/network/api/src/lib.rs index 6575756131..c38a5c5c3b 100644 --- a/network/api/src/lib.rs +++ b/network/api/src/lib.rs @@ -1,6 +1,6 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -#![deny(clippy::integer_arithmetic)] +#![deny(clippy::arithmetic_side_effects)] use crate::messages::{ BanPeer, GetPeerById, GetPeerSet, GetSelfPeer, NotificationMessage, PeerMessage, diff --git a/network/api/src/peer_provider.rs b/network/api/src/peer_provider.rs index 0987895bbf..fe51c7d0a3 100644 --- a/network/api/src/peer_provider.rs +++ b/network/api/src/peer_provider.rs @@ -86,18 +86,16 @@ impl From<(PeerInfo, u64)> for PeerDetail { } #[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Serialize, JsonSchema)] +#[derive(Default)] pub enum PeerStrategy { Random, + #[default] WeightedRandom, Best, Avg, } -impl Default for PeerStrategy { - fn default() -> Self { - PeerStrategy::WeightedRandom - } -} + impl std::fmt::Display for PeerStrategy { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { diff --git a/network/src/lib.rs b/network/src/lib.rs index da1c2a5fff..05f65b1809 100644 --- a/network/src/lib.rs +++ b/network/src/lib.rs @@ -1,7 +1,7 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -#![deny(clippy::integer_arithmetic)] +#![deny(clippy::arithmetic_side_effects)] pub mod helper; mod network_metrics; diff --git a/network/src/network_p2p_handle.rs b/network/src/network_p2p_handle.rs index 0c58124c82..4278bf7f4c 100644 --- a/network/src/network_p2p_handle.rs +++ b/network/src/network_p2p_handle.rs @@ -114,7 +114,7 @@ impl BusinessLayerHandle for Networkp2pHandle { Ok(()) } Err(error) => { - return Err(anyhow!( + Err(anyhow!( "failed to decode the generic data for the reason: {}", error )) @@ -129,7 +129,7 @@ impl BusinessLayerHandle for Networkp2pHandle { Ok(()) } Err(error) => { - return Err(anyhow!( + Err(anyhow!( "failed to decode the generic data for the reason: {}", error )) diff --git a/network/types/Cargo.toml b/network/types/Cargo.toml index 404a0910cf..e74b7e9587 100644 --- a/network/types/Cargo.toml +++ b/network/types/Cargo.toml @@ -1,6 +1,6 @@ [dependencies] anyhow = { workspace = true } -serde = { default-features = false, workspace = true } +serde = { features = ["derive"], workspace = true } network-p2p-types = { workspace = true } schemars = { workspace = true } starcoin-crypto = { workspace = true } diff --git a/node/Cargo.toml b/node/Cargo.toml index c879d297d3..1544e88535 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -39,7 +39,7 @@ starcoin-statedb = { workspace = true } starcoin-storage = { workspace = true } starcoin-stratum = { workspace = true } starcoin-sync = { workspace = true } -starcoin-sync-api = { package = "starcoin-sync-api", workspace = true } +starcoin-sync-api = { workspace = true } starcoin-txpool = { workspace = true } starcoin-txpool-api = { workspace = true } starcoin-types = { workspace = true } diff --git a/node/src/node.rs b/node/src/node.rs index 359717f9d4..829fb1fd91 100644 --- a/node/src/node.rs +++ b/node/src/node.rs @@ -267,8 +267,7 @@ impl NodeService { }); system.run().map_err(|e| e.into()) }); - let (registry, node_service) = - block_on(async { start_receiver.await }).expect("Wait node start error.")?; + let (registry, node_service) = block_on(start_receiver).expect("Wait node start error.")?; Ok(NodeHandle::new(join_handle, node_service, registry)) } diff --git a/rpc/api/Cargo.toml b/rpc/api/Cargo.toml index 93e42af08e..1f5979d9e1 100644 --- a/rpc/api/Cargo.toml +++ b/rpc/api/Cargo.toml @@ -5,7 +5,7 @@ path = "src/generate_schema.rs" [dependencies] anyhow = { workspace = true } async-trait = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } clap = { features = ["derive"], workspace = true } futures = { workspace = true } hex = { workspace = true } @@ -20,7 +20,7 @@ jsonrpc-core-client = { features = [ jsonrpc-derive = { workspace = true } jsonrpc-pubsub = { workspace = true } jsonrpc-server-utils = { workspace = true } -network-api = { package = "network-api", workspace = true } +network-api = { workspace = true } network-p2p-types = { workspace = true } network-types = { workspace = true } openrpc-derive = { workspace = true } diff --git a/rpc/api/src/types/pubsub.rs b/rpc/api/src/types/pubsub.rs index ebae1595f3..1048ca47bb 100644 --- a/rpc/api/src/types/pubsub.rs +++ b/rpc/api/src/types/pubsub.rs @@ -59,18 +59,16 @@ impl Serialize for Result { /// Subscription kind. #[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)] +#[derive(Default)] pub enum Params { /// No parameters passed. + #[default] None, /// Log parameters. Events(EventParams), } -impl Default for Params { - fn default() -> Self { - Params::None - } -} + impl<'a> Deserialize<'a> for Params { fn deserialize(deserializer: D) -> ::std::result::Result diff --git a/rpc/client/Cargo.toml b/rpc/client/Cargo.toml index 7813d58e9f..7a16313caa 100644 --- a/rpc/client/Cargo.toml +++ b/rpc/client/Cargo.toml @@ -3,7 +3,7 @@ actix = { workspace = true } actix-rt = { workspace = true } anyhow = { workspace = true } async-std = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } futures = { workspace = true } futures-timer = { workspace = true } hex = { workspace = true } @@ -24,7 +24,7 @@ jsonrpc-derive = { workspace = true } jsonrpc-pubsub = { workspace = true } jsonrpc-server-utils = { workspace = true } log = { workspace = true } -network-api = { package = "network-api", workspace = true } +network-api = { workspace = true } network-p2p-types = { workspace = true } network-types = { workspace = true } parity-tokio-ipc = { workspace = true } diff --git a/rpc/client/src/remote_state_reader.rs b/rpc/client/src/remote_state_reader.rs index 796d71cd9e..7b0f191bc5 100644 --- a/rpc/client/src/remote_state_reader.rs +++ b/rpc/client/src/remote_state_reader.rs @@ -16,17 +16,15 @@ use starcoin_vm_types::state_store::table::{TableHandle, TableInfo}; use std::str::FromStr; #[derive(Debug, Clone, Copy)] +#[derive(Default)] pub enum StateRootOption { + #[default] Latest, BlockHash(HashValue), BlockNumber(BlockNumber), } -impl Default for StateRootOption { - fn default() -> Self { - StateRootOption::Latest - } -} + impl FromStr for StateRootOption { type Err = anyhow::Error; diff --git a/rpc/server/Cargo.toml b/rpc/server/Cargo.toml index 14713fa5e0..e4eb30dcb5 100644 --- a/rpc/server/Cargo.toml +++ b/rpc/server/Cargo.toml @@ -4,12 +4,12 @@ actix-rt = { workspace = true } anyhow = { workspace = true } api-limiter = { workspace = true } bcs = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } dashmap = { workspace = true } futures = { workspace = true } futures-channel = { workspace = true } governor = { features = ["dashmap"], workspace = true } -hex = { default-features = false, workspace = true } +hex = { features = ["serde"], workspace = true } jsonrpc-core = { features = ["arbitrary_precision"], workspace = true } jsonrpc-core-client = { features = [ "http", diff --git a/rpc/server/src/module/txpool_rpc.rs b/rpc/server/src/module/txpool_rpc.rs index cb108c9a49..67e656b901 100644 --- a/rpc/server/src/module/txpool_rpc.rs +++ b/rpc/server/src/module/txpool_rpc.rs @@ -4,8 +4,6 @@ use crate::module::{convert_to_rpc_error, map_err}; use bcs_ext::BCSCodec; use starcoin_crypto::HashValue; -/// Re-export the API -pub use starcoin_rpc_api::txpool::*; use starcoin_rpc_api::types::{SignedUserTransactionView, StrView}; use starcoin_rpc_api::{txpool::TxPoolApi, FutureResult}; use starcoin_txpool_api::{TxPoolStatus, TxPoolSyncService}; @@ -13,9 +11,6 @@ use starcoin_types::account_address::AccountAddress; use starcoin_types::transaction::SignedUserTransaction; use std::convert::TryInto; -/// Re-export the API -pub use starcoin_rpc_api::txpool::*; - pub struct TxPoolRpcImpl where S: TxPoolSyncService + 'static, diff --git a/rust-toolchain.toml b/rust-toolchain.toml index aef0a9a008..d3ed9f3240 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -2,4 +2,4 @@ # The default profile includes rustc, rust-std, cargo, rust-docs, rustfmt and clippy. # https://rust-lang.github.io/rustup/concepts/profiles.html profile = "default" -channel = "1.66.1" +channel = "1.75.0" diff --git a/state/api/Cargo.toml b/state/api/Cargo.toml index 61ec75da17..f43919118f 100644 --- a/state/api/Cargo.toml +++ b/state/api/Cargo.toml @@ -1,7 +1,7 @@ [dependencies] anyhow = { workspace = true } async-trait = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } serde = { features = ["derive"], workspace = true } starcoin-crypto = { workspace = true } starcoin-service-registry = { workspace = true } diff --git a/state/state-tree/Cargo.toml b/state/state-tree/Cargo.toml index 75dfbd0e5b..a04b9dcc31 100644 --- a/state/state-tree/Cargo.toml +++ b/state/state-tree/Cargo.toml @@ -1,8 +1,8 @@ [dependencies] anyhow = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } forkable-jellyfish-merkle = { workspace = true } -starcoin-logger = { package = "starcoin-logger", workspace = true } +starcoin-logger = { workspace = true } parking_lot = { workspace = true } serde = { workspace = true } starcoin-crypto = { workspace = true } diff --git a/state/statedb/Cargo.toml b/state/statedb/Cargo.toml index 2fc7bc6f60..4ad779f664 100644 --- a/state/statedb/Cargo.toml +++ b/state/statedb/Cargo.toml @@ -1,6 +1,6 @@ [dependencies] anyhow = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } forkable-jellyfish-merkle = { workspace = true } lru = { workspace = true } parking_lot = { workspace = true } diff --git a/storage/Cargo.toml b/storage/Cargo.toml index b7ece6ca02..5767f60867 100644 --- a/storage/Cargo.toml +++ b/storage/Cargo.toml @@ -1,6 +1,6 @@ [dependencies] anyhow = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } byteorder = { workspace = true } chrono = { workspace = true } lru = { workspace = true } @@ -13,11 +13,11 @@ serde = { workspace = true } starcoin-types = { workspace = true } starcoin-crypto = { workspace = true } thiserror = { workspace = true } -starcoin-accumulator = { package = "starcoin-accumulator", workspace = true } +starcoin-accumulator = { workspace = true } starcoin-state-store-api = { workspace = true } coarsetime = { workspace = true } -forkable-jellyfish-merkle = { package = "forkable-jellyfish-merkle", workspace = true } -starcoin-logger = { package = "starcoin-logger", workspace = true } +forkable-jellyfish-merkle = { workspace = true } +starcoin-logger = { workspace = true } network-types = { workspace = true } network-p2p-types = { workspace = true } starcoin-config = { workspace = true } diff --git a/stratum/Cargo.toml b/stratum/Cargo.toml index 6e94f32762..4c34d9c954 100644 --- a/stratum/Cargo.toml +++ b/stratum/Cargo.toml @@ -2,7 +2,7 @@ anyhow = { workspace = true } byteorder = { workspace = true } futures = { workspace = true } -hex = { default-features = false, workspace = true } +hex = { features = ["serde"], workspace = true } jsonrpc-core = { features = ["arbitrary_precision"], workspace = true } jsonrpc-core-client = { workspace = true } jsonrpc-derive = { workspace = true } diff --git a/sync/Cargo.toml b/sync/Cargo.toml index a08dc1c437..8a94582092 100644 --- a/sync/Cargo.toml +++ b/sync/Cargo.toml @@ -2,22 +2,22 @@ anyhow = { workspace = true } async-std = { workspace = true } async-trait = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } forkable-jellyfish-merkle = { workspace = true } futures = { workspace = true } futures-retry = { workspace = true } futures-timer = { workspace = true } -itertools = { default-features = false, workspace = true } -starcoin-logger = { package = "starcoin-logger", workspace = true } +itertools = { features = ["use_alloc"], workspace = true } +starcoin-logger = { workspace = true } starcoin-config = { workspace = true } -starcoin-network = { package = "starcoin-network", workspace = true } +starcoin-network = { workspace = true } network-api = { workspace = true } network-p2p-core = { workspace = true } parking_lot = { workspace = true } pin-project = { workspace = true } pin-utils = { workspace = true } rand = { workspace = true } -starcoin-accumulator = { package = "starcoin-accumulator", workspace = true } +starcoin-accumulator = { workspace = true } starcoin-chain = { workspace = true } starcoin-chain-api = { workspace = true } starcoin-chain-service = { workspace = true } @@ -25,13 +25,13 @@ starcoin-crypto = { workspace = true } starcoin-executor = { workspace = true } starcoin-genesis = { workspace = true } starcoin-metrics = { workspace = true } -starcoin-network-rpc = { package = "starcoin-network-rpc", workspace = true } +starcoin-network-rpc = { workspace = true } starcoin-network-rpc-api = { workspace = true } starcoin-service-registry = { workspace = true } starcoin-state-api = { workspace = true } -starcoin-state-tree = { package = "starcoin-state-tree", workspace = true } +starcoin-state-tree = { workspace = true } starcoin-storage = { workspace = true } -starcoin-sync-api = { package = "starcoin-sync-api", workspace = true } +starcoin-sync-api = { workspace = true } starcoin-time-service = { workspace = true } starcoin-transaction-builder = { workspace = true } starcoin-txpool = { workspace = true } diff --git a/sync/api/Cargo.toml b/sync/api/Cargo.toml index f4ed821ebb..514ff76cc6 100644 --- a/sync/api/Cargo.toml +++ b/sync/api/Cargo.toml @@ -1,14 +1,14 @@ [dependencies] anyhow = { workspace = true } async-trait = { workspace = true } -network-api = { package = "network-api", workspace = true } +network-api = { workspace = true } schemars = { workspace = true } -serde = { default-features = false, workspace = true } +serde = { features = ["derive"], workspace = true } starcoin-accumulator = { workspace = true } starcoin-crypto = { workspace = true } -starcoin-logger = { package = "starcoin-logger", workspace = true } +starcoin-logger = { workspace = true } starcoin-service-registry = { workspace = true } -starcoin-types = { package = "starcoin-types", workspace = true } +starcoin-types = { workspace = true } stream-task = { workspace = true } [package] diff --git a/sync/src/lib.rs b/sync/src/lib.rs index 5c5bdff0df..b6ecf59f0d 100644 --- a/sync/src/lib.rs +++ b/sync/src/lib.rs @@ -1,7 +1,7 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -#![deny(clippy::integer_arithmetic)] +#![deny(clippy::arithmetic_side_effects)] pub mod announcement; pub mod block_connector; pub mod sync; diff --git a/sync/src/verified_rpc_client.rs b/sync/src/verified_rpc_client.rs index fc4bc6f8f5..5dcaabe6dc 100644 --- a/sync/src/verified_rpc_client.rs +++ b/sync/src/verified_rpc_client.rs @@ -65,7 +65,6 @@ where ) -> Result>, RpcVerifyError> { req.into_iter() .zip(resp.into_iter()) - .into_iter() .map(|(req_item, resp_item)| { if let Some(resp_item) = resp_item { if (self)(&req_item, &resp_item) { diff --git a/test-helper/Cargo.toml b/test-helper/Cargo.toml index 795680e0a4..50b6934088 100644 --- a/test-helper/Cargo.toml +++ b/test-helper/Cargo.toml @@ -2,7 +2,7 @@ anyhow = { workspace = true } async-trait = { workspace = true } backtrace = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } futures = { workspace = true } futures-timer = { workspace = true } hex = { workspace = true } @@ -39,7 +39,7 @@ starcoin-state-service = { workspace = true } starcoin-statedb = { workspace = true } starcoin-storage = { workspace = true } starcoin-sync = { workspace = true } -starcoin-sync-api = { package = "starcoin-sync-api", workspace = true } +starcoin-sync-api = { workspace = true } starcoin-transaction-builder = { workspace = true } starcoin-txpool = { workspace = true } starcoin-txpool-api = { workspace = true } diff --git a/testsuite/Cargo.toml b/testsuite/Cargo.toml index 74c650f8e1..4c4427f613 100644 --- a/testsuite/Cargo.toml +++ b/testsuite/Cargo.toml @@ -17,7 +17,7 @@ serde_json = { features = ["arbitrary_precision"], workspace = true } starcoin-account-api = { workspace = true } starcoin-account-provider = { workspace = true } starcoin-chain = { workspace = true } -starcoin-cmd = { package = "starcoin-cmd", workspace = true } +starcoin-cmd = { workspace = true } starcoin-config = { workspace = true } starcoin-consensus = { workspace = true } starcoin-crypto = { workspace = true } diff --git a/txpool/Cargo.toml b/txpool/Cargo.toml index e1146ea56c..0ec076c251 100644 --- a/txpool/Cargo.toml +++ b/txpool/Cargo.toml @@ -6,14 +6,14 @@ futures = { workspace = true } futures-channel = { workspace = true } linked-hash-map = { workspace = true } log = { workspace = true } -network-api = { package = "network-api", workspace = true } +network-api = { workspace = true } parking_lot = { workspace = true } rand = { workspace = true } rand_core = { default-features = false, workspace = true } serde = { workspace = true } serde_derive = { workspace = true } starcoin-config = { workspace = true } -starcoin-crypto = { package = "starcoin-crypto", workspace = true } +starcoin-crypto = { workspace = true } starcoin-executor = { workspace = true } starcoin-logger = { workspace = true } starcoin-metrics = { workspace = true } @@ -21,15 +21,15 @@ starcoin-service-registry = { workspace = true } starcoin-state-api = { workspace = true } starcoin-state-tree = { workspace = true } starcoin-statedb = { workspace = true } -starcoin-types = { package = "starcoin-types", workspace = true } +starcoin-types = { workspace = true } starcoin-storage = { workspace = true } -starcoin-txpool-api = { package = "starcoin-txpool-api", workspace = true } +starcoin-txpool-api = { workspace = true } stest = { workspace = true } tokio = { workspace = true } trace-time = { workspace = true } transaction-pool = { workspace = true } -proptest = { default-features = false, optional = true, workspace = true } -proptest-derive = { default-features = false, optional = true, workspace = true } +proptest = { features = ["std"], optional = true, workspace = true } +proptest-derive = { optional = true, workspace = true } [dev-dependencies] proptest = { workspace = true } diff --git a/txpool/api/Cargo.toml b/txpool/api/Cargo.toml index 3442468de4..41344553bb 100644 --- a/txpool/api/Cargo.toml +++ b/txpool/api/Cargo.toml @@ -3,9 +3,9 @@ anyhow = { workspace = true } async-trait = { workspace = true } futures-channel = { workspace = true } schemars = { workspace = true } -serde = { default-features = false, workspace = true } +serde = { features = ["derive"], workspace = true } starcoin-crypto = { workspace = true } -starcoin-types = { package = "starcoin-types", workspace = true } +starcoin-types = { workspace = true } [package] authors = { workspace = true } diff --git a/txpool/mock-service/Cargo.toml b/txpool/mock-service/Cargo.toml index dad0e1267e..3c4a6ad361 100644 --- a/txpool/mock-service/Cargo.toml +++ b/txpool/mock-service/Cargo.toml @@ -4,7 +4,7 @@ async-trait = { workspace = true } starcoin-crypto = { workspace = true } starcoin-types = { workspace = true } futures-channel = { workspace = true } -starcoin-txpool-api = { package = "starcoin-txpool-api", workspace = true } +starcoin-txpool-api = { workspace = true } stest = { workspace = true } tokio = { workspace = true } diff --git a/types/Cargo.toml b/types/Cargo.toml index c3f4b09a7e..512815d6df 100644 --- a/types/Cargo.toml +++ b/types/Cargo.toml @@ -1,17 +1,17 @@ [dependencies] anyhow = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } -byteorder = { default-features = false, workspace = true } +bcs-ext = { workspace = true } +byteorder = { features = ["std"], workspace = true } bytes = { workspace = true } forkable-jellyfish-merkle = { workspace = true } -hex = { default-features = false, features = ["serde"], workspace = true } +hex = { features = ["serde"], workspace = true } num_enum = { workspace = true } -proptest = { default-features = false, optional = true, workspace = true } -proptest-derive = { default-features = false, optional = true, workspace = true } +proptest = { features = ["std"], optional = true, workspace = true } +proptest-derive = { optional = true, workspace = true } rand = { workspace = true } rand_core = { default-features = false, workspace = true } schemars = { workspace = true } -serde = { default-features = false, workspace = true } +serde = { features = ["derive"], workspace = true } serde_json = { workspace = true } starcoin-accumulator = { workspace = true } starcoin-crypto = { workspace = true } diff --git a/types/src/lib.rs b/types/src/lib.rs index ec49aa8bed..973e7a48a6 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -1,7 +1,7 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 #![forbid(unsafe_code)] -#![deny(clippy::integer_arithmetic)] +#![deny(clippy::arithmetic_side_effects)] mod event_info; diff --git a/types/uint/Cargo.toml b/types/uint/Cargo.toml index 884fe347fa..768b36adf2 100644 --- a/types/uint/Cargo.toml +++ b/types/uint/Cargo.toml @@ -1,6 +1,6 @@ [dependencies] -hex = { default-features = false, workspace = true } -serde = { default-features = false, workspace = true } +hex = { features = ["serde"], workspace = true } +serde = { features = ["derive"], workspace = true } starcoin-crypto = { workspace = true } uint = { workspace = true } diff --git a/vm/compiler/Cargo.toml b/vm/compiler/Cargo.toml index 0f7958f527..a4738fba84 100644 --- a/vm/compiler/Cargo.toml +++ b/vm/compiler/Cargo.toml @@ -2,13 +2,10 @@ anyhow = { workspace = true } move-binary-format = { workspace = true } move-command-line-common = { workspace = true } -move-compiler = { package = "move-compiler", workspace = true } +move-compiler = { workspace = true } once_cell = { workspace = true } petgraph = { workspace = true } -regex = { default-features = false, features = [ - "std", - "perf", -], workspace = true } +regex = { features = [ "std", "perf" ], workspace = true } starcoin-crypto = { workspace = true } starcoin-logger = { workspace = true } starcoin-vm-types = { workspace = true } diff --git a/vm/e2e-tests/Cargo.toml b/vm/e2e-tests/Cargo.toml index 73e90843c2..d16aaa80ee 100644 --- a/vm/e2e-tests/Cargo.toml +++ b/vm/e2e-tests/Cargo.toml @@ -19,7 +19,7 @@ once_cell = { workspace = true } proptest = { workspace = true } proptest-derive = { workspace = true } rand = { workspace = true } -serde = { workspace = true, default-features = false } +serde = { workspace = true, features = ["derive"] } starcoin-config = { workspace = true } starcoin-crypto = { workspace = true, features = ["fuzzing"] } diff --git a/vm/move-coverage/Cargo.toml b/vm/move-coverage/Cargo.toml index 0a7294e226..f706091ce6 100644 --- a/vm/move-coverage/Cargo.toml +++ b/vm/move-coverage/Cargo.toml @@ -5,7 +5,7 @@ clap = { features = ["derive"], workspace = true } codespan = { features = ["serialization"], workspace = true } colored = { workspace = true } petgraph = { workspace = true } -serde = { default-features = false, workspace = true } +serde = { features = ["derive"], workspace = true } move-binary-format = { workspace = true } move-bytecode-source-map = { workspace = true } move-command-line-common = { workspace = true } diff --git a/vm/move-explain/Cargo.toml b/vm/move-explain/Cargo.toml index d5d3ff8f28..3a46e367b4 100644 --- a/vm/move-explain/Cargo.toml +++ b/vm/move-explain/Cargo.toml @@ -1,8 +1,8 @@ [dependencies] -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } clap = { features = ["derive"], workspace = true } move-core-types = { workspace = true } -stdlib = { package = "stdlib", workspace = true } +stdlib = { workspace = true } [features] default = [] diff --git a/vm/move-package-manager/Cargo.toml b/vm/move-package-manager/Cargo.toml index bad80af33f..d79dffd97c 100644 --- a/vm/move-package-manager/Cargo.toml +++ b/vm/move-package-manager/Cargo.toml @@ -26,7 +26,7 @@ walkdir = { workspace = true } futures = { workspace = true } tempfile = { workspace = true } tokio = { features = ["full"], workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } datatest-stable = { git = "https://github.com/starcoinorg/diem-devtools", branch = "feature/pub-test-opts" } move-binary-format = { workspace = true } move-bytecode-verifier = { workspace = true } diff --git a/vm/move-package-manager/src/lib.rs b/vm/move-package-manager/src/lib.rs index 6045bb1c69..2f1f2723e9 100644 --- a/vm/move-package-manager/src/lib.rs +++ b/vm/move-package-manager/src/lib.rs @@ -61,7 +61,9 @@ pub struct TestOpts { } #[derive(Debug, Eq, PartialEq)] +#[derive(Default)] enum Format { + #[default] Pretty, Terse, Json, @@ -96,11 +98,7 @@ impl FromStr for Format { } } -impl Default for Format { - fn default() -> Self { - Format::Pretty - } -} + #[derive(Args, Debug)] pub struct IntegrationTestCommand { diff --git a/vm/starcoin-transactional-test-harness/Cargo.toml b/vm/starcoin-transactional-test-harness/Cargo.toml index 9f3eb713f6..5db7657a1b 100644 --- a/vm/starcoin-transactional-test-harness/Cargo.toml +++ b/vm/starcoin-transactional-test-harness/Cargo.toml @@ -42,7 +42,7 @@ jsonrpc-derive = { workspace = true } jsonrpc-http-server = { workspace = true } move-resource-viewer = { workspace = true } starcoin-abi-decoder = { workspace = true } -starcoin-accumulator = { package = "starcoin-accumulator", workspace = true } +starcoin-accumulator = { workspace = true } starcoin-chain-api = { workspace = true } starcoin-config = { workspace = true } starcoin-crypto = { workspace = true } diff --git a/vm/starcoin-transactional-test-harness/src/lib.rs b/vm/starcoin-transactional-test-harness/src/lib.rs index 6e023aabfe..8727440b00 100644 --- a/vm/starcoin-transactional-test-harness/src/lib.rs +++ b/vm/starcoin-transactional-test-harness/src/lib.rs @@ -979,7 +979,7 @@ impl<'a> StarcoinTestAdapter<'a> { module, (data_path.to_owned(), data), ); - Ok((warnings_opt, Some(serde_json::to_value(&package_result)?))) + Ok((warnings_opt, Some(serde_json::to_value(package_result)?))) } fn handle_deploy( diff --git a/vm/stdlib/Cargo.toml b/vm/stdlib/Cargo.toml index c6ae597b9a..7fad1bc942 100644 --- a/vm/stdlib/Cargo.toml +++ b/vm/stdlib/Cargo.toml @@ -1,6 +1,6 @@ [dependencies] anyhow = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } clap = { features = ["derive"], workspace = true } fs_extra = { workspace = true } include_dir = { workspace = true } @@ -10,7 +10,7 @@ move-bytecode-verifier = { workspace = true } move-compiler = { workspace = true } move-prover = { workspace = true } once_cell = { workspace = true } -serde = { default-features = false, workspace = true } +serde = { features = ["derive"], workspace = true } sha2 = { workspace = true } simplelog = { workspace = true } starcoin-crypto = { workspace = true } diff --git a/vm/stdlib/src/main.rs b/vm/stdlib/src/main.rs index 8055452294..2bb853cd9b 100644 --- a/vm/stdlib/src/main.rs +++ b/vm/stdlib/src/main.rs @@ -326,7 +326,6 @@ fn main() { .collect::>(); let incompatible_module_ids = new_modules .values() - .into_iter() .filter_map(|module| { let module_id = module.self_id(); if let Some(old_module) = pre_stable_modules.get(&module_id) { diff --git a/vm/transaction-benchmarks/Cargo.toml b/vm/transaction-benchmarks/Cargo.toml index c59878921c..83d1636140 100644 --- a/vm/transaction-benchmarks/Cargo.toml +++ b/vm/transaction-benchmarks/Cargo.toml @@ -11,7 +11,7 @@ rust-version = { workspace = true } [dependencies] num_cpus = { workspace = true } -starcoin-crypto = { package = "starcoin-crypto", workspace = true } +starcoin-crypto = { workspace = true } starcoin-types = { workspace = true } starcoin-vm-runtime = { workspace = true } starcoin-vm-types = { workspace = true } diff --git a/vm/transaction-builder/Cargo.toml b/vm/transaction-builder/Cargo.toml index 93ba1112a6..2b3d3e1dd1 100644 --- a/vm/transaction-builder/Cargo.toml +++ b/vm/transaction-builder/Cargo.toml @@ -1,12 +1,12 @@ [dependencies] anyhow = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } starcoin-config = { workspace = true } starcoin-crypto = { workspace = true } starcoin-logger = { workspace = true } starcoin-vm-types = { workspace = true } starcoin-types = { workspace = true } -stdlib = { package = "stdlib", workspace = true } +stdlib = { workspace = true } [dev-dependencies] stest = { workspace = true } diff --git a/vm/types/Cargo.toml b/vm/types/Cargo.toml index fb30eba5be..7864006008 100644 --- a/vm/types/Cargo.toml +++ b/vm/types/Cargo.toml @@ -8,7 +8,7 @@ mirai-annotations = { workspace = true } num_enum = { workspace = true } once_cell = { workspace = true } rand = { workspace = true } -serde = { default-features = false, workspace = true } +serde = { features = ["derive"], workspace = true } serde_bytes = { workspace = true } serde_json = { features = ["arbitrary_precision"], workspace = true } move-bytecode-verifier = { workspace = true } @@ -16,10 +16,10 @@ move-core-types = { workspace = true } move-ir-types = { workspace = true } move-vm-types = { workspace = true } move-table-extension = { workspace = true } -proptest = { default-features = false, optional = true, workspace = true } -proptest-derive = { default-features = false, optional = true, workspace = true } +proptest = { features = ["std"], optional = true, workspace = true } +proptest-derive = { optional = true, workspace = true } starcoin-time-service = { optional = true, workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } +bcs-ext = { workspace = true } starcoin-gas-algebra-ext = { workspace = true } forkable-jellyfish-merkle = { workspace = true } schemars = { workspace = true } diff --git a/vm/types/src/account_config/constants/mod.rs b/vm/types/src/account_config/constants/mod.rs index dbf745b1ce..fdc008300c 100644 --- a/vm/types/src/account_config/constants/mod.rs +++ b/vm/types/src/account_config/constants/mod.rs @@ -1,10 +1,10 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -pub mod account; -pub mod addresses; -pub mod chain; -pub mod event; +mod account; +mod addresses; +mod chain; +mod event; pub use crate::token::stc::*; pub use crate::token::*; diff --git a/vm/types/src/account_config/resources/mod.rs b/vm/types/src/account_config/resources/mod.rs index cc98f01ed5..46443d8634 100644 --- a/vm/types/src/account_config/resources/mod.rs +++ b/vm/types/src/account_config/resources/mod.rs @@ -1,12 +1,12 @@ // Copyright (c) The Diem Core Contributors // SPDX-License-Identifier: Apache-2.0 -pub mod account; +mod account; pub mod auto_accept_token; -pub mod balance; -pub mod key_rotation_capability; -pub mod module_upgrade_strategy; -pub mod withdraw_capability; +mod balance; +mod key_rotation_capability; +mod module_upgrade_strategy; +mod withdraw_capability; pub use crate::token::token_info::*; pub use account::*; diff --git a/vm/types/src/genesis_config.rs b/vm/types/src/genesis_config.rs index 26c7584398..d13dd35d98 100644 --- a/vm/types/src/genesis_config.rs +++ b/vm/types/src/genesis_config.rs @@ -11,7 +11,9 @@ use std::fmt::{self, Formatter}; use std::fmt::{Debug, Display}; use std::str::FromStr; #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] +#[derive(Default)] pub enum StdlibVersion { + #[default] Latest, Version(VersionNumber), } @@ -71,11 +73,7 @@ impl Ord for StdlibVersion { } } -impl Default for StdlibVersion { - fn default() -> Self { - StdlibVersion::Latest - } -} + impl FromStr for StdlibVersion { type Err = anyhow::Error; @@ -114,7 +112,9 @@ impl Display for StdlibVersion { )] #[repr(u8)] #[serde(tag = "type")] +#[derive(Default)] pub enum ConsensusStrategy { + #[default] Dummy = 0, Argon = 1, Keccak = 2, @@ -127,11 +127,7 @@ impl ConsensusStrategy { } } -impl Default for ConsensusStrategy { - fn default() -> Self { - ConsensusStrategy::Dummy - } -} + impl fmt::Display for ConsensusStrategy { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/vm/types/src/proptest_types.rs b/vm/types/src/proptest_types.rs index 78bff6b101..6b4a746890 100644 --- a/vm/types/src/proptest_types.rs +++ b/vm/types/src/proptest_types.rs @@ -249,7 +249,7 @@ impl RawUserTransactionGen { expired_time: u64, payload: Option, ) -> RawUserTransaction { - let mut sender_info = universe.get_account_info_mut(sender_index); + let sender_info = universe.get_account_info_mut(sender_index); let sequence_number = sender_info.sequence_number; let temp_payload = payload.unwrap_or(self.payload); diff --git a/vm/vm-runtime/Cargo.toml b/vm/vm-runtime/Cargo.toml index ea938b6aef..5bfa0f8076 100644 --- a/vm/vm-runtime/Cargo.toml +++ b/vm/vm-runtime/Cargo.toml @@ -11,8 +11,8 @@ rust-version = { workspace = true } [dependencies] anyhow = { workspace = true } -bcs-ext = { package = "bcs-ext", workspace = true } -starcoin-crypto = { package = "starcoin-crypto", workspace = true } +bcs-ext = { workspace = true } +starcoin-crypto = { workspace = true } starcoin-config = { workspace = true } move-core-types = { workspace = true } once_cell = { workspace = true } @@ -37,7 +37,7 @@ num_cpus = { workspace = true } hex = "0.4.3" [dev-dependencies] -stdlib = { package = "stdlib", workspace = true } +stdlib = { workspace = true } [features] default = ["metrics"] diff --git a/vm/vm-runtime/src/move_vm_ext/mod.rs b/vm/vm-runtime/src/move_vm_ext/mod.rs index f3acf98181..8f94d87d3c 100644 --- a/vm/vm-runtime/src/move_vm_ext/mod.rs +++ b/vm/vm-runtime/src/move_vm_ext/mod.rs @@ -1,8 +1,8 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -///! MoveVM and Session wrapped, to make sure Starcoin natives and extensions are always installed and -///! taken care of after session finish. +//! MoveVM and Session wrapped, to make sure Starcoin natives and extensions are always installed and +//! taken care of after session finish. mod resolver; mod session; mod vm; diff --git a/vm/vm-runtime/src/starcoin_vm.rs b/vm/vm-runtime/src/starcoin_vm.rs index f7e526d385..215b42b203 100644 --- a/vm/vm-runtime/src/starcoin_vm.rs +++ b/vm/vm-runtime/src/starcoin_vm.rs @@ -1363,10 +1363,10 @@ impl StarcoinVM { vm.execute_block_transactions(state_view, txns, block_gas_limit) } - pub fn load_module<'r, R: MoveResolverExt>( + pub fn load_module( &self, module_id: &ModuleId, - remote: &'r R, + remote: &R, ) -> VMResult> { self.move_vm.load_module(module_id, remote) } From fc8b032d95c34f46a76e8b37f59257791a79c8cd Mon Sep 17 00:00:00 2001 From: simonjiao Date: Tue, 2 Apr 2024 14:57:42 +0800 Subject: [PATCH 2/3] fix clippy and fmt warnings --- account/api/src/provider.rs | 4 +--- account/src/account_test.rs | 2 +- chain/src/chain.rs | 4 +++- chain/tests/test_txn_info_and_proof.rs | 2 +- cmd/db-exporter/src/main.rs | 4 ++-- .../src/account/sign_multisig_txn_cmd.rs | 7 ++---- cmd/starcoin/src/cli_state.rs | 3 +-- cmd/tx-factory/src/main.rs | 8 +++---- .../src/jellyfish_merkle_test.rs | 22 +++++++++---------- commons/forkable-jellyfish-merkle/src/lib.rs | 2 +- commons/service-registry/src/bus/sys_bus.rs | 4 ++-- config/src/api_config.rs | 5 +---- config/src/genesis_config.rs | 2 -- config/src/network_config.rs | 4 ++-- consensus/src/consensus_test.rs | 2 +- executor/benchmark/src/lib.rs | 2 +- genesis/src/lib.rs | 2 +- miner/src/create_block_template/mod.rs | 2 +- network-p2p/derive/src/helper.rs | 1 - network-p2p/peerset/tests/fuzz.rs | 5 +---- network-p2p/src/peer_info.rs | 2 +- network-p2p/src/service_test.rs | 2 ++ network/api/src/peer_provider.rs | 9 +++----- network/api/src/tests.rs | 2 +- network/src/network_p2p_handle.rs | 20 +++++++---------- rpc/api/src/types/pubsub.rs | 5 +---- rpc/client/src/chain_watcher.rs | 5 +---- rpc/client/src/remote_state_reader.rs | 5 +---- rpc/client/tests/client_server_test.rs | 4 ++-- .../api/src/mock/mock_chain_state_service.rs | 1 + state/state-tree/src/mock/mod.rs | 2 +- state/state-tree/src/state_tree_test.rs | 8 +++---- state/statedb/src/tests.rs | 1 - storage/src/tests/test_batch.rs | 6 ++--- storage/src/tests/test_storage.rs | 4 ++-- storage/src/transaction/test.rs | 2 +- .../src/block_connector/test_illegal_block.rs | 2 +- .../block_connector/test_write_block_chain.rs | 2 +- sync/src/block_connector/write_block_chain.rs | 2 +- sync/src/tasks/mock.rs | 8 ++----- sync/src/tasks/tests.rs | 2 +- sync/src/verified_rpc_client.rs | 2 +- txpool/src/test.rs | 2 -- vm/gas-algebra-ext/src/natives.rs | 17 +++++--------- vm/gas-algebra-ext/src/params.rs | 19 +++++----------- vm/move-package-manager/src/lib.rs | 5 +---- vm/mvhashmap/src/lib.rs | 2 +- vm/mvhashmap/src/unit_tests/proptest_types.rs | 2 +- vm/resource-viewer/src/lib.rs | 5 +---- .../src/fork_chain.rs | 5 +---- .../src/lib.rs | 4 ++-- vm/transaction-builder-generator/src/dart.rs | 4 ++-- vm/transaction-builder/src/lib.rs | 4 ++-- .../resources/auto_accept_token.rs | 2 +- .../src/account_config/resources/balance.rs | 2 +- vm/types/src/genesis_config.rs | 7 +----- vm/types/src/on_chain_resource/nft.rs | 4 ++-- vm/types/src/token/token_code.rs | 2 +- vm/types/src/transaction/authenticator.rs | 1 - vm/types/src/write_set.rs | 7 +++--- vm/vm-runtime/src/errors.rs | 2 +- 61 files changed, 109 insertions(+), 170 deletions(-) diff --git a/account/api/src/provider.rs b/account/api/src/provider.rs index d8ef109af2..7a23210f12 100644 --- a/account/api/src/provider.rs +++ b/account/api/src/provider.rs @@ -5,8 +5,7 @@ use starcoin_types::account_config::token_code::TokenCode; use starcoin_types::sign_message::{SignedMessage, SigningMessage}; use starcoin_types::transaction::{RawUserTransaction, SignedUserTransaction}; -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[derive(Default)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] pub enum AccountProviderStrategy { #[default] RPC, @@ -14,7 +13,6 @@ pub enum AccountProviderStrategy { PrivateKey, } - pub trait AccountProvider { fn create_account(&self, password: String) -> Result; diff --git a/account/src/account_test.rs b/account/src/account_test.rs index bba50ab6cb..705f421f48 100644 --- a/account/src/account_test.rs +++ b/account/src/account_test.rs @@ -187,7 +187,7 @@ pub fn test_wallet_account() -> Result<()> { let hash_value = HashValue::sha3_256_of(&public_key.to_bytes()); let key = AuthenticationKey::new(*HashValue::sha3_256_of(&public_key.to_bytes()).as_ref()); - let sign = vec![ + let sign = [ 227, 94, 250, 168, 43, 200, 137, 74, 61, 254, 197, 71, 245, 135, 201, 43, 222, 190, 56, 235, 247, 254, 56, 247, 108, 36, 250, 192, 143, 236, 101, 153, 61, 241, 129, 47, 38, 146, 213, 9, 79, 56, 90, 210, 179, 53, 73, 208, 248, 231, 22, 9, 55, 177, 154, 212, 248, 2, 66, diff --git a/chain/src/chain.rs b/chain/src/chain.rs index 1b85f28c88..0231e49015 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -1294,7 +1294,9 @@ impl BlockChain { let pre_total_difficulty = parent_status .map(|status| status.total_difficulty()) .unwrap_or_default(); - let total_difficulty = pre_total_difficulty + header.difficulty(); + let total_difficulty = pre_total_difficulty + .checked_add(header.difficulty()) + .ok_or(format_err!("failed to calculate total difficulty"))?; block_accumulator.append(&[block_id])?; let txn_accumulator_info: AccumulatorInfo = txn_accumulator.get_info(); diff --git a/chain/tests/test_txn_info_and_proof.rs b/chain/tests/test_txn_info_and_proof.rs index d817366953..749d64d622 100644 --- a/chain/tests/test_txn_info_and_proof.rs +++ b/chain/tests/test_txn_info_and_proof.rs @@ -34,7 +34,7 @@ fn test_transaction_info_and_proof() -> Result<()> { //put the genesis txn, the genesis block metadata txn do not generate txn info all_txns.push(Transaction::UserTransaction( - genesis_block.body.transactions.get(0).cloned().unwrap(), + genesis_block.body.transactions.first().cloned().unwrap(), )); (0..block_count).for_each(|_block_idx| { diff --git a/cmd/db-exporter/src/main.rs b/cmd/db-exporter/src/main.rs index 1c4b68c484..da760214ad 100644 --- a/cmd/db-exporter/src/main.rs +++ b/cmd/db-exporter/src/main.rs @@ -872,7 +872,7 @@ pub fn apply_block( } if let Some(last_block) = blocks.last() { - let start = blocks.get(0).unwrap().header().number(); + let start = blocks.first().unwrap().header().number(); let end = last_block.header().number(); println!( "current number {}, import [{},{}] block number", @@ -2148,7 +2148,7 @@ pub fn apply_turbo_stm_block( } if let Some(last_block) = blocks.last() { - let start = blocks.get(0).unwrap().header().number(); + let start = blocks.first().unwrap().header().number(); let end = last_block.header().number(); println!( "current number {}, import [{},{}] block number", diff --git a/cmd/starcoin/src/account/sign_multisig_txn_cmd.rs b/cmd/starcoin/src/account/sign_multisig_txn_cmd.rs index 1326356e2c..f4de302deb 100644 --- a/cmd/starcoin/src/account/sign_multisig_txn_cmd.rs +++ b/cmd/starcoin/src/account/sign_multisig_txn_cmd.rs @@ -146,11 +146,8 @@ impl CommandAction for GenerateMultisigTxnCommand { unreachable!() }; let mut raw_txn_view: RawUserTransactionView = raw_txn.clone().try_into()?; - raw_txn_view.decoded_payload = Some( - ctx.state() - .decode_txn_payload(raw_txn.payload())? - .try_into()?, - ); + raw_txn_view.decoded_payload = + Some(ctx.state().decode_txn_payload(raw_txn.payload())?.into()); // Use `eprintln` instead of `println`, for keep the cli stdout's format(such as json) is not broken by print. eprintln!( "Prepare to sign the transaction: \n {}", diff --git a/cmd/starcoin/src/cli_state.rs b/cmd/starcoin/src/cli_state.rs index 6b5d8b2a71..47a75af33f 100644 --- a/cmd/starcoin/src/cli_state.rs +++ b/cmd/starcoin/src/cli_state.rs @@ -287,8 +287,7 @@ impl CliState { raw_txn: raw_txn.clone(), })?; let mut raw_txn_view: RawUserTransactionView = raw_txn.clone().try_into()?; - raw_txn_view.decoded_payload = - Some(self.decode_txn_payload(raw_txn.payload())?.try_into()?); + raw_txn_view.decoded_payload = Some(self.decode_txn_payload(raw_txn.payload())?.into()); let mut execute_result = ExecuteResultView::new(raw_txn_view, raw_txn.to_hex(), dry_output); if only_dry_run diff --git a/cmd/tx-factory/src/main.rs b/cmd/tx-factory/src/main.rs index 45958fed46..f2606c14bc 100644 --- a/cmd/tx-factory/src/main.rs +++ b/cmd/tx-factory/src/main.rs @@ -133,7 +133,7 @@ fn main() { let batch_size = opts.batch_size; let mut connected = RpcClient::connect_ipc(opts.ipc_path.clone()); - while matches!(connected, Err(_)) { + while connected.is_err() { std::thread::sleep(Duration::from_millis(1000)); connected = RpcClient::connect_ipc(opts.ipc_path.clone()); info!("re connecting..."); @@ -316,7 +316,7 @@ impl TxnMocker { let result = self.client.submit_transaction(user_txn); // increase sequence number if added in pool. - if matches!(result, Ok(_)) { + if result.is_ok() { self.next_sequence_number += 1; } if blocking { @@ -374,7 +374,7 @@ impl TxnMocker { let txn_hash = user_txn.id(); let result = self.client.submit_transaction(user_txn); - if matches!(result, Ok(_)) && blocking { + if result.is_ok() && blocking { self.client.watch_txn( txn_hash, Some(Duration::from_secs(self.watch_timeout as u64)), @@ -495,7 +495,7 @@ impl TxnMocker { expiration_timestamp, )?; let result = self.submit_txn(txn, self.account_address, true); - if matches!(result, Ok(_)) { + if result.is_ok() { info!("account transfer submit ok."); } else { info!("error: {:?}", result); diff --git a/commons/forkable-jellyfish-merkle/src/jellyfish_merkle_test.rs b/commons/forkable-jellyfish-merkle/src/jellyfish_merkle_test.rs index 2aa9a185d0..30b317cf91 100644 --- a/commons/forkable-jellyfish-merkle/src/jellyfish_merkle_test.rs +++ b/commons/forkable-jellyfish-merkle/src/jellyfish_merkle_test.rs @@ -309,7 +309,7 @@ fn test_batch_insertion() { let tree = JellyfishMerkleTree::new(&db); let mut batches2 = vec![]; - for (_idx, sub_vec) in batches.iter().enumerate() { + for sub_vec in batches.iter() { for x in sub_vec { batches2.push(vec![(x.0, Some(x.1.clone()))]); } @@ -555,7 +555,7 @@ fn test_put_blob_sets() { let mut root_hashes_one_by_one = vec![]; let mut batch_one_by_one = TreeUpdateBatch::default(); { - let mut iter = keys.clone().into_iter().zip(values.clone().into_iter()); + let mut iter = keys.clone().into_iter().zip(values.clone()); let db = MockTreeStore::default(); let tree = JellyfishMerkleTree::new(&db); @@ -579,7 +579,7 @@ fn test_put_blob_sets() { } } { - let mut iter = keys.into_iter().zip(values.into_iter()); + let mut iter = keys.into_iter().zip(values); let db = MockTreeStore::default(); let tree = JellyfishMerkleTree::new(&db); let mut blob_sets = vec![]; @@ -649,7 +649,7 @@ fn many_versions_get_proof_and_verify_tree_root(seed: &[u8], num_versions: usize let mut roots = vec![]; let mut current_root = None; - for (_idx, kvs) in kvs.iter().enumerate() { + for kvs in kvs.iter() { let (root, batch) = tree .put_blob_set(current_root, vec![(kvs.0.into(), kvs.1.clone())]) .unwrap(); @@ -659,7 +659,7 @@ fn many_versions_get_proof_and_verify_tree_root(seed: &[u8], num_versions: usize } // Update value of all keys - for (_idx, kvs) in kvs.iter().enumerate() { + for kvs in kvs.iter() { let (root, batch) = tree .put_blob_set(current_root, vec![(kvs.0.into(), kvs.2.clone())]) .unwrap(); @@ -764,8 +764,8 @@ proptest! { } } -fn test_existent_keys_impl<'a>( - tree: &JellyfishMerkleTree<'a, HashValueKey, MockTreeStore>, +fn test_existent_keys_impl( + tree: &JellyfishMerkleTree<'_, HashValueKey, MockTreeStore>, root_hash: HashValue, existent_kvs: &HashMap, ) { @@ -778,8 +778,8 @@ fn test_existent_keys_impl<'a>( } } -fn test_nonexistent_keys_impl<'a>( - tree: &JellyfishMerkleTree<'a, HashValueKey, MockTreeStore>, +fn test_nonexistent_keys_impl( + tree: &JellyfishMerkleTree<'_, HashValueKey, MockTreeStore>, root_hash: HashValue, nonexistent_keys: &[HashValueKey], ) { @@ -792,8 +792,8 @@ fn test_nonexistent_keys_impl<'a>( } } -fn test_nonexistent_key_value_update_impl<'a>( - tree: &JellyfishMerkleTree<'a, HashValueKey, MockTreeStore>, +fn test_nonexistent_key_value_update_impl( + tree: &JellyfishMerkleTree<'_, HashValueKey, MockTreeStore>, db: &MockTreeStore, root_hash: HashValue, noneexistent_kv: (HashValue, Blob), diff --git a/commons/forkable-jellyfish-merkle/src/lib.rs b/commons/forkable-jellyfish-merkle/src/lib.rs index 9604e0289c..dc368bc037 100644 --- a/commons/forkable-jellyfish-merkle/src/lib.rs +++ b/commons/forkable-jellyfish-merkle/src/lib.rs @@ -354,7 +354,7 @@ where blob_sets: Vec)>>, ) -> Result<(Vec, TreeUpdateBatch)> { let mut tree_cache = TreeCache::new(self.reader, state_root_hash); - for (_idx, blob_set) in blob_sets.into_iter().enumerate() { + for blob_set in blob_sets.into_iter() { assert!( !blob_set.is_empty(), "Transactions that output empty write set should not be included.", diff --git a/commons/service-registry/src/bus/sys_bus.rs b/commons/service-registry/src/bus/sys_bus.rs index 9a00fae149..2506743aaf 100644 --- a/commons/service-registry/src/bus/sys_bus.rs +++ b/commons/service-registry/src/bus/sys_bus.rs @@ -88,7 +88,7 @@ impl SysBus { M: Send + Clone + Debug + 'static, { let type_id = TypeId::of::(); - let topic_subscribes = self.subscriptions.entry(type_id).or_insert_with(Vec::new); + let topic_subscribes = self.subscriptions.entry(type_id).or_default(); debug!("do_subscribe: {:?}", subscription); topic_subscribes.push(Box::new(subscription)); } @@ -249,7 +249,7 @@ mod tests { let mut bus = SysBus::new(); let receiver = bus.oneshot::(); assert_eq!(1, bus.len_by_type::()); - let job = task::spawn(async { receiver.await }); + let job = task::spawn(receiver); Delay::new(Duration::from_millis(10)).await; bus.broadcast(Message {}); let result = job.await; diff --git a/config/src/api_config.rs b/config/src/api_config.rs index c2ff0dae6f..e59e117a90 100644 --- a/config/src/api_config.rs +++ b/config/src/api_config.rs @@ -82,8 +82,7 @@ impl FromStr for Api { } } -#[derive(Debug, Clone)] -#[derive(Default)] +#[derive(Debug, Clone, Default)] pub enum ApiSet { // Unsafe context (like jsonrpc over http) #[default] @@ -98,8 +97,6 @@ pub enum ApiSet { List(HashSet), } - - impl PartialEq for ApiSet { fn eq(&self, other: &Self) -> bool { self.list_apis() == other.list_apis() diff --git a/config/src/genesis_config.rs b/config/src/genesis_config.rs index 830bd24a89..521a3e0b12 100644 --- a/config/src/genesis_config.rs +++ b/config/src/genesis_config.rs @@ -201,8 +201,6 @@ impl BuiltinNetworkID { } } - - impl From for ChainNetwork { fn from(network: BuiltinNetworkID) -> Self { ChainNetwork::new( diff --git a/config/src/network_config.rs b/config/src/network_config.rs index c9594aa5b6..70538bd9dd 100644 --- a/config/src/network_config.rs +++ b/config/src/network_config.rs @@ -127,8 +127,8 @@ impl Seeds { } pub fn merge(&mut self, other: &Seeds) { let mut seeds = HashSet::new(); - seeds.extend(self.0.clone().into_iter()); - seeds.extend(other.0.clone().into_iter()); + seeds.extend(self.0.clone()); + seeds.extend(other.0.clone()); let mut seeds: Vec = seeds.into_iter().collect(); //keep order in config seeds.sort(); diff --git a/consensus/src/consensus_test.rs b/consensus/src/consensus_test.rs index 7c1997a186..c3fe95bb4f 100644 --- a/consensus/src/consensus_test.rs +++ b/consensus/src/consensus_test.rs @@ -1,7 +1,7 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -#![allow(clippy::integer_arithmetic)] +#![allow(clippy::arithmetic_side_effects)] use crate::consensus::Consensus; use crate::difficulty::{get_next_target_helper, BlockDiffInfo}; diff --git a/executor/benchmark/src/lib.rs b/executor/benchmark/src/lib.rs index 3706971393..31ded865ba 100644 --- a/executor/benchmark/src/lib.rs +++ b/executor/benchmark/src/lib.rs @@ -108,7 +108,7 @@ impl TransactionGenerator { /// Generates transactions that allocate `init_account_balance` to every account. fn gen_create_account_transactions(&mut self, init_account_balance: u64, block_size: usize) { - for (_i, block) in self.accounts.chunks(block_size).enumerate() { + for block in self.accounts.chunks(block_size) { self.net.time_service().sleep(1000); let mut transactions = Vec::with_capacity(block_size + 1); diff --git a/genesis/src/lib.rs b/genesis/src/lib.rs index c22090f371..9165631cae 100644 --- a/genesis/src/lib.rs +++ b/genesis/src/lib.rs @@ -550,7 +550,7 @@ mod tests { storage2.get_accumulator_store(AccumulatorStoreType::Transaction), ); - let genesis_txn = genesis_block.body.transactions.get(0).cloned().unwrap(); + let genesis_txn = genesis_block.body.transactions.first().cloned().unwrap(); assert_eq!( txn_accumulator.get_leaf(0).unwrap().unwrap(), storage1 diff --git a/miner/src/create_block_template/mod.rs b/miner/src/create_block_template/mod.rs index 5e6ba1ae50..3f68cf408d 100644 --- a/miner/src/create_block_template/mod.rs +++ b/miner/src/create_block_template/mod.rs @@ -230,7 +230,7 @@ where pub fn insert_uncle(&mut self, uncle: BlockHeader) { self.parent_uncle .entry(uncle.parent_hash()) - .or_insert_with(Vec::new) + .or_default() .push(uncle.id()); self.uncles.insert(uncle.id(), uncle); if let Some(metrics) = self.metrics.as_ref() { diff --git a/network-p2p/derive/src/helper.rs b/network-p2p/derive/src/helper.rs index 8fb54a8e91..d3c25b1357 100644 --- a/network-p2p/derive/src/helper.rs +++ b/network-p2p/derive/src/helper.rs @@ -78,7 +78,6 @@ pub fn compute_args(method: &syn::TraitItemMethod) -> Punctuated continue, }; let syn::PathSegment { ident, .. } = &segments[0]; - let ident = ident; if *ident == "Self" { continue; } diff --git a/network-p2p/peerset/tests/fuzz.rs b/network-p2p/peerset/tests/fuzz.rs index d7d5a1f29c..7940554594 100644 --- a/network-p2p/peerset/tests/fuzz.rs +++ b/network-p2p/peerset/tests/fuzz.rs @@ -81,10 +81,7 @@ fn test_once() { for _ in 0..2500 { // Each of these weights corresponds to an action that we may perform. let action_weights = [150, 90, 90, 30, 30, 1, 1, 4, 4]; - match WeightedIndex::new(&action_weights) - .unwrap() - .sample(&mut rng) - { + match WeightedIndex::new(action_weights).unwrap().sample(&mut rng) { // If we generate 0, poll the peerset. 0 => match Stream::poll_next(Pin::new(&mut peerset), cx) { Poll::Ready(Some(Message::Connect { peer_id, .. })) => { diff --git a/network-p2p/src/peer_info.rs b/network-p2p/src/peer_info.rs index eaabbdc75b..c9f28e741a 100644 --- a/network-p2p/src/peer_info.rs +++ b/network-p2p/src/peer_info.rs @@ -144,7 +144,7 @@ pub struct Node<'a>(&'a NodeInfo); impl<'a> Node<'a> { /// Returns the endpoint of an established connection to the peer. pub fn endpoint(&self) -> Option<&'a ConnectedPoint> { - self.0.endpoints.get(0) // `endpoints` will trigger an exception if no item was pushed + self.0.endpoints.first() // `endpoints` will trigger an exception if no item was pushed } /// Returns the latest version information we know of. diff --git a/network-p2p/src/service_test.rs b/network-p2p/src/service_test.rs index 35b8f7a1fc..aa01968542 100644 --- a/network-p2p/src/service_test.rs +++ b/network-p2p/src/service_test.rs @@ -507,6 +507,7 @@ const PROTOCOL_NAME: &str = "/starcoin/notify/1"; // } // +#[allow(clippy::let_underscore_future)] #[stest::test] async fn test_handshake_fail() { let protocol = ProtocolId::from("starcoin"); @@ -592,6 +593,7 @@ fn test_handshake_message() { assert_eq!(status, status2); } +#[allow(clippy::let_underscore_future)] #[stest::test] async fn test_support_protocol() { let protocol = ProtocolId::from("starcoin"); diff --git a/network/api/src/peer_provider.rs b/network/api/src/peer_provider.rs index fe51c7d0a3..54c3ff7320 100644 --- a/network/api/src/peer_provider.rs +++ b/network/api/src/peer_provider.rs @@ -85,8 +85,7 @@ impl From<(PeerInfo, u64)> for PeerDetail { } } -#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Serialize, JsonSchema)] -#[derive(Default)] +#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Serialize, JsonSchema, Default)] pub enum PeerStrategy { Random, #[default] @@ -95,8 +94,6 @@ pub enum PeerStrategy { Avg, } - - impl std::fmt::Display for PeerStrategy { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let display = match self { @@ -434,7 +431,7 @@ impl PeerSelector { } if self.len() == 1 { - return self.details.lock().get(0).map(|peer| peer.peer_id()); + return self.details.lock().first().map(|peer| peer.peer_id()); } let mut random = rand::thread_rng(); @@ -461,7 +458,7 @@ impl PeerSelector { pub fn first_peer(&self) -> Option { self.details .lock() - .get(0) + .first() .map(|peer| peer.peer_info.clone()) } diff --git a/network/api/src/tests.rs b/network/api/src/tests.rs index 801277064e..b74a829bd2 100644 --- a/network/api/src/tests.rs +++ b/network/api/src/tests.rs @@ -77,7 +77,7 @@ fn test_better_peer() { peers.push(PeerInfo::random()); } - let first_peer = peers.get(0).cloned().expect("first peer must exist."); + let first_peer = peers.first().cloned().expect("first peer must exist."); let peer_selector = PeerSelector::new(peers, PeerStrategy::default(), None); let better_selector = peer_selector.betters(first_peer.total_difficulty(), 10); diff --git a/network/src/network_p2p_handle.rs b/network/src/network_p2p_handle.rs index 4278bf7f4c..3931a80606 100644 --- a/network/src/network_p2p_handle.rs +++ b/network/src/network_p2p_handle.rs @@ -113,12 +113,10 @@ impl BusinessLayerHandle for Networkp2pHandle { self.status.info = other_chain_info; Ok(()) } - Err(error) => { - Err(anyhow!( - "failed to decode the generic data for the reason: {}", - error - )) - } + Err(error) => Err(anyhow!( + "failed to decode the generic data for the reason: {}", + error + )), } } @@ -128,12 +126,10 @@ impl BusinessLayerHandle for Networkp2pHandle { self.status.info.update_status(status); Ok(()) } - Err(error) => { - Err(anyhow!( - "failed to decode the generic data for the reason: {}", - error - )) - } + Err(error) => Err(anyhow!( + "failed to decode the generic data for the reason: {}", + error + )), } } diff --git a/rpc/api/src/types/pubsub.rs b/rpc/api/src/types/pubsub.rs index 1048ca47bb..e2c95821cb 100644 --- a/rpc/api/src/types/pubsub.rs +++ b/rpc/api/src/types/pubsub.rs @@ -58,8 +58,7 @@ impl Serialize for Result { } /// Subscription kind. -#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize)] -#[derive(Default)] +#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Default)] pub enum Params { /// No parameters passed. #[default] @@ -68,8 +67,6 @@ pub enum Params { Events(EventParams), } - - impl<'a> Deserialize<'a> for Params { fn deserialize(deserializer: D) -> ::std::result::Result where diff --git a/rpc/client/src/chain_watcher.rs b/rpc/client/src/chain_watcher.rs index 58dde7e5d5..f9a1ba433b 100644 --- a/rpc/client/src/chain_watcher.rs +++ b/rpc/client/src/chain_watcher.rs @@ -118,10 +118,7 @@ impl Handler for ChainWatcher { /// This method is called for every message received by this actor. fn handle(&mut self, msg: WatchBlock, _ctx: &mut Self::Context) -> Self::Result { let (tx, rx) = oneshot::channel(); - self.watched_blocks - .entry(msg.0) - .or_insert_with(Vec::new) - .push(tx); + self.watched_blocks.entry(msg.0).or_default().push(tx); MessageResult(rx) } } diff --git a/rpc/client/src/remote_state_reader.rs b/rpc/client/src/remote_state_reader.rs index 7b0f191bc5..dd3926143c 100644 --- a/rpc/client/src/remote_state_reader.rs +++ b/rpc/client/src/remote_state_reader.rs @@ -15,8 +15,7 @@ use starcoin_vm_types::state_store::state_key::StateKey; use starcoin_vm_types::state_store::table::{TableHandle, TableInfo}; use std::str::FromStr; -#[derive(Debug, Clone, Copy)] -#[derive(Default)] +#[derive(Debug, Clone, Copy, Default)] pub enum StateRootOption { #[default] Latest, @@ -24,8 +23,6 @@ pub enum StateRootOption { BlockNumber(BlockNumber), } - - impl FromStr for StateRootOption { type Err = anyhow::Error; diff --git a/rpc/client/tests/client_server_test.rs b/rpc/client/tests/client_server_test.rs index bf053a449b..a59d78cc66 100644 --- a/rpc/client/tests/client_server_test.rs +++ b/rpc/client/tests/client_server_test.rs @@ -133,8 +133,8 @@ fn test_client_reconnect_subscribe() -> Result<()> { std::thread::sleep(Duration::from_millis(300)); let _e = node_handle.stop(); - let events1 = futures::executor::block_on(async move { handle1.await }); - let events2 = futures::executor::block_on(async move { handle2.await }); + let events1 = futures::executor::block_on(handle1); + let events2 = futures::executor::block_on(handle2); assert_ne!(events1.len(), 0); assert_ne!(events2.len(), 0); Ok(()) diff --git a/state/api/src/mock/mock_chain_state_service.rs b/state/api/src/mock/mock_chain_state_service.rs index 545a17027e..4a6da4811e 100644 --- a/state/api/src/mock/mock_chain_state_service.rs +++ b/state/api/src/mock/mock_chain_state_service.rs @@ -20,6 +20,7 @@ impl MockChainStateService { } } +#[allow(clippy::diverging_sub_expression)] #[async_trait::async_trait] impl ChainStateAsyncService for MockChainStateService { async fn get(self, _access_path: AccessPath) -> Result>> { diff --git a/state/state-tree/src/mock/mod.rs b/state/state-tree/src/mock/mod.rs index 88efa7e2e9..a58ed5cf24 100644 --- a/state/state-tree/src/mock/mod.rs +++ b/state/state-tree/src/mock/mod.rs @@ -40,7 +40,7 @@ impl StateNodeStore for MockStateNodeStore { fn write_nodes(&self, nodes: BTreeMap) -> Result<(), Error> { let mut store_nodes = self.nodes.write(); - store_nodes.extend(nodes.into_iter()); + store_nodes.extend(nodes); Ok(()) } diff --git a/state/state-tree/src/state_tree_test.rs b/state/state-tree/src/state_tree_test.rs index a890660614..36a2e5a7cf 100644 --- a/state/state-tree/src/state_tree_test.rs +++ b/state/state-tree/src/state_tree_test.rs @@ -128,7 +128,7 @@ pub fn test_put_blob_continue_commit_flush_same() -> Result<()> { assert_eq!(updates2.stale_node_index_batch.len(), 2); let account13 = update_nibble(&account11, 2, 3); - for (k, v) in vec![(account11, vec![1, 1, 0]), (account13, vec![0, 0, 0])] { + for (k, v) in [(account11, vec![1, 1, 0]), (account13, vec![0, 0, 0])] { state1.put(k, v); } assert_eq!(state1.get(&account11)?, Some(vec![1, 1, 0])); @@ -146,7 +146,7 @@ pub fn test_put_blob_continue_commit_flush_same() -> Result<()> { assert_eq!(updates1.stale_node_index_batch.len(), 2); let account23 = update_nibble(&account21, 2, 3); - for (k, v) in vec![(account21, vec![1, 1, 0]), (account23, vec![0, 0, 0])] { + for (k, v) in [(account21, vec![1, 1, 0]), (account23, vec![0, 0, 0])] { state2.put(k, v); } assert_eq!(state2.get(&account21)?, Some(vec![1, 1, 0])); @@ -190,7 +190,7 @@ pub fn test_state_proof() -> Result<()> { let account1 = update_nibble(&account1, 2, 1); let account2 = update_nibble(&account1, 2, 2); - for (k, v) in vec![(account1, vec![0, 0, 0]), (account2, vec![1, 1, 1])] { + for (k, v) in [(account1, vec![0, 0, 0]), (account2, vec![1, 1, 1])] { state.put(k, v); } let (value, _) = state.get_with_proof(&account1)?; @@ -225,7 +225,7 @@ pub fn test_state_commit() -> Result<()> { let _new_root_hash = state.commit()?; let account3 = update_nibble(&account1, 2, 3); - for (k, v) in vec![(account1, vec![1, 1, 0]), (account3, vec![0, 0, 0])] { + for (k, v) in [(account1, vec![1, 1, 0]), (account3, vec![0, 0, 0])] { state.put(k, v); } let new_root_hash = state.commit()?; diff --git a/state/statedb/src/tests.rs b/state/statedb/src/tests.rs index 2765675fa2..303a248d0e 100644 --- a/state/statedb/src/tests.rs +++ b/state/statedb/src/tests.rs @@ -25,7 +25,6 @@ fn state_keys_to_write_set(state_keys: Vec, values: Vec>) -> W state_keys .into_iter() .zip(values) - .into_iter() .map(|(key, val)| (key, WriteOp::Value(val))) .collect::>(), ) diff --git a/storage/src/tests/test_batch.rs b/storage/src/tests/test_batch.rs index caeaaf5acf..fa05c28f86 100644 --- a/storage/src/tests/test_batch.rs +++ b/storage/src/tests/test_batch.rs @@ -208,7 +208,7 @@ fn test_write_batch_multi_get() -> Result<()> { vec![id1.to_vec(), id2.to_vec()], )?; assert_eq!( - RichTransactionInfo::decode_value(&infos.get(0).unwrap().clone().unwrap())?, + RichTransactionInfo::decode_value(&infos.first().unwrap().clone().unwrap())?, transaction_info1 ); assert_eq!( @@ -260,7 +260,7 @@ fn test_cache_multi_get_no_evict() -> Result<()> { )?; assert_eq!( - RichTransactionInfo::decode_value(&infos.get(0).unwrap().clone().unwrap())?, + RichTransactionInfo::decode_value(&infos.first().unwrap().clone().unwrap())?, transaction_info1 ); assert_eq!( @@ -326,7 +326,7 @@ fn test_cache_multi_get_with_evict() -> Result<()> { vec![id1.to_vec(), id2.to_vec(), id3.to_vec()], )?; - assert!(&infos.get(0).unwrap().is_none(), "id1 has evicted"); + assert!(&infos.first().unwrap().is_none(), "id1 has evicted"); assert_eq!( RichTransactionInfo::decode_value(&infos.get(1).unwrap().clone().unwrap())?, transaction_info2 diff --git a/storage/src/tests/test_storage.rs b/storage/src/tests/test_storage.rs index be7a2eaa44..e801bda6fb 100644 --- a/storage/src/tests/test_storage.rs +++ b/storage/src/tests/test_storage.rs @@ -458,7 +458,7 @@ pub fn test_cache_evict_multi_get() -> Result<()> { TRANSACTION_INFO_PREFIX_NAME_V2, vec![id1.to_vec(), id2.to_vec(), id3.to_vec()], )?; - assert!(&cache_infos.get(0).unwrap().is_none(), "id1 has evicted"); + assert!(&cache_infos.first().unwrap().is_none(), "id1 has evicted"); assert_eq!( RichTransactionInfo::decode_value(&cache_infos.get(1).unwrap().clone().unwrap())?, transaction_info2 @@ -470,7 +470,7 @@ pub fn test_cache_evict_multi_get() -> Result<()> { let infos = storage .transaction_info_storage .multiple_get(vec![id1, id2, id3])?; - assert_eq!(infos.get(0).unwrap().clone().unwrap(), transaction_info1); + assert_eq!(infos.first().unwrap().clone().unwrap(), transaction_info1); assert_eq!(infos.get(1).unwrap().clone().unwrap(), transaction_info2); assert_eq!(infos.get(2).unwrap().clone().unwrap(), transaction_info3); Ok(()) diff --git a/storage/src/transaction/test.rs b/storage/src/transaction/test.rs index cbf90ada75..83df1a6ded 100644 --- a/storage/src/transaction/test.rs +++ b/storage/src/transaction/test.rs @@ -53,7 +53,7 @@ proptest! { .unwrap(); let txns = init_store(universe, gens, &storage); - for (_ver, txn) in txns.iter().enumerate() { + for txn in txns.iter() { prop_assert_eq!(storage .transaction_storage .get_transaction(txn.id()).unwrap().unwrap(), txn.clone()); diff --git a/sync/src/block_connector/test_illegal_block.rs b/sync/src/block_connector/test_illegal_block.rs index ec2b662895..e1b3c4e7e7 100644 --- a/sync/src/block_connector/test_illegal_block.rs +++ b/sync/src/block_connector/test_illegal_block.rs @@ -1,6 +1,6 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -#![allow(clippy::integer_arithmetic)] +#![allow(clippy::arithmetic_side_effects)] use crate::block_connector::{ create_writeable_block_chain, gen_blocks, new_block, WriteBlockChainService, }; diff --git a/sync/src/block_connector/test_write_block_chain.rs b/sync/src/block_connector/test_write_block_chain.rs index c94ebe91b9..739c45e2df 100644 --- a/sync/src/block_connector/test_write_block_chain.rs +++ b/sync/src/block_connector/test_write_block_chain.rs @@ -1,6 +1,6 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -#![allow(clippy::integer_arithmetic)] +#![allow(clippy::arithmetic_side_effects)] use crate::block_connector::WriteBlockChainService; use starcoin_account_api::AccountInfo; use starcoin_chain::{BlockChain, ChainReader}; diff --git a/sync/src/block_connector/write_block_chain.rs b/sync/src/block_connector/write_block_chain.rs index c22ff42408..cd887b69f6 100644 --- a/sync/src/block_connector/write_block_chain.rs +++ b/sync/src/block_connector/write_block_chain.rs @@ -162,7 +162,7 @@ where } fn block_exist(&self, block_id: HashValue) -> Result { - Ok(matches!(self.storage.get_block_info(block_id)?, Some(_))) + Ok(self.storage.get_block_info(block_id)?.is_some()) } pub fn get_main(&self) -> &BlockChain { diff --git a/sync/src/tasks/mock.rs b/sync/src/tasks/mock.rs index 5f5c66034d..2428863534 100644 --- a/sync/src/tasks/mock.rs +++ b/sync/src/tasks/mock.rs @@ -26,19 +26,15 @@ use starcoin_types::block::{Block, BlockIdAndNumber, BlockInfo, BlockNumber}; use std::sync::Arc; use std::time::Duration; +#[derive(Default)] pub enum ErrorStrategy { _RateLimitErr, Timeout(u64), + #[default] RandomErr, MethodNotFound, } -impl Default for ErrorStrategy { - fn default() -> Self { - ErrorStrategy::RandomErr - } -} - pub struct ErrorMocker { strategy: ErrorStrategy, pub random_error_percent: u32, diff --git a/sync/src/tasks/tests.rs b/sync/src/tasks/tests.rs index 06206f227e..bc76ee38c4 100644 --- a/sync/src/tasks/tests.rs +++ b/sync/src/tasks/tests.rs @@ -1,7 +1,7 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -#![allow(clippy::integer_arithmetic)] +#![allow(clippy::arithmetic_side_effects)] use crate::tasks::block_sync_task::SyncBlockData; use crate::tasks::mock::{ErrorStrategy, MockBlockIdFetcher, SyncNodeMocker}; use crate::tasks::{ diff --git a/sync/src/verified_rpc_client.rs b/sync/src/verified_rpc_client.rs index 5dcaabe6dc..fd9e4d301e 100644 --- a/sync/src/verified_rpc_client.rs +++ b/sync/src/verified_rpc_client.rs @@ -64,7 +64,7 @@ where resp: Vec>, ) -> Result>, RpcVerifyError> { req.into_iter() - .zip(resp.into_iter()) + .zip(resp) .map(|(req_item, resp_item)| { if let Some(resp_item) = resp_item { if (self)(&req_item, &resp_item) { diff --git a/txpool/src/test.rs b/txpool/src/test.rs index e205b388e6..d70e1ede1d 100644 --- a/txpool/src/test.rs +++ b/txpool/src/test.rs @@ -108,7 +108,6 @@ async fn test_pool_pending() -> Result<()> { let metrics_config: &MetricsConfig = &node_config.metrics; let txn_vec = (0..pool_size + expect_reject) - .into_iter() .map(|index| generate_txn(node_config.clone(), index)) .collect::>(); @@ -152,7 +151,6 @@ async fn test_pool_pending() -> Result<()> { ); let txn_vec = (pool_size..(pool_size + expect_reject)) - .into_iter() .map(|index| generate_txn(node_config.clone(), index)) .collect::>(); diff --git a/vm/gas-algebra-ext/src/natives.rs b/vm/gas-algebra-ext/src/natives.rs index 664128179b..8608b07db5 100644 --- a/vm/gas-algebra-ext/src/natives.rs +++ b/vm/gas-algebra-ext/src/natives.rs @@ -197,16 +197,11 @@ mod tests { #[test] fn optional_should_be_honored() { - assert!(matches!( - GasParameters::from_on_chain_gas_schedule( - &[("test.foo".to_string(), 0)].into_iter().collect(), - ), - Some(_) - )); - - assert!(matches!( - GasParameters::from_on_chain_gas_schedule(&[].into_iter().collect()), - None - )); + assert!(GasParameters::from_on_chain_gas_schedule( + &[("test.foo".to_string(), 0)].into_iter().collect(), + ) + .is_some()); + + assert!(GasParameters::from_on_chain_gas_schedule(&[].into_iter().collect()).is_none()); } } diff --git a/vm/gas-algebra-ext/src/params.rs b/vm/gas-algebra-ext/src/params.rs index 872a96ee7e..f33c1fb1ef 100644 --- a/vm/gas-algebra-ext/src/params.rs +++ b/vm/gas-algebra-ext/src/params.rs @@ -88,18 +88,11 @@ mod tests { #[test] fn optional_should_be_honored() { - assert!( - matches!( - GasParameters::from_on_chain_gas_schedule( - &[("test.foo".to_string(), 0)].into_iter().collect(), - ), - Some(_) - ) - ); - - assert!(matches!( - GasParameters::from_on_chain_gas_schedule(&[].into_iter().collect()), - None - )); + assert!(GasParameters::from_on_chain_gas_schedule( + &[("test.foo".to_string(), 0)].into_iter().collect(), + ) + .is_some()); + + assert!(GasParameters::from_on_chain_gas_schedule(&[].into_iter().collect()).is_none(),); } } diff --git a/vm/move-package-manager/src/lib.rs b/vm/move-package-manager/src/lib.rs index 2f1f2723e9..42d6592394 100644 --- a/vm/move-package-manager/src/lib.rs +++ b/vm/move-package-manager/src/lib.rs @@ -60,8 +60,7 @@ pub struct TestOpts { format: Format, } -#[derive(Debug, Eq, PartialEq)] -#[derive(Default)] +#[derive(Debug, Eq, PartialEq, Default)] enum Format { #[default] Pretty, @@ -98,8 +97,6 @@ impl FromStr for Format { } } - - #[derive(Args, Debug)] pub struct IntegrationTestCommand { #[clap(flatten)] diff --git a/vm/mvhashmap/src/lib.rs b/vm/mvhashmap/src/lib.rs index 52fc6ff013..9ce76866b4 100644 --- a/vm/mvhashmap/src/lib.rs +++ b/vm/mvhashmap/src/lib.rs @@ -77,7 +77,7 @@ impl MVHashMap { pub fn write(&self, key: &K, version: Version, data: V) { let (txn_idx, incarnation) = version; - let mut map = self.data.entry(key.clone()).or_insert(BTreeMap::new()); + let mut map = self.data.entry(key.clone()).or_default(); let prev_cell = map.insert( txn_idx, CachePadded::new(WriteCell::new_from(FLAG_DONE, incarnation, data)), diff --git a/vm/mvhashmap/src/unit_tests/proptest_types.rs b/vm/mvhashmap/src/unit_tests/proptest_types.rs index 739db06211..4a9b588419 100644 --- a/vm/mvhashmap/src/unit_tests/proptest_types.rs +++ b/vm/mvhashmap/src/unit_tests/proptest_types.rs @@ -44,7 +44,7 @@ where baseline .entry(k.clone()) - .or_insert_with(BTreeMap::new) + .or_default() .insert(idx, value_to_update); } Self(baseline) diff --git a/vm/resource-viewer/src/lib.rs b/vm/resource-viewer/src/lib.rs index cc9c044620..48febc6732 100644 --- a/vm/resource-viewer/src/lib.rs +++ b/vm/resource-viewer/src/lib.rs @@ -168,10 +168,7 @@ impl<'a> MoveValueAnnotator<'a> { Ok(AnnotatedMoveStruct { abilities: ty.abilities.0, type_: struct_tag, - value: field_names - .into_iter() - .zip(annotated_fields.into_iter()) - .collect(), + value: field_names.into_iter().zip(annotated_fields).collect(), }) } diff --git a/vm/starcoin-transactional-test-harness/src/fork_chain.rs b/vm/starcoin-transactional-test-harness/src/fork_chain.rs index 9d0dda112d..37a8c6e6aa 100644 --- a/vm/starcoin-transactional-test-harness/src/fork_chain.rs +++ b/vm/starcoin-transactional-test-harness/src/fork_chain.rs @@ -325,10 +325,7 @@ impl ChainApi for MockChainApi { } else if number <= current_number { let hash = number_hash_map.get(&number).map(|h| *h); let block_view = match hash { - Some(hash) => match storage.get_block_info(hash)? { - Some(b) => Some(BlockInfoView::try_from(b)?), - None => None, - }, + Some(hash) => storage.get_block_info(hash)?.map(BlockInfoView::from), None => None, }; Ok(block_view) diff --git a/vm/starcoin-transactional-test-harness/src/lib.rs b/vm/starcoin-transactional-test-harness/src/lib.rs index 8727440b00..3c44589575 100644 --- a/vm/starcoin-transactional-test-harness/src/lib.rs +++ b/vm/starcoin-transactional-test-harness/src/lib.rs @@ -998,7 +998,7 @@ impl<'a> StarcoinTestAdapter<'a> { ) })?; - let signer = match signers.get(0) { + let signer = match signers.first() { Some(addr) => self.compiled_state.resolve_address(addr), None => package.package_address(), }; @@ -1254,7 +1254,7 @@ impl<'a> MoveTestAdapter<'a> for StarcoinTestAdapter<'a> { } match is_vec_u8 { true => { - assert_eq!(vals.get(0), Some(&MoveValue::U8(48))); + assert_eq!(vals.first(), Some(&MoveValue::U8(48))); assert_eq!(vals.get(1), Some(&MoveValue::U8(120))); let mut vals_compress = vec![]; for i in (2..vals.len()).step_by(2) { diff --git a/vm/transaction-builder-generator/src/dart.rs b/vm/transaction-builder-generator/src/dart.rs index 4ef84c9b9b..44006b43c9 100644 --- a/vm/transaction-builder-generator/src/dart.rs +++ b/vm/transaction-builder-generator/src/dart.rs @@ -488,10 +488,10 @@ return TransactionPayloadScriptFunctionItem(ScriptFunction(module,function,ty_ar )?; self.out.indent(); - for (_, ty_arg) in abi.ty_args().iter().enumerate() { + for ty_arg in abi.ty_args().iter() { writeln!(self.out, "{},", ty_arg.name(),)?; } - for (_, arg) in abi.args().iter().enumerate() { + for arg in abi.args().iter() { writeln!(self.out, "{},", arg.name(),)?; } self.out.unindent(); diff --git a/vm/transaction-builder/src/lib.rs b/vm/transaction-builder/src/lib.rs index 0019c4512b..dfa9602d4e 100644 --- a/vm/transaction-builder/src/lib.rs +++ b/vm/transaction-builder/src/lib.rs @@ -376,7 +376,7 @@ pub fn build_init_script_v1(net: &ChainNetwork) -> ScriptFunction { .genesis_key_pair .as_ref() .map(|(_, public_key)| AuthenticationKey::ed25519(public_key).to_vec()) - .unwrap_or_else(Vec::new); + .unwrap_or_default(); let association_auth_key = AuthenticationKey::multi_ed25519(&genesis_config.association_key_pair.1).to_vec(); @@ -539,7 +539,7 @@ pub fn build_init_script_v2(net: &ChainNetwork) -> ScriptFunction { .genesis_key_pair .as_ref() .map(|(_, public_key)| AuthenticationKey::ed25519(public_key).to_vec()) - .unwrap_or_else(Vec::new); + .unwrap_or_default(); let association_auth_key = AuthenticationKey::multi_ed25519(&genesis_config.association_key_pair.1).to_vec(); diff --git a/vm/types/src/account_config/resources/auto_accept_token.rs b/vm/types/src/account_config/resources/auto_accept_token.rs index c49bae97a7..859ac8bf0c 100644 --- a/vm/types/src/account_config/resources/auto_accept_token.rs +++ b/vm/types/src/account_config/resources/auto_accept_token.rs @@ -26,7 +26,7 @@ impl AutoAcceptToken { && struct_tag.module.as_str() == Self::MODULE_NAME && struct_tag.name.as_str() == Self::STRUCT_NAME { - if let Some(TypeTag::Struct(token_tag)) = struct_tag.type_params.get(0) { + if let Some(TypeTag::Struct(token_tag)) = struct_tag.type_params.first() { Some((*(token_tag.clone())).into()) } else { None diff --git a/vm/types/src/account_config/resources/balance.rs b/vm/types/src/account_config/resources/balance.rs index d4e8561f8c..a9070483e8 100644 --- a/vm/types/src/account_config/resources/balance.rs +++ b/vm/types/src/account_config/resources/balance.rs @@ -47,7 +47,7 @@ impl BalanceResource { && struct_tag.module.as_str() == Self::MODULE_NAME && struct_tag.name.as_str() == Self::STRUCT_NAME { - if let Some(TypeTag::Struct(token_tag)) = struct_tag.type_params.get(0) { + if let Some(TypeTag::Struct(token_tag)) = struct_tag.type_params.first() { Some((*(token_tag.clone())).into()) } else { None diff --git a/vm/types/src/genesis_config.rs b/vm/types/src/genesis_config.rs index d13dd35d98..2e6e8eedd2 100644 --- a/vm/types/src/genesis_config.rs +++ b/vm/types/src/genesis_config.rs @@ -10,8 +10,7 @@ use std::cmp::Ordering; use std::fmt::{self, Formatter}; use std::fmt::{Debug, Display}; use std::str::FromStr; -#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] -#[derive(Default)] +#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Default)] pub enum StdlibVersion { #[default] Latest, @@ -73,8 +72,6 @@ impl Ord for StdlibVersion { } } - - impl FromStr for StdlibVersion { type Err = anyhow::Error; @@ -127,8 +124,6 @@ impl ConsensusStrategy { } } - - impl fmt::Display for ConsensusStrategy { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/vm/types/src/on_chain_resource/nft.rs b/vm/types/src/on_chain_resource/nft.rs index a26d661afb..344d2121c5 100644 --- a/vm/types/src/on_chain_resource/nft.rs +++ b/vm/types/src/on_chain_resource/nft.rs @@ -294,7 +294,7 @@ impl NFTGallery { { if struct_tag.type_params.len() == 2 { let (meta_type, body_type) = ( - struct_tag.type_params.get(0).cloned().unwrap(), + struct_tag.type_params.first().cloned().unwrap(), struct_tag.type_params.get(1).cloned().unwrap(), ); Some(NFTType { @@ -346,7 +346,7 @@ impl IdentifierNFT { { if struct_tag.type_params.len() == 2 { let (meta_type, body_type) = ( - struct_tag.type_params.get(0).cloned().unwrap(), + struct_tag.type_params.first().cloned().unwrap(), struct_tag.type_params.get(1).cloned().unwrap(), ); Some(NFTType { diff --git a/vm/types/src/token/token_code.rs b/vm/types/src/token/token_code.rs index 02ec55af8c..ec6b885b3c 100644 --- a/vm/types/src/token/token_code.rs +++ b/vm/types/src/token/token_code.rs @@ -163,7 +163,7 @@ mod test { parse_type_tag(token).unwrap(), TypeTag::Struct(Box::new(type_tag.clone())) ); - assert_eq!(tc, type_tag.try_into().unwrap()); + assert_eq!(tc, type_tag.into()); } #[derive(Serialize, Deserialize, Debug, Clone, PartialOrd, Eq, PartialEq)] diff --git a/vm/types/src/transaction/authenticator.rs b/vm/types/src/transaction/authenticator.rs index e4cc3575c5..87462678ca 100644 --- a/vm/types/src/transaction/authenticator.rs +++ b/vm/types/src/transaction/authenticator.rs @@ -520,7 +520,6 @@ mod tests { let mut key_gen = KeyGen::from_os_rng(); let threshold = 2; let pubkeys = (0..2) - .into_iter() .map(|_| key_gen.generate_keypair().1) .collect::>(); let account_public_key = AccountPublicKey::multi(pubkeys.clone(), threshold).unwrap(); diff --git a/vm/types/src/write_set.rs b/vm/types/src/write_set.rs index e37993c855..5bede2efef 100644 --- a/vm/types/src/write_set.rs +++ b/vm/types/src/write_set.rs @@ -7,6 +7,7 @@ use crate::state_store::state_key::StateKey; use anyhow::Result; use serde::{Deserialize, Serialize}; +use std::ops::Add; #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] pub enum WriteOp { @@ -30,10 +31,8 @@ impl std::fmt::Debug for WriteOp { WriteOp::Value(value) => write!( f, "Value({})", - value - .iter() - .map(|byte| format!("{:02x}", byte)) - .collect::() + value.iter().fold(String::new(), |acc, byte| acc + .add(format!("{:02x}", byte).as_str())) ), WriteOp::Deletion => write!(f, "Deletion"), } diff --git a/vm/vm-runtime/src/errors.rs b/vm/vm-runtime/src/errors.rs index 71d6b2ea89..386088fc9d 100644 --- a/vm/vm-runtime/src/errors.rs +++ b/vm/vm-runtime/src/errors.rs @@ -110,7 +110,7 @@ pub fn convert_normal_success_epilogue_error(error: VMError) -> Result<(), VMSta let (category, reason) = error_split(code); match (category, reason) { (LIMIT_EXCEEDED, EINSUFFICIENT_BALANCE) => { - if location != account_module_abort() {} + let _ = location != account_module_abort(); VMStatus::MoveAbort(location, code) } (category, reason) => { From 77e048dc92e7b76626cf8d54992a76eab81cb768 Mon Sep 17 00:00:00 2001 From: simonjiao Date: Sun, 7 Apr 2024 22:20:24 +0800 Subject: [PATCH 3/3] fix creating test_txpool --- rpc/server/src/module/pubsub/tests.rs | 2 +- test-helper/src/txpool.rs | 28 ++++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/rpc/server/src/module/pubsub/tests.rs b/rpc/server/src/module/pubsub/tests.rs index fc5d74cc7d..33c4c6853e 100644 --- a/rpc/server/src/module/pubsub/tests.rs +++ b/rpc/server/src/module/pubsub/tests.rs @@ -29,7 +29,7 @@ use std::sync::Arc; use tokio::time::timeout; use tokio::time::Duration; -#[actix_rt::test] +#[stest::test] pub async fn test_subscribe_to_events() -> Result<()> { starcoin_logger::init_for_test(); // prepare diff --git a/test-helper/src/txpool.rs b/test-helper/src/txpool.rs index fb1b86a15f..102dd1e7f8 100644 --- a/test-helper/src/txpool.rs +++ b/test-helper/src/txpool.rs @@ -1,17 +1,16 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 -use futures_timer::Delay; use starcoin_account_service::{AccountService, AccountStorage}; use starcoin_config::NodeConfig; +use starcoin_executor::VMMetrics; use starcoin_genesis::Genesis; use starcoin_miner::{BlockBuilderService, MinerService}; use starcoin_service_registry::bus::BusService; use starcoin_service_registry::{RegistryAsyncService, RegistryService, ServiceRef}; -use starcoin_storage::Storage; +use starcoin_storage::{BlockStore, Storage}; use starcoin_txpool::{TxPoolActorService, TxPoolService}; use std::sync::Arc; -use std::time::Duration; pub async fn start_txpool_with_size( pool_size: u64, @@ -59,14 +58,29 @@ pub async fn start_txpool_with_miner( .unwrap(); registry.register::().await.unwrap(); + let txpool_service = { + let startup_info = storage.get_startup_info().unwrap().unwrap(); + let best_block = storage + .get_block_by_hash(startup_info.main) + .unwrap() + .unwrap(); + let best_block_header = best_block.into_inner().0; + let vm_metric = registry.get_shared::().await.ok(); + TxPoolService::new( + node_config.clone(), + storage.clone(), + best_block_header, + vm_metric, + ) + }; + registry.put_shared(txpool_service.clone()).await.unwrap(); + //registry.register::().await.unwrap(); + let pool_actor = registry.register::().await.unwrap(); + if enable_miner { registry.register::().await.unwrap(); registry.register::().await.unwrap(); } - //registry.register::().await.unwrap(); - let pool_actor = registry.register::().await.unwrap(); - Delay::new(Duration::from_millis(200)).await; - let txpool_service = registry.get_shared::().await.unwrap(); (txpool_service, storage, node_config, pool_actor, registry) }