diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 000000000..fc82ca587 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,31 @@ +# An auto defined `clippy` feature was introduced, +# but it was found to clash with user defined features, +# so was renamed to `cargo-clippy`. +# +# If you want standard clippy run: +# RUSTFLAGS= cargo clippy +[target.'cfg(feature = "cargo-clippy")'] +rustflags = [ + "-Aclippy::all", + "-Dclippy::correctness", + "-Aclippy::if-same-then-else", + "-Aclippy::clone-double-ref", + "-Dclippy::complexity", + "-Aclippy::zero-prefixed-literal", # 00_1000_000 + "-Aclippy::type_complexity", # raison d'etre + "-Aclippy::nonminimal-bool", # maybe + "-Aclippy::borrowed-box", # Reasonable to fix this one + "-Aclippy::too-many-arguments", # (Turning this on would lead to) + "-Aclippy::unnecessary_cast", # Types may change + "-Aclippy::identity-op", # One case where we do 0 + + "-Aclippy::useless_conversion", # Types may change + "-Aclippy::unit_arg", # styalistic. + "-Aclippy::option-map-unit-fn", # styalistic + "-Aclippy::bind_instead_of_map", # styalistic + "-Aclippy::erasing_op", # E.g. 0 * DOLLARS + "-Aclippy::eq_op", # In tests we test equality. + "-Aclippy::while_immutable_condition", # false positives + "-Aclippy::needless_option_as_deref", # false positives + "-Aclippy::derivable_impls", # false positives + "-Aclippy::stable_sort_primitive", # prefer stable sort +] diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index db63d8d96..1ecb04c4b 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -35,6 +35,10 @@ jobs: - name: Rust Cache uses: Swatinem/rust-cache@v2 + - name: Check with Clippy + run: | + cargo clippy --no-deps --all-targets --features runtime-benchmarks --workspace -- --deny warnings + - name: Check Build run: | SKIP_WASM_BUILD=1 cargo check --release diff --git a/.gitignore b/.gitignore index 90db35e94..ac9d585fc 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,8 @@ .DS_Store # The cache for docker container dependency -.cargo +.cargo/** +!/.cargo/config.toml # The cache for chain data in container .local @@ -19,5 +20,3 @@ # ddc-metrics-offchain-worker mock files pallets/ddc-metrics-offchain-worker/src/tests/test_data/ddc.contract -pallets/ddc-metrics-offchain-worker/src/tests/test_data/ddc.wasm -pallets/ddc-metrics-offchain-worker/src/tests/test_data/metadata.json diff --git a/Cargo.lock b/Cargo.lock index 149864ce3..025b489bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -759,7 +759,6 @@ version = "4.8.1" dependencies = [ "cere-cli", "sc-cli", - "ss58-registry", "substrate-build-script-utils", ] @@ -785,7 +784,6 @@ dependencies = [ "cere-dev-runtime", "cere-runtime", "frame-benchmarking", - "frame-benchmarking-cli", "frame-system", "frame-system-rpc-runtime-api", "node-primitives", @@ -801,10 +799,8 @@ dependencies = [ "sp-blockchain", "sp-consensus", "sp-consensus-babe", - "sp-core", "sp-finality-grandpa", "sp-inherents", - "sp-keyring", "sp-offchain", "sp-runtime", "sp-session", @@ -880,7 +876,6 @@ dependencies = [ "pallet-tips", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", - "pallet-transaction-storage", "pallet-treasury", "pallet-utility", "pallet-vesting", @@ -909,7 +904,6 @@ name = "cere-dev-runtime-constants" version = "4.8.1" dependencies = [ "node-primitives", - "sp-runtime", ] [[package]] @@ -1005,7 +999,6 @@ dependencies = [ "pallet-tips", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", - "pallet-transaction-storage", "pallet-treasury", "pallet-utility", "pallet-vesting", @@ -1044,7 +1037,6 @@ name = "cere-runtime-constants" version = "4.8.1" dependencies = [ "node-primitives", - "sp-runtime", ] [[package]] @@ -1056,17 +1048,14 @@ dependencies = [ "cere-dev-runtime-constants", "cere-rpc", "cere-runtime", - "cere-runtime-constants", "futures", "jsonrpsee", "node-primitives", "pallet-im-online", - "parity-scale-codec", "rand 0.8.5", "sc-authority-discovery", "sc-basic-authorship", "sc-chain-spec", - "sc-cli", "sc-client-api", "sc-consensus", "sc-consensus-babe", @@ -1087,7 +1076,6 @@ dependencies = [ "sp-authority-discovery", "sp-authorship", "sp-blockchain", - "sp-consensus", "sp-consensus-babe", "sp-core", "sp-finality-grandpa", @@ -1651,11 +1639,7 @@ name = "ddc-traits" version = "0.1.0" dependencies = [ "ddc-primitives", - "frame-support", "frame-system", - "sp-core", - "sp-staking", - "sp-std", ] [[package]] @@ -4045,24 +4029,6 @@ version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" -[[package]] -name = "lite-json" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd0e787ffe1153141a0f6f6d759fdf1cc34b1226e088444523812fd412a5cca2" -dependencies = [ - "lite-parser", -] - -[[package]] -name = "lite-parser" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d5f9dc37c52d889a21fd701983d02bb6a84f852c5140a6c80ef4557f7dc29e" -dependencies = [ - "paste", -] - [[package]] name = "lock_api" version = "0.4.11" @@ -4778,16 +4744,13 @@ dependencies = [ name = "pallet-chainbridge" version = "4.8.1" dependencies = [ - "frame-benchmarking", "frame-support", "frame-system", - "lite-json", "pallet-balances", "parity-scale-codec", "scale-info", "sp-core", "sp-io", - "sp-keystore", "sp-runtime", "sp-std", ] @@ -4917,18 +4880,14 @@ version = "4.8.1" dependencies = [ "ddc-primitives", "ddc-traits", - "frame-benchmarking", "frame-support", "frame-system", - "log", "pallet-contracts", "pallet-ddc-nodes", "parity-scale-codec", "scale-info", "sp-core", - "sp-io", "sp-runtime", - "sp-staking", "sp-std", "sp-tracing", "substrate-test-utils", @@ -4945,9 +4904,7 @@ dependencies = [ "log", "parity-scale-codec", "scale-info", - "sp-io", "sp-runtime", - "sp-staking", "sp-std", "substrate-test-utils", ] @@ -4961,7 +4918,6 @@ dependencies = [ "frame-system", "hex", "hex-literal", - "lite-json", "pallet-balances", "pallet-contracts", "pallet-randomness-collective-flip", @@ -4969,7 +4925,6 @@ dependencies = [ "parity-scale-codec", "pretty_assertions", "scale-info", - "serde", "serde_json 1.0.44", "sp-core", "sp-io", @@ -4984,16 +4939,12 @@ version = "4.8.1" dependencies = [ "ddc-primitives", "ddc-traits", - "frame-benchmarking", "frame-support", "frame-system", - "log", "parity-scale-codec", "scale-info", "sp-core", - "sp-io", "sp-runtime", - "sp-staking", "sp-std", "sp-tracing", "substrate-test-utils", @@ -5008,7 +4959,6 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "log", "pallet-balances", "pallet-timestamp", "parity-scale-codec", @@ -5016,7 +4966,6 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-staking", "sp-std", "sp-tracing", "substrate-test-utils", @@ -5097,7 +5046,6 @@ dependencies = [ name = "pallet-erc20" version = "4.8.1" dependencies = [ - "frame-benchmarking", "frame-support", "frame-system", "pallet-balances", @@ -5105,7 +5053,6 @@ dependencies = [ "pallet-erc721", "parity-scale-codec", "scale-info", - "serde", "sp-arithmetic", "sp-core", "sp-io", @@ -5117,14 +5064,12 @@ dependencies = [ name = "pallet-erc721" version = "4.8.1" dependencies = [ - "frame-benchmarking", "frame-support", "frame-system", "pallet-balances", "pallet-chainbridge", "parity-scale-codec", "scale-info", - "serde", "sp-core", "sp-io", "sp-runtime", @@ -5585,24 +5530,6 @@ dependencies = [ "sp-runtime", ] -[[package]] -name = "pallet-transaction-storage" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.30#a3ed0119c45cdd0d571ad34e5b3ee7518c8cef8d" -dependencies = [ - "frame-support", - "frame-system", - "log", - "pallet-balances", - "parity-scale-codec", - "scale-info", - "sp-inherents", - "sp-io", - "sp-runtime", - "sp-std", - "sp-transaction-storage-proof", -] - [[package]] name = "pallet-treasury" version = "4.0.0-dev" diff --git a/Cargo.toml b/Cargo.toml index 3d7599231..27cff6711 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ build = "build.rs" [dependencies] cere-cli = { path = "cli", features = [ "cere-dev-native" ] } sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } -ss58-registry = { version = "1.38.0", default-features = false } [build-dependencies] substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } diff --git a/cli/src/command.rs b/cli/src/command.rs index 9865ccf85..665ba9d31 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -67,7 +67,7 @@ impl SubstrateCli for Cli { #[cfg(feature = "cere-native")] { - return &cere_service::cere_runtime::VERSION + &cere_service::cere_runtime::VERSION } #[cfg(not(feature = "cere-native"))] @@ -161,17 +161,17 @@ pub fn run() -> sc_cli::Result<()> { #[cfg(feature = "cere-dev-native")] if chain_spec.is_cere_dev() { - return Ok(runner.sync_run(|config| { + return runner.sync_run(|config| { cmd.run::(config) - })?) + }) } // else we assume it is Cere #[cfg(feature = "cere-native")] { - return Ok(runner.sync_run(|config| { + runner.sync_run(|config| { cmd.run::(config) - })?) + }) } #[cfg(not(feature = "cere-native"))] diff --git a/node/client/Cargo.toml b/node/client/Cargo.toml index dbafa5fa8..d83bb5b03 100644 --- a/node/client/Cargo.toml +++ b/node/client/Cargo.toml @@ -8,7 +8,6 @@ sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/subs sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } node-primitives = { version = "2.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -29,8 +28,6 @@ sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/su sp-storage = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-keyring = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" } # Local cere-runtime = { path = "../../runtime/cere", optional = true } diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index d444e3244..c6c8abdfb 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -4,13 +4,10 @@ version = "4.8.1" edition = "2021" [dependencies] -codec = { package = "parity-scale-codec", version = "3.1.5" } serde = { version = "1.0.136", features = ["derive"] } rand = "0.8" futures = "0.3.21" jsonrpsee = { version = "0.15.1", features = ["server"] } - -sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", features = ["wasmtime"] } @@ -18,7 +15,6 @@ sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/sub sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-consensus-babe = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sc-finality-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -47,8 +43,6 @@ sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/su # Local cere-client = { path = "../client", default-features = false, optional = true } cere-rpc = { path = "../../rpc" } - -cere-runtime-constants = { path = "../../runtime/cere/constants", optional = true } cere-dev-runtime-constants = { path = "../../runtime/cere-dev/constants", optional = true } cere-runtime = { path = "../../runtime/cere", optional = true } @@ -57,7 +51,7 @@ cere-dev-runtime = { path = "../../runtime/cere-dev", optional = true } [features] default = ["cere-native"] -cere-native = [ "cere-runtime", "cere-runtime-constants", "cere-client/cere" ] +cere-native = [ "cere-runtime", "cere-client/cere" ] cere-dev-native = [ "cere-dev-runtime", "cere-dev-runtime-constants", "cere-client/cere-dev" ] runtime-benchmarks = [ diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 6988b5641..ee62d08d1 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -88,7 +88,7 @@ where let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts::( - &config, + config, telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()), executor, )?; @@ -103,6 +103,7 @@ where Ok(Basics { task_manager, client, backend, keystore_container, telemetry }) } +#[allow(clippy::type_complexity)] fn new_partial( config: &Configuration, Basics { task_manager, backend, client, keystore_container, telemetry }: Basics< @@ -287,7 +288,7 @@ pub fn build_full( #[cfg(feature = "cere-native")] { - return new_full::( + new_full::( config, disable_hardware_benchmarks, enable_ddc_validation, @@ -347,7 +348,7 @@ where { let hwbench = if !disable_hardware_benchmarks { config.database.path().map(|database_path| { - let _ = std::fs::create_dir_all(&database_path); + let _ = std::fs::create_dir_all(database_path); sc_sysinfo::gather_hwbench(Some(database_path)) }) } else { @@ -461,7 +462,7 @@ where let proposer = sc_basic_authorship::ProposerFactory::new( task_manager.spawn_handle(), client.clone(), - transaction_pool.clone(), + transaction_pool, prometheus_registry.as_ref(), telemetry.as_ref().map(|x| x.handle()), ); @@ -628,6 +629,7 @@ macro_rules! chain_ops { }}; } +#[allow(clippy::type_complexity)] pub fn new_chain_ops( config: &Configuration, ) -> Result< @@ -646,7 +648,7 @@ pub fn new_chain_ops( #[cfg(feature = "cere-native")] { - return chain_ops!(config; cere_runtime, CereExecutorDispatch, Cere) + chain_ops!(config; cere_runtime, CereExecutorDispatch, Cere) } #[cfg(not(feature = "cere-native"))] diff --git a/pallets/chainbridge/Cargo.toml b/pallets/chainbridge/Cargo.toml index de714f861..455a0aa8a 100644 --- a/pallets/chainbridge/Cargo.toml +++ b/pallets/chainbridge/Cargo.toml @@ -20,26 +20,18 @@ sp-core = { version = "6.0.0", default-features = false, git = "https://github.c sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -lite-json = { version = "0.2.0", default-features = false } -sp-keystore = { version = "0.12.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } - [features] default = ["std"] std = [ "codec/std", "sp-runtime/std", - "frame-benchmarking/std", "frame-support/std", "frame-system/std", "pallet-balances/std", "sp-io/std", "sp-std/std", "sp-core/std", - "lite-json/std", - "sp-keystore", ] -runtime-benchmarks = ["frame-benchmarking"] diff --git a/pallets/chainbridge/src/lib.rs b/pallets/chainbridge/src/lib.rs index 1e48b4a7d..9972be688 100644 --- a/pallets/chainbridge/src/lib.rs +++ b/pallets/chainbridge/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::all)] // Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] @@ -36,7 +37,7 @@ pub fn derive_resource_id(chain: u8, id: &[u8]) -> ResourceId { for i in 0..range { r_id[30 - i] = id[range - 1 - i]; // Ensure left padding for eth compatibility } - return r_id + r_id } #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, scale_info::TypeInfo)] @@ -76,7 +77,7 @@ impl ProposalVotes { /// Returns true if `who` has voted for or against the proposal fn has_voted(&self, who: &A) -> bool { - self.votes_for.contains(&who) || self.votes_against.contains(&who) + self.votes_for.contains(who) || self.votes_against.contains(who) } /// Return true if the expiry time has been reached @@ -294,7 +295,7 @@ decl_module! { /// # /// - weight of proposed call, regardless of whether execution is performed /// # - #[weight = (call.get_dispatch_info().weight + Weight::from_ref_time(195_000_000 as u64), call.get_dispatch_info().class, Pays::Yes)] + #[weight = (call.get_dispatch_info().weight + Weight::from_ref_time(195_000_000_u64), call.get_dispatch_info().class, Pays::Yes)] pub fn acknowledge_proposal(origin, nonce: DepositNonce, src_id: ChainId, r_id: ResourceId, call: Box<::Proposal>) -> DispatchResult { let who = ensure_signed(origin)?; ensure!(Self::is_relayer(&who), Error::::MustBeRelayer); @@ -327,7 +328,7 @@ decl_module! { /// # /// - weight of proposed call, regardless of whether execution is performed /// # - #[weight = (prop.get_dispatch_info().weight + Weight::from_ref_time(195_000_000 as u64), prop.get_dispatch_info().class, Pays::Yes)] + #[weight = (prop.get_dispatch_info().weight + Weight::from_ref_time(195_000_000_u64), prop.get_dispatch_info().class, Pays::Yes)] pub fn eval_vote_state(origin, nonce: DepositNonce, src_id: ChainId, prop: Box<::Proposal>) -> DispatchResult { ensure_signed(origin)?; @@ -357,12 +358,12 @@ impl Module { /// Asserts if a resource is registered pub fn resource_exists(id: ResourceId) -> bool { - return Self::resources(id) != None + Self::resources(id).is_some() } /// Checks if a chain exists as a whitelisted destination pub fn chain_whitelisted(id: ChainId) -> bool { - return Self::chains(id) != None + Self::chains(id).is_some() } /// Increments the deposit nonce for the specified chain ID @@ -400,7 +401,7 @@ impl Module { ensure!(id != T::ChainId::get(), Error::::InvalidChainId); // Cannot whitelist with an existing entry ensure!(!Self::chain_whitelisted(id), Error::::ChainAlreadyWhitelisted); - ::insert(&id, 0); + ::insert(id, 0); Self::deposit_event(RawEvent::ChainWhitelisted(id)); Ok(()) } @@ -451,13 +452,13 @@ impl Module { if in_favour { votes.votes_for.push(who.clone()); - Self::deposit_event(RawEvent::VoteFor(src_id, nonce, who.clone())); + Self::deposit_event(RawEvent::VoteFor(src_id, nonce, who)); } else { votes.votes_against.push(who.clone()); - Self::deposit_event(RawEvent::VoteAgainst(src_id, nonce, who.clone())); + Self::deposit_event(RawEvent::VoteAgainst(src_id, nonce, who)); } - >::insert(src_id, (nonce, prop.clone()), votes.clone()); + >::insert(src_id, (nonce, prop), votes.clone()); Ok(()) } diff --git a/pallets/chainbridge/src/mock.rs b/pallets/chainbridge/src/mock.rs index 5e22f6e92..2a3fd20b5 100644 --- a/pallets/chainbridge/src/mock.rs +++ b/pallets/chainbridge/src/mock.rs @@ -152,6 +152,6 @@ pub fn assert_events(mut expected: Vec) { for evt in expected { let next = actual.pop().expect("event expected"); - assert_eq!(next, evt.into(), "Events don't match (actual,expected)"); + assert_eq!(next, evt, "Events don't match (actual,expected)"); } } diff --git a/pallets/chainbridge/src/tests.rs b/pallets/chainbridge/src/tests.rs index bd0ae5a03..ce0e308c0 100644 --- a/pallets/chainbridge/src/tests.rs +++ b/pallets/chainbridge/src/tests.rs @@ -137,50 +137,50 @@ fn asset_transfer_success() { let token_id = vec![1, 2, 3, 4]; let method = "Erc20.transfer".as_bytes().to_vec(); - assert_ok!(Bridge::set_resource(RuntimeOrigin::root(), resource_id, method.clone())); + assert_ok!(Bridge::set_resource(RuntimeOrigin::root(), resource_id, method)); assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), TEST_THRESHOLD,)); - assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), dest_id.clone())); + assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), dest_id)); assert_ok!(Bridge::transfer_fungible( - dest_id.clone(), - resource_id.clone(), + dest_id, + resource_id, to.clone(), amount.into() )); assert_events(vec![ - RuntimeEvent::Bridge(RawEvent::ChainWhitelisted(dest_id.clone())), + RuntimeEvent::Bridge(RawEvent::ChainWhitelisted(dest_id)), RuntimeEvent::Bridge(RawEvent::FungibleTransfer( - dest_id.clone(), + dest_id, 1, - resource_id.clone(), + resource_id, amount.into(), to.clone(), )), ]); assert_ok!(Bridge::transfer_nonfungible( - dest_id.clone(), - resource_id.clone(), + dest_id, + resource_id, token_id.clone(), to.clone(), metadata.clone() )); assert_events(vec![RuntimeEvent::Bridge(RawEvent::NonFungibleTransfer( - dest_id.clone(), + dest_id, 2, - resource_id.clone(), + resource_id, token_id, - to.clone(), + to, metadata.clone(), ))]); assert_ok!(Bridge::transfer_generic( - dest_id.clone(), - resource_id.clone(), + dest_id, + resource_id, metadata.clone() )); assert_events(vec![RuntimeEvent::Bridge(RawEvent::GenericTransfer( - dest_id.clone(), + dest_id, 3, resource_id, metadata, @@ -197,13 +197,13 @@ fn asset_transfer_invalid_resource_id() { let amount = 100; assert_ok!(Bridge::set_threshold(RuntimeOrigin::root(), TEST_THRESHOLD,)); - assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), dest_id.clone())); + assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), dest_id)); assert_noop!( Bridge::transfer_fungible( - dest_id.clone(), - resource_id.clone(), - to.clone(), + dest_id, + resource_id, + to, amount.into() ), Error::::ResourceDoesNotExist @@ -211,8 +211,8 @@ fn asset_transfer_invalid_resource_id() { assert_noop!( Bridge::transfer_nonfungible( - dest_id.clone(), - resource_id.clone(), + dest_id, + resource_id, vec![], vec![], vec![] @@ -221,7 +221,7 @@ fn asset_transfer_invalid_resource_id() { ); assert_noop!( - Bridge::transfer_generic(dest_id.clone(), resource_id.clone(), vec![]), + Bridge::transfer_generic(dest_id, resource_id, vec![]), Error::::ResourceDoesNotExist ); }) @@ -234,21 +234,21 @@ fn asset_transfer_invalid_chain() { let bad_dest_id = 3; let resource_id = [4; 32]; - assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), chain_id.clone())); - assert_events(vec![RuntimeEvent::Bridge(RawEvent::ChainWhitelisted(chain_id.clone()))]); + assert_ok!(Bridge::whitelist_chain(RuntimeOrigin::root(), chain_id)); + assert_events(vec![RuntimeEvent::Bridge(RawEvent::ChainWhitelisted(chain_id))]); assert_noop!( - Bridge::transfer_fungible(bad_dest_id, resource_id.clone(), vec![], U256::zero()), + Bridge::transfer_fungible(bad_dest_id, resource_id, vec![], U256::zero()), Error::::ChainNotWhitelisted ); assert_noop!( - Bridge::transfer_nonfungible(bad_dest_id, resource_id.clone(), vec![], vec![], vec![]), + Bridge::transfer_nonfungible(bad_dest_id, resource_id, vec![], vec![], vec![]), Error::::ChainNotWhitelisted ); assert_noop!( - Bridge::transfer_generic(bad_dest_id, resource_id.clone(), vec![]), + Bridge::transfer_generic(bad_dest_id, resource_id, vec![]), Error::::ChainNotWhitelisted ); }) @@ -310,7 +310,7 @@ fn create_sucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -327,7 +327,7 @@ fn create_sucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![RELAYER_B], @@ -344,7 +344,7 @@ fn create_sucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A, RELAYER_C], votes_against: vec![RELAYER_B], @@ -380,7 +380,7 @@ fn create_unsucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -397,7 +397,7 @@ fn create_unsucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![RELAYER_B], @@ -414,7 +414,7 @@ fn create_unsucessful_proposal() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![RELAYER_B, RELAYER_C], @@ -452,7 +452,7 @@ fn execute_after_threshold_change() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -472,7 +472,7 @@ fn execute_after_threshold_change() { Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -510,7 +510,7 @@ fn proposal_expires() { r_id, Box::new(proposal.clone()) )); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -535,7 +535,7 @@ fn proposal_expires() { ); // Proposal state should remain unchanged - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal.clone())).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], @@ -554,7 +554,7 @@ fn proposal_expires() { ), Error::::ProposalExpired ); - let prop = Bridge::votes(src_id, (prop_id.clone(), proposal.clone())).unwrap(); + let prop = Bridge::votes(src_id, (prop_id, proposal)).unwrap(); let expected = ProposalVotes { votes_for: vec![RELAYER_A], votes_against: vec![], diff --git a/pallets/ddc-clusters/Cargo.toml b/pallets/ddc-clusters/Cargo.toml index 62f59dd67..0ef556a69 100644 --- a/pallets/ddc-clusters/Cargo.toml +++ b/pallets/ddc-clusters/Cargo.toml @@ -7,16 +7,11 @@ edition = "2021" codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } pallet-contracts = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-ddc-nodes = { version = "4.7.0", default-features = false, path = "../ddc-nodes" } @@ -32,14 +27,10 @@ std = [ "ddc-primitives/std", "frame-support/std", "frame-system/std", - "frame-benchmarking/std", "pallet-contracts/std", "pallet-ddc-nodes/std", "scale-info/std", "sp-core/std", - "sp-io/std", "sp-runtime/std", - "sp-staking/std", "sp-std/std", ] -runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/pallets/ddc-clusters/src/lib.rs b/pallets/ddc-clusters/src/lib.rs index cb4aafb7b..4c52afd96 100644 --- a/pallets/ddc-clusters/src/lib.rs +++ b/pallets/ddc-clusters/src/lib.rs @@ -16,7 +16,7 @@ #![feature(is_some_and)] // ToDo: delete at rustc > 1.70 use crate::{ - cluster::{Cluster, ClusterError, ClusterGovParams, ClusterParams}, + cluster::{Cluster, ClusterGovParams, ClusterParams}, node_provider_auth::{NodeProviderAuthContract, NodeProviderAuthContractError}, }; use ddc_primitives::{ClusterId, NodePubKey, NodeType}; @@ -124,17 +124,13 @@ pub mod pallet { cluster_gov_params: ClusterGovParams, T::BlockNumber>, ) -> DispatchResult { ensure_root(origin)?; // requires Governance approval - let cluster = Cluster::new( - cluster_id.clone(), - cluster_manager_id, - cluster_reserve_id, - cluster_params, - ) - .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; - ensure!(!Clusters::::contains_key(&cluster_id), Error::::ClusterAlreadyExists); - - Clusters::::insert(cluster_id.clone(), cluster); - ClustersGovParams::::insert(cluster_id.clone(), cluster_gov_params); + let cluster = + Cluster::new(cluster_id, cluster_manager_id, cluster_reserve_id, cluster_params) + .map_err(Into::>::into)?; + ensure!(!Clusters::::contains_key(cluster_id), Error::::ClusterAlreadyExists); + + Clusters::::insert(cluster_id, cluster); + ClustersGovParams::::insert(cluster_id, cluster_gov_params); Self::deposit_event(Event::::ClusterCreated { cluster_id }); Ok(()) @@ -148,7 +144,7 @@ pub mod pallet { ) -> DispatchResult { let caller_id = ensure_signed(origin)?; let cluster = - Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + Clusters::::try_get(cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); // Node with this node with this public key exists. @@ -158,12 +154,12 @@ pub mod pallet { // Sufficient funds are locked at the DDC Staking module. let has_stake = T::StakingVisitor::node_has_stake(&node_pub_key, &cluster_id) - .map_err(|e| Into::>::into(StakingVisitorError::from(e)))?; + .map_err(Into::>::into)?; ensure!(has_stake, Error::::NodeHasNoStake); // Candidate is not planning to pause operations any time soon. let is_chilling = T::StakingVisitor::node_is_chilling(&node_pub_key) - .map_err(|e| Into::>::into(StakingVisitorError::from(e)))?; + .map_err(Into::>::into)?; ensure!(!is_chilling, Error::::NodeChillingIsProhibited); // Cluster extension smart contract allows joining. @@ -174,16 +170,16 @@ pub mod pallet { let is_authorized = auth_contract .is_authorized( node.get_provider_id().to_owned(), - node.get_pub_key().to_owned(), + node.get_pub_key(), node.get_type(), ) - .map_err(|e| Into::>::into(NodeProviderAuthContractError::from(e)))?; + .map_err(Into::>::into)?; ensure!(is_authorized, Error::::NodeIsNotAuthorized); // Add node to the cluster. - node.set_cluster_id(Some(cluster_id.clone())); + node.set_cluster_id(Some(cluster_id)); T::NodeRepository::update(node).map_err(|_| Error::::AttemptToAddNonExistentNode)?; - ClustersNodes::::insert(cluster_id.clone(), node_pub_key.clone(), true); + ClustersNodes::::insert(cluster_id, node_pub_key.clone(), true); Self::deposit_event(Event::::ClusterNodeAdded { cluster_id, node_pub_key }); Ok(()) @@ -197,7 +193,7 @@ pub mod pallet { ) -> DispatchResult { let caller_id = ensure_signed(origin)?; let cluster = - Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + Clusters::::try_get(cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); let mut node = T::NodeRepository::get(node_pub_key.clone()) .map_err(|_| Error::::AttemptToRemoveNonExistentNode)?; @@ -205,7 +201,7 @@ pub mod pallet { node.set_cluster_id(None); T::NodeRepository::update(node) .map_err(|_| Error::::AttemptToRemoveNonExistentNode)?; - ClustersNodes::::remove(cluster_id.clone(), node_pub_key.clone()); + ClustersNodes::::remove(cluster_id, node_pub_key.clone()); Self::deposit_event(Event::::ClusterNodeRemoved { cluster_id, node_pub_key }); Ok(()) @@ -220,12 +216,10 @@ pub mod pallet { ) -> DispatchResult { let caller_id = ensure_signed(origin)?; let mut cluster = - Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + Clusters::::try_get(cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; ensure!(cluster.manager_id == caller_id, Error::::OnlyClusterManager); - cluster - .set_params(cluster_params) - .map_err(|e: ClusterError| Into::>::into(ClusterError::from(e)))?; - Clusters::::insert(cluster_id.clone(), cluster); + cluster.set_params(cluster_params).map_err(Into::>::into)?; + Clusters::::insert(cluster_id, cluster); Self::deposit_event(Event::::ClusterParamsSet { cluster_id }); Ok(()) @@ -240,8 +234,8 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; // requires Governance approval let _cluster = - Clusters::::try_get(&cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; - ClustersGovParams::::insert(cluster_id.clone(), cluster_gov_params); + Clusters::::try_get(cluster_id).map_err(|_| Error::::ClusterDoesNotExist)?; + ClustersGovParams::::insert(cluster_id, cluster_gov_params); Self::deposit_event(Event::::ClusterGovParamsSet { cluster_id }); Ok(()) @@ -254,7 +248,7 @@ pub mod pallet { } fn ensure_cluster(cluster_id: &ClusterId) -> Result<(), ClusterVisitorError> { - Clusters::::get(&cluster_id) + Clusters::::get(cluster_id) .map(|_| ()) .ok_or(ClusterVisitorError::ClusterDoesNotExist) } diff --git a/pallets/ddc-customers/Cargo.toml b/pallets/ddc-customers/Cargo.toml index 48cdf287f..8d60ba44f 100644 --- a/pallets/ddc-customers/Cargo.toml +++ b/pallets/ddc-customers/Cargo.toml @@ -10,9 +10,7 @@ ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } log = { version = "0.4.17", default-features = false } @@ -27,8 +25,6 @@ std = [ "frame-support/std", "frame-system/std", "scale-info/std", - "sp-io/std", "sp-runtime/std", - "sp-staking/std", "sp-std/std", ] diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index d544ced22..f807f0985 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -333,7 +333,7 @@ pub mod pallet { Self::update_ledger_and_deposit(&owner, &ledger)?; - Self::deposit_event(Event::::Deposited(owner.clone(), extra)); + Self::deposit_event(Event::::Deposited(owner, extra)); Ok(()) } @@ -500,7 +500,7 @@ pub mod pallet { /// This is called: /// - after a `withdraw_unlocked_deposit()` call that frees all of a owner's locked balance. fn kill_owner(owner: &T::AccountId) -> DispatchResult { - >::remove(&owner); + >::remove(owner); frame_system::Pallet::::dec_consumers(owner); diff --git a/pallets/ddc-metrics-offchain-worker/Cargo.toml b/pallets/ddc-metrics-offchain-worker/Cargo.toml index 74747a397..3ab61de26 100644 --- a/pallets/ddc-metrics-offchain-worker/Cargo.toml +++ b/pallets/ddc-metrics-offchain-worker/Cargo.toml @@ -16,14 +16,12 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["full"] } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -serde = { version = "1.0.136", optional = true } sp-keystore = { version = "0.12.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-contracts = { version = '4.0.0-dev', default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -lite-json = { version = "0.2.0", default-features = false } alt_serde = { version = "1", default-features = false, features = ["derive"] } serde_json = { version = "1", default-features = false, git = "https://github.com/Cerebellum-Network/json", branch = "no-std-cere", features = ["alloc"] } # pallet-contracts-rpc-runtime-api = { version = "0.8.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -38,8 +36,6 @@ std = [ "sp-keystore", "frame-support/std", "frame-system/std", - "serde", - "lite-json/std", "sp-core/std", "sp-io/std", "sp-runtime/std", diff --git a/pallets/ddc-metrics-offchain-worker/src/lib.rs b/pallets/ddc-metrics-offchain-worker/src/lib.rs index 991fdabb2..ffa2dfbb1 100644 --- a/pallets/ddc-metrics-offchain-worker/src/lib.rs +++ b/pallets/ddc-metrics-offchain-worker/src/lib.rs @@ -1,7 +1,7 @@ // Offchain worker for DDC metrics. // // Inspired from https://github.com/paritytech/substrate/tree/master/frame/example-offchain-worker - +#![allow(clippy::all)] #![cfg_attr(not(feature = "std"), no_std)] #[cfg(test)] @@ -19,7 +19,7 @@ use frame_system::offchain::{ }; use hex_literal::hex; -use pallet_contracts; + use sp_core::crypto::{KeyTypeId, UncheckedFrom}; use sp_runtime::{ offchain::{http, storage::StorageValueRef, Duration}, @@ -194,7 +194,7 @@ where }; let should_proceed = Self::check_if_should_proceed(block_number); - if should_proceed == false { + if !should_proceed { return Ok(()) } @@ -246,7 +246,7 @@ where let block_timestamp = sp_io::offchain::timestamp().unix_millis(); if day_end_ms < block_timestamp { - Self::finalize_metric_period(contract_address.clone(), &signer, day_start_ms).map_err( + Self::finalize_metric_period(contract_address, &signer, day_start_ms).map_err( |err| { error!("[OCW] Contract error occurred: {:?}", err); "could not call finalize_metric_period TX" @@ -304,11 +304,10 @@ where ); Err("Skipping") } else { - let block_interval_configured = Self::get_block_interval(); let mut block_interval = T::BlockInterval::get(); - if block_interval_configured.is_some() { + if let Some(block_interval_configured) = Self::get_block_interval() { block_interval = ::BlockNumber::from( - block_interval_configured.unwrap(), + block_interval_configured, ); } @@ -327,8 +326,8 @@ where fn get_start_of_day_ms() -> u64 { let now = sp_io::offchain::timestamp(); - let day_start_ms = (now.unix_millis() / MS_PER_DAY) * MS_PER_DAY; - day_start_ms + + (now.unix_millis() / MS_PER_DAY) * MS_PER_DAY } fn get_signer() -> ResultStr> { @@ -520,7 +519,7 @@ where account.id, p2p_id, is_online, ); - let call_data = Self::encode_report_ddn_status(&p2p_id, is_online); + let call_data = Self::encode_report_ddn_status(p2p_id, is_online); let contract_id_unl = <::Lookup as StaticLookup>::unlookup( contract_id.clone(), @@ -641,12 +640,12 @@ where "HTTP GET error" })?; - let parsed = serde_json::from_slice(&body).map_err(|err| { + + + serde_json::from_slice(&body).map_err(|err| { warn!("[OCW] Error while parsing JSON from {}: {:?}", url, err); "HTTP JSON parse error" - }); - - parsed + }) } fn http_get_request(http_url: &str) -> Result, http::Error> { @@ -753,7 +752,12 @@ impl MetricsAggregator { let existing_pubkey_index = self.0.iter().position(|one_result_obj| metric.app_id == one_result_obj.app_id); - if existing_pubkey_index.is_none() { + if let Some(existing_pubkey_index) = existing_pubkey_index { + // Add to metrics of an existing app. + self.0[existing_pubkey_index].storage_bytes += metric.storage_bytes; + self.0[existing_pubkey_index].wcu_used += metric.wcu_used; + self.0[existing_pubkey_index].rcu_used += metric.rcu_used; + } else { // New app. let new_metric_obj = Metric { app_id: metric.app_id.clone(), @@ -762,11 +766,6 @@ impl MetricsAggregator { rcu_used: metric.rcu_used, }; self.0.push(new_metric_obj); - } else { - // Add to metrics of an existing app. - self.0[existing_pubkey_index.unwrap()].storage_bytes += metric.storage_bytes; - self.0[existing_pubkey_index.unwrap()].wcu_used += metric.wcu_used; - self.0[existing_pubkey_index.unwrap()].rcu_used += metric.rcu_used; } } diff --git a/pallets/ddc-metrics-offchain-worker/src/tests/mod.rs b/pallets/ddc-metrics-offchain-worker/src/tests/mod.rs index a261b10c8..7480f8ea3 100644 --- a/pallets/ddc-metrics-offchain-worker/src/tests/mod.rs +++ b/pallets/ddc-metrics-offchain-worker/src/tests/mod.rs @@ -295,7 +295,7 @@ fn should_run_contract() { .unwrap(); let contract_exec_result = pallet_contracts::Pallet::::bare_call( - alice.clone(), + alice, contract_id, 0, Weight::from_ref_time(100_000_000_000), @@ -317,7 +317,7 @@ pub const CTOR_SELECTOR: [u8; 4] = hex!("9bae9d5e"); fn encode_constructor() -> Vec { let mut call_data = CTOR_SELECTOR.to_vec(); - let x = 0 as u128; + let x = 0_u128; for _ in 0..9 { x.encode_to(&mut call_data); } @@ -344,13 +344,13 @@ fn deploy_contract() -> AccountId { GAS_LIMIT, None, wasm.to_vec(), - contract_args.clone(), + contract_args, vec![], ) .unwrap(); // Configure worker with the contract address. - let contract_id = Contracts::contract_address(&alice, &wasm_hash, &vec![]); + let contract_id = Contracts::contract_address(&alice, &wasm_hash, &[]); pub const ADD_DDC_NODE_SELECTOR: [u8; 4] = hex!("11a9e1b9"); diff --git a/pallets/ddc-metrics-offchain-worker/src/tests/test_data/ddc.wasm b/pallets/ddc-metrics-offchain-worker/src/tests/test_data/ddc.wasm new file mode 100644 index 000000000..e69de29bb diff --git a/pallets/ddc-metrics-offchain-worker/src/tests/test_data/metadata.json b/pallets/ddc-metrics-offchain-worker/src/tests/test_data/metadata.json new file mode 100644 index 000000000..e69de29bb diff --git a/pallets/ddc-nodes/Cargo.toml b/pallets/ddc-nodes/Cargo.toml index 65f5d098b..a233a53c7 100644 --- a/pallets/ddc-nodes/Cargo.toml +++ b/pallets/ddc-nodes/Cargo.toml @@ -7,16 +7,11 @@ edition = "2021" codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false, features = ["derive"] } ddc-primitives = { version = "0.1.0", default-features = false, path = "../../primitives" } ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits" } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", default-features = false } [dev-dependencies] sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -30,12 +25,8 @@ std = [ "ddc-primitives/std", "frame-support/std", "frame-system/std", - "frame-benchmarking/std", "scale-info/std", - "sp-io/std", "sp-runtime/std", - "sp-staking/std", "sp-std/std", "sp-core/std", ] -runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/pallets/ddc-nodes/src/cdn_node.rs b/pallets/ddc-nodes/src/cdn_node.rs index 5b3954953..1c8f19de1 100644 --- a/pallets/ddc-nodes/src/cdn_node.rs +++ b/pallets/ddc-nodes/src/cdn_node.rs @@ -1,4 +1,4 @@ -use crate::node::{Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKeyRef, NodeTrait}; +use crate::node::{NodeError, NodeParams, NodeProps, NodePropsRef, NodeTrait}; use codec::{Decode, Encode}; use ddc_primitives::{CDNNodePubKey, ClusterId, NodePubKey, NodeType}; use frame_support::{parameter_types, BoundedVec}; @@ -36,15 +36,44 @@ pub struct CDNNodeParams { pub p2p_port: u16, } +impl CDNNode { + pub fn new( + node_pub_key: NodePubKey, + provider_id: T::AccountId, + node_params: NodeParams, + ) -> Result { + match node_pub_key { + NodePubKey::CDNPubKey(pub_key) => match node_params { + NodeParams::CDNParams(node_params) => Ok(CDNNode:: { + provider_id, + pub_key, + cluster_id: None, + props: CDNNodeProps { + host: match node_params.host.try_into() { + Ok(vec) => vec, + Err(_) => return Err(NodeError::CDNHostLenExceedsLimit), + }, + http_port: node_params.http_port, + grpc_port: node_params.grpc_port, + p2p_port: node_params.p2p_port, + }, + }), + _ => Err(NodeError::InvalidCDNNodeParams), + }, + _ => Err(NodeError::InvalidCDNNodePubKey), + } + } +} + impl NodeTrait for CDNNode { - fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { - NodePubKeyRef::CDNPubKeyRef(&self.pub_key) + fn get_pub_key(&self) -> NodePubKey { + NodePubKey::CDNPubKey(self.pub_key.clone()) } fn get_provider_id(&self) -> &T::AccountId { &self.provider_id } - fn get_props<'a>(&'a self) -> NodePropsRef<'a> { - NodePropsRef::CDNPropsRef(&self.props) + fn get_props(&self) -> NodePropsRef { + NodePropsRef::CDNPropsRef(self.props.clone()) } fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError> { self.props = match props { @@ -77,30 +106,4 @@ impl NodeTrait for CDNNode { fn get_type(&self) -> NodeType { NodeType::CDN } - fn new( - node_pub_key: NodePubKey, - provider_id: T::AccountId, - node_params: NodeParams, - ) -> Result, NodeError> { - match node_pub_key { - NodePubKey::CDNPubKey(pub_key) => match node_params { - NodeParams::CDNParams(node_params) => Ok(Node::CDN(CDNNode:: { - provider_id, - pub_key, - cluster_id: None, - props: CDNNodeProps { - host: match node_params.host.try_into() { - Ok(vec) => vec, - Err(_) => return Err(NodeError::CDNHostLenExceedsLimit), - }, - http_port: node_params.http_port, - grpc_port: node_params.grpc_port, - p2p_port: node_params.p2p_port, - }, - })), - _ => Err(NodeError::InvalidCDNNodeParams), - }, - _ => Err(NodeError::InvalidCDNNodePubKey), - } - } } diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index 6da1c7076..c655feb53 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -84,8 +84,8 @@ pub mod pallet { ) -> DispatchResult { let caller_id = ensure_signed(origin)?; let node = Node::::new(node_pub_key.clone(), caller_id, node_params) - .map_err(|e| Into::>::into(NodeError::from(e)))?; - Self::create(node).map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + .map_err(Into::>::into)?; + Self::create(node).map_err(Into::>::into)?; Self::deposit_event(Event::::NodeCreated { node_pub_key }); Ok(()) } @@ -93,12 +93,10 @@ pub mod pallet { #[pallet::weight(10_000)] pub fn delete_node(origin: OriginFor, node_pub_key: NodePubKey) -> DispatchResult { let caller_id = ensure_signed(origin)?; - let node = Self::get(node_pub_key.clone()) - .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + let node = Self::get(node_pub_key.clone()).map_err(Into::>::into)?; ensure!(node.get_provider_id() == &caller_id, Error::::OnlyNodeProvider); ensure!(node.get_cluster_id().is_none(), Error::::NodeIsAssignedToCluster); - Self::delete(node_pub_key.clone()) - .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + Self::delete(node_pub_key.clone()).map_err(Into::>::into)?; Self::deposit_event(Event::::NodeDeleted { node_pub_key }); Ok(()) } @@ -110,12 +108,10 @@ pub mod pallet { node_params: NodeParams, ) -> DispatchResult { let caller_id = ensure_signed(origin)?; - let mut node = Self::get(node_pub_key.clone()) - .map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + let mut node = Self::get(node_pub_key.clone()).map_err(Into::>::into)?; ensure!(node.get_provider_id() == &caller_id, Error::::OnlyNodeProvider); - node.set_params(node_params) - .map_err(|e| Into::>::into(NodeError::from(e)))?; - Self::update(node).map_err(|e| Into::>::into(NodeRepositoryError::from(e)))?; + node.set_params(node_params).map_err(Into::>::into)?; + Self::update(node).map_err(Into::>::into)?; Self::deposit_event(Event::::NodeParamsChanged { node_pub_key }); Ok(()) } diff --git a/pallets/ddc-nodes/src/node.rs b/pallets/ddc-nodes/src/node.rs index 25ab35f44..fbf962d1f 100644 --- a/pallets/ddc-nodes/src/node.rs +++ b/pallets/ddc-nodes/src/node.rs @@ -1,3 +1,5 @@ +#![allow(clippy::needless_lifetimes)] // ToDo + use crate::{ cdn_node::{CDNNode, CDNNodeParams, CDNNodeProps}, pallet::Error, @@ -5,7 +7,7 @@ use crate::{ ClusterId, }; use codec::{Decode, Encode}; -use ddc_primitives::{CDNNodePubKey, NodePubKey, NodeType, StorageNodePubKey}; +use ddc_primitives::{NodePubKey, NodeType}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; @@ -30,46 +32,39 @@ pub enum NodeProps { } #[derive(Clone, RuntimeDebug, PartialEq)] -pub enum NodePubKeyRef<'a> { - StoragePubKeyRef(&'a StorageNodePubKey), - CDNPubKeyRef(&'a CDNNodePubKey), -} - -impl<'a> NodePubKeyRef<'a> { - pub fn to_owned(&self) -> NodePubKey { - match &self { - NodePubKeyRef::StoragePubKeyRef(pub_key_ref) => - NodePubKey::StoragePubKey((**pub_key_ref).clone()), - NodePubKeyRef::CDNPubKeyRef(pub_key_ref) => - NodePubKey::CDNPubKey((**pub_key_ref).clone()), - } - } -} - -#[derive(Clone, RuntimeDebug, PartialEq)] -pub enum NodePropsRef<'a> { - StoragePropsRef(&'a StorageNodeProps), - CDNPropsRef(&'a CDNNodeProps), +pub enum NodePropsRef { + StoragePropsRef(StorageNodeProps), + CDNPropsRef(CDNNodeProps), } pub trait NodeTrait { - fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a>; + fn get_pub_key(&self) -> NodePubKey; fn get_provider_id(&self) -> &T::AccountId; - fn get_props<'a>(&'a self) -> NodePropsRef<'a>; + fn get_props(&self) -> NodePropsRef; fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError>; fn set_params(&mut self, props: NodeParams) -> Result<(), NodeError>; fn get_cluster_id(&self) -> &Option; fn set_cluster_id(&mut self, cluster_id: Option); fn get_type(&self) -> NodeType; - fn new( +} + +impl Node { + pub fn new( node_pub_key: NodePubKey, provider_id: T::AccountId, - params: NodeParams, - ) -> Result, NodeError>; + node_params: NodeParams, + ) -> Result { + match node_pub_key { + NodePubKey::StoragePubKey(_) => + StorageNode::new(node_pub_key, provider_id, node_params).map(|n| Node::Storage(n)), + NodePubKey::CDNPubKey(_) => + CDNNode::new(node_pub_key, provider_id, node_params).map(|n| Node::CDN(n)), + } + } } impl NodeTrait for Node { - fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { + fn get_pub_key(&self) -> NodePubKey { match &self { Node::Storage(node) => node.get_pub_key(), Node::CDN(node) => node.get_pub_key(), @@ -81,7 +76,7 @@ impl NodeTrait for Node { Node::CDN(node) => node.get_provider_id(), } } - fn get_props<'a>(&'a self) -> NodePropsRef<'a> { + fn get_props(&self) -> NodePropsRef { match &self { Node::Storage(node) => node.get_props(), Node::CDN(node) => node.get_props(), @@ -117,17 +112,6 @@ impl NodeTrait for Node { Node::CDN(node) => node.get_type(), } } - fn new( - node_pub_key: NodePubKey, - provider_id: T::AccountId, - node_params: NodeParams, - ) -> Result, NodeError> { - match node_pub_key { - NodePubKey::StoragePubKey(_) => - StorageNode::new(node_pub_key, provider_id, node_params), - NodePubKey::CDNPubKey(_) => CDNNode::new(node_pub_key, provider_id, node_params), - } - } } pub enum NodeError { diff --git a/pallets/ddc-nodes/src/storage_node.rs b/pallets/ddc-nodes/src/storage_node.rs index 578afeb09..83fd2b11f 100644 --- a/pallets/ddc-nodes/src/storage_node.rs +++ b/pallets/ddc-nodes/src/storage_node.rs @@ -1,4 +1,4 @@ -use crate::node::{Node, NodeError, NodeParams, NodeProps, NodePropsRef, NodePubKeyRef, NodeTrait}; +use crate::node::{NodeError, NodeParams, NodeProps, NodePropsRef, NodeTrait}; use codec::{Decode, Encode}; use ddc_primitives::{ClusterId, NodePubKey, NodeType, StorageNodePubKey}; use frame_support::{parameter_types, BoundedVec}; @@ -36,15 +36,44 @@ pub struct StorageNodeParams { pub p2p_port: u16, } +impl StorageNode { + pub fn new( + node_pub_key: NodePubKey, + provider_id: T::AccountId, + node_params: NodeParams, + ) -> Result { + match node_pub_key { + NodePubKey::StoragePubKey(pub_key) => match node_params { + NodeParams::StorageParams(node_params) => Ok(StorageNode:: { + provider_id, + pub_key, + cluster_id: None, + props: StorageNodeProps { + host: match node_params.host.try_into() { + Ok(vec) => vec, + Err(_) => return Err(NodeError::StorageHostLenExceedsLimit), + }, + http_port: node_params.http_port, + grpc_port: node_params.grpc_port, + p2p_port: node_params.p2p_port, + }, + }), + _ => Err(NodeError::InvalidStorageNodeParams), + }, + _ => Err(NodeError::InvalidStorageNodePubKey), + } + } +} + impl NodeTrait for StorageNode { - fn get_pub_key<'a>(&'a self) -> NodePubKeyRef<'a> { - NodePubKeyRef::StoragePubKeyRef(&self.pub_key) + fn get_pub_key(&self) -> NodePubKey { + NodePubKey::StoragePubKey(self.pub_key.clone()) } fn get_provider_id(&self) -> &T::AccountId { &self.provider_id } - fn get_props<'a>(&'a self) -> NodePropsRef<'a> { - NodePropsRef::StoragePropsRef(&self.props) + fn get_props(&self) -> NodePropsRef { + NodePropsRef::StoragePropsRef(self.props.clone()) } fn set_props(&mut self, props: NodeProps) -> Result<(), NodeError> { self.props = match props { @@ -77,30 +106,4 @@ impl NodeTrait for StorageNode { fn get_type(&self) -> NodeType { NodeType::Storage } - fn new( - node_pub_key: NodePubKey, - provider_id: T::AccountId, - node_params: NodeParams, - ) -> Result, NodeError> { - match node_pub_key { - NodePubKey::StoragePubKey(pub_key) => match node_params { - NodeParams::StorageParams(node_params) => Ok(Node::Storage(StorageNode:: { - provider_id, - pub_key, - cluster_id: None, - props: StorageNodeProps { - host: match node_params.host.try_into() { - Ok(vec) => vec, - Err(_) => return Err(NodeError::StorageHostLenExceedsLimit), - }, - http_port: node_params.http_port, - grpc_port: node_params.grpc_port, - p2p_port: node_params.p2p_port, - }, - })), - _ => Err(NodeError::InvalidStorageNodeParams), - }, - _ => Err(NodeError::InvalidStorageNodePubKey), - } - } } diff --git a/pallets/ddc-staking/Cargo.toml b/pallets/ddc-staking/Cargo.toml index 9fbcc154e..0f9c57433 100644 --- a/pallets/ddc-staking/Cargo.toml +++ b/pallets/ddc-staking/Cargo.toml @@ -10,11 +10,9 @@ ddc-traits = { version = "0.1.0", default-features = false, path = "../../traits frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -log = { version = "0.4.17", default-features = false } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } sp-io = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-runtime = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } [dev-dependencies] @@ -35,7 +33,6 @@ std = [ "scale-info/std", "sp-io/std", "sp-runtime/std", - "sp-staking/std", "sp-std/std", ] runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"] diff --git a/pallets/ddc-staking/src/benchmarking.rs b/pallets/ddc-staking/src/benchmarking.rs index d682ec9c0..6353e4a5d 100644 --- a/pallets/ddc-staking/src/benchmarking.rs +++ b/pallets/ddc-staking/src/benchmarking.rs @@ -5,7 +5,7 @@ use crate::Pallet as DdcStaking; use ddc_primitives::{CDNNodePubKey, NodeType}; use testing_utils::*; -use frame_support::traits::{Currency, Get}; +use frame_support::traits::Currency; use sp_runtime::traits::StaticLookup; use sp_std::prelude::*; @@ -91,7 +91,7 @@ benchmarks! { assert!(CDNs::::contains_key(&cdn_stash)); frame_system::Pallet::::set_block_number(T::BlockNumber::from(1u32)); DdcStaking::::chill(RawOrigin::Signed(cdn_controller.clone()).into())?; - frame_system::Pallet::::set_block_number(T::BlockNumber::from(1u32) + T::ClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or(T::BlockNumber::from(10u32))); + frame_system::Pallet::::set_block_number(T::BlockNumber::from(1u32) + T::ClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::CDN).unwrap_or_else(|_| T::BlockNumber::from(10u32))); whitelist_account!(cdn_controller); }: _(RawOrigin::Signed(cdn_controller)) diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 786962dd8..9c8469785 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -197,7 +197,9 @@ pub mod pallet { #[pallet::genesis_config] pub struct GenesisConfig { + #[allow(clippy::type_complexity)] pub cdns: Vec<(T::AccountId, T::AccountId, NodePubKey, BalanceOf, ClusterId)>, + #[allow(clippy::type_complexity)] pub storages: Vec<(T::AccountId, T::AccountId, NodePubKey, BalanceOf, ClusterId)>, } @@ -214,7 +216,7 @@ pub mod pallet { // Add initial CDN participants for &(ref stash, ref controller, ref node, balance, cluster) in &self.cdns { assert!( - T::Currency::free_balance(&stash) >= balance, + T::Currency::free_balance(stash) >= balance, "Stash do not have enough balance to participate in CDN." ); assert_ok!(Pallet::::bond( @@ -232,7 +234,7 @@ pub mod pallet { // Add initial storage network participants for &(ref stash, ref controller, ref node, balance, cluster) in &self.storages { assert!( - T::Currency::free_balance(&stash) >= balance, + T::Currency::free_balance(stash) >= balance, "Stash do not have enough balance to participate in storage network." ); assert_ok!(Pallet::::bond( @@ -409,12 +411,12 @@ pub mod pallet { let min_active_bond = if let Some(cluster_id) = Self::cdns(&ledger.stash) { let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::CDN) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + .map_err(Into::>::into)?; bond_size.saturated_into::>() } else if let Some(cluster_id) = Self::storages(&ledger.stash) { let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::Storage) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + .map_err(Into::>::into)?; bond_size.saturated_into::>() } else { Zero::zero() @@ -427,10 +429,10 @@ pub mod pallet { let unbonding_delay_in_blocks = if let Some(cluster_id) = Self::cdns(&ledger.stash) { T::ClusterVisitor::get_unbonding_delay(&cluster_id, NodeType::CDN) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))? + .map_err(Into::>::into)? } else if let Some(cluster_id) = Self::storages(&ledger.stash) { T::ClusterVisitor::get_unbonding_delay(&cluster_id, NodeType::Storage) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))? + .map_err(Into::>::into)? } else { let node_pub_key = >::get(&ledger.stash).ok_or(Error::::BadState)?; @@ -439,12 +441,12 @@ pub mod pallet { match node_pub_key { NodePubKey::CDNPubKey(_) => T::ClusterVisitor::get_unbonding_delay(&cluster_id, NodeType::CDN) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?, + .map_err(Into::>::into)?, NodePubKey::StoragePubKey(_) => T::ClusterVisitor::get_unbonding_delay( &cluster_id, NodeType::Storage, ) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?, + .map_err(Into::>::into)?, } } else { // If node is not a member of any cluster, allow immediate unbonding. @@ -526,13 +528,12 @@ pub mod pallet { pub fn serve(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { let controller = ensure_signed(origin)?; - T::ClusterVisitor::ensure_cluster(&cluster_id) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + T::ClusterVisitor::ensure_cluster(&cluster_id).map_err(Into::>::into)?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; // Retrieve the respective bond size from Cluster Visitor let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::CDN) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + .map_err(Into::>::into)?; ensure!( ledger.active >= bond_size.saturated_into::>(), @@ -541,10 +542,10 @@ pub mod pallet { let stash = &ledger.stash; // Can't participate in CDN if already participating in storage network. - ensure!(!Storages::::contains_key(&stash), Error::::AlreadyInRole); + ensure!(!Storages::::contains_key(stash), Error::::AlreadyInRole); // Is it an attempt to cancel a previous "chill"? - if let Some(current_cluster) = Self::cdns(&stash) { + if let Some(current_cluster) = Self::cdns(stash) { // Switching the cluster is prohibited. The user should chill first. ensure!(current_cluster == cluster_id, Error::::AlreadyInRole); // Cancel previous "chill" attempts @@ -567,13 +568,12 @@ pub mod pallet { pub fn store(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { let controller = ensure_signed(origin)?; - T::ClusterVisitor::ensure_cluster(&cluster_id) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + T::ClusterVisitor::ensure_cluster(&cluster_id).map_err(Into::>::into)?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; // Retrieve the respective bond size from Cluster Visitor let bond_size = T::ClusterVisitor::get_bond_size(&cluster_id, NodeType::Storage) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + .map_err(Into::>::into)?; ensure!( ledger.active >= bond_size.saturated_into::>(), Error::::InsufficientBond @@ -581,10 +581,10 @@ pub mod pallet { let stash = &ledger.stash; // Can't participate in storage network if already participating in CDN. - ensure!(!CDNs::::contains_key(&stash), Error::::AlreadyInRole); + ensure!(!CDNs::::contains_key(stash), Error::::AlreadyInRole); // Is it an attempt to cancel a previous "chill"? - if let Some(current_cluster) = Self::storages(&stash) { + if let Some(current_cluster) = Self::storages(stash) { // Switching the cluster is prohibited. The user should chill first. ensure!(current_cluster == cluster_id, Error::::AlreadyInRole); // Cancel previous "chill" attempts @@ -622,12 +622,11 @@ pub mod pallet { // Extract delay from the cluster settings. let (cluster, delay) = if let Some(cluster) = Self::cdns(&ledger.stash) { let chill_delay = T::ClusterVisitor::get_chill_delay(&cluster, NodeType::CDN) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + .map_err(Into::>::into)?; (cluster, chill_delay) } else if let Some(cluster) = Self::storages(&ledger.stash) { - let chill_delay = - T::ClusterVisitor::get_chill_delay(&cluster, NodeType::Storage) - .map_err(|e| Into::>::into(ClusterVisitorError::from(e)))?; + let chill_delay = T::ClusterVisitor::get_chill_delay(&cluster, NodeType::Storage) + .map_err(Into::>::into)?; (cluster, chill_delay) } else { return Ok(()) // already chilled @@ -724,7 +723,7 @@ pub mod pallet { ensure!(stash == node_stash, Error::::NotNodeController); let cluster_id = >::get(&stash) - .or(>::get(&stash)) + .or_else(|| >::get(&stash)) .ok_or(Error::::NodeHasNoStake)?; let is_cluster_node = T::ClusterVisitor::cluster_has_node(&cluster_id, &node_pub_key); @@ -771,7 +770,7 @@ pub mod pallet { cluster: ClusterId, can_chill_from: T::BlockNumber, ) { - Ledger::::mutate(&controller, |maybe_ledger| { + Ledger::::mutate(controller, |maybe_ledger| { if let Some(ref mut ledger) = maybe_ledger { ledger.chilling = Some(can_chill_from) } @@ -834,7 +833,7 @@ pub mod pallet { /// Reset the chilling block for a controller. pub fn reset_chilling(controller: &T::AccountId) { - Ledger::::mutate(&controller, |maybe_ledger| { + Ledger::::mutate(controller, |maybe_ledger| { if let Some(ref mut ledger) = maybe_ledger { ledger.chilling = None } @@ -848,7 +847,7 @@ pub mod pallet { cluster_id: &ClusterId, ) -> Result { let stash = - >::get(&node_pub_key).ok_or(StakingVisitorError::NodeStakeDoesNotExist)?; + >::get(node_pub_key).ok_or(StakingVisitorError::NodeStakeDoesNotExist)?; let maybe_cdn_in_cluster = CDNs::::get(&stash); let maybe_storage_in_cluster = Storages::::get(&stash); @@ -861,7 +860,7 @@ pub mod pallet { fn node_is_chilling(node_pub_key: &NodePubKey) -> Result { let stash = - >::get(&node_pub_key).ok_or(StakingVisitorError::NodeStakeDoesNotExist)?; + >::get(node_pub_key).ok_or(StakingVisitorError::NodeStakeDoesNotExist)?; let controller = >::get(&stash).ok_or(StakingVisitorError::NodeStakeIsInBadState)?; diff --git a/pallets/ddc-staking/src/mock.rs b/pallets/ddc-staking/src/mock.rs index c76b90dcb..549653b92 100644 --- a/pallets/ddc-staking/src/mock.rs +++ b/pallets/ddc-staking/src/mock.rs @@ -264,7 +264,7 @@ impl ExtBuilder { TestExternalities::new(storage) } - pub fn build_and_execute(self, test: impl FnOnce() -> ()) { + pub fn build_and_execute(self, test: impl FnOnce()) { sp_tracing::try_init_simple(); let mut ext = self.build(); ext.execute_with(test); diff --git a/pallets/ddc-staking/src/testing_utils.rs b/pallets/ddc-staking/src/testing_utils.rs index 05f2a2bda..58e6b656b 100644 --- a/pallets/ddc-staking/src/testing_utils.rs +++ b/pallets/ddc-staking/src/testing_utils.rs @@ -60,7 +60,7 @@ pub fn create_stash_controller_node( node.clone(), amount, )?; - return Ok((stash, controller, node)) + Ok((stash, controller, node)) } /// Create a stash and controller pair with fixed balance. diff --git a/pallets/ddc-staking/src/tests.rs b/pallets/ddc-staking/src/tests.rs index 10f325b46..37d971bca 100644 --- a/pallets/ddc-staking/src/tests.rs +++ b/pallets/ddc-staking/src/tests.rs @@ -1,11 +1,9 @@ //! Tests for the module. use super::{mock::*, *}; -use ddc_primitives::{CDNNodePubKey, NodeType}; -use ddc_traits::cluster::{ClusterVisitor, ClusterVisitorError}; -use frame_support::{ - assert_noop, assert_ok, assert_storage_noop, error::BadOrigin, traits::ReservableCurrency, -}; +use ddc_primitives::CDNNodePubKey; + +use frame_support::{assert_noop, assert_ok, traits::ReservableCurrency}; use pallet_balances::Error as BalancesError; pub const BLOCK_TIME: u64 = 1000; @@ -113,7 +111,7 @@ fn staking_should_work() { assert_ok!(DdcStaking::chill(RuntimeOrigin::signed(4))); // Removal is scheduled, stashed value of 4 is still lock. - let chilling = System::block_number() + BlockNumber::from(10u64); + let chilling = System::block_number() + 10u64; // TestClusterVisitor::get_chill_delay(&ClusterId::from([1; 20]), NodeType::CDN) // .unwrap_or(10_u64); assert_eq!( diff --git a/pallets/ddc-staking/src/weights.rs b/pallets/ddc-staking/src/weights.rs index 969385330..efca88632 100644 --- a/pallets/ddc-staking/src/weights.rs +++ b/pallets/ddc-staking/src/weights.rs @@ -46,9 +46,9 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcStaking Nodes (r:1 w:1) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - Weight::from_ref_time(55_007_000 as u64) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(4 as u64)) + Weight::from_ref_time(55_007_000_u64) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CDNs (r:1 w:0) @@ -57,36 +57,36 @@ impl WeightInfo for SubstrateWeight { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - Weight::from_ref_time(47_727_000 as u64) - .saturating_add(T::DbWeight::get().reads(6 as u64)) - .saturating_add(T::DbWeight::get().writes(3 as u64)) + Weight::from_ref_time(47_727_000_u64) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CurrentEra (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unbonded() -> Weight { - Weight::from_ref_time(69_750_000 as u64) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(3 as u64)) + Weight::from_ref_time(69_750_000_u64) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:1) fn store() -> Weight { - Weight::from_ref_time(26_112_000 as u64) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) + Weight::from_ref_time(26_112_000_u64) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:1) fn serve() -> Weight { - Weight::from_ref_time(19_892_000 as u64) - .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) + Weight::from_ref_time(19_892_000_u64) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CurrentEra (r:1 w:0) @@ -94,22 +94,22 @@ impl WeightInfo for SubstrateWeight { // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { - Weight::from_ref_time(77_450_000 as u64) - .saturating_add(T::DbWeight::get().reads(5 as u64)) - .saturating_add(T::DbWeight::get().writes(2 as u64)) + Weight::from_ref_time(77_450_000_u64) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:2 w:2) fn set_controller() -> Weight { - Weight::from_ref_time(38_521_000 as u64) - .saturating_add(T::DbWeight::get().reads(3 as u64)) - .saturating_add(T::DbWeight::get().writes(3 as u64)) + Weight::from_ref_time(38_521_000_u64) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } // Storage: DdcStaking Nodes (r:1 w:1) fn set_node() -> Weight { - Weight::from_ref_time(21_779_000 as u64) - .saturating_add(T::DbWeight::get().reads(1 as u64)) - .saturating_add(T::DbWeight::get().writes(1 as u64)) + Weight::from_ref_time(21_779_000_u64) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) } } @@ -120,9 +120,9 @@ impl WeightInfo for () { // Storage: DdcStaking Nodes (r:1 w:1) // Storage: Balances Locks (r:1 w:1) fn bond() -> Weight { - Weight::from_ref_time(55_007_000 as u64) - .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().writes(4 as u64)) + Weight::from_ref_time(55_007_000_u64) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CDNs (r:1 w:0) @@ -131,36 +131,36 @@ impl WeightInfo for () { // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn unbond() -> Weight { - Weight::from_ref_time(47_727_000 as u64) - .saturating_add(RocksDbWeight::get().reads(6 as u64)) - .saturating_add(RocksDbWeight::get().writes(3 as u64)) + Weight::from_ref_time(47_727_000_u64) + .saturating_add(RocksDbWeight::get().reads(6_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CurrentEra (r:1 w:0) // Storage: Balances Locks (r:1 w:1) // Storage: System Account (r:1 w:1) fn withdraw_unbonded() -> Weight { - Weight::from_ref_time(69_750_000 as u64) - .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().writes(3 as u64)) + Weight::from_ref_time(69_750_000_u64) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:1) fn store() -> Weight { - Weight::from_ref_time(26_112_000 as u64) - .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) + Weight::from_ref_time(26_112_000_u64) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:0) // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) // Storage: DdcStaking CDNs (r:1 w:1) fn serve() -> Weight { - Weight::from_ref_time(19_892_000 as u64) - .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) + Weight::from_ref_time(19_892_000_u64) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } // Storage: DdcStaking Ledger (r:1 w:1) // Storage: DdcStaking CurrentEra (r:1 w:0) @@ -168,21 +168,21 @@ impl WeightInfo for () { // Storage: DdcStaking Settings (r:1 w:0) // Storage: DdcStaking Storages (r:1 w:0) fn chill() -> Weight { - Weight::from_ref_time(77_450_000 as u64) - .saturating_add(RocksDbWeight::get().reads(5 as u64)) - .saturating_add(RocksDbWeight::get().writes(2 as u64)) + Weight::from_ref_time(77_450_000_u64) + .saturating_add(RocksDbWeight::get().reads(5_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } // Storage: DdcStaking Bonded (r:1 w:1) // Storage: DdcStaking Ledger (r:2 w:2) fn set_controller() -> Weight { - Weight::from_ref_time(38_521_000 as u64) - .saturating_add(RocksDbWeight::get().reads(3 as u64)) - .saturating_add(RocksDbWeight::get().writes(3 as u64)) + Weight::from_ref_time(38_521_000_u64) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) } // Storage: DdcStaking Nodes (r:1 w:1) fn set_node() -> Weight { - Weight::from_ref_time(21_779_000 as u64) - .saturating_add(RocksDbWeight::get().reads(1 as u64)) - .saturating_add(RocksDbWeight::get().writes(1 as u64)) + Weight::from_ref_time(21_779_000_u64) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) } } diff --git a/pallets/ddc/Cargo.toml b/pallets/ddc/Cargo.toml index 9c89014d1..867c36f52 100644 --- a/pallets/ddc/Cargo.toml +++ b/pallets/ddc/Cargo.toml @@ -35,3 +35,6 @@ std = [ 'frame-support/std', 'frame-system/std', ] + +[package.metadata.cargo-machete] +ignored = ["scale-info", "codec"] diff --git a/pallets/ddc/src/lib.rs b/pallets/ddc/src/lib.rs index e1d572af6..c7bdc1d73 100644 --- a/pallets/ddc/src/lib.rs +++ b/pallets/ddc/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::all)] #![cfg_attr(not(feature = "std"), no_std)] use frame_support::{ @@ -96,10 +97,10 @@ decl_module! { ensure!(data.len() >= T::MinLength::get(), Error::::TooShort); ensure!(data.len() <= T::MaxLength::get(), Error::::TooLong); - if let Some(_) = >::get(&sender) { - Self::deposit_event(RawEvent::DataStringChanged(sender.clone())); + if >::get(&sender).is_some() { + Self::deposit_event(RawEvent::DataStringChanged(sender)); } else { - Self::deposit_event(RawEvent::DataStringSet(sender.clone())); + Self::deposit_event(RawEvent::DataStringSet(sender)); }; >::insert(send_to, data); diff --git a/pallets/erc20/Cargo.toml b/pallets/erc20/Cargo.toml index 6cce2c8d4..3bf27fea6 100644 --- a/pallets/erc20/Cargo.toml +++ b/pallets/erc20/Cargo.toml @@ -13,7 +13,6 @@ readme = "README.md" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -serde = { version = "1.0.136", optional = true } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -27,15 +26,11 @@ pallet-chainbridge = { version = "4.2.0", default-features = false, path = "../c pallet-erc721 = { version = "4.2.0", default-features = false, path = "../erc721" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } - [features] default = ["std"] std = [ - "serde", "codec/std", "sp-runtime/std", - "frame-benchmarking/std", "frame-support/std", "frame-system/std", "pallet-balances/std", @@ -46,4 +41,6 @@ std = [ "pallet-chainbridge/std", "pallet-erc721/std" ] -runtime-benchmarks = ["frame-benchmarking"] + +[package.metadata.cargo-machete] +ignored = ["scale-info"] diff --git a/pallets/erc20/src/lib.rs b/pallets/erc20/src/lib.rs index a9474ae2f..8e7967ed6 100644 --- a/pallets/erc20/src/lib.rs +++ b/pallets/erc20/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::all)] // Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] @@ -81,7 +82,7 @@ decl_module! { let source = ensure_signed(origin)?; ensure!(>::chain_whitelisted(dest_id), Error::::InvalidTransfer); let bridge_id = >::account_id(); - T::Currency::transfer(&source, &bridge_id, amount.into(), AllowDeath)?; + T::Currency::transfer(&source, &bridge_id, amount, AllowDeath)?; let resource_id = T::NativeTokenId::get(); let number_amount: u128 = amount.saturated_into(); @@ -95,7 +96,7 @@ decl_module! { pub fn transfer_erc721(origin, recipient: Vec, token_id: U256, dest_id: bridge::ChainId) -> DispatchResult { let source = ensure_signed(origin)?; ensure!(>::chain_whitelisted(dest_id), Error::::InvalidTransfer); - match >::tokens(&token_id) { + match >::tokens(token_id) { Some(token) => { >::burn_token(source, token_id)?; let resource_id = T::Erc721Id::get(); @@ -115,7 +116,7 @@ decl_module! { #[weight = 195_000_000] pub fn transfer(origin, to: T::AccountId, amount: BalanceOf) -> DispatchResult { let source = T::BridgeOrigin::ensure_origin(origin)?; - ::Currency::transfer(&source, &to, amount.into(), AllowDeath)?; + ::Currency::transfer(&source, &to, amount, AllowDeath)?; Ok(()) } diff --git a/pallets/erc721/Cargo.toml b/pallets/erc721/Cargo.toml index 3f586f103..e6e12c37f 100644 --- a/pallets/erc721/Cargo.toml +++ b/pallets/erc721/Cargo.toml @@ -13,7 +13,6 @@ readme = "README.md" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -serde = { version = "1.0.136", optional = true } codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } @@ -25,15 +24,11 @@ sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate.gi pallet-chainbridge = { version = "4.2.0", default-features = false, path = "../chainbridge" } scale-info = { version = "2.1.2", default-features = false, features = ["derive"] } -frame-benchmarking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30", optional = true } - [features] default = ["std"] std = [ - "serde", "codec/std", "sp-runtime/std", - "frame-benchmarking/std", "frame-support/std", "frame-system/std", "pallet-balances/std", @@ -42,4 +37,3 @@ std = [ "sp-core/std", "pallet-chainbridge/std" ] -runtime-benchmarks = ["frame-benchmarking"] diff --git a/pallets/erc721/src/lib.rs b/pallets/erc721/src/lib.rs index c5b7244d7..638dc864a 100644 --- a/pallets/erc721/src/lib.rs +++ b/pallets/erc721/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::all)] // Ensure we're `no_std` when compiling for Wasm. #![cfg_attr(not(feature = "std"), no_std)] @@ -113,8 +114,8 @@ impl Module { let new_token = Erc721Token { id, metadata }; - ::insert(&id, new_token); - >::insert(&id, owner.clone()); + ::insert(id, new_token); + >::insert(id, owner.clone()); let new_total = ::get().saturating_add(U256::one()); ::put(new_total); @@ -129,7 +130,7 @@ impl Module { let owner = Self::owner_of(id).ok_or(Error::::TokenIdDoesNotExist)?; ensure!(owner == from, Error::::NotOwner); // Update owner - >::insert(&id, to.clone()); + >::insert(id, to.clone()); Self::deposit_event(RawEvent::Transferred(from, to, id)); @@ -141,8 +142,8 @@ impl Module { let owner = Self::owner_of(id).ok_or(Error::::TokenIdDoesNotExist)?; ensure!(owner == from, Error::::NotOwner); - ::remove(&id); - >::remove(&id); + ::remove(id); + >::remove(id); let new_total = ::get().saturating_sub(U256::one()); ::put(new_total); diff --git a/pallets/erc721/src/tests.rs b/pallets/erc721/src/tests.rs index f273f83a3..9fa6cde1b 100644 --- a/pallets/erc721/src/tests.rs +++ b/pallets/erc721/src/tests.rs @@ -22,7 +22,7 @@ fn mint_burn_tokens() { ); assert_eq!(Erc721::token_count(), 1.into()); assert_noop!( - Erc721::mint(RuntimeOrigin::root(), USER_A, id_a, metadata_a.clone()), + Erc721::mint(RuntimeOrigin::root(), USER_A, id_a, metadata_a), Error::::TokenAlreadyExists ); @@ -33,19 +33,19 @@ fn mint_burn_tokens() { ); assert_eq!(Erc721::token_count(), 2.into()); assert_noop!( - Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b.clone()), + Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b), Error::::TokenAlreadyExists ); assert_ok!(Erc721::burn(RuntimeOrigin::root(), id_a)); assert_eq!(Erc721::token_count(), 1.into()); - assert!(!::contains_key(&id_a)); - assert!(!>::contains_key(&id_a)); + assert!(!::contains_key(id_a)); + assert!(!>::contains_key(id_a)); assert_ok!(Erc721::burn(RuntimeOrigin::root(), id_b)); assert_eq!(Erc721::token_count(), 0.into()); - assert!(!::contains_key(&id_b)); - assert!(!>::contains_key(&id_b)); + assert!(!::contains_key(id_b)); + assert!(!>::contains_key(id_b)); }) } @@ -57,8 +57,8 @@ fn transfer_tokens() { let metadata_a: Vec = vec![1, 2, 3]; let metadata_b: Vec = vec![4, 5, 6]; - assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_a, metadata_a.clone())); - assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b.clone())); + assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_a, metadata_a)); + assert_ok!(Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b)); assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_A), USER_B, id_a)); assert_eq!(Erc721::owner_of(id_a).unwrap(), USER_B); diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index a3abee7c4..0564f3c16 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -11,6 +11,9 @@ use sp_runtime::{AccountId32, RuntimeDebug}; pub type ClusterId = H160; pub type BucketId = u64; +pub type StorageNodePubKey = AccountId32; +pub type CDNNodePubKey = AccountId32; + #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodePubKey { @@ -18,9 +21,6 @@ pub enum NodePubKey { CDNPubKey(CDNNodePubKey), } -pub type StorageNodePubKey = AccountId32; -pub type CDNNodePubKey = AccountId32; - #[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq)] pub enum NodeType { Storage = 1, diff --git a/runtime/cere-dev/Cargo.toml b/runtime/cere-dev/Cargo.toml index f5ba45aba..e78c7dd17 100644 --- a/runtime/cere-dev/Cargo.toml +++ b/runtime/cere-dev/Cargo.toml @@ -92,7 +92,6 @@ pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "http pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-transaction-storage = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-vesting = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } cere-runtime-common = { path = "../common", default-features = false } cere-dev-runtime-constants = { path = "./constants", default-features = false } @@ -197,7 +196,6 @@ runtime-benchmarks = [ "pallet-bags-list/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-bounties/runtime-benchmarks", - "pallet-chainbridge/runtime-benchmarks", "pallet-child-bounties/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-contracts/runtime-benchmarks", diff --git a/runtime/cere-dev/constants/Cargo.toml b/runtime/cere-dev/constants/Cargo.toml index 5fdb89737..201630962 100644 --- a/runtime/cere-dev/constants/Cargo.toml +++ b/runtime/cere-dev/constants/Cargo.toml @@ -6,10 +6,9 @@ edition = "2021" [dependencies] node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } [features] default = ["std"] std = [ - "sp-runtime/std" + "node-primitives/std" ] diff --git a/runtime/cere-dev/src/impls.rs b/runtime/cere-dev/src/impls.rs index c576e8d31..3e725dca7 100644 --- a/runtime/cere-dev/src/impls.rs +++ b/runtime/cere-dev/src/impls.rs @@ -98,7 +98,7 @@ mod multiplier_tests { fn run_with_system_weight(w: Weight, assertions: F) where - F: Fn() -> (), + F: Fn(), { let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default() .build_storage::() @@ -114,12 +114,12 @@ mod multiplier_tests { fn truth_value_update_poc_works() { let fm = Multiplier::saturating_from_rational(1, 2); let test_set = vec![ - (0, fm.clone()), - (100, fm.clone()), - (1000, fm.clone()), - (target().ref_time(), fm.clone()), - (max_normal().ref_time() / 2, fm.clone()), - (max_normal().ref_time(), fm.clone()), + (0, fm), + (100, fm), + (1000, fm), + (target().ref_time(), fm), + (max_normal().ref_time() / 2, fm), + (max_normal().ref_time(), fm), ]; test_set.into_iter().for_each(|(w, fm)| { run_with_system_weight(Weight::from_ref_time(w), || { @@ -325,7 +325,7 @@ mod multiplier_tests { #[test] fn weight_to_fee_should_not_overflow_on_large_weights() { - let kb = 1024 as u64; + let kb = 1024_u64; let mb = kb * kb; let max_fm = Multiplier::saturating_from_integer(i128::MAX); diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 7e8be086a..518b398dc 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -405,7 +405,7 @@ impl pallet_indices::Config for Runtime { } parameter_types! { - pub const ExistentialDeposit: Balance = 1 * DOLLARS; + pub const ExistentialDeposit: Balance = DOLLARS; // For weight estimation, we assume that the most locks on an individual account will be 50. // This number may need to be adjusted in the future if this assumption no longer holds true. pub const MaxLocks: u32 = 50; @@ -565,9 +565,9 @@ parameter_types! { pub const UnsignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4; // signed config - pub const SignedRewardBase: Balance = 1 * DOLLARS; - pub const SignedDepositBase: Balance = 1 * DOLLARS; - pub const SignedDepositByte: Balance = 1 * CENTS; + pub const SignedRewardBase: Balance = DOLLARS; + pub const SignedDepositBase: Balance = DOLLARS; + pub const SignedDepositByte: Balance = CENTS; pub BetterUnsignedThreshold: Perbill = Perbill::from_rational(1u32, 10_000); @@ -722,11 +722,11 @@ impl pallet_bags_list::Config for Runtime { } parameter_types! { - pub const LaunchPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; - pub const VotingPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; + pub const LaunchPeriod: BlockNumber = 24 * 60 * MINUTES; + pub const VotingPeriod: BlockNumber = 24 * 60 * MINUTES; pub const FastTrackVotingPeriod: BlockNumber = 3 * 60 * MINUTES; pub const MinimumDeposit: Balance = 50_000 * DOLLARS; - pub const EnactmentPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; + pub const EnactmentPeriod: BlockNumber = 24 * 60 * MINUTES; pub const CooloffPeriod: BlockNumber = 7 * 24 * 60 * MINUTES; pub const MaxProposals: u32 = 100; } @@ -804,7 +804,7 @@ parameter_types! { pub const CandidacyBond: Balance = 5_000_000 * DOLLARS; // 1 storage item created, key size is 32 bytes, value size is 16+16. pub const VotingBondBase: Balance = deposit(1, 64); - pub const VotingBondFactor: Balance = 1 * DOLLARS; + pub const VotingBondFactor: Balance = DOLLARS; pub const TermDuration: BlockNumber = 182 * DAYS; pub const DesiredMembers: u32 = 13; pub const DesiredRunnersUp: u32 = 20; @@ -876,12 +876,12 @@ impl pallet_membership::Config for Runtime { parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); pub const ProposalBondMinimum: Balance = 50_000 * DOLLARS; - pub const SpendPeriod: BlockNumber = 1 * DAYS; + pub const SpendPeriod: BlockNumber = DAYS; pub const Burn: Permill = Permill::from_percent(0); - pub const TipCountdown: BlockNumber = 1 * DAYS; + pub const TipCountdown: BlockNumber = DAYS; pub const TipFindersFee: Percent = Percent::from_percent(20); pub const TipReportDepositBase: Balance = 50_000 * DOLLARS; - pub const DataDepositPerByte: Balance = 1 * DOLLARS; + pub const DataDepositPerByte: Balance = DOLLARS; pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); pub const MaximumReasonLength: u32 = 16384; pub const MaxApprovals: u32 = 100; @@ -917,7 +917,7 @@ parameter_types! { pub const BountyValueMinimum: Balance = 10 * DOLLARS; pub const BountyDepositBase: Balance = 50_000 * DOLLARS; pub const CuratorDepositMultiplier: Permill = Permill::from_percent(50); - pub const CuratorDepositMin: Balance = 1 * DOLLARS; + pub const CuratorDepositMin: Balance = DOLLARS; pub const CuratorDepositMax: Balance = 100 * DOLLARS; pub const BountyDepositPayoutDelay: BlockNumber = 8 * DAYS; pub const BountyUpdatePeriod: BlockNumber = 90 * DAYS; @@ -939,7 +939,7 @@ impl pallet_bounties::Config for Runtime { } parameter_types! { - pub const ChildBountyValueMinimum: Balance = 1 * DOLLARS; + pub const ChildBountyValueMinimum: Balance = DOLLARS; } impl pallet_child_bounties::Config for Runtime { @@ -1192,7 +1192,7 @@ impl pallet_society::Config for Runtime { } parameter_types! { - pub const MinVestedTransfer: Balance = 1 * DOLLARS; + pub const MinVestedTransfer: Balance = DOLLARS; } impl pallet_vesting::Config for Runtime { diff --git a/runtime/cere/Cargo.toml b/runtime/cere/Cargo.toml index 59a2668cd..698fa079b 100644 --- a/runtime/cere/Cargo.toml +++ b/runtime/cere/Cargo.toml @@ -92,7 +92,6 @@ pallet-treasury = { version = "4.0.0-dev", default-features = false, git = "http pallet-utility = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-transaction-payment-rpc-runtime-api = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -pallet-transaction-storage = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } pallet-vesting = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } cere-runtime-common = { path = "../common", default-features = false } cere-runtime-constants = { path = "./constants", default-features = false } @@ -189,7 +188,6 @@ runtime-benchmarks = [ "pallet-bags-list/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-bounties/runtime-benchmarks", - "pallet-chainbridge/runtime-benchmarks", "pallet-child-bounties/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-contracts/runtime-benchmarks", @@ -260,3 +258,4 @@ try-runtime = [ "pallet-utility/try-runtime", "pallet-vesting/try-runtime", ] + diff --git a/runtime/cere/constants/Cargo.toml b/runtime/cere/constants/Cargo.toml index 2188486ef..629d01bcb 100644 --- a/runtime/cere/constants/Cargo.toml +++ b/runtime/cere/constants/Cargo.toml @@ -6,10 +6,9 @@ edition = "2021" [dependencies] node-primitives = { version = "2.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-runtime = { version = "6.0.0", git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.30" } [features] default = ["std"] std = [ - "sp-runtime/std" + "node-primitives/std" ] diff --git a/runtime/cere/src/impls.rs b/runtime/cere/src/impls.rs index 6895f794e..f1763dea1 100644 --- a/runtime/cere/src/impls.rs +++ b/runtime/cere/src/impls.rs @@ -98,7 +98,7 @@ mod multiplier_tests { fn run_with_system_weight(w: Weight, assertions: F) where - F: Fn() -> (), + F: Fn(), { let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::default() .build_storage::() @@ -114,12 +114,12 @@ mod multiplier_tests { fn truth_value_update_poc_works() { let fm = Multiplier::saturating_from_rational(1, 2); let test_set = vec![ - (0, fm.clone()), - (100, fm.clone()), - (1000, fm.clone()), - (target().ref_time(), fm.clone()), - (max_normal().ref_time() / 2, fm.clone()), - (max_normal().ref_time(), fm.clone()), + (0, fm), + (100, fm), + (1000, fm), + (target().ref_time(), fm), + (max_normal().ref_time() / 2, fm), + (max_normal().ref_time(), fm), ]; test_set.into_iter().for_each(|(w, fm)| { run_with_system_weight(Weight::from_ref_time(w), || { @@ -325,7 +325,7 @@ mod multiplier_tests { #[test] fn weight_to_fee_should_not_overflow_on_large_weights() { - let kb = 1024 as u64; + let kb = 1024_u64; let mb = kb * kb; let max_fm = Multiplier::saturating_from_integer(i128::MAX); diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index be5ab085d..984ffb7bc 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -401,7 +401,7 @@ impl pallet_indices::Config for Runtime { } parameter_types! { - pub const ExistentialDeposit: Balance = 1 * DOLLARS; + pub const ExistentialDeposit: Balance = DOLLARS; // For weight estimation, we assume that the most locks on an individual account will be 50. // This number may need to be adjusted in the future if this assumption no longer holds true. pub const MaxLocks: u32 = 50; @@ -562,9 +562,9 @@ parameter_types! { pub const UnsignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4; // signed config - pub const SignedRewardBase: Balance = 1 * DOLLARS; - pub const SignedDepositBase: Balance = 1 * DOLLARS; - pub const SignedDepositByte: Balance = 1 * CENTS; + pub const SignedRewardBase: Balance = DOLLARS; + pub const SignedDepositBase: Balance = DOLLARS; + pub const SignedDepositByte: Balance = CENTS; pub BetterUnsignedThreshold: Perbill = Perbill::from_rational(1u32, 10_000); @@ -719,11 +719,11 @@ impl pallet_bags_list::Config for Runtime { } parameter_types! { - pub const LaunchPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; - pub const VotingPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; + pub const LaunchPeriod: BlockNumber = 24 * 60 * MINUTES; + pub const VotingPeriod: BlockNumber = 24 * 60 * MINUTES; pub const FastTrackVotingPeriod: BlockNumber = 3 * 60 * MINUTES; pub const MinimumDeposit: Balance = 50_000 * DOLLARS; - pub const EnactmentPeriod: BlockNumber = 1 * 24 * 60 * MINUTES; + pub const EnactmentPeriod: BlockNumber = 24 * 60 * MINUTES; pub const CooloffPeriod: BlockNumber = 7 * 24 * 60 * MINUTES; pub const MaxProposals: u32 = 100; } @@ -801,7 +801,7 @@ parameter_types! { pub const CandidacyBond: Balance = 5_000_000 * DOLLARS; // 1 storage item created, key size is 32 bytes, value size is 16+16. pub const VotingBondBase: Balance = deposit(1, 64); - pub const VotingBondFactor: Balance = 1 * DOLLARS; + pub const VotingBondFactor: Balance = DOLLARS; pub const TermDuration: BlockNumber = 182 * DAYS; pub const DesiredMembers: u32 = 13; pub const DesiredRunnersUp: u32 = 20; @@ -873,12 +873,12 @@ impl pallet_membership::Config for Runtime { parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); pub const ProposalBondMinimum: Balance = 50_000 * DOLLARS; - pub const SpendPeriod: BlockNumber = 1 * DAYS; + pub const SpendPeriod: BlockNumber = DAYS; pub const Burn: Permill = Permill::from_percent(0); - pub const TipCountdown: BlockNumber = 1 * DAYS; + pub const TipCountdown: BlockNumber = DAYS; pub const TipFindersFee: Percent = Percent::from_percent(20); pub const TipReportDepositBase: Balance = 50_000 * DOLLARS; - pub const DataDepositPerByte: Balance = 1 * DOLLARS; + pub const DataDepositPerByte: Balance = DOLLARS; pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry"); pub const MaximumReasonLength: u32 = 16384; pub const MaxApprovals: u32 = 100; @@ -914,7 +914,7 @@ parameter_types! { pub const BountyValueMinimum: Balance = 10 * DOLLARS; pub const BountyDepositBase: Balance = 50_000 * DOLLARS; pub const CuratorDepositMultiplier: Permill = Permill::from_percent(50); - pub const CuratorDepositMin: Balance = 1 * DOLLARS; + pub const CuratorDepositMin: Balance = DOLLARS; pub const CuratorDepositMax: Balance = 100 * DOLLARS; pub const BountyDepositPayoutDelay: BlockNumber = 8 * DAYS; pub const BountyUpdatePeriod: BlockNumber = 90 * DAYS; @@ -936,7 +936,7 @@ impl pallet_bounties::Config for Runtime { } parameter_types! { - pub const ChildBountyValueMinimum: Balance = 1 * DOLLARS; + pub const ChildBountyValueMinimum: Balance = DOLLARS; } impl pallet_child_bounties::Config for Runtime { @@ -1189,7 +1189,7 @@ impl pallet_society::Config for Runtime { } parameter_types! { - pub const MinVestedTransfer: Balance = 1 * DOLLARS; + pub const MinVestedTransfer: Balance = DOLLARS; } impl pallet_vesting::Config for Runtime { diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 9bcb924a2..bcf909e27 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] channel = "nightly-2022-10-09" -components = [ "rustfmt" ] +components = [ "clippy", "rustfmt" ] targets = [ "wasm32-unknown-unknown" ] diff --git a/rustfmt.toml b/rustfmt.toml index 441913f61..f58198d98 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -21,3 +21,11 @@ match_block_trailing_comma = true trailing_comma = "Vertical" trailing_semicolon = false use_field_init_shorthand = true + +ignore = [ + "pallets/chainbridge", + "pallets/ddc-metrics-offchain-worker", + "pallets/ddc", + "pallets/erc20", + "pallets/erc721", +] diff --git a/scripts/init.sh b/scripts/init.sh index beca622b2..1472424dc 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -9,3 +9,4 @@ rustup install nightly-2022-10-09 rustup target add wasm32-unknown-unknown --toolchain nightly-2022-10-09 ln -sf $PWD/scripts/pre-commit.sh $PWD/.git/hooks/pre-commit || true +ln -sf $PWD/scripts/pre-push.sh $PWD/.git/hooks/pre-push || true diff --git a/scripts/pre-push.sh b/scripts/pre-push.sh new file mode 100755 index 000000000..9c6679c02 --- /dev/null +++ b/scripts/pre-push.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +# Check code with clippy before publishing +cargo clippy --all --all-targets -- -D warnings +if [ $? -ne 0 ]; then + echo "Run \`cargo clippy --fix --all --allow-staged --allow-dirty\` to apply clippy's suggestions." + exit 1 +fi diff --git a/traits/Cargo.toml b/traits/Cargo.toml index b224e2d28..202996ef0 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -4,9 +4,5 @@ version = "0.1.0" edition = "2021" [dependencies] -sp-std = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-core = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -sp-staking = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } -frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.30" } ddc-primitives = { version = "0.1.0", default-features = false, path = "../primitives" }