From e17fd28f7d9a6e305a3a815b5b779c0836fca26c Mon Sep 17 00:00:00 2001 From: Dastan Samatov Date: Wed, 5 Jul 2023 13:21:39 +0600 Subject: [PATCH 1/7] Initial changes --- Cargo.lock | 2 +- node/src/chain_spec.rs | 4 ++-- node/src/command.rs | 21 +++++++++++++-------- runtime/Cargo.toml | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eff603a2..d87da085 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5912,7 +5912,7 @@ dependencies = [ [[package]] name = "pallet-livingassets-ownership" version = "0.0.1" -source = "git+https://github.com/freeverseio/pallet-livingassets-ownership?rev=a15098e080aee626580a383df1382b3cd020deae#a15098e080aee626580a383df1382b3cd020deae" +source = "git+https://github.com/freeverseio/pallet-livingassets-ownership?branch=fix/clippy#7b0765d4bd26fa107aadc4e4986905db635271fe" dependencies = [ "frame-benchmarking", "frame-support", diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index ab554f0c..3c5cbcad 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -1,5 +1,5 @@ use cumulus_primitives_core::ParaId; -use parachain_template_runtime::{AccountId, AuraId, Signature, EXISTENTIAL_DEPOSIT, SudoConfig}; +use parachain_template_runtime::{AccountId, AuraId, Signature, SudoConfig, EXISTENTIAL_DEPOSIT}; use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; use sc_service::ChainType; use serde::{Deserialize, Serialize}; @@ -15,7 +15,7 @@ const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; /// Helper function to generate a crypto pair from seed pub fn get_from_seed(seed: &str) -> ::Public { - TPublic::Pair::from_string(&format!("//{}", seed), None) + TPublic::Pair::from_string(&format!("//{seed}"), None) .expect("static values are valid; qed") .public() } diff --git a/node/src/command.rs b/node/src/command.rs index dce143da..ddcd648e 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -23,7 +23,9 @@ use crate::{ fn load_spec(id: &str) -> std::result::Result, String> { Ok(match id { - "arrakis" => Box::new(chain_spec::ChainSpec::from_json_bytes(&include_bytes!("../../specs/arrakis.json")[..])?), + "arrakis" => Box::new(chain_spec::ChainSpec::from_json_bytes( + &include_bytes!("../../specs/arrakis.json")[..], + )?), "dev" => Box::new(chain_spec::development_config()), "template-rococo" => Box::new(chain_spec::local_testnet_config()), "" | "local" => Box::new(chain_spec::local_testnet_config()), @@ -104,8 +106,11 @@ impl SubstrateCli for RelayChainCli { fn load_spec(&self, id: &str) -> std::result::Result, String> { match id { - "rococo_freeverse" => Ok(Box::new(RococoChainSpec::from_json_bytes(&include_bytes!("../../specs/rococo-freeverse-chainspec.json")[..])?)), - _ => polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id), + "rococo_freeverse" => Ok(Box::new(RococoChainSpec::from_json_bytes( + &include_bytes!("../../specs/rococo-freeverse-chainspec.json")[..], + )?)), + _ => polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()) + .load_spec(id), } } @@ -173,7 +178,7 @@ pub fn run() -> Result<()> { &polkadot_cli, config.tokio_handle.clone(), ) - .map_err(|err| format!("Relay chain argument error: {}", err))?; + .map_err(|err| format!("Relay chain argument error: {err}"))?; cmd.run(config, polkadot_config) }) @@ -249,7 +254,7 @@ pub fn run() -> Result<()> { let registry = &runner.config().prometheus_config.as_ref().map(|cfg| &cfg.registry); let task_manager = sc_service::TaskManager::new(runner.config().tokio_handle.clone(), *registry) - .map_err(|e| format!("Error: {:?}", e))?; + .map_err(|e| format!("Error: {e}"))?; let info_provider = timestamp_with_aura_info(MILLISECS_PER_BLOCK); @@ -273,13 +278,13 @@ pub fn run() -> Result<()> { runner.run_node_until_exit(|config| async move { let hwbench = (!cli.no_hardware_benchmarks).then_some( 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)) })).flatten(); let para_id = chain_spec::Extensions::try_get(&*config.chain_spec) .map(|e| e.para_id) - .ok_or_else(|| "Could not find parachain ID in chain-spec.")?; + .ok_or("Could not find parachain ID in chain-spec.")?; let polkadot_cli = RelayChainCli::new( &config, @@ -293,7 +298,7 @@ pub fn run() -> Result<()> { let state_version = Cli::native_runtime_version(&config.chain_spec).state_version(); let block: Block = generate_genesis_block(&*config.chain_spec, state_version) - .map_err(|e| format!("{:?}", e))?; + .map_err(|e| format!("{e}"))?; let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode())); let tokio_handle = config.tokio_handle.clone(); diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 26a77a1a..0f841bf1 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -49,7 +49,7 @@ sp-std = { git = "https://github.com/paritytech/substrate", default-features = f sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" } sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" } -pallet-livingassets-ownership = { git = "https://github.com/freeverseio/pallet-livingassets-ownership", rev="a15098e080aee626580a383df1382b3cd020deae", default-features = false } +pallet-livingassets-ownership = { git = "https://github.com/freeverseio/pallet-livingassets-ownership", branch="fix/clippy", default-features = false } # Polkadot pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.42" } From c9af6b9ec8162496d8dd7a419a73725866e2505a Mon Sep 17 00:00:00 2001 From: Dastan Samatov Date: Wed, 5 Jul 2023 13:32:23 +0600 Subject: [PATCH 2/7] Fix clippy warnings --- node/src/cli.rs | 1 + node/src/command.rs | 12 +++++------- node/src/service.rs | 2 ++ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/node/src/cli.rs b/node/src/cli.rs index 2e64a53e..1fa5d114 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -2,6 +2,7 @@ use std::path::PathBuf; /// Sub-commands supported by the collator. #[derive(Debug, clap::Subcommand)] +#[allow(clippy::large_enum_variant)] pub enum Subcommand { /// Build a chain specification. BuildSpec(sc_cli::BuildSpecCmd), diff --git a/node/src/command.rs b/node/src/command.rs index ddcd648e..b2fc475e 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -216,12 +216,11 @@ pub fn run() -> Result<()> { }), #[cfg(not(feature = "runtime-benchmarks"))] BenchmarkCmd::Storage(_) => - return Err(sc_cli::Error::Input( + Err(sc_cli::Error::Input( "Compile with --features=runtime-benchmarks \ to enable storage benchmarks." .into(), - ) - .into()), + )), #[cfg(feature = "runtime-benchmarks")] BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| { let partials = new_partial(&config)?; @@ -297,21 +296,20 @@ pub fn run() -> Result<()> { AccountIdConversion::::into_account_truncating(&id); let state_version = Cli::native_runtime_version(&config.chain_spec).state_version(); - let block: Block = generate_genesis_block(&*config.chain_spec, state_version) - .map_err(|e| format!("{e}"))?; + let block: Block = generate_genesis_block(&*config.chain_spec, state_version)?; let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode())); let tokio_handle = config.tokio_handle.clone(); let polkadot_config = SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle) - .map_err(|err| format!("Relay chain argument error: {}", err))?; + .map_err(|err| format!("Relay chain argument error: {err}"))?; info!("Parachain id: {:?}", id); info!("Parachain Account: {}", parachain_account); info!("Parachain genesis state: {}", genesis_state); info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" }); - if !collator_options.relay_chain_rpc_urls.is_empty() && cli.relay_chain_args.len() > 0 { + if !collator_options.relay_chain_rpc_urls.is_empty() && !cli.relay_chain_args.is_empty() { warn!("Detected relay chain node arguments together with --relay-chain-rpc-url. This command starts a minimal Polkadot node that only uses a network-related subset of all relay chain CLI options."); } diff --git a/node/src/service.rs b/node/src/service.rs index 4c9e1feb..1d258a62 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -59,6 +59,7 @@ type ParachainBlockImport = TParachainBlockImport, P /// /// Use this macro if you don't actually need the full service, but just the builder in order to /// be able to perform chain operations. +#[allow(clippy::type_complexity)] pub fn new_partial( config: &Configuration, ) -> Result< @@ -354,6 +355,7 @@ fn build_import_queue( .map_err(Into::into) } +#[allow(clippy::too_many_arguments)] fn build_consensus( client: Arc, block_import: ParachainBlockImport, From 8f1c6a6296ec6222e9112d5838ad25e8c739a919 Mon Sep 17 00:00:00 2001 From: Dastan Samatov Date: Wed, 5 Jul 2023 13:48:44 +0600 Subject: [PATCH 3/7] More clippy fixes and add workflow --- .github/workflows/test.yml | 11 +++++++---- runtime/src/lib.rs | 12 ++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3434722c..bdf4984d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,7 @@ name: Test # Controls when the action will run. on: push: - branches: '**' + branches: '*' jobs: test: @@ -38,6 +38,9 @@ jobs: run: | SKIP_WASM_BUILD=1 cargo check --release - # # Test code - # - name: Test - # run: cargo test \ No newline at end of file + - name: Check clippy + run: | + cargo clippy --all-targets --workspace --features runtime-benchmarks --features try-runtime + + - name: Run tests + run: cargo test \ No newline at end of file diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index d522ba31..4536d9c7 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -478,24 +478,24 @@ construct_runtime!( ParachainSystem: cumulus_pallet_parachain_system = 1, Timestamp: pallet_timestamp = 2, ParachainInfo: parachain_info = 3, - + // Monetary stuff. Balances: pallet_balances = 10, TransactionPayment: pallet_transaction_payment = 11, - + // Collator support. The order of these 4 are important and shall not change. Authorship: pallet_authorship = 20, CollatorSelection: pallet_collator_selection = 21, Session: pallet_session = 22, Aura: pallet_aura = 23, AuraExt: cumulus_pallet_aura_ext = 24, - + // XCM helpers. XcmpQueue: cumulus_pallet_xcmp_queue = 30, PolkadotXcm: pallet_xcm = 31, CumulusXcm: cumulus_pallet_xcm = 32, DmpQueue: cumulus_pallet_dmp_queue = 33, - + // Template Sudo: pallet_sudo = 40, LivingassetsOwnership: pallet_livingassets_ownership = 41, @@ -692,13 +692,13 @@ impl_runtime_apis! { list_benchmarks!(list, extra); let storage_info = AllPalletsWithSystem::storage_info(); - return (list, storage_info) + (list, storage_info) } fn dispatch_benchmark( config: frame_benchmarking::BenchmarkConfig ) -> Result, sp_runtime::RuntimeString> { - use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey}; + use frame_benchmarking::{Benchmarking, BenchmarkBatch}; use frame_system_benchmarking::Pallet as SystemBench; impl frame_system_benchmarking::Config for Runtime {} From f067c88cf584bfe40f504c9ae2e9e2070c2cd816 Mon Sep 17 00:00:00 2001 From: Dastan Samatov Date: Wed, 5 Jul 2023 13:51:47 +0600 Subject: [PATCH 4/7] Trigger action --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bdf4984d..20022e07 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,7 @@ name: Test # Controls when the action will run. on: push: - branches: '*' + branches: '**' jobs: test: From a8b87cc255070b6f0dbcac34808698444f6e662b Mon Sep 17 00:00:00 2001 From: Dastan Samatov Date: Wed, 5 Jul 2023 14:05:47 +0600 Subject: [PATCH 5/7] Add clippy --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 20022e07..a75793fa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,6 +32,7 @@ jobs: run: | rustup update stable --no-self-update rustup target add wasm32-unknown-unknown + rustup component add clippy # Check the build - name: Check Build From 34069870631730a35d540abd9fdb41a10677d448 Mon Sep 17 00:00:00 2001 From: Dastan Samatov Date: Wed, 5 Jul 2023 16:37:20 +0600 Subject: [PATCH 6/7] Remove test and rename file --- .github/workflows/{test.yml => lint.yml} | 3 --- 1 file changed, 3 deletions(-) rename .github/workflows/{test.yml => lint.yml} (96%) diff --git a/.github/workflows/test.yml b/.github/workflows/lint.yml similarity index 96% rename from .github/workflows/test.yml rename to .github/workflows/lint.yml index a75793fa..3d715642 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/lint.yml @@ -42,6 +42,3 @@ jobs: - name: Check clippy run: | cargo clippy --all-targets --workspace --features runtime-benchmarks --features try-runtime - - - name: Run tests - run: cargo test \ No newline at end of file From 4ec7104565d4b29777fccd2ba1577904626a8646 Mon Sep 17 00:00:00 2001 From: Dastan Samatov Date: Thu, 6 Jul 2023 13:22:31 +0600 Subject: [PATCH 7/7] Change ownership pallet branch --- Cargo.lock | 2 +- runtime/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d87da085..4b7aa29c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5912,7 +5912,7 @@ dependencies = [ [[package]] name = "pallet-livingassets-ownership" version = "0.0.1" -source = "git+https://github.com/freeverseio/pallet-livingassets-ownership?branch=fix/clippy#7b0765d4bd26fa107aadc4e4986905db635271fe" +source = "git+https://github.com/freeverseio/pallet-livingassets-ownership?branch=dev#939d6dcc0e745eab5c96b21c6ea1b2947281c3d1" dependencies = [ "frame-benchmarking", "frame-support", diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 0f841bf1..91e027bd 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -49,7 +49,7 @@ sp-std = { git = "https://github.com/paritytech/substrate", default-features = f sp-transaction-pool = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" } sp-version = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42" } -pallet-livingassets-ownership = { git = "https://github.com/freeverseio/pallet-livingassets-ownership", branch="fix/clippy", default-features = false } +pallet-livingassets-ownership = { git = "https://github.com/freeverseio/pallet-livingassets-ownership", branch="dev", default-features = false } # Polkadot pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.42" }