-
Notifications
You must be signed in to change notification settings - Fork 47
feat: benchmarks #585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: benchmarks #585
Changes from 68 commits
0c56e4c
2df9776
e1f186d
f20beba
bc2bdc2
fddc666
681dc77
279d241
7fe3593
2ccadf5
70431ef
538a234
cacf04c
870f424
22ccaad
c8aed6f
da6314d
5706638
14748ef
0cba1d1
90f5fe4
cc00b0b
d276f0e
489806f
b493baf
8b97889
048b72d
192e665
a5d246e
b0f42c4
db976e4
11f9e28
faf0a30
e94caab
2481a5a
650d311
3b33c61
9dfcf03
ad270c5
1fe7290
daea05f
76c79bf
9594535
9899e4d
8b7dc12
34c2aad
757f1cf
a3daa24
9625dfc
1c70fcb
052254a
1f59a54
e73c686
e91bb50
e8f0200
4fad41b
42414a5
0bad8c0
6b3e1e3
c0efd83
78e0959
09f1f6c
387767b
7a8e572
b33e6ca
2d3ee23
459ab82
69ad8e4
e64d943
82ac447
b7add42
8a44925
1ccc2fe
20b0d16
3c5e579
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -434,6 +434,30 @@ impl pallet_web3_names::Config for Runtime { | |
| type WeightInfo = (); | ||
| } | ||
|
|
||
| #[cfg(feature = "runtime-benchmarks")] | ||
| mod benches { | ||
| frame_benchmarking::define_benchmarks!( | ||
| [frame_system, SystemBench::<Runtime>] | ||
| [cumulus_pallet_parachain_system, ParachainSystem] | ||
| [pallet_timestamp, Timestamp] | ||
| [pallet_sudo, Sudo] | ||
| [pallet_utility, Utility] | ||
| [pallet_balances, Balances] | ||
| [pallet_transaction_payment, TransactionPayment] | ||
| [pallet_authorship, Authorship] | ||
| [pallet_collator_selection, CollatorSelection] | ||
| [pallet_session, Session] | ||
| [pallet_aura, Aura] | ||
| [cumulus_pallet_aura_ext, AuraExt] | ||
| [did, Did] | ||
| [pallet_did_lookup, DidLookup] | ||
| [pallet_web3_names, Web3Names] | ||
| [pallet_deposit_storage, DepositStorage] | ||
| [pallet_dip_provider, DipProvider] | ||
| [frame_benchmarking::baseline, Baseline::<Runtime>] | ||
| ); | ||
| } | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps I made a mistake. I compiled the branch using: When I run:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mhh, I might have missed some dependency when the benchmark feature is enabled. I will investigate that |
||
| impl_runtime_apis! { | ||
| impl sp_consensus_aura::AuraApi<Block, AuraId> for Runtime { | ||
| fn slot_duration() -> SlotDuration { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,63 @@ | ||
| [package] | ||
| authors.workspace = true | ||
| description = "Stores all deposits under a single pallet, with suport for namespacing different deposit contexts." | ||
| documentation.workspace = true | ||
| edition.workspace = true | ||
| homepage.workspace = true | ||
| license-file.workspace = true | ||
| name = "pallet-deposit-storage" | ||
| readme.workspace = true | ||
| repository.workspace = true | ||
| version.workspace = true | ||
| name = "pallet-deposit-storage" | ||
| description = "Stores all deposits under a single pallet, with suport for namespacing different deposit contexts." | ||
|
|
||
| [package.metadata.docs.rs] | ||
| targets = ["x86_64-unknown-linux-gnu"] | ||
|
|
||
| [dev-dependencies] | ||
| pallet-balances = {workspace = true, features = ["std"]} | ||
| sp-io = {workspace = true, features = ["std"]} | ||
| sp-keystore = {workspace = true, features = ["std"]} | ||
|
|
||
| [dependencies] | ||
| # Substrate dependencies | ||
| frame-support.workspace = true | ||
| frame-system.workspace = true | ||
| kilt-support.workspace = true | ||
| log.workspace = true | ||
| pallet-dip-provider.workspace = true | ||
| parity-scale-codec = {workspace = true, features = ["derive"]} | ||
| scale-info = {workspace = true, features = ["derive"]} | ||
| sp-runtime.workspace = true | ||
| sp-std.workspace = true | ||
|
|
||
| log.workspace = true | ||
| # Benchmarking | ||
| frame-benchmarking = {workspace = true, optional = true} | ||
| pallet-balances = {workspace = true, optional = true} | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [ | ||
| "frame-support/std", | ||
| "frame-system/std", | ||
| "kilt-support/std", | ||
| "log/std", | ||
| "pallet-dip-provider/std", | ||
| "parity-scale-codec/std", | ||
| "scale-info/std", | ||
| "sp-runtime/std", | ||
| "sp-std/std", | ||
| "log/std", | ||
| "frame-benchmarking?/std", | ||
| "pallet-balances?/std", | ||
| ] | ||
|
|
||
| runtime-benchmarks = [ | ||
| "frame-support/runtime-benchmarks", | ||
| "frame-system/runtime-benchmarks", | ||
| "kilt-support/runtime-benchmarks", | ||
| "pallet-dip-provider/runtime-benchmarks", | ||
| "sp-runtime/runtime-benchmarks", | ||
| "frame-benchmarking/runtime-benchmarks", | ||
| "pallet-balances/runtime-benchmarks", | ||
| ] | ||
ntn-x2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| try-runtime = [ "kilt-support/try-runtime" ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // KILT Blockchain – https://botlabs.org | ||
| // Copyright (C) 2019-2023 BOTLabs GmbH | ||
|
|
||
| // The KILT Blockchain is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // The KILT Blockchain is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| // If you feel like getting in touch with us, you can do so at [email protected] | ||
|
|
||
| use crate::{Call, Config, DepositEntryOf, DepositKeyOf, Deposits, HoldReason, Pallet}; | ||
| use frame_benchmarking::v2::*; | ||
| use frame_support::traits::fungible::Mutate; | ||
| use frame_system::RawOrigin; | ||
| use kilt_support::{traits::Instanciate, Deposit}; | ||
| use sp_runtime::SaturatedConversion; | ||
|
|
||
| #[benchmarks( | ||
| where | ||
| T::AccountId: Instanciate, | ||
| T: Config + pallet_balances::Config, | ||
| T::Namespace: Default | ||
| )] | ||
| mod benchmarks { | ||
|
|
||
| use sp_runtime::BoundedVec; | ||
|
|
||
| use super::*; | ||
|
|
||
| const KILT: u128 = 10u128.pow(15); | ||
|
|
||
| #[benchmark] | ||
| fn reclaim_deposit() { | ||
| let submitter = T::AccountId::new(1); | ||
|
|
||
| let origin = RawOrigin::Signed(submitter.clone()); | ||
|
|
||
| let namespace: <T as Config>::Namespace = Default::default(); | ||
|
|
||
| let key: DepositKeyOf<T> = BoundedVec::try_from(vec![1]).expect("Creation of key should not fail."); | ||
|
|
||
| assert!(Deposits::<T>::get(&namespace, &key).is_none()); | ||
|
|
||
| let entry = DepositEntryOf::<T> { | ||
| deposit: Deposit { | ||
| amount: KILT.saturated_into(), | ||
| owner: submitter.clone(), | ||
| }, | ||
| reason: <T as Config>::RuntimeHoldReason::from(HoldReason::Deposit), | ||
| }; | ||
|
|
||
| let amount = KILT * 100; | ||
|
|
||
| <pallet_balances::Pallet<T> as Mutate<<T as frame_system::Config>::AccountId>>::set_balance( | ||
| &submitter, | ||
| amount.saturated_into(), | ||
| ); | ||
|
|
||
| Pallet::<T>::add_deposit(namespace.clone(), key.clone(), entry).expect("Creating Deposit should not fail."); | ||
|
|
||
| assert!(Deposits::<T>::get(&namespace, &key).is_some()); | ||
|
|
||
| let cloned_namespace = namespace.clone(); | ||
| let cloned_key = key.clone(); | ||
|
|
||
| #[extrinsic_call] | ||
| Pallet::<T>::reclaim_deposit(origin, cloned_namespace, cloned_key); | ||
|
|
||
| assert!(Deposits::<T>::get(&namespace, &key).is_none()); | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod benchmarks_tests { | ||
| use crate::Pallet; | ||
| use frame_benchmarking::impl_benchmark_test_suite; | ||
|
|
||
| impl_benchmark_test_suite!( | ||
| Pallet, | ||
| crate::mock::ExtBuilder::default().build_with_keystore(), | ||
| crate::mock::TestRuntime, | ||
| ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
|
|
||
| //! Autogenerated weights for pallet_deposit_storage | ||
| //! | ||
| //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev | ||
| //! DATE: 2023-11-24 | ||
| //! STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` | ||
| //! WORST CASE MAP SIZE: `1000000` | ||
| //! HOSTNAME: `rust-2`, CPU: `12th Gen Intel(R) Core(TM) i9-12900K` | ||
| //! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 | ||
|
|
||
| // Executed Command: | ||
| // ./target/debug/kilt-parachain | ||
| // benchmark | ||
| // pallet | ||
| // --pallet | ||
| // pallet-deposit-storage | ||
| // --extrinsic | ||
| // * | ||
| // --template | ||
| // ./.maintain/weight-template.hbs | ||
| // --output | ||
| // ./pallets/pallet-deposit-storage/src/defaul_weights.rs | ||
|
|
||
| #![cfg_attr(rustfmt, rustfmt_skip)] | ||
| #![allow(unused_parens)] | ||
| #![allow(unused_imports)] | ||
|
|
||
| use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; | ||
| use sp_std::marker::PhantomData; | ||
|
|
||
| /// Weight functions needed for pallet_deposit_storage. | ||
| pub trait WeightInfo { | ||
| fn reclaim_deposit() -> Weight; | ||
| } | ||
|
|
||
| /// Weights for pallet_deposit_storage using the Substrate node and recommended hardware. | ||
| pub struct SubstrateWeight<T>(PhantomData<T>); | ||
| impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { | ||
| /// Storage: `StorageDeposit::Deposits` (r:1 w:1) | ||
| /// Proof: `StorageDeposit::Deposits` (`max_values`: None, `max_size`: None, mode: `Measured`) | ||
| /// Storage: `System::Account` (r:1 w:1) | ||
| /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(132), added: 2607, mode: `MaxEncodedLen`) | ||
| /// Storage: `Balances::Holds` (r:1 w:1) | ||
| /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(949), added: 3424, mode: `MaxEncodedLen`) | ||
| fn reclaim_deposit() -> Weight { | ||
| // Proof Size summary in bytes: | ||
| // Measured: `907` | ||
| // Estimated: `4414` | ||
| // Minimum execution time: 704_964 nanoseconds. | ||
| Weight::from_parts(1_003_107_000, 4414) | ||
| .saturating_add(T::DbWeight::get().reads(3_u64)) | ||
| .saturating_add(T::DbWeight::get().writes(3_u64)) | ||
| } | ||
| } | ||
|
|
||
| // For backwards compatibility and tests | ||
| impl WeightInfo for () { | ||
| /// Storage: `StorageDeposit::Deposits` (r:1 w:1) | ||
| /// Proof: `StorageDeposit::Deposits` (`max_values`: None, `max_size`: None, mode: `Measured`) | ||
| /// Storage: `System::Account` (r:1 w:1) | ||
| /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(132), added: 2607, mode: `MaxEncodedLen`) | ||
| /// Storage: `Balances::Holds` (r:1 w:1) | ||
| /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(949), added: 3424, mode: `MaxEncodedLen`) | ||
| fn reclaim_deposit() -> Weight { | ||
| // Proof Size summary in bytes: | ||
| // Measured: `907` | ||
| // Estimated: `4414` | ||
| // Minimum execution time: 704_964 nanoseconds. | ||
| Weight::from_parts(1_003_107_000, 4414) | ||
| .saturating_add(RocksDbWeight::get().reads(3_u64)) | ||
| .saturating_add(RocksDbWeight::get().writes(3_u64)) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.