Skip to content
Merged
Show file tree
Hide file tree
Changes from 68 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
912 changes: 478 additions & 434 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/kilt-dip-support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ std = [
]
runtime-benchmarks = [
"pallet-dip-consumer/runtime-benchmarks",
"pallet-dip-provider/runtime-benchmarks",
"rococo-runtime/runtime-benchmarks"
]
1 change: 0 additions & 1 deletion crates/kilt-dip-support/src/export/child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ mod v0 {
// 1.2 If so, extract the state root from the header
let state_root_at_height = proof.relay_header.state_root;

// FIXME: Compilation error
// 2. Verify relay chain proof
let provider_parachain_header =
ParachainHeadProofVerifier::<RelayChainInfo>::verify_proof_for_parachain_with_root(
Expand Down
2 changes: 2 additions & 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 Expand Up @@ -123,4 +124,5 @@ impl DipCallOriginFilter<RuntimeCall> for DipCallFilter {

impl pallet_relay_store::Config for Runtime {
type MaxRelayBlocksStored = ConstU32<100>;
type WeightInfo = ();
}
3 changes: 1 addition & 2 deletions dip-template/runtimes/dip-consumer/src/origin_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ impl EnsureOrigin<RuntimeOrigin> for EnsureDipOriginAdapter {

#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin() -> Result<RuntimeOrigin, ()> {
// TODO: Replace with actual DIP origin upon benchmarking
Ok(RuntimeOrigin::root())
EnsureDipOrigin::<DidIdentifier, AccountId, MerkleProofVerifierOutput>::try_successful_origin()
}
}

Expand Down
9 changes: 7 additions & 2 deletions dip-template/runtimes/dip-provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ cumulus-primitives-utility.workspace = true
pallet-collator-selection.workspace = true
parachain-info.workspace = true

# Benchmarks
frame-benchmarking = {workspace = true, optional = true}

[features]
default = [
"std",
Expand Down Expand Up @@ -115,7 +118,8 @@ std = [
"cumulus-primitives-timestamp/std",
"cumulus-primitives-utility/std",
"pallet-collator-selection/std",
"parachain-info/std"
"parachain-info/std",
"frame-benchmarking?/std",
]
runtime-benchmarks = [
"did/runtime-benchmarks",
Expand All @@ -126,5 +130,6 @@ runtime-benchmarks = [
"runtime-common/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"pallet-utility/runtime-benchmarks"
"pallet-utility/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
]
6 changes: 5 additions & 1 deletion dip-template/runtimes/dip-provider/src/dip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ use crate::{
AccountId, Balances, DidIdentifier, Runtime, RuntimeEvent, RuntimeHoldReason,
};

const MAX_LINKED_ACCOUNTS: u32 = 20;

pub mod runtime_api {
use super::*;

Expand Down Expand Up @@ -133,14 +135,16 @@ 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 {
type CommitOriginCheck = EnsureDidOrigin<DidIdentifier, AccountId>;
type CommitOrigin = DidRawOrigin<DidIdentifier, AccountId>;
type Identifier = DidIdentifier;
type IdentityCommitmentGenerator = DidMerkleRootGenerator<Runtime>;
type IdentityProvider = LinkedDidInfoProvider;
type IdentityProvider = LinkedDidInfoProvider<MAX_LINKED_ACCOUNTS>;
type ProviderHooks = deposit::DepositCollectorHooks;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}
24 changes: 24 additions & 0 deletions dip-template/runtimes/dip-provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>]
);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I made a mistake. I compiled the branch using: cargo build --features runtime-benchmarks.

When I run: ./target/debug/dip-provider-node-template -h, the benchmark command is not appearing.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 {
Expand Down
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
30 changes: 26 additions & 4 deletions pallets/pallet-deposit-storage/Cargo.toml
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",
]

try-runtime = [ "kilt-support/try-runtime" ]
91 changes: 91 additions & 0 deletions pallets/pallet-deposit-storage/src/benchmarking.rs
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,
);
}
}
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))
}
}
Loading