From b6e6c5dc975bfa8b3954d63f02be71f4ce2ea7f1 Mon Sep 17 00:00:00 2001 From: Benjamin Gallois <business@gallois.cc> Date: Wed, 20 Dec 2023 15:43:56 +0100 Subject: [PATCH] Refactor pallet_identity (nodes/rust/duniter-v2s!218) * add check metadata * Revert "add automatic metadata generation at commit" This reverts commit b8f0e439ef1661895a995013d95272f8a95e0841. * add automatic metadata generation at commit * add clippy checks for runtime-features * fix clippy errors runtime-benchmarks * remove unused BenchmarkSetupHandler trait * optimize AccountLinker --- .gitlab-ci.yml | 12 ++++++- Cargo.lock | 32 +++++++++--------- node/src/command.rs | 12 +++---- pallets/authority-members/src/benchmarking.rs | 4 +-- pallets/certification/src/benchmarking.rs | 8 ++--- pallets/distance/src/benchmarking.rs | 6 ++-- pallets/distance/src/mock.rs | 2 -- pallets/duniter-account/src/benchmarking.rs | 3 +- pallets/duniter-account/src/lib.rs | 16 ++++----- pallets/duniter-wot/src/mock.rs | 2 -- pallets/identity/src/benchmarking.rs | 16 ++++----- pallets/identity/src/lib.rs | 9 ++--- pallets/identity/src/mock.rs | 2 -- pallets/identity/src/traits.rs | 17 ++-------- pallets/membership/src/benchmarking.rs | 8 ++--- pallets/membership/src/lib.rs | 8 ++--- .../provide-randomness/src/benchmarking.rs | 10 +++--- pallets/quota/src/benchmarking.rs | 2 +- pallets/quota/src/mock.rs | 2 -- resources/metadata.scale | Bin 132039 -> 132226 bytes runtime/common/src/pallets_config.rs | 2 -- runtime/common/src/providers.rs | 2 -- scripts/check_metadata.sh | 15 ++++++++ 23 files changed, 91 insertions(+), 99 deletions(-) create mode 100755 scripts/check_metadata.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b53eb7df5..ce5414b95 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -41,6 +41,16 @@ check_labels: script: - ./scripts/check_labels.sh $CI_MERGE_REQUEST_LABELS $CI_MERGE_REQUEST_MILESTONE + +check_metadata: + extends: .env + stage: tests + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - when: never + script: + - ./scripts/check_metadata.sh + .env: image: paritytech/ci-linux:production tags: @@ -63,7 +73,7 @@ fmt_and_clippy: - cargo fmt -- --version - cargo fmt -- --check - cargo clippy -- -V - - cargo clippy --all --tests -- -D warnings + - cargo clippy --features runtime-benchmarks --all --tests -- -D warnings run_benchmarks: stage: tests diff --git a/Cargo.lock b/Cargo.lock index b66692b9c..1ba7482db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -985,9 +985,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.8" +version = "4.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2275f18819641850fa26c89acc84d465c1bf91ce57bc2748b28c420473352f64" +checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2" dependencies = [ "clap_builder", "clap_derive 4.4.7", @@ -995,9 +995,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.8" +version = "4.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07cdf1b148b25c1e1f7a42225e30a0d99a615cd4637eae7365548dd4529b95bc" +checksum = "a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb" dependencies = [ "anstream", "anstyle", @@ -1011,7 +1011,7 @@ version = "4.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bffe91f06a11b4b9420f62103854e90867812cd5d01557f853c5ee8e791b12ae" dependencies = [ - "clap 4.4.8", + "clap 4.4.11", ] [[package]] @@ -1402,9 +1402,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.16" +version = "0.8.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +checksum = "c06d96137f14f244c37f989d9fff8f95e6c18b918e71f36638f8c49112e4c78f" dependencies = [ "cfg-if 1.0.0", ] @@ -1944,7 +1944,7 @@ name = "distance-oracle" version = "0.1.0" dependencies = [ "bincode", - "clap 4.4.8", + "clap 4.4.11", "dubp-wot", "flate2", "fnv", @@ -1999,7 +1999,7 @@ version = "0.7.1" dependencies = [ "async-io 1.13.0", "bs58 0.5.0", - "clap 4.4.8", + "clap 4.4.11", "clap_complete", "common-runtime", "dc-distance", @@ -2658,7 +2658,7 @@ dependencies = [ "Inflector", "array-bytes", "chrono", - "clap 4.4.8", + "clap 4.4.11", "comfy-table", "frame-benchmarking", "frame-support", @@ -6939,9 +6939,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" dependencies = [ "unicode-ident", ] @@ -7827,7 +7827,7 @@ source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9 dependencies = [ "array-bytes", "chrono", - "clap 4.4.8", + "clap 4.4.11", "fdlimit", "futures 0.3.29", "libp2p", @@ -8645,7 +8645,7 @@ name = "sc-storage-monitor" version = "0.1.0" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.42#f1c396107a2312e5e029a5fe8e36f05234fc2511" dependencies = [ - "clap 4.4.8", + "clap 4.4.11", "fs4", "futures 0.3.29", "log", @@ -11018,7 +11018,7 @@ version = "0.10.0-dev" source = "git+https://github.com/duniter/substrate?branch=duniter-substrate-v0.9.42#f1c396107a2312e5e029a5fe8e36f05234fc2511" dependencies = [ "async-trait", - "clap 4.4.8", + "clap 4.4.11", "frame-remote-externalities", "hex", "log", @@ -12327,7 +12327,7 @@ name = "xtask" version = "0.1.0" dependencies = [ "anyhow", - "clap 4.4.8", + "clap 4.4.11", "frame-metadata", "graphql_client", "hex", diff --git a/node/src/command.rs b/node/src/command.rs index 86b2e5233..4008229ee 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -310,20 +310,20 @@ pub fn run() -> sc_cli::Result<()> { let chain_spec = &runner.config().chain_spec; match &**cmd { - BenchmarkCmd::Storage(cmd) => runner.sync_run(|mut config| { - let (client, backend, _, _) = service::new_chain_ops(&mut config, false)?; + BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| { + let (client, backend, _, _) = service::new_chain_ops(&config, false)?; let db = backend.expose_db(); let storage = backend.expose_storage(); unwrap_client!(client, cmd.run(config, client.clone(), db, storage)) }), - BenchmarkCmd::Block(cmd) => runner.sync_run(|mut config| { - let (client, _, _, _) = service::new_chain_ops(&mut config, false)?; + BenchmarkCmd::Block(cmd) => runner.sync_run(|config| { + let (client, _, _, _) = service::new_chain_ops(&config, false)?; unwrap_client!(client, cmd.run(client.clone())) }), - BenchmarkCmd::Overhead(cmd) => runner.sync_run(|mut config| { - let (client, _, _, _) = service::new_chain_ops(&mut config, false)?; + BenchmarkCmd::Overhead(cmd) => runner.sync_run(|config| { + let (client, _, _, _) = service::new_chain_ops(&config, false)?; let wrapped = client.clone(); let inherent_data = crate::service::client::benchmark_inherent_data() diff --git a/pallets/authority-members/src/benchmarking.rs b/pallets/authority-members/src/benchmarking.rs index 18e6472f8..893d89ba8 100644 --- a/pallets/authority-members/src/benchmarking.rs +++ b/pallets/authority-members/src/benchmarking.rs @@ -59,12 +59,12 @@ benchmarks! { let caller: T::AccountId = Members::<T>::get(id).unwrap().owner_key; let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into(); let validator_id = T::ValidatorIdOf::convert(caller.clone()).unwrap(); - let session_keys: T::Keys = pallet_session::NextKeys::<T>::get(validator_id).unwrap().into(); + let session_keys: T::Keys = pallet_session::NextKeys::<T>::get(validator_id).unwrap(); }: _<T::RuntimeOrigin>(caller_origin, session_keys) remove_member { let id: T::MemberId = OnlineAuthorities::<T>::get()[0]; let caller_origin = RawOrigin::Root.into(); - }: _<T::RuntimeOrigin>(caller_origin, id.clone()) + }: _<T::RuntimeOrigin>(caller_origin, id) verify { assert_has_event::<T>(Event::<T>::MemberRemoved{member: id}.into()); } diff --git a/pallets/certification/src/benchmarking.rs b/pallets/certification/src/benchmarking.rs index f265a95f7..4a4b61a8e 100644 --- a/pallets/certification/src/benchmarking.rs +++ b/pallets/certification/src/benchmarking.rs @@ -60,7 +60,7 @@ benchmarks_instance_pallet! { frame_system::pallet::Pallet::<T>::set_block_number(T::CertPeriod::get()); }: _<T::RuntimeOrigin>(caller_origin, issuer, receiver) verify { - assert_has_event::<T, I>(Event::<T, I>::CertAdded{ issuer: issuer, receiver: receiver }.into()); + assert_has_event::<T, I>(Event::<T, I>::CertAdded{ issuer, receiver }.into()); } del_cert { let issuer: T::IdtyIndex = 1.into(); @@ -70,14 +70,14 @@ benchmarks_instance_pallet! { let issuer_cert: u32 = StorageIdtyCertMeta::<T, I>::get(issuer).issued_count; }: _<T::RuntimeOrigin>(RawOrigin::Root.into(), issuer, receiver) verify { - assert_has_event::<T, I>(Event::<T, I>::CertRemoved{ issuer: issuer, receiver: receiver, expiration: false }.into()); + assert_has_event::<T, I>(Event::<T, I>::CertRemoved{ issuer, receiver, expiration: false }.into()); } remove_all_certs_received_by { let receiver: T::IdtyIndex = 0.into(); let i in 2..1000 => add_certs::<T, I>(i, receiver)?; }: _<T::RuntimeOrigin>(RawOrigin::Root.into(), receiver) verify { - assert!(CertsByReceiver::<T, I>::get(receiver).len() == 0 ); + assert!(CertsByReceiver::<T, I>::get(receiver).is_empty() ); } on_initialize { assert!(StorageCertsRemovableOn::<T, I>::try_get(T::BlockNumber::zero()).is_err()); @@ -94,7 +94,7 @@ benchmarks_instance_pallet! { frame_system::pallet::Pallet::<T>::set_block_number(block_number); }: {Pallet::<T, I>::do_remove_cert(issuer, receiver, Some(block_number));} verify { - assert_has_event::<T, I>(Event::<T, I>::CertRemoved{ issuer: issuer, receiver: receiver, expiration: true }.into()); + assert_has_event::<T, I>(Event::<T, I>::CertRemoved{ issuer, receiver, expiration: true }.into()); } impl_benchmark_test_suite!( diff --git a/pallets/distance/src/benchmarking.rs b/pallets/distance/src/benchmarking.rs index 9fbbd3242..33ba9419b 100644 --- a/pallets/distance/src/benchmarking.rs +++ b/pallets/distance/src/benchmarking.rs @@ -37,7 +37,7 @@ fn populate_pool<T: Config>(i: u32) -> Result<(), &'static str> { for j in 0..i { current_pool .evaluations - .try_push((j.into(), median::MedianAcc::new())) + .try_push((j, median::MedianAcc::new())) .map_err(|_| Error::<T>::QueueFull)?; } Ok(()) @@ -57,7 +57,7 @@ benchmarks! { let _ = <Balances<T> as Currency<_>>::make_free_balance_be(&caller, T::Balance::max_value()); }: _<T::RuntimeOrigin>(caller_origin.clone()) verify { - assert!(IdentityDistanceStatus::<T>::get(&idty) == Some((caller.clone(), DistanceStatus::Pending)), "Request not added"); + assert!(IdentityDistanceStatus::<T>::get(idty) == Some((caller.clone(), DistanceStatus::Pending)), "Request not added"); assert_has_event::<T>(Event::<T>::EvaluationRequested { idty_index: idty, who: caller }.into()); } update_evaluation { @@ -89,7 +89,7 @@ benchmarks! { let status = Some((caller.clone(), DistanceStatus::Valid)); }: _<T::RuntimeOrigin>(RawOrigin::Root.into(), idty, status.clone()) verify { - assert!(IdentityDistanceStatus::<T>::get(&idty) == Some((caller, DistanceStatus::Valid)), "Status not set"); + assert!(IdentityDistanceStatus::<T>::get(idty) == Some((caller, DistanceStatus::Valid)), "Status not set"); assert_has_event::<T>(Event::<T>::EvaluationStatusForced { idty_index: idty, status }.into()); } on_finalize { diff --git a/pallets/distance/src/mock.rs b/pallets/distance/src/mock.rs index 988c9b43f..a05d58577 100644 --- a/pallets/distance/src/mock.rs +++ b/pallets/distance/src/mock.rs @@ -245,8 +245,6 @@ impl pallet_identity::Config for Test { type OnIdtyChange = (); type RuntimeEvent = RuntimeEvent; type WeightInfo = (); - #[cfg(feature = "runtime-benchmarks")] - type BenchmarkSetupHandler = (); } parameter_types! { diff --git a/pallets/duniter-account/src/benchmarking.rs b/pallets/duniter-account/src/benchmarking.rs index e0e300d0f..6c99b5532 100644 --- a/pallets/duniter-account/src/benchmarking.rs +++ b/pallets/duniter-account/src/benchmarking.rs @@ -40,8 +40,7 @@ fn create_pending_accounts<T: Config>( let existential_deposit = T::ExistentialDeposit::get(); let balance = existential_deposit.saturating_mul((200u32).into()); let _ = <pallet_balances::Pallet<T> as Currency<T::AccountId>>::make_free_balance_be( - &caller, - balance.into(), + &caller, balance, ); } else { assert!( diff --git a/pallets/duniter-account/src/lib.rs b/pallets/duniter-account/src/lib.rs index 7244fd3d9..7184febf0 100644 --- a/pallets/duniter-account/src/lib.rs +++ b/pallets/duniter-account/src/lib.rs @@ -219,22 +219,18 @@ pub mod pallet { /// link account to identity pub fn do_link_identity( - account_id: T::AccountId, + account_id: &T::AccountId, idty_id: IdtyIdOf<T>, ) -> Result<(), DispatchError> { // Check that account exist ensure!( - (frame_system::Account::<T>::get(&account_id).providers >= 1) - || (frame_system::Account::<T>::get(&account_id).sufficients >= 1), + (frame_system::Account::<T>::get(account_id).providers >= 1) + || (frame_system::Account::<T>::get(account_id).sufficients >= 1), pallet_identity::Error::<T>::AccountNotExist ); // no-op if identity does not change - if frame_system::Account::<T>::get(&account_id) - .data - .linked_idty - != Some(idty_id) - { - frame_system::Account::<T>::mutate(&account_id, |account| { + if frame_system::Account::<T>::get(account_id).data.linked_idty != Some(idty_id) { + frame_system::Account::<T>::mutate(account_id, |account| { account.data.linked_idty = Some(idty_id); Self::deposit_event(Event::AccountLinked { who: account_id.clone(), @@ -335,7 +331,7 @@ impl<T> pallet_identity::traits::LinkIdty<T::AccountId, IdtyIdOf<T>> for Pallet< where T: Config, { - fn link_identity(account_id: T::AccountId, idty_id: IdtyIdOf<T>) -> Result<(), DispatchError> { + fn link_identity(account_id: &T::AccountId, idty_id: IdtyIdOf<T>) -> Result<(), DispatchError> { Self::do_link_identity(account_id, idty_id) } } diff --git a/pallets/duniter-wot/src/mock.rs b/pallets/duniter-wot/src/mock.rs index 9420b482f..268a6bf01 100644 --- a/pallets/duniter-wot/src/mock.rs +++ b/pallets/duniter-wot/src/mock.rs @@ -138,8 +138,6 @@ impl pallet_identity::Config for Test { type OnIdtyChange = (DuniterWot, SmithSubWot); type RuntimeEvent = RuntimeEvent; type WeightInfo = (); - #[cfg(feature = "runtime-benchmarks")] - type BenchmarkSetupHandler = (); } // Membership diff --git a/pallets/identity/src/benchmarking.rs b/pallets/identity/src/benchmarking.rs index fb5950a66..f7ba053f6 100644 --- a/pallets/identity/src/benchmarking.rs +++ b/pallets/identity/src/benchmarking.rs @@ -61,7 +61,7 @@ fn create_one_identity<T: Config>(owner_key: T::AccountId) -> Result<Account<T>, Pallet::<T>::confirm_identity(owner_key_origin.clone(), name.clone())?; let idty_index = IdentityIndexOf::<T>::get(&owner_key).unwrap(); // make identity member - <Identities<T>>::mutate_exists(T::IdtyIndex::from(idty_index), |idty_val_opt| { + <Identities<T>>::mutate_exists(idty_index, |idty_val_opt| { if let Some(ref mut idty_val) = idty_val_opt { idty_val.status = IdtyStatus::Member; } @@ -133,7 +133,7 @@ benchmarks! { verify { let idty_index = IdentityIndexOf::<T>::get(&owner_key); assert!(idty_index.is_some(), "Identity not added"); - assert_has_event::<T>(Event::<T>::IdtyCreated { idty_index: idty_index.unwrap(), owner_key: owner_key }.into()); + assert_has_event::<T>(Event::<T>::IdtyCreated { idty_index: idty_index.unwrap(), owner_key }.into()); } // confirm identity @@ -146,7 +146,7 @@ benchmarks! { }: _<T::RuntimeOrigin>(owner_key_origin.clone(), IdtyName("new_identity".into())) verify { let idty_index = IdentityIndexOf::<T>::get(&owner_key); - assert_has_event::<T>(Event::<T>::IdtyConfirmed { idty_index: idty_index.unwrap(), owner_key: owner_key, name: IdtyName("new_identity".into()) }.into()); + assert_has_event::<T>(Event::<T>::IdtyConfirmed { idty_index: idty_index.unwrap(), owner_key, name: IdtyName("new_identity".into()) }.into()); } // change owner key @@ -163,7 +163,7 @@ benchmarks! { }; let message = (NEW_OWNER_KEY_PAYLOAD_PREFIX, new_key_payload).encode(); let caller_public = sr25519_generate(0.into(), None); - let caller: T::AccountId = MultiSigner::Sr25519(caller_public.clone()).into_account().into(); + let caller: T::AccountId = MultiSigner::Sr25519(caller_public).into_account().into(); let signature = sr25519_sign(0.into(), &caller_public, &message).unwrap().into(); Pallet::<T>::change_owner_key(account.origin.clone(), caller.clone(), signature)?; @@ -178,7 +178,7 @@ benchmarks! { }; let message = (NEW_OWNER_KEY_PAYLOAD_PREFIX, new_key_payload).encode(); let caller_public = sr25519_generate(0.into(), None); - let caller: T::AccountId = MultiSigner::Sr25519(caller_public.clone()).into_account().into(); + let caller: T::AccountId = MultiSigner::Sr25519(caller_public).into_account().into(); let signature = sr25519_sign(0.into(), &caller_public, &message).unwrap().into(); <frame_system::Pallet<T>>::set_block_number(<frame_system::Pallet<T>>::block_number() + T::ChangeOwnerKeyPeriod::get()); }: _<T::RuntimeOrigin>(caller_origin.clone(), caller.clone(), signature) @@ -202,18 +202,18 @@ benchmarks! { }; let message = (NEW_OWNER_KEY_PAYLOAD_PREFIX, new_key_payload).encode(); let caller_public = sr25519_generate(0.into(), None); - let caller: T::AccountId = MultiSigner::Sr25519(caller_public.clone()).into_account().into(); + let caller: T::AccountId = MultiSigner::Sr25519(caller_public).into_account().into(); let signature = sr25519_sign(0.into(), &caller_public, &message).unwrap().into(); Pallet::<T>::change_owner_key(account.origin.clone(), caller.clone(), signature)?; let genesis_hash = frame_system::Pallet::<T>::block_hash(T::BlockNumber::zero()); let revocation_payload = RevocationPayload { genesis_hash: &genesis_hash, - idty_index: account.index.clone(), + idty_index: account.index, }; let message = (REVOCATION_PAYLOAD_PREFIX, revocation_payload).encode(); let signature = sr25519_sign(0.into(), &caller_public, &message).unwrap().into(); - }: _<T::RuntimeOrigin>(account.origin.clone(), account.index.clone().into(), caller.clone(), signature) + }: _<T::RuntimeOrigin>(account.origin, account.index, caller.clone(), signature) verify { assert_has_event::<T>(Event::<T>::IdtyRevoked { idty_index: account.index, reason: RevocationReason::User }.into()); // revocation does not mean deletion anymore diff --git a/pallets/identity/src/lib.rs b/pallets/identity/src/lib.rs index c89d77aac..c9656a498 100644 --- a/pallets/identity/src/lib.rs +++ b/pallets/identity/src/lib.rs @@ -125,9 +125,6 @@ pub mod pallet { type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; /// Type representing the weight of this pallet type WeightInfo: WeightInfo; - /// Type representing the a distance handler to prepare identity for benchmarking - #[cfg(feature = "runtime-benchmarks")] - type BenchmarkSetupHandler: SetupBenchmark<Self::IdtyIndex, Self::AccountId>; } // GENESIS STUFFĂ‚ // @@ -328,7 +325,7 @@ pub mod pallet { idty_index, owner_key: owner_key.clone(), }); - T::AccountLinker::link_identity(owner_key.clone(), idty_index)?; + T::AccountLinker::link_identity(&owner_key, idty_index)?; T::OnIdtyChange::on_idty_change( idty_index, &IdtyEvent::Created { @@ -455,7 +452,7 @@ pub mod pallet { frame_system::Pallet::<T>::inc_sufficients(&idty_value.owner_key); IdentityIndexOf::<T>::insert(&idty_value.owner_key, idty_index); Identities::<T>::insert(idty_index, idty_value); - T::AccountLinker::link_identity(new_key.clone(), idty_index)?; + T::AccountLinker::link_identity(&new_key, idty_index)?; Self::deposit_event(Event::IdtyChangedOwnerKey { idty_index, new_owner_key: new_key, @@ -586,7 +583,7 @@ pub mod pallet { Error::<T>::InvalidSignature ); // apply - T::AccountLinker::link_identity(account_id, idty_index)?; + T::AccountLinker::link_identity(&account_id, idty_index)?; Ok(().into()) } diff --git a/pallets/identity/src/mock.rs b/pallets/identity/src/mock.rs index 9421a70f0..59242164b 100644 --- a/pallets/identity/src/mock.rs +++ b/pallets/identity/src/mock.rs @@ -118,8 +118,6 @@ impl pallet_identity::Config for Test { type OnIdtyChange = (); type RuntimeEvent = RuntimeEvent; type WeightInfo = (); - #[cfg(feature = "runtime-benchmarks")] - type BenchmarkSetupHandler = (); } // Build genesis storage according to the mock runtime. diff --git a/pallets/identity/src/traits.rs b/pallets/identity/src/traits.rs index ffc230aa7..925714813 100644 --- a/pallets/identity/src/traits.rs +++ b/pallets/identity/src/traits.rs @@ -53,23 +53,10 @@ impl<T: Config> OnIdtyChange<T> for Tuple { /// trait used to link an account to an identity pub trait LinkIdty<AccountId, IdtyIndex> { - fn link_identity(account_id: AccountId, idty_index: IdtyIndex) -> Result<(), DispatchError>; + fn link_identity(account_id: &AccountId, idty_index: IdtyIndex) -> Result<(), DispatchError>; } impl<AccountId, IdtyIndex> LinkIdty<AccountId, IdtyIndex> for () { - fn link_identity(_: AccountId, _: IdtyIndex) -> Result<(), DispatchError> { + fn link_identity(_: &AccountId, _: IdtyIndex) -> Result<(), DispatchError> { Ok(()) } } - -/// trait used only in benchmarks to prepare identity for benchmarking -#[cfg(feature = "runtime-benchmarks")] -pub trait SetupBenchmark<IndtyIndex, AccountId> { - fn force_status_ok(idty_index: &IndtyIndex, account: &AccountId) -> (); - fn add_cert(issuer: &IndtyIndex, receiver: &IndtyIndex) -> (); -} - -#[cfg(feature = "runtime-benchmarks")] -impl<IdtyIndex, AccountId> SetupBenchmark<IdtyIndex, AccountId> for () { - fn force_status_ok(_idty_id: &IdtyIndex, _account: &AccountId) -> () {} - fn add_cert(_issuer: &IdtyIndex, _receiver: &IdtyIndex) -> () {} -} diff --git a/pallets/membership/src/benchmarking.rs b/pallets/membership/src/benchmarking.rs index 48849bd51..531bd3e13 100644 --- a/pallets/membership/src/benchmarking.rs +++ b/pallets/membership/src/benchmarking.rs @@ -42,7 +42,7 @@ benchmarks_instance_pallet! { claim_membership { let idty: T::IdtyId = 3.into(); Membership::<T, I>::take(idty); - let caller: T::AccountId = T::AccountIdOf::convert(idty.clone()).unwrap(); + let caller: T::AccountId = T::AccountIdOf::convert(idty).unwrap(); let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into(); T::BenchmarkSetupHandler::force_status_ok(&idty, &caller); }: _<T::RuntimeOrigin>(caller_origin) @@ -53,7 +53,7 @@ benchmarks_instance_pallet! { // renew membership renew_membership { let idty: T::IdtyId = 3.into(); - let caller: T::AccountId = T::AccountIdOf::convert(idty.clone()).unwrap(); + let caller: T::AccountId = T::AccountIdOf::convert(idty).unwrap(); let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into(); T::BenchmarkSetupHandler::force_status_ok(&idty, &caller); }: _<T::RuntimeOrigin>(caller_origin) @@ -64,7 +64,7 @@ benchmarks_instance_pallet! { // revoke membership revoke_membership { let idty: T::IdtyId = 3.into(); - let caller: T::AccountId = T::AccountIdOf::convert(idty.clone()).unwrap(); + let caller: T::AccountId = T::AccountIdOf::convert(idty).unwrap(); let caller_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(caller.clone()).into(); }: _<T::RuntimeOrigin>(caller_origin) verify { @@ -87,7 +87,7 @@ benchmarks_instance_pallet! { assert_eq!(MembershipsExpireOn::<T, I>::get(BlockNumberFor::<T>::zero()).len(), i as usize); }: {Pallet::<T, I>::expire_memberships(BlockNumberFor::<T>::zero());} verify { - assert_eq!(MembershipsExpireOn::<T, I>::get(BlockNumberFor::<T>::zero()).len(), 0 as usize); + assert_eq!(MembershipsExpireOn::<T, I>::get(BlockNumberFor::<T>::zero()).len(), 0_usize); } impl_benchmark_test_suite!( diff --git a/pallets/membership/src/lib.rs b/pallets/membership/src/lib.rs index 4f44e11dc..284a03244 100644 --- a/pallets/membership/src/lib.rs +++ b/pallets/membership/src/lib.rs @@ -44,14 +44,14 @@ use std::collections::BTreeMap; #[cfg(feature = "runtime-benchmarks")] pub trait SetupBenchmark<IdtyId, AccountId> { - fn force_status_ok(idty_index: &IdtyId, account: &AccountId) -> (); - fn add_cert(_issuer: &IdtyId, _receiver: &IdtyId) -> (); + fn force_status_ok(idty_index: &IdtyId, account: &AccountId); + fn add_cert(_issuer: &IdtyId, _receiver: &IdtyId); } #[cfg(feature = "runtime-benchmarks")] impl<IdtyId, AccountId> SetupBenchmark<IdtyId, AccountId> for () { - fn force_status_ok(_idty_id: &IdtyId, _account: &AccountId) -> () {} - fn add_cert(_issuer: &IdtyId, _receiver: &IdtyId) -> () {} + fn force_status_ok(_idty_id: &IdtyId, _account: &AccountId) {} + fn add_cert(_issuer: &IdtyId, _receiver: &IdtyId) {} } #[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)] diff --git a/pallets/provide-randomness/src/benchmarking.rs b/pallets/provide-randomness/src/benchmarking.rs index 4562461ee..cbbf0f685 100644 --- a/pallets/provide-randomness/src/benchmarking.rs +++ b/pallets/provide-randomness/src/benchmarking.rs @@ -80,11 +80,11 @@ benchmarks! { // Set randomness parameters let random = RandomnessType::RandomnessFromOneEpochAgo; let salt: H256 = H256([1; 32]); - }: _<T::RuntimeOrigin>(caller_origin.clone(), random, salt.clone()) + }: _<T::RuntimeOrigin>(caller_origin.clone(), random, salt) verify { let request_id = RequestIdProvider::<T>::get() - 1; assert_has_event::<T>(Event::RequestedRandomness { - request_id: request_id, salt: salt, r#type: random }.into() ); + request_id, salt, r#type: random }.into() ); } on_initialize { let i in 1 .. T::MaxRequests::get() => add_requests_next_block::<T>(i)?; @@ -97,11 +97,11 @@ benchmarks! { }: { Pallet::<T>::on_initialize(T::BlockNumber::one()); } verify { ensure!(RequestsIds::<T>::count() == 0, "List not processed."); - ensure!(RequestsReadyAtNextBlock::<T>::get().len() == 0, "List not processed."); + ensure!(RequestsReadyAtNextBlock::<T>::get().is_empty(), "List not processed."); } on_initialize_epoch { let i in 1 .. T::MaxRequests::get() => add_requests_next_epoch::<T>(i)?; - ensure!(RequestsReadyAtNextBlock::<T>::get().len() == 0, "List not filled properly."); + ensure!(RequestsReadyAtNextBlock::<T>::get().is_empty(), "List not filled properly."); ensure!(RequestsIds::<T>::count() == i, "List not filled properly."); ensure!(RequestsReadyAtEpoch::<T>::get(T::GetCurrentEpochIndex::get()).len() == i as usize, "List not filled properly."); let next_epoch_hook_in = NexEpochHookIn::<T>::mutate(|next_in| { @@ -110,6 +110,6 @@ benchmarks! { }: { Pallet::<T>::on_initialize(1.into()); } verify { ensure!(RequestsIds::<T>::count() == 0, "List not processed."); - ensure!(RequestsReadyAtEpoch::<T>::get(T::GetCurrentEpochIndex::get()).len() == 0, "List not processed properly."); + ensure!(RequestsReadyAtEpoch::<T>::get(T::GetCurrentEpochIndex::get()).is_empty(), "List not processed properly."); } } diff --git a/pallets/quota/src/benchmarking.rs b/pallets/quota/src/benchmarking.rs index 4519eea02..124f2e66f 100644 --- a/pallets/quota/src/benchmarking.rs +++ b/pallets/quota/src/benchmarking.rs @@ -63,7 +63,7 @@ benchmarks! { amount: quota_amount.into(), }, ); - }: { Pallet::<T>::spend_quota(idty_id.into(), amount.into()) } + }: { Pallet::<T>::spend_quota(idty_id, amount.into()) } verify { let quota_growth = sp_runtime::Perbill::from_rational( T::BlockNumber::one(), diff --git a/pallets/quota/src/mock.rs b/pallets/quota/src/mock.rs index d023eebee..06548263b 100644 --- a/pallets/quota/src/mock.rs +++ b/pallets/quota/src/mock.rs @@ -164,8 +164,6 @@ impl pallet_identity::Config for Test { type OnIdtyChange = (); type RuntimeEvent = RuntimeEvent; type WeightInfo = (); - #[cfg(feature = "runtime-benchmarks")] - type BenchmarkSetupHandler = (); } // Build genesis storage according to the mock runtime. diff --git a/resources/metadata.scale b/resources/metadata.scale index 60cf370fe64aecd0dc9bbdd157c56e90b5653228..919f543f21a57970a0b67040b2ff16e6d54034ec 100644 GIT binary patch delta 354 zcmX@!&e7D#vB5!|QD(EF`X(mv2;bD)q|_qEl$6wzkbI|{#N_Op%;J*Cf|?R?Y%CRy z3b|l;g^a{vg{0KfJcT5<l7$|5o8z<&ujQG_7~=2Zub^ybYN;^U;DNP#3ebeayyR4c z%wmPqvc#Oy#FEq$g@XLz%#zHq)SS%)H}<iUqsxGC^V)}3>luBvHzzWFV`RKCy(*c} zgi&w%x@1O4MqLNToTAjkluCu7)Uy2S)D*oK=fpg}{E{FrH#9FfKQAq_C^t2QL4ak) zbemL0T}Hj>3aO0Jj1Zoso{eL2a(-!E2~d-31<(@=LM&5&X5{6UDCA`3Wh<2AD<tMA cWag!UBs25U6%rxpr(bMgEZlxGmGRwN0OEFlm;e9( delta 186 zcmZqb<T&2WvB5!|QDU>B`X;8yOflJ;*J&MI%VfzodEo<Vp|ZrB%#_5E%)E4k%#_r; zlFX9LzaJPdZf3vL$A(u8Ya^q_cE%*eZ;Xr=rvFH0G}*43!YIk8W8;`pl$w}QsZf+! zmY<!P662hh=a*j+1m=b2CFkd*WftY8rZ5PwY?;0{l~H&4!c<0SMkxD23uD3dDQS%F G<^lj^bx3aj diff --git a/runtime/common/src/pallets_config.rs b/runtime/common/src/pallets_config.rs index 0e27e3b04..6efcf29e3 100644 --- a/runtime/common/src/pallets_config.rs +++ b/runtime/common/src/pallets_config.rs @@ -481,8 +481,6 @@ macro_rules! pallets_config { type OnIdtyChange = (Wot, SmithSubWot, Quota); type RuntimeEvent = RuntimeEvent; type WeightInfo = common_runtime::weights::pallet_identity::WeightInfo<Runtime>; - #[cfg(feature = "runtime-benchmarks")] - type BenchmarkSetupHandler = common_runtime::providers::BenchmarkSetupHandler<Runtime>; } impl pallet_membership::Config<frame_support::instances::Instance1> for Runtime { diff --git a/runtime/common/src/providers.rs b/runtime/common/src/providers.rs index e950bf47b..1518c1060 100644 --- a/runtime/common/src/providers.rs +++ b/runtime/common/src/providers.rs @@ -123,5 +123,3 @@ macro_rules! impl_benchmark_setup_handler { #[cfg(feature = "runtime-benchmarks")] impl_benchmark_setup_handler!(pallet_membership::SetupBenchmark<<T as pallet_identity::Config>::IdtyIndex, T::AccountId>); -#[cfg(feature = "runtime-benchmarks")] -impl_benchmark_setup_handler!(pallet_identity::traits::SetupBenchmark<<T as pallet_identity::Config>::IdtyIndex, T::AccountId>); diff --git a/scripts/check_metadata.sh b/scripts/check_metadata.sh new file mode 100755 index 000000000..96b2c4720 --- /dev/null +++ b/scripts/check_metadata.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +cargo install subxt-cli +cargo build +cargo run -- --dev& +sleep 15 +subxt metadata -f bytes > resources/new_metadata.scale +kill $! + +if cmp -s resources/new_metadata.scale resources/metadata.scale; then + exit 0 +else + echo "Metadata file needs to be generated. How to do it? $HOME/.cargo/bin/subxt metadata -f bytes > resources/metadata.scale" + exit 1 +fi -- GitLab