Skip to content
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

Merged
merged 75 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
0c56e4c
change trait for retrieve
Ad96el Nov 14, 2023
2df9776
identity provider
Ad96el Nov 15, 2023
e1f186d
alter traits
Ad96el Nov 15, 2023
f20beba
compiling
Ad96el Nov 16, 2023
bc2bdc2
Merge branch 'aa/dip' into ag-dip-benchmarks
Ad96el Nov 16, 2023
fddc666
runtime missing
Ad96el Nov 16, 2023
681dc77
Clean up runtime-common Cargo.toml
ntn-x2 Nov 17, 2023
279d241
DIP provider pallet benchmarks WIP
ntn-x2 Nov 17, 2023
7fe3593
intermediate state
Ad96el Nov 21, 2023
2ccadf5
compiling
Ad96el Nov 21, 2023
70431ef
std error with features
Ad96el Nov 21, 2023
538a234
compiling
Ad96el Nov 22, 2023
cacf04c
remove stuff
Ad96el Nov 22, 2023
870f424
remove whitespaces
Ad96el Nov 22, 2023
22ccaad
remove generic
Ad96el Nov 22, 2023
c8aed6f
feature error
Ad96el Nov 22, 2023
da6314d
feature error
Ad96el Nov 22, 2023
5706638
with working features
Ad96el Nov 22, 2023
14748ef
linked accounts missing
Ad96el Nov 23, 2023
0cba1d1
finish worst case for LinkedDidInfoOf
Ad96el Nov 23, 2023
90f5fe4
give money
Ad96el Nov 23, 2023
cc00b0b
add default weights
Ad96el Nov 23, 2023
d276f0e
has to be reverted. Add provider and cosumer to peregrine
Ad96el Nov 23, 2023
489806f
lockfile
Ad96el Nov 23, 2023
b493baf
adjust cargo toml
Ad96el Nov 23, 2023
8b97889
compiling
Ad96el Nov 24, 2023
048b72d
comment
Ad96el Nov 24, 2023
192e665
compiling
Ad96el Nov 24, 2023
a5d246e
clean up
Ad96el Nov 24, 2023
b0f42c4
clean up
Ad96el Nov 24, 2023
db976e4
remove trait
Ad96el Nov 24, 2023
11f9e28
comment
Ad96el Nov 24, 2023
faf0a30
comments
Ad96el Nov 24, 2023
e94caab
pallet storage deposit!
Ad96el Nov 24, 2023
2481a5a
Merge branch 'aa/dip' into ag-dip-benchmarks
Ad96el Nov 24, 2023
650d311
add weightinfo
Ad96el Nov 24, 2023
3b33c61
add weight logic
Ad96el Nov 24, 2023
9dfcf03
remove comments
Ad96el Nov 24, 2023
ad270c5
remove comments
Ad96el Nov 24, 2023
1fe7290
change imports
Ad96el Nov 29, 2023
daea05f
change default implementation
Ad96el Nov 29, 2023
76c79bf
remove dummy impl
Ad96el Nov 29, 2023
9594535
remove casts
Ad96el Nov 29, 2023
9899e4d
alter feature flag
Ad96el Nov 29, 2023
8b7dc12
Update pallets/pallet-did-lookup/src/try_state.rs
Ad96el Nov 29, 2023
34c2aad
change trait implementation
Ad96el Nov 29, 2023
757f1cf
Merge branch 'ag-dip-benchmarks' of github.com:KILTprotocol/kilt-node…
Ad96el Nov 29, 2023
a3daa24
revert
Ad96el Nov 29, 2023
9625dfc
adjust mocks
Ad96el Nov 29, 2023
1c70fcb
fix mock
Ad96el Nov 29, 2023
052254a
limit linked accounts
Ad96el Nov 29, 2023
1f59a54
compiling
Ad96el Nov 29, 2023
e73c686
changed max accounts
Ad96el Nov 29, 2023
e91bb50
none not some
Ad96el Nov 29, 2023
e8f0200
clippy
Ad96el Nov 29, 2023
4fad41b
fmt cargo file
Ad96el Nov 30, 2023
42414a5
change error
Ad96el Nov 30, 2023
0bad8c0
change comment
Ad96el Nov 30, 2023
6b3e1e3
remove dev mode
Ad96el Nov 30, 2023
c0efd83
Remove clone in benchmarks
ntn-x2 Dec 1, 2023
78e0959
Benchmarks for pallet-relay-store
ntn-x2 Dec 1, 2023
09f1f6c
Fix features
ntn-x2 Dec 1, 2023
387767b
Default weights
ntn-x2 Dec 1, 2023
7a8e572
Fix compilation
ntn-x2 Dec 1, 2023
b33e6ca
Revert logic
ntn-x2 Dec 1, 2023
2d3ee23
Merge commit '55e45f8f952bd07ec3d6925ac26455c95a92fe9e' into ag-dip-b…
ntn-x2 Dec 1, 2023
459ab82
Final changes
ntn-x2 Dec 1, 2023
69ad8e4
Remove some TODOs and FIXMEs
ntn-x2 Dec 1, 2023
e64d943
Fix features in node binaries
ntn-x2 Dec 4, 2023
82ac447
Fix features
ntn-x2 Dec 5, 2023
b7add42
Compiling
ntn-x2 Dec 5, 2023
8a44925
Benchmarks working
ntn-x2 Dec 5, 2023
1ccc2fe
Compiling
ntn-x2 Dec 5, 2023
20b0d16
Weights
ntn-x2 Dec 6, 2023
3c5e579
Last fixes
ntn-x2 Dec 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
910 changes: 476 additions & 434 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions crates/kilt-dip-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pallet-relay-store.workspace = true
pallet-web3-names.workspace = true

# Parity dependencies
parity-scale-codec = {workspace = true, features = ["derive"]}
scale-info = {workspace = true, features = ["derive"]}
parity-scale-codec = { workspace = true, features = ["derive"] }
scale-info = { workspace = true, features = ["derive"] }

# Substrate dependencies
frame-system.workspace = true
Expand Down Expand Up @@ -81,5 +81,6 @@ std = [
]
runtime-benchmarks = [
"pallet-dip-consumer/runtime-benchmarks",
"rococo-runtime/runtime-benchmarks"
"rococo-runtime/runtime-benchmarks",
"pallet-dip-provider/runtime-benchmarks",
ntn-x2 marked this conversation as resolved.
Show resolved Hide resolved
]
1 change: 1 addition & 0 deletions dip-template/runtimes/dip-consumer/src/dip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl pallet_dip_consumer::Config for Runtime {
type ProofVerifier = ProofVerifier;
type RuntimeCall = RuntimeCall;
type RuntimeOrigin = RuntimeOrigin;
type WeightInfo = ();
}

pub struct PreliminaryDipOriginFilter;
Expand Down
2 changes: 2 additions & 0 deletions dip-template/runtimes/dip-provider/src/dip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ impl pallet_deposit_storage::Config for Runtime {
type Namespace = DepositNamespaces;
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type WeightInfo = ();
}

impl pallet_dip_provider::Config for Runtime {
Expand All @@ -143,4 +144,5 @@ impl pallet_dip_provider::Config for Runtime {
type IdentityProvider = LinkedDidInfoProvider;
type ProviderHooks = deposit::DepositCollectorHooks;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}
2 changes: 1 addition & 1 deletion pallets/ctype/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub mod pallet {

#[pallet::config]
pub trait Config: frame_system::Config {
type EnsureOrigin: EnsureOrigin<<Self as frame_system::Config>::RuntimeOrigin, Success = Self::OriginSuccess>;
type EnsureOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = Self::OriginSuccess>;
type OverarchingOrigin: EnsureOrigin<<Self as frame_system::Config>::RuntimeOrigin>;
type OriginSuccess: CallSources<AccountIdOf<Self>, CtypeCreatorOf<Self>>;
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
Expand Down
18 changes: 16 additions & 2 deletions pallets/pallet-deposit-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,28 @@ description = "Stores all deposits under a single pallet, with suport for namesp
[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dev-dependencies]
sp-keystore = { workspace = true, features = ["std"] }

[dependencies]
# Substrate dependencies
frame-support.workspace = true
frame-system.workspace = true
kilt-support.workspace = true
pallet-dip-provider.workspace = true
parity-scale-codec = {workspace = true, features = ["derive"]}
scale-info = {workspace = true, features = ["derive"]}
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
pallet-balances = { workspace = true, optional = true }
frame-benchmarking = { workspace = true, optional = true }
sp-io = { workspace = true, optional = true }
ntn-x2 marked this conversation as resolved.
Show resolved Hide resolved


[features]
default = ["std"]
std = [
Expand All @@ -38,4 +47,9 @@ std = [
"sp-runtime/std",
"sp-std/std",
"log/std",
"sp-keystore/std",
ntn-x2 marked this conversation as resolved.
Show resolved Hide resolved
]

runtime-benchmarks = ["frame-benchmarking", "pallet-balances"]

try-runtime = ["kilt-support/try-runtime"]
88 changes: 88 additions & 0 deletions pallets/pallet-deposit-storage/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// 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 info@botlabs.org

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());

#[extrinsic_call]
Pallet::<T>::reclaim_deposit(origin, namespace.clone(), key.clone());
ntn-x2 marked this conversation as resolved.
Show resolved Hide resolved

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,
);
}
}
73 changes: 73 additions & 0 deletions pallets/pallet-deposit-storage/src/default_weights.rs
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))
}
}
14 changes: 12 additions & 2 deletions pallets/pallet-deposit-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,24 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![recursion_limit = "256"]

pub mod default_weights;
mod deposit;
pub mod traits;

#[cfg(test)]
mod mock;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;

pub use deposit::FixedDepositCollectorViaDepositsPallet;
pub use pallet::*;
pub use traits::NoopDepositStorageHooks;

#[frame_support::pallet(dev_mode)]
ntn-x2 marked this conversation as resolved.
Show resolved Hide resolved
pub mod pallet {
use crate::{
default_weights::WeightInfo,
deposit::{free_deposit, reserve_deposit, DepositEntry},
traits::DepositStorageHooks,
};
Expand Down Expand Up @@ -67,6 +75,7 @@ pub mod pallet {
type Namespace: Parameter;
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
type RuntimeHoldReason: From<HoldReason> + Clone + PartialEq + Debug + FullCodec + MaxEncodedLen + TypeInfo;
type WeightInfo: WeightInfo;
}

#[pallet::composite_enum]
Expand Down Expand Up @@ -110,8 +119,9 @@ pub mod pallet {
#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
// TODO: Update weight
#[pallet::weight(0)]
#[pallet::weight({
<T as Config>::WeightInfo::reclaim_deposit()
})]
pub fn reclaim_deposit(origin: OriginFor<T>, namespace: T::Namespace, key: DepositKeyOf<T>) -> DispatchResult {
let dispatcher = T::CheckOrigin::ensure_origin(origin)?;

Expand Down
Loading