From 8f0506eba66038e6126746a52f1f3af33faeffc7 Mon Sep 17 00:00:00 2001 From: nanocryk <6422796+nanocryk@users.noreply.github.com> Date: Thu, 2 May 2024 12:10:26 +0200 Subject: [PATCH 01/13] profiles storage and extrinsics --- pallets/data-preservers/src/lib.rs | 235 ++++++++++++++++++++++++++++- 1 file changed, 231 insertions(+), 4 deletions(-) diff --git a/pallets/data-preservers/src/lib.rs b/pallets/data-preservers/src/lib.rs index 5626c3944..b577370e4 100644 --- a/pallets/data-preservers/src/lib.rs +++ b/pallets/data-preservers/src/lib.rs @@ -33,19 +33,29 @@ mod benchmarks; pub mod weights; pub use weights::WeightInfo; +#[cfg(feature = "std")] +use serde::{Deserialize, Serialize}; + use { dp_core::ParaId, frame_support::{ pallet_prelude::*, traits::{ - fungible::{Balanced, Inspect}, + fungible::{Balanced, Inspect, MutateHold}, + tokens::Precision, EnsureOriginWithArg, }, DefaultNoBound, }, frame_system::pallet_prelude::*, - sp_runtime::traits::Get, - sp_std::vec::Vec, + sp_runtime::{ + traits::{CheckedAdd, CheckedSub, Get}, + ArithmeticError, + }, + sp_std::{ + ops::{Add, Mul}, + vec::Vec, + }, }; #[frame_support::pallet] @@ -95,7 +105,12 @@ pub mod pallet { pub trait Config: frame_system::Config { /// Overarching event type. type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type Currency: Inspect + Balanced; + + type RuntimeHoldReason: From; + + type Currency: Inspect + + Balanced + + MutateHold; // Who can call set_boot_nodes? type SetBootNodesOrigin: EnsureOriginWithArg; @@ -103,6 +118,11 @@ pub mod pallet { type MaxBootNodes: Get; #[pallet::constant] type MaxBootNodeUrlLen: Get; + #[pallet::constant] + type MaxParaIdsVecLen: Get; + + /// How much must be deposited to register a profile. + type ProfileDeposit: ProfileDeposit, BalanceOf>; type WeightInfo: WeightInfo; } @@ -112,12 +132,35 @@ pub mod pallet { pub enum Event { /// The list of boot_nodes changed. BootNodesChanged { para_id: ParaId }, + ProfileCreated { + account: T::AccountId, + profile_id: ProfileId, + deposit: BalanceOf, + }, + ProfileUpdated { + profile_id: ProfileId, + old_deposit: BalanceOf, + new_deposit: BalanceOf, + }, + ProfileDeleted { + profile_id: ProfileId, + released_deposit: BalanceOf, + }, } #[pallet::error] pub enum Error { /// This container chain does not have any boot nodes NoBootNodes, + + UnknownProfileId, + NextProfileIdShouldBeAvailable, + CanOnlyModifyOwnProfile, + } + + #[pallet::composite_enum] + pub enum HoldReason { + ProfileDeposit, } #[pallet::storage] @@ -130,6 +173,77 @@ pub mod pallet { ValueQuery, >; + #[pallet::storage] + pub type Profiles = + StorageMap<_, Blake2_128Concat, ProfileId, RegisteredProfile, OptionQuery>; + + #[pallet::storage] + pub type NextProfileId = StorageValue<_, ProfileId, ValueQuery>; + + /// Balance used by this pallet + pub type BalanceOf = + <::Currency as Inspect<::AccountId>>::Balance; + + pub type ProfileId = u64; + + /// Data preserver profile. + #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] + #[derive( + RuntimeDebugNoBound, PartialEqNoBound, EqNoBound, Encode, Decode, CloneNoBound, TypeInfo, + )] + #[scale_info(skip_type_params(T))] + pub struct Profile { + url: BoundedVec, + limited_to_para_ids: Option>, + mode: ProfileMode, + } + + #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] + #[derive( + RuntimeDebug, PartialEq, Eq, Encode, Decode, Clone, TypeInfo, + )] + pub enum ProfileMode { + Bootnode, + Rpc { supports_ethereum_rpcs: bool }, + } + + /// Profile with additional data: + /// - the account id which created (and manage) the profile + /// - the amount deposited to register the profile + #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] + #[derive( + RuntimeDebugNoBound, PartialEqNoBound, EqNoBound, Encode, Decode, CloneNoBound, TypeInfo, + )] + #[scale_info(skip_type_params(T))] + pub struct RegisteredProfile { + pub account: T::AccountId, + pub deposit: BalanceOf, + pub profile: Profile, + } + + pub trait ProfileDeposit { + fn profile_deposit(profile: &Profile) -> Balance; + } + + pub struct BytesProfileDeposit(PhantomData<(BaseCost, ByteCost)>); + + impl ProfileDeposit + for BytesProfileDeposit + where + BaseCost: Get, + ByteCost: Get, + Profile: Encode, + Balance: From + Add + Mul, + { + fn profile_deposit(profile: &Profile) -> Balance { + let base = BaseCost::get(); + let byte = ByteCost::get(); + let size = profile.encoded_size(); + + base + byte * size.into() + } + } + #[pallet::call] impl Pallet { /// Set boot_nodes for this para id @@ -151,6 +265,119 @@ pub mod pallet { Ok(()) } + + #[pallet::call_index(1)] + // TODO: Benchmark + #[pallet::weight(0)] + pub fn create_profile( + origin: OriginFor, + profile: Profile, + ) -> DispatchResultWithPostInfo { + let origin = ensure_signed(origin)?; + + let deposit = T::ProfileDeposit::profile_deposit(&profile); + T::Currency::hold(&HoldReason::ProfileDeposit.into(), &origin, deposit)?; + + let id = NextProfileId::::get(); + NextProfileId::::set(id.checked_add(1).ok_or(ArithmeticError::Overflow)?); + + ensure!( + !Profiles::::contains_key(&id), + Error::::NextProfileIdShouldBeAvailable + ); + + Profiles::::insert( + id, + RegisteredProfile { + account: origin.clone(), + deposit, + profile, + }, + ); + + Self::deposit_event(Event::ProfileCreated { account: origin, profile_id: id, deposit }); + + Ok(().into()) + } + + #[pallet::call_index(2)] + // TODO: Benchmark + #[pallet::weight(0)] + pub fn update_profile( + origin: OriginFor, + profile_id: ProfileId, + profile: Profile, + ) -> DispatchResultWithPostInfo { + let origin = ensure_signed(origin)?; + + let Some(existing_profile) = Profiles::::get(&profile_id) else { + Err(Error::::UnknownProfileId)? + }; + + ensure!( + existing_profile.account == origin, + Error::::CanOnlyModifyOwnProfile + ); + + // Update deposit + let new_deposit = T::ProfileDeposit::profile_deposit(&profile); + + if let Some(diff) = new_deposit.checked_sub(&existing_profile.deposit) { + T::Currency::hold(&HoldReason::ProfileDeposit.into(), &origin, diff)?; + } else if let Some(diff) = existing_profile.deposit.checked_sub(&new_deposit) { + T::Currency::release( + &HoldReason::ProfileDeposit.into(), + &origin, + diff, + Precision::Exact, + )?; + } + + Profiles::::insert( + profile_id, + RegisteredProfile { + account: origin, + deposit: new_deposit, + profile, + }, + ); + + Self::deposit_event(Event::ProfileUpdated { profile_id, old_deposit: existing_profile.deposit, new_deposit: new_deposit }); + + Ok(().into()) + } + + #[pallet::call_index(3)] + // TODO: Benchmark + #[pallet::weight(0)] + pub fn delete_profile( + origin: OriginFor, + profile_id: ProfileId, + ) -> DispatchResultWithPostInfo { + let origin = ensure_signed(origin)?; + + let Some(profile) = Profiles::::get(&profile_id) else { + Err(Error::::UnknownProfileId)? + }; + + ensure!( + profile.account == origin, + Error::::CanOnlyModifyOwnProfile + ); + + T::Currency::release( + &HoldReason::ProfileDeposit.into(), + &origin, + profile.deposit, + Precision::Exact, + )?; + + Profiles::::remove(&profile_id); + + Self::deposit_event(Event::ProfileDeleted { profile_id, released_deposit: profile.deposit }); + + Ok(().into()) + } } impl Pallet { From 2fe7fd245a39a345ae99fea965c8dacb26a99400 Mon Sep 17 00:00:00 2001 From: nanocryk <6422796+nanocryk@users.noreply.github.com> Date: Mon, 13 May 2024 11:08:16 +0200 Subject: [PATCH 02/13] wip tests --- pallets/data-preservers/src/lib.rs | 55 ++++++++++++++++++--------- pallets/data-preservers/src/mock.rs | 48 +++++++++++++++++++----- pallets/data-preservers/src/tests.rs | 56 ++++++++++++++++++++++++---- 3 files changed, 123 insertions(+), 36 deletions(-) diff --git a/pallets/data-preservers/src/lib.rs b/pallets/data-preservers/src/lib.rs index b577370e4..51db43d80 100644 --- a/pallets/data-preservers/src/lib.rs +++ b/pallets/data-preservers/src/lib.rs @@ -39,6 +39,7 @@ use serde::{Deserialize, Serialize}; use { dp_core::ParaId, frame_support::{ + dispatch::DispatchErrorWithPostInfo, pallet_prelude::*, traits::{ fungible::{Balanced, Inspect, MutateHold}, @@ -49,7 +50,7 @@ use { }, frame_system::pallet_prelude::*, sp_runtime::{ - traits::{CheckedAdd, CheckedSub, Get}, + traits::{CheckedAdd, CheckedMul, CheckedSub, Get}, ArithmeticError, }, sp_std::{ @@ -193,15 +194,13 @@ pub mod pallet { )] #[scale_info(skip_type_params(T))] pub struct Profile { - url: BoundedVec, - limited_to_para_ids: Option>, - mode: ProfileMode, + pub url: BoundedVec, + pub limited_to_para_ids: Option>, + pub mode: ProfileMode, } #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] - #[derive( - RuntimeDebug, PartialEq, Eq, Encode, Decode, Clone, TypeInfo, - )] + #[derive(RuntimeDebug, PartialEq, Eq, Encode, Decode, Clone, TypeInfo)] pub enum ProfileMode { Bootnode, Rpc { supports_ethereum_rpcs: bool }, @@ -222,7 +221,7 @@ pub mod pallet { } pub trait ProfileDeposit { - fn profile_deposit(profile: &Profile) -> Balance; + fn profile_deposit(profile: &Profile) -> Result; } pub struct BytesProfileDeposit(PhantomData<(BaseCost, ByteCost)>); @@ -233,14 +232,23 @@ pub mod pallet { BaseCost: Get, ByteCost: Get, Profile: Encode, - Balance: From + Add + Mul, + Balance: TryFrom + CheckedAdd + CheckedMul, { - fn profile_deposit(profile: &Profile) -> Balance { + fn profile_deposit(profile: &Profile) -> Result { let base = BaseCost::get(); let byte = ByteCost::get(); - let size = profile.encoded_size(); - - base + byte * size.into() + let size: Balance = profile + .encoded_size() + .try_into() + .map_err(|_| ArithmeticError::Overflow)?; + + let deposit = byte + .checked_mul(&size) + .ok_or(ArithmeticError::Overflow)? + .checked_add(&base) + .ok_or(ArithmeticError::Overflow)?; + + Ok(deposit) } } @@ -275,7 +283,7 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { let origin = ensure_signed(origin)?; - let deposit = T::ProfileDeposit::profile_deposit(&profile); + let deposit = T::ProfileDeposit::profile_deposit(&profile)?; T::Currency::hold(&HoldReason::ProfileDeposit.into(), &origin, deposit)?; let id = NextProfileId::::get(); @@ -295,7 +303,11 @@ pub mod pallet { }, ); - Self::deposit_event(Event::ProfileCreated { account: origin, profile_id: id, deposit }); + Self::deposit_event(Event::ProfileCreated { + account: origin, + profile_id: id, + deposit, + }); Ok(().into()) } @@ -320,7 +332,7 @@ pub mod pallet { ); // Update deposit - let new_deposit = T::ProfileDeposit::profile_deposit(&profile); + let new_deposit = T::ProfileDeposit::profile_deposit(&profile)?; if let Some(diff) = new_deposit.checked_sub(&existing_profile.deposit) { T::Currency::hold(&HoldReason::ProfileDeposit.into(), &origin, diff)?; @@ -342,7 +354,11 @@ pub mod pallet { }, ); - Self::deposit_event(Event::ProfileUpdated { profile_id, old_deposit: existing_profile.deposit, new_deposit: new_deposit }); + Self::deposit_event(Event::ProfileUpdated { + profile_id, + old_deposit: existing_profile.deposit, + new_deposit: new_deposit, + }); Ok(().into()) } @@ -374,7 +390,10 @@ pub mod pallet { Profiles::::remove(&profile_id); - Self::deposit_event(Event::ProfileDeleted { profile_id, released_deposit: profile.deposit }); + Self::deposit_event(Event::ProfileDeleted { + profile_id, + released_deposit: profile.deposit, + }); Ok(().into()) } diff --git a/pallets/data-preservers/src/mock.rs b/pallets/data-preservers/src/mock.rs index d4f99cfd7..8400be1be 100644 --- a/pallets/data-preservers/src/mock.rs +++ b/pallets/data-preservers/src/mock.rs @@ -20,7 +20,7 @@ use { frame_support::{ pallet_prelude::*, parameter_types, - traits::{ConstU64, EitherOfDiverse, EnsureOriginWithArg, Everything}, + traits::{ConstU128, ConstU64, EitherOfDiverse, EnsureOriginWithArg, Everything}, }, frame_system::{EnsureRoot, EnsureSigned, RawOrigin}, sp_core::H256, @@ -88,7 +88,7 @@ impl pallet_balances::Config for Test { type AccountStore = System; type FreezeIdentifier = (); type MaxFreezes = (); - type RuntimeHoldReason = (); + type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = (); type MaxHolds = ConstU32<5>; type WeightInfo = (); @@ -217,24 +217,52 @@ where impl pallet_data_preservers::Config for Test { type RuntimeEvent = RuntimeEvent; + type RuntimeHoldReason = RuntimeHoldReason; type Currency = Balances; type SetBootNodesOrigin = MockContainerChainManagerOrRootOrigin>; type MaxBootNodes = ConstU32<10>; type MaxBootNodeUrlLen = ConstU32<200>; + type MaxParaIdsVecLen = ConstU32<20>; + type ProfileDeposit = crate::BytesProfileDeposit, ConstU128<51>>; type WeightInfo = (); } -// Build genesis storage according to the mock runtime. -pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::::default() - .build_storage() - .unwrap(); +#[derive(Default)] +pub struct ExtBuilder { + balances: Vec<(AccountId, Balance)>, +} - let balances = vec![(0, 10_000)]; +impl ExtBuilder { + pub fn with_balances(mut self, balances: Vec<(AccountId, Balance)>) -> Self { + self.balances = balances; + self + } + + pub fn build(self) -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap(); - pallet_balances::GenesisConfig:: { balances } + pallet_balances::GenesisConfig:: { + balances: self.balances, + } .assimilate_storage(&mut t) .unwrap(); - t.into() + t.into() + } +} + +pub(crate) fn events() -> Vec> { + System::events() + .into_iter() + .map(|r| r.event) + .filter_map(|e| { + if let RuntimeEvent::DataPreservers(inner) = e { + Some(inner) + } else { + None + } + }) + .collect::>() } diff --git a/pallets/data-preservers/src/tests.rs b/pallets/data-preservers/src/tests.rs index bc738b2f3..66743ea07 100644 --- a/pallets/data-preservers/src/tests.rs +++ b/pallets/data-preservers/src/tests.rs @@ -24,7 +24,7 @@ const BOB: u64 = 2; #[test] fn set_boot_nodes_bad_origin() { - new_test_ext().execute_with(|| { + ExtBuilder::default().build().execute_with(|| { // Para 1001 has no manager, Alice cannot set boot nodes assert_noop!(DataPreservers::set_boot_nodes( RuntimeOrigin::signed(ALICE), @@ -40,7 +40,7 @@ fn set_boot_nodes_bad_origin() { #[test] fn set_boot_nodes_by_root_no_manager() { - new_test_ext().execute_with(|| { + ExtBuilder::default().build().execute_with(|| { // Para 1001 has no manager, root can set boot nodes let boot_nodes: BoundedVec, _> = vec![ b"/ip4/127.0.0.1/tcp/33049/ws/p2p/12D3KooWHVMhQDHBpj9vQmssgyfspYecgV6e3hH1dQVDUkUbCYC9" @@ -61,7 +61,7 @@ fn set_boot_nodes_by_root_no_manager() { #[test] fn set_boot_nodes_by_root_with_manager() { - new_test_ext().execute_with(|| { + ExtBuilder::default().build().execute_with(|| { // Set ALICE as manager of para 1002 MockData::mutate(|m| { m.container_chain_managers.insert(1002.into(), Some(ALICE)); @@ -86,7 +86,7 @@ fn set_boot_nodes_by_root_with_manager() { #[test] fn set_boot_nodes_by_para_id_registrar() { - new_test_ext().execute_with(|| { + ExtBuilder::default().build().execute_with(|| { // Set ALICE as manager of para 1002 MockData::mutate(|m| { m.container_chain_managers.insert(1002.into(), Some(ALICE)); @@ -111,7 +111,7 @@ fn set_boot_nodes_by_para_id_registrar() { #[test] fn set_boot_nodes_by_invalid_user_no_manager() { - new_test_ext().execute_with(|| { + ExtBuilder::default().build().execute_with(|| { // Para 1001 has no manager MockData::mutate(|m| { m.container_chain_managers.insert(1002.into(), Some(ALICE)); @@ -131,7 +131,7 @@ fn set_boot_nodes_by_invalid_user_no_manager() { #[test] fn set_boot_nodes_by_invalid_user() { - new_test_ext().execute_with(|| { + ExtBuilder::default().build().execute_with(|| { // Set ALICE as manager of para 1002 MockData::mutate(|m| { m.container_chain_managers.insert(1002.into(), Some(ALICE)); @@ -161,7 +161,7 @@ fn set_boot_nodes_by_invalid_user() { #[test] fn set_boot_nodes_by_invalid_user_bad_para_id() { - new_test_ext().execute_with(|| { + ExtBuilder::default().build().execute_with(|| { // Para 1003 does not exist, only root can set bootnodes assert_noop!(DataPreservers::set_boot_nodes( RuntimeOrigin::signed(BOB), @@ -179,7 +179,7 @@ fn set_boot_nodes_by_invalid_user_bad_para_id() { fn set_boot_nodes_bad_para_id() { // Para 1003 does not exist, only root can set bootnodes // This is allowed in case we want to set bootnodes before registering the chain - new_test_ext().execute_with(|| { + ExtBuilder::default().build().execute_with(|| { let boot_nodes: BoundedVec, _> = vec![ b"/ip4/127.0.0.1/tcp/33049/ws/p2p/12D3KooWHVMhQDHBpj9vQmssgyfspYecgV6e3hH1dQVDUkUbCYC9" .to_vec() @@ -196,3 +196,43 @@ fn set_boot_nodes_bad_para_id() { assert_eq!(DataPreservers::boot_nodes(ParaId::from(1003)), boot_nodes); }); } + +mod create_profile { + use super::*; + + #[test] + fn can_create_profile() { + ExtBuilder::default() + .with_balances(vec![(ALICE, 1_000_000_000_000)]) + .build() + .execute_with(|| { + let profile = Profile { + url: b"test".to_vec().try_into().unwrap(), + limited_to_para_ids: None, + mode: ProfileMode::Bootnode, + }; + + assert_ok!(DataPreservers::create_profile( + RuntimeOrigin::signed(ALICE), + profile.clone() + )); + + assert_eq!(Profiles::::get(0), Some(RegisteredProfile { + account: ALICE, + deposit: 1_357, // 1_000 base deposit + 51 * 7 bytes deposit + profile + })); + + assert_eq!(NextProfileId::::get(), 1); + + assert_eq!( + events(), + vec![Event::ProfileCreated { + account: ALICE, + profile_id: 0, + deposit: 1_357, + }] + ); + }); + } +} From 3222574996b3789e2bcf7c5a7e4ee6aa53e4a508 Mon Sep 17 00:00:00 2001 From: nanocryk <6422796+nanocryk@users.noreply.github.com> Date: Wed, 15 May 2024 10:28:58 +0200 Subject: [PATCH 03/13] forced mode + tests --- pallets/data-preservers/src/lib.rs | 88 ++-- pallets/data-preservers/src/mock.rs | 5 +- pallets/data-preservers/src/tests.rs | 592 ++++++++++++++++++++++++++- 3 files changed, 651 insertions(+), 34 deletions(-) diff --git a/pallets/data-preservers/src/lib.rs b/pallets/data-preservers/src/lib.rs index 51db43d80..5857ee9c1 100644 --- a/pallets/data-preservers/src/lib.rs +++ b/pallets/data-preservers/src/lib.rs @@ -50,13 +50,10 @@ use { }, frame_system::pallet_prelude::*, sp_runtime::{ - traits::{CheckedAdd, CheckedMul, CheckedSub, Get}, + traits::{CheckedAdd, CheckedMul, CheckedSub, Get, Zero}, ArithmeticError, }, - sp_std::{ - ops::{Add, Mul}, - vec::Vec, - }, + sp_std::vec::Vec, }; #[frame_support::pallet] @@ -115,6 +112,8 @@ pub mod pallet { // Who can call set_boot_nodes? type SetBootNodesOrigin: EnsureOriginWithArg; + type ForceSetProfileOrigin: EnsureOrigin; + #[pallet::constant] type MaxBootNodes: Get; #[pallet::constant] @@ -156,7 +155,6 @@ pub mod pallet { UnknownProfileId, NextProfileIdShouldBeAvailable, - CanOnlyModifyOwnProfile, } #[pallet::composite_enum] @@ -280,11 +278,24 @@ pub mod pallet { pub fn create_profile( origin: OriginFor, profile: Profile, + forced_for: Option, ) -> DispatchResultWithPostInfo { - let origin = ensure_signed(origin)?; + let account = match forced_for.clone() { + Some(account) => { + T::ForceSetProfileOrigin::ensure_origin(origin)?; + account + } + None => ensure_signed(origin)?, + }; - let deposit = T::ProfileDeposit::profile_deposit(&profile)?; - T::Currency::hold(&HoldReason::ProfileDeposit.into(), &origin, deposit)?; + let deposit = match forced_for { + Some(_) => Zero::zero(), // don't deposit anything if forced + None => { + let deposit = T::ProfileDeposit::profile_deposit(&profile)?; + T::Currency::hold(&HoldReason::ProfileDeposit.into(), &account, deposit)?; + deposit + } + }; let id = NextProfileId::::get(); NextProfileId::::set(id.checked_add(1).ok_or(ArithmeticError::Overflow)?); @@ -297,14 +308,14 @@ pub mod pallet { Profiles::::insert( id, RegisteredProfile { - account: origin.clone(), + account: account.clone(), deposit, profile, }, ); Self::deposit_event(Event::ProfileCreated { - account: origin, + account, profile_id: id, deposit, }); @@ -319,27 +330,44 @@ pub mod pallet { origin: OriginFor, profile_id: ProfileId, profile: Profile, + force: bool, ) -> DispatchResultWithPostInfo { - let origin = ensure_signed(origin)?; + let account = if force { + T::ForceSetProfileOrigin::ensure_origin(origin)?; + None + } else { + Some(ensure_signed(origin)?) + }; let Some(existing_profile) = Profiles::::get(&profile_id) else { Err(Error::::UnknownProfileId)? }; - ensure!( - existing_profile.account == origin, - Error::::CanOnlyModifyOwnProfile - ); + if let Some(account) = account { + ensure!( + existing_profile.account == account, + sp_runtime::DispatchError::BadOrigin, + ); + } // Update deposit - let new_deposit = T::ProfileDeposit::profile_deposit(&profile)?; + // If forced update we release the previous deposit + let new_deposit = if force { + Zero::zero() + } else { + T::ProfileDeposit::profile_deposit(&profile)? + }; if let Some(diff) = new_deposit.checked_sub(&existing_profile.deposit) { - T::Currency::hold(&HoldReason::ProfileDeposit.into(), &origin, diff)?; + T::Currency::hold( + &HoldReason::ProfileDeposit.into(), + &existing_profile.account, + diff, + )?; } else if let Some(diff) = existing_profile.deposit.checked_sub(&new_deposit) { T::Currency::release( &HoldReason::ProfileDeposit.into(), - &origin, + &existing_profile.account, diff, Precision::Exact, )?; @@ -348,7 +376,7 @@ pub mod pallet { Profiles::::insert( profile_id, RegisteredProfile { - account: origin, + account: existing_profile.account, deposit: new_deposit, profile, }, @@ -369,21 +397,29 @@ pub mod pallet { pub fn delete_profile( origin: OriginFor, profile_id: ProfileId, + force: bool, ) -> DispatchResultWithPostInfo { - let origin = ensure_signed(origin)?; + let account = if force { + T::ForceSetProfileOrigin::ensure_origin(origin)?; + None + } else { + Some(ensure_signed(origin)?) + }; let Some(profile) = Profiles::::get(&profile_id) else { Err(Error::::UnknownProfileId)? }; - ensure!( - profile.account == origin, - Error::::CanOnlyModifyOwnProfile - ); + if let Some(account) = account { + ensure!( + profile.account == account, + sp_runtime::DispatchError::BadOrigin, + ); + } T::Currency::release( &HoldReason::ProfileDeposit.into(), - &origin, + &profile.account, profile.deposit, Precision::Exact, )?; diff --git a/pallets/data-preservers/src/mock.rs b/pallets/data-preservers/src/mock.rs index 8400be1be..006f638d7 100644 --- a/pallets/data-preservers/src/mock.rs +++ b/pallets/data-preservers/src/mock.rs @@ -220,6 +220,7 @@ impl pallet_data_preservers::Config for Test { type RuntimeHoldReason = RuntimeHoldReason; type Currency = Balances; type SetBootNodesOrigin = MockContainerChainManagerOrRootOrigin>; + type ForceSetProfileOrigin = EnsureRoot; type MaxBootNodes = ConstU32<10>; type MaxBootNodeUrlLen = ConstU32<200>; type MaxParaIdsVecLen = ConstU32<20>; @@ -249,7 +250,9 @@ impl ExtBuilder { .assimilate_storage(&mut t) .unwrap(); - t.into() + let mut ext: sp_io::TestExternalities = t.into(); + ext.execute_with(|| System::set_block_number(1)); + ext } } diff --git a/pallets/data-preservers/src/tests.rs b/pallets/data-preservers/src/tests.rs index 66743ea07..324ea279b 100644 --- a/pallets/data-preservers/src/tests.rs +++ b/pallets/data-preservers/src/tests.rs @@ -17,6 +17,7 @@ use { crate::{mock::*, *}, frame_support::{assert_noop, assert_ok, pallet_prelude::*}, + sp_runtime::TokenError, }; const ALICE: u64 = 1; @@ -201,7 +202,7 @@ mod create_profile { use super::*; #[test] - fn can_create_profile() { + fn create_profile_works() { ExtBuilder::default() .with_balances(vec![(ALICE, 1_000_000_000_000)]) .build() @@ -214,14 +215,18 @@ mod create_profile { assert_ok!(DataPreservers::create_profile( RuntimeOrigin::signed(ALICE), - profile.clone() + profile.clone(), + None, )); - assert_eq!(Profiles::::get(0), Some(RegisteredProfile { - account: ALICE, - deposit: 1_357, // 1_000 base deposit + 51 * 7 bytes deposit - profile - })); + assert_eq!( + Profiles::::get(0), + Some(RegisteredProfile { + account: ALICE, + deposit: 1_357, // 1_000 base deposit + 51 * 7 bytes deposit + profile + }) + ); assert_eq!(NextProfileId::::get(), 1); @@ -235,4 +240,577 @@ mod create_profile { ); }); } + + #[test] + fn insufficient_balance_for_deposit() { + ExtBuilder::default() + .with_balances(vec![(ALICE, 1_356)]) + .build() + .execute_with(|| { + let profile = Profile { + url: b"test".to_vec().try_into().unwrap(), + limited_to_para_ids: None, + mode: ProfileMode::Bootnode, + }; + + assert_noop!( + DataPreservers::create_profile( + RuntimeOrigin::signed(ALICE), + profile.clone(), + None + ), + TokenError::FundsUnavailable + ); + + assert_eq!(Profiles::::get(0), None); + assert_eq!(NextProfileId::::get(), 0); + assert_eq!(events(), vec![],); + }); + } + + #[test] + fn protection_for_existing_profile() { + ExtBuilder::default() + .with_balances(vec![(ALICE, 1_000_000_000_000)]) + .build() + .execute_with(|| { + let profile = Profile { + url: b"test".to_vec().try_into().unwrap(), + limited_to_para_ids: None, + mode: ProfileMode::Bootnode, + }; + + // Set some profile at next id. (this shouldn't occur but we protect from it + // anyway) + Profiles::::insert( + 0, + RegisteredProfile { + account: ALICE, + deposit: 0, + profile: profile.clone(), + }, + ); + + assert_noop!( + DataPreservers::create_profile( + RuntimeOrigin::signed(ALICE), + profile.clone(), + None + ), + Error::::NextProfileIdShouldBeAvailable + ); + }); + } + + #[test] + fn forced_create_profile_works() { + ExtBuilder::default() + .with_balances(vec![(ALICE, 1_000_000_000_000)]) + .build() + .execute_with(|| { + let profile = Profile { + url: b"test".to_vec().try_into().unwrap(), + limited_to_para_ids: None, + mode: ProfileMode::Bootnode, + }; + + assert_ok!(DataPreservers::create_profile( + RuntimeOrigin::root(), + profile.clone(), + Some(ALICE), + )); + + assert_eq!( + Profiles::::get(0), + Some(RegisteredProfile { + account: ALICE, + deposit: 0, // no deposit when forced + profile + }) + ); + + assert_eq!(NextProfileId::::get(), 1); + + assert_eq!( + events(), + vec![Event::ProfileCreated { + account: ALICE, + profile_id: 0, + deposit: 0, // no deposit when forced + }] + ); + }); + } + + #[test] + fn forced_create_profile_filter() { + ExtBuilder::default() + .with_balances(vec![(ALICE, 1_000_000_000_000)]) + .build() + .execute_with(|| { + let profile = Profile { + url: b"test".to_vec().try_into().unwrap(), + limited_to_para_ids: None, + mode: ProfileMode::Bootnode, + }; + + assert_noop!( + DataPreservers::create_profile( + RuntimeOrigin::signed(BOB), + profile.clone(), + Some(ALICE), + ), + sp_runtime::DispatchError::BadOrigin + ); + }); + } +} + +mod update_profile { + use super::*; + + #[test] + fn update_profile_works() { + ExtBuilder::default() + .with_balances(vec![(ALICE, 1_000_000_000_000)]) + .build() + .execute_with(|| { + let profile = Profile { + url: b"test".to_vec().try_into().unwrap(), + limited_to_para_ids: None, + mode: ProfileMode::Bootnode, + }; + + assert_ok!(DataPreservers::create_profile( + RuntimeOrigin::signed(ALICE), + profile.clone(), + None + )); + + let profile2 = Profile { + url: b"test2".to_vec().try_into().unwrap(), + limited_to_para_ids: Some(vec![ParaId::from(42)].try_into().unwrap()), + mode: ProfileMode::Rpc { + supports_ethereum_rpcs: false, + }, + }; + + assert_ok!(DataPreservers::update_profile( + RuntimeOrigin::signed(ALICE), + 0, + profile2.clone(), + false, + )); + + assert_eq!( + Profiles::::get(0), + Some(RegisteredProfile { + account: ALICE, + deposit: 1_714, // 1_000 base deposit + 51 * 14 bytes deposit + profile: profile2 + }) + ); + + assert_eq!( + events(), + vec![ + Event::ProfileCreated { + account: ALICE, + profile_id: 0, + deposit: 1_357, + }, + Event::ProfileUpdated { + profile_id: 0, + old_deposit: 1_357, + new_deposit: 1_714, + } + ] + ); + }); + } + + #[test] + fn unknown_profile_id() { + ExtBuilder::default() + .with_balances(vec![(ALICE, 1_400)]) + .build() + .execute_with(|| { + let profile = Profile { + url: b"test".to_vec().try_into().unwrap(), + limited_to_para_ids: None, + mode: ProfileMode::Bootnode, + }; + + assert_ok!(DataPreservers::create_profile( + RuntimeOrigin::signed(ALICE), + profile.clone(), + None + )); + + let profile2 = Profile { + url: b"test2".to_vec().try_into().unwrap(), + limited_to_para_ids: Some(vec![ParaId::from(42)].try_into().unwrap()), + mode: ProfileMode::Rpc { + supports_ethereum_rpcs: false, + }, + }; + + assert_noop!( + DataPreservers::update_profile( + RuntimeOrigin::signed(ALICE), + 1, // wrong profile id + profile2.clone(), + false, + ), + Error::::UnknownProfileId + ); + }); + } + + #[test] + fn wrong_user() { + ExtBuilder::default() + .with_balances(vec![(ALICE, 1_400)]) + .build() + .execute_with(|| { + let profile = Profile { + url: b"test".to_vec().try_into().unwrap(), + limited_to_para_ids: None, + mode: ProfileMode::Bootnode, + }; + + assert_ok!(DataPreservers::create_profile( + RuntimeOrigin::signed(ALICE), + profile.clone(), + None + )); + + let profile2 = Profile { + url: b"test2".to_vec().try_into().unwrap(), + limited_to_para_ids: Some(vec![ParaId::from(42)].try_into().unwrap()), + mode: ProfileMode::Rpc { + supports_ethereum_rpcs: false, + }, + }; + + assert_noop!( + DataPreservers::update_profile( + RuntimeOrigin::signed(BOB), // not the profile's owner + 0, + profile2.clone(), + false, + ), + sp_runtime::DispatchError::BadOrigin, + ); + }); + } + + #[test] + fn insufficient_balance_for_new_deposit() { + ExtBuilder::default() + .with_balances(vec![(ALICE, 1_400)]) + .build() + .execute_with(|| { + let profile = Profile { + url: b"test".to_vec().try_into().unwrap(), + limited_to_para_ids: None, + mode: ProfileMode::Bootnode, + }; + + assert_ok!(DataPreservers::create_profile( + RuntimeOrigin::signed(ALICE), + profile.clone(), + None + )); + + let profile2 = Profile { + url: b"test2".to_vec().try_into().unwrap(), + limited_to_para_ids: Some(vec![ParaId::from(42)].try_into().unwrap()), + mode: ProfileMode::Rpc { + supports_ethereum_rpcs: false, + }, + }; + + assert_noop!( + DataPreservers::update_profile( + RuntimeOrigin::signed(ALICE), + 0, + profile2.clone(), + false, + ), + TokenError::FundsUnavailable + ); + }); + } + + #[test] + fn forced_update_profile_works() { + ExtBuilder::default() + .with_balances(vec![(ALICE, 1_000_000_000_000)]) + .build() + .execute_with(|| { + let profile = Profile { + url: b"test".to_vec().try_into().unwrap(), + limited_to_para_ids: None, + mode: ProfileMode::Bootnode, + }; + + assert_ok!(DataPreservers::create_profile( + RuntimeOrigin::signed(ALICE), + profile.clone(), + None + )); + + let profile2 = Profile { + url: b"test2".to_vec().try_into().unwrap(), + limited_to_para_ids: Some(vec![ParaId::from(42)].try_into().unwrap()), + mode: ProfileMode::Rpc { + supports_ethereum_rpcs: false, + }, + }; + + assert_ok!(DataPreservers::update_profile( + RuntimeOrigin::root(), + 0, + profile2.clone(), + true, + )); + + assert_eq!( + Profiles::::get(0), + Some(RegisteredProfile { + account: ALICE, + deposit: 0, // forced update release deposit + profile: profile2 + }) + ); + + assert_eq!( + events(), + vec![ + Event::ProfileCreated { + account: ALICE, + profile_id: 0, + deposit: 1_357, + }, + Event::ProfileUpdated { + profile_id: 0, + old_deposit: 1_357, + new_deposit: 0, + } + ] + ); + }); + } + + #[test] + fn forced_update_profile_filter() { + ExtBuilder::default() + .with_balances(vec![(ALICE, 1_000_000_000_000)]) + .build() + .execute_with(|| { + let profile = Profile { + url: b"test".to_vec().try_into().unwrap(), + limited_to_para_ids: None, + mode: ProfileMode::Bootnode, + }; + + assert_ok!(DataPreservers::create_profile( + RuntimeOrigin::signed(ALICE), + profile.clone(), + None + )); + + let profile2 = Profile { + url: b"test2".to_vec().try_into().unwrap(), + limited_to_para_ids: Some(vec![ParaId::from(42)].try_into().unwrap()), + mode: ProfileMode::Rpc { + supports_ethereum_rpcs: false, + }, + }; + + assert_noop!( + DataPreservers::update_profile( + RuntimeOrigin::signed(ALICE), + 0, + profile2.clone(), + true, + ), + sp_runtime::DispatchError::BadOrigin, + ); + }); + } +} + +mod delete_profile { + use super::*; + + #[test] + fn delete_profile_works() { + ExtBuilder::default() + .with_balances(vec![(ALICE, 1_000_000_000_000)]) + .build() + .execute_with(|| { + let profile = Profile { + url: b"test".to_vec().try_into().unwrap(), + limited_to_para_ids: None, + mode: ProfileMode::Bootnode, + }; + + assert_ok!(DataPreservers::create_profile( + RuntimeOrigin::signed(ALICE), + profile.clone(), + None + )); + + assert_ok!(DataPreservers::delete_profile( + RuntimeOrigin::signed(ALICE), + 0, + false, + )); + + assert_eq!(Profiles::::get(0), None); + + assert_eq!( + events(), + vec![ + Event::ProfileCreated { + account: ALICE, + profile_id: 0, + deposit: 1_357, + }, + Event::ProfileDeleted { + profile_id: 0, + released_deposit: 1_357, + } + ] + ); + }); + } + + #[test] + fn unknown_profile_id() { + ExtBuilder::default() + .with_balances(vec![(ALICE, 1_400)]) + .build() + .execute_with(|| { + let profile = Profile { + url: b"test".to_vec().try_into().unwrap(), + limited_to_para_ids: None, + mode: ProfileMode::Bootnode, + }; + + assert_ok!(DataPreservers::create_profile( + RuntimeOrigin::signed(ALICE), + profile.clone(), + None + )); + + assert_noop!( + DataPreservers::delete_profile( + RuntimeOrigin::signed(ALICE), + 1, // wrong profile id + false, + ), + Error::::UnknownProfileId + ); + }); + } + + #[test] + fn wrong_user() { + ExtBuilder::default() + .with_balances(vec![(ALICE, 1_400)]) + .build() + .execute_with(|| { + let profile = Profile { + url: b"test".to_vec().try_into().unwrap(), + limited_to_para_ids: None, + mode: ProfileMode::Bootnode, + }; + + assert_ok!(DataPreservers::create_profile( + RuntimeOrigin::signed(ALICE), + profile.clone(), + None + )); + + assert_noop!( + DataPreservers::delete_profile( + RuntimeOrigin::signed(BOB), // not the profile's owner + 0, + false, + ), + sp_runtime::DispatchError::BadOrigin, + ); + }); + } + + #[test] + fn forced_delete_profile_works() { + ExtBuilder::default() + .with_balances(vec![(ALICE, 1_000_000_000_000)]) + .build() + .execute_with(|| { + let profile = Profile { + url: b"test".to_vec().try_into().unwrap(), + limited_to_para_ids: None, + mode: ProfileMode::Bootnode, + }; + + assert_ok!(DataPreservers::create_profile( + RuntimeOrigin::signed(ALICE), + profile.clone(), + None + )); + + assert_ok!(DataPreservers::delete_profile( + RuntimeOrigin::root(), + 0, + true, + )); + + assert_eq!(Profiles::::get(0), None); + + assert_eq!( + events(), + vec![ + Event::ProfileCreated { + account: ALICE, + profile_id: 0, + deposit: 1_357, + }, + Event::ProfileDeleted { + profile_id: 0, + released_deposit: 1_357, + } + ] + ); + }); + } + + #[test] + fn forced_delete_profile_filter() { + ExtBuilder::default() + .with_balances(vec![(ALICE, 1_000_000_000_000)]) + .build() + .execute_with(|| { + let profile = Profile { + url: b"test".to_vec().try_into().unwrap(), + limited_to_para_ids: None, + mode: ProfileMode::Bootnode, + }; + + assert_ok!(DataPreservers::create_profile( + RuntimeOrigin::signed(ALICE), + profile.clone(), + None + )); + + assert_noop!( + DataPreservers::delete_profile(RuntimeOrigin::signed(ALICE), 0, true,), + sp_runtime::DispatchError::BadOrigin, + ); + }); + } } From 23bbbad4df90b3a960c69cd23ee391c1e5eba0db Mon Sep 17 00:00:00 2001 From: nanocryk <6422796+nanocryk@users.noreply.github.com> Date: Wed, 15 May 2024 10:43:20 +0200 Subject: [PATCH 04/13] separate extrinsics for forced --- pallets/data-preservers/src/lib.rs | 168 +++++++++++++++++++-------- pallets/data-preservers/src/tests.rs | 50 ++------ 2 files changed, 130 insertions(+), 88 deletions(-) diff --git a/pallets/data-preservers/src/lib.rs b/pallets/data-preservers/src/lib.rs index 5857ee9c1..4f4186421 100644 --- a/pallets/data-preservers/src/lib.rs +++ b/pallets/data-preservers/src/lib.rs @@ -278,24 +278,11 @@ pub mod pallet { pub fn create_profile( origin: OriginFor, profile: Profile, - forced_for: Option, ) -> DispatchResultWithPostInfo { - let account = match forced_for.clone() { - Some(account) => { - T::ForceSetProfileOrigin::ensure_origin(origin)?; - account - } - None => ensure_signed(origin)?, - }; + let account = ensure_signed(origin)?; - let deposit = match forced_for { - Some(_) => Zero::zero(), // don't deposit anything if forced - None => { - let deposit = T::ProfileDeposit::profile_deposit(&profile)?; - T::Currency::hold(&HoldReason::ProfileDeposit.into(), &account, deposit)?; - deposit - } - }; + let deposit = T::ProfileDeposit::profile_deposit(&profile)?; + T::Currency::hold(&HoldReason::ProfileDeposit.into(), &account, deposit)?; let id = NextProfileId::::get(); NextProfileId::::set(id.checked_add(1).ok_or(ArithmeticError::Overflow)?); @@ -330,33 +317,20 @@ pub mod pallet { origin: OriginFor, profile_id: ProfileId, profile: Profile, - force: bool, ) -> DispatchResultWithPostInfo { - let account = if force { - T::ForceSetProfileOrigin::ensure_origin(origin)?; - None - } else { - Some(ensure_signed(origin)?) - }; + let account = ensure_signed(origin)?; let Some(existing_profile) = Profiles::::get(&profile_id) else { Err(Error::::UnknownProfileId)? }; - if let Some(account) = account { - ensure!( - existing_profile.account == account, - sp_runtime::DispatchError::BadOrigin, - ); - } + ensure!( + existing_profile.account == account, + sp_runtime::DispatchError::BadOrigin, + ); // Update deposit - // If forced update we release the previous deposit - let new_deposit = if force { - Zero::zero() - } else { - T::ProfileDeposit::profile_deposit(&profile)? - }; + let new_deposit = T::ProfileDeposit::profile_deposit(&profile)?; if let Some(diff) = new_deposit.checked_sub(&existing_profile.deposit) { T::Currency::hold( @@ -397,25 +371,123 @@ pub mod pallet { pub fn delete_profile( origin: OriginFor, profile_id: ProfileId, - force: bool, ) -> DispatchResultWithPostInfo { - let account = if force { - T::ForceSetProfileOrigin::ensure_origin(origin)?; - None - } else { - Some(ensure_signed(origin)?) - }; + let account = ensure_signed(origin)?; let Some(profile) = Profiles::::get(&profile_id) else { Err(Error::::UnknownProfileId)? }; - if let Some(account) = account { - ensure!( - profile.account == account, - sp_runtime::DispatchError::BadOrigin, - ); - } + ensure!( + profile.account == account, + sp_runtime::DispatchError::BadOrigin, + ); + + T::Currency::release( + &HoldReason::ProfileDeposit.into(), + &profile.account, + profile.deposit, + Precision::Exact, + )?; + + Profiles::::remove(&profile_id); + + Self::deposit_event(Event::ProfileDeleted { + profile_id, + released_deposit: profile.deposit, + }); + + Ok(().into()) + } + + #[pallet::call_index(4)] + // TODO: Benchmark + #[pallet::weight(0)] + pub fn force_create_profile( + origin: OriginFor, + profile: Profile, + for_account: T::AccountId, + ) -> DispatchResultWithPostInfo { + T::ForceSetProfileOrigin::ensure_origin(origin)?; + + let id = NextProfileId::::get(); + NextProfileId::::set(id.checked_add(1).ok_or(ArithmeticError::Overflow)?); + + ensure!( + !Profiles::::contains_key(&id), + Error::::NextProfileIdShouldBeAvailable + ); + + Profiles::::insert( + id, + RegisteredProfile { + account: for_account.clone(), + deposit: Zero::zero(), + profile, + }, + ); + + Self::deposit_event(Event::ProfileCreated { + account: for_account, + profile_id: id, + deposit: Zero::zero(), + }); + + Ok(().into()) + } + + #[pallet::call_index(5)] + // TODO: Benchmark + #[pallet::weight(0)] + pub fn force_update_profile( + origin: OriginFor, + profile_id: ProfileId, + profile: Profile, + ) -> DispatchResultWithPostInfo { + T::ForceSetProfileOrigin::ensure_origin(origin)?; + + let Some(existing_profile) = Profiles::::get(&profile_id) else { + Err(Error::::UnknownProfileId)? + }; + + // We release the previous deposit + T::Currency::release( + &HoldReason::ProfileDeposit.into(), + &existing_profile.account, + existing_profile.deposit, + Precision::Exact, + )?; + + Profiles::::insert( + profile_id, + RegisteredProfile { + account: existing_profile.account, + deposit: Zero::zero(), + profile, + }, + ); + + Self::deposit_event(Event::ProfileUpdated { + profile_id, + old_deposit: existing_profile.deposit, + new_deposit: Zero::zero(), + }); + + Ok(().into()) + } + + #[pallet::call_index(6)] + // TODO: Benchmark + #[pallet::weight(0)] + pub fn force_delete_profile( + origin: OriginFor, + profile_id: ProfileId, + ) -> DispatchResultWithPostInfo { + T::ForceSetProfileOrigin::ensure_origin(origin)?; + + let Some(profile) = Profiles::::get(&profile_id) else { + Err(Error::::UnknownProfileId)? + }; T::Currency::release( &HoldReason::ProfileDeposit.into(), diff --git a/pallets/data-preservers/src/tests.rs b/pallets/data-preservers/src/tests.rs index 324ea279b..bbf68833a 100644 --- a/pallets/data-preservers/src/tests.rs +++ b/pallets/data-preservers/src/tests.rs @@ -216,7 +216,6 @@ mod create_profile { assert_ok!(DataPreservers::create_profile( RuntimeOrigin::signed(ALICE), profile.clone(), - None, )); assert_eq!( @@ -254,11 +253,7 @@ mod create_profile { }; assert_noop!( - DataPreservers::create_profile( - RuntimeOrigin::signed(ALICE), - profile.clone(), - None - ), + DataPreservers::create_profile(RuntimeOrigin::signed(ALICE), profile.clone(),), TokenError::FundsUnavailable ); @@ -292,11 +287,7 @@ mod create_profile { ); assert_noop!( - DataPreservers::create_profile( - RuntimeOrigin::signed(ALICE), - profile.clone(), - None - ), + DataPreservers::create_profile(RuntimeOrigin::signed(ALICE), profile.clone(),), Error::::NextProfileIdShouldBeAvailable ); }); @@ -314,10 +305,10 @@ mod create_profile { mode: ProfileMode::Bootnode, }; - assert_ok!(DataPreservers::create_profile( + assert_ok!(DataPreservers::force_create_profile( RuntimeOrigin::root(), profile.clone(), - Some(ALICE), + ALICE, )); assert_eq!( @@ -355,10 +346,10 @@ mod create_profile { }; assert_noop!( - DataPreservers::create_profile( + DataPreservers::force_create_profile( RuntimeOrigin::signed(BOB), profile.clone(), - Some(ALICE), + ALICE, ), sp_runtime::DispatchError::BadOrigin ); @@ -384,7 +375,6 @@ mod update_profile { assert_ok!(DataPreservers::create_profile( RuntimeOrigin::signed(ALICE), profile.clone(), - None )); let profile2 = Profile { @@ -399,7 +389,6 @@ mod update_profile { RuntimeOrigin::signed(ALICE), 0, profile2.clone(), - false, )); assert_eq!( @@ -444,7 +433,6 @@ mod update_profile { assert_ok!(DataPreservers::create_profile( RuntimeOrigin::signed(ALICE), profile.clone(), - None )); let profile2 = Profile { @@ -460,7 +448,6 @@ mod update_profile { RuntimeOrigin::signed(ALICE), 1, // wrong profile id profile2.clone(), - false, ), Error::::UnknownProfileId ); @@ -482,7 +469,6 @@ mod update_profile { assert_ok!(DataPreservers::create_profile( RuntimeOrigin::signed(ALICE), profile.clone(), - None )); let profile2 = Profile { @@ -498,7 +484,6 @@ mod update_profile { RuntimeOrigin::signed(BOB), // not the profile's owner 0, profile2.clone(), - false, ), sp_runtime::DispatchError::BadOrigin, ); @@ -520,7 +505,6 @@ mod update_profile { assert_ok!(DataPreservers::create_profile( RuntimeOrigin::signed(ALICE), profile.clone(), - None )); let profile2 = Profile { @@ -536,7 +520,6 @@ mod update_profile { RuntimeOrigin::signed(ALICE), 0, profile2.clone(), - false, ), TokenError::FundsUnavailable ); @@ -558,7 +541,6 @@ mod update_profile { assert_ok!(DataPreservers::create_profile( RuntimeOrigin::signed(ALICE), profile.clone(), - None )); let profile2 = Profile { @@ -569,11 +551,10 @@ mod update_profile { }, }; - assert_ok!(DataPreservers::update_profile( + assert_ok!(DataPreservers::force_update_profile( RuntimeOrigin::root(), 0, profile2.clone(), - true, )); assert_eq!( @@ -618,7 +599,6 @@ mod update_profile { assert_ok!(DataPreservers::create_profile( RuntimeOrigin::signed(ALICE), profile.clone(), - None )); let profile2 = Profile { @@ -630,11 +610,10 @@ mod update_profile { }; assert_noop!( - DataPreservers::update_profile( + DataPreservers::force_update_profile( RuntimeOrigin::signed(ALICE), 0, profile2.clone(), - true, ), sp_runtime::DispatchError::BadOrigin, ); @@ -660,13 +639,11 @@ mod delete_profile { assert_ok!(DataPreservers::create_profile( RuntimeOrigin::signed(ALICE), profile.clone(), - None )); assert_ok!(DataPreservers::delete_profile( RuntimeOrigin::signed(ALICE), 0, - false, )); assert_eq!(Profiles::::get(0), None); @@ -703,14 +680,12 @@ mod delete_profile { assert_ok!(DataPreservers::create_profile( RuntimeOrigin::signed(ALICE), profile.clone(), - None )); assert_noop!( DataPreservers::delete_profile( RuntimeOrigin::signed(ALICE), 1, // wrong profile id - false, ), Error::::UnknownProfileId ); @@ -732,14 +707,12 @@ mod delete_profile { assert_ok!(DataPreservers::create_profile( RuntimeOrigin::signed(ALICE), profile.clone(), - None )); assert_noop!( DataPreservers::delete_profile( RuntimeOrigin::signed(BOB), // not the profile's owner 0, - false, ), sp_runtime::DispatchError::BadOrigin, ); @@ -761,13 +734,11 @@ mod delete_profile { assert_ok!(DataPreservers::create_profile( RuntimeOrigin::signed(ALICE), profile.clone(), - None )); - assert_ok!(DataPreservers::delete_profile( + assert_ok!(DataPreservers::force_delete_profile( RuntimeOrigin::root(), 0, - true, )); assert_eq!(Profiles::::get(0), None); @@ -804,11 +775,10 @@ mod delete_profile { assert_ok!(DataPreservers::create_profile( RuntimeOrigin::signed(ALICE), profile.clone(), - None )); assert_noop!( - DataPreservers::delete_profile(RuntimeOrigin::signed(ALICE), 0, true,), + DataPreservers::force_delete_profile(RuntimeOrigin::signed(ALICE), 0), sp_runtime::DispatchError::BadOrigin, ); }); From 1299a64fb57a54dfc6a0fcc59dec6aa6b002df4f Mon Sep 17 00:00:00 2001 From: nanocryk <6422796+nanocryk@users.noreply.github.com> Date: Fri, 17 May 2024 15:52:32 +0200 Subject: [PATCH 05/13] benchmarks --- pallets/data-preservers/src/benchmarks.rs | 217 +++++++++++++++- pallets/data-preservers/src/lib.rs | 48 ++-- pallets/data-preservers/src/weights.rs | 237 ++++++++++++++++-- runtime/dancebox/src/lib.rs | 18 +- .../src/weights/pallet_data_preservers.rs | 24 ++ runtime/flashbox/src/lib.rs | 19 +- .../src/weights/pallet_data_preservers.rs | 24 ++ 7 files changed, 542 insertions(+), 45 deletions(-) diff --git a/pallets/data-preservers/src/benchmarks.rs b/pallets/data-preservers/src/benchmarks.rs index 6a07dd3b1..bbc0e3d72 100644 --- a/pallets/data-preservers/src/benchmarks.rs +++ b/pallets/data-preservers/src/benchmarks.rs @@ -18,10 +18,15 @@ //! Benchmarking use { - crate::{Call, Config, Pallet}, + crate::{ + Call, Config, Pallet, Profile, ProfileDeposit, ProfileMode, Profiles, RegisteredProfile, + }, frame_benchmarking::v2::*, frame_support::{ - traits::{EnsureOriginWithArg, OriginTrait}, + traits::{ + fungible::{Inspect, Mutate}, + EnsureOrigin, EnsureOriginWithArg, OriginTrait, + }, BoundedVec, }, frame_system::RawOrigin, @@ -29,7 +34,21 @@ use { tp_traits::ParaId, }; -#[benchmarks] +const SEED: u32 = 0; + +fn create_funded_user(string: &'static str, n: u32, balance_factor: u32) -> T::AccountId +where + T::Currency: Mutate, +{ + let user = account(string, n, SEED); + let balance = ::minimum_balance() * balance_factor.into(); + let _ = ::set_balance(&user, balance); + user +} + +#[benchmarks( + where T::Currency: Mutate +)] mod benchmarks { use super::*; @@ -55,5 +74,197 @@ mod benchmarks { assert_eq!(Pallet::::boot_nodes(para_id), boot_nodes); } + #[benchmark] + fn create_profile(x: Linear<1, 200>, y: Linear<1, 10>) { + // x: url len, y: para ids len + let url = BoundedVec::try_from(vec![b'A'; x as usize]).unwrap(); + let para_ids = BoundedVec::try_from(vec![ParaId::from(42); y as usize]).unwrap(); + + let profile = Profile { + url, + limited_to_para_ids: Some(para_ids), + mode: ProfileMode::Bootnode, + }; + + let deposit = T::ProfileDeposit::profile_deposit(&profile).expect("deposit to be computed"); + + let caller = create_funded_user::("caller", 1, 1_000_000_000u32); + + #[extrinsic_call] + Pallet::::create_profile(RawOrigin::Signed(caller.clone()), profile.clone()); + + assert_eq!( + Profiles::::get(0), + Some(RegisteredProfile { + account: caller, + deposit, + profile + }) + ); + } + + #[benchmark] + fn force_create_profile(x: Linear<1, 200>, y: Linear<1, 10>) { + // x: url len, y: para ids len + let url = BoundedVec::try_from(vec![b'A'; x as usize]).unwrap(); + let para_ids = BoundedVec::try_from(vec![ParaId::from(42); y as usize]).unwrap(); + + let profile = Profile { + url, + limited_to_para_ids: Some(para_ids), + mode: ProfileMode::Bootnode, + }; + + let owner = create_funded_user::("owner", 1, 1_000_000_000u32); + let origin_force = T::ForceSetProfileOrigin::try_successful_origin() + .expect("failed to create ForceSetProfileOrigin"); + + #[extrinsic_call] + Pallet::::force_create_profile( + origin_force as T::RuntimeOrigin, + profile.clone(), + owner.clone(), + ); + + assert_eq!( + Profiles::::get(0), + Some(RegisteredProfile { + account: owner, + deposit: 0u32.into(), + profile + }) + ); + } + + #[benchmark] + fn update_profile(x: Linear<1, 200>, y: Linear<1, 10>) { + let url = BoundedVec::try_from(vec![b'A'; 10]).unwrap(); + let para_ids = BoundedVec::try_from(vec![ParaId::from(42); 2]).unwrap(); + + let profile = Profile { + url, + limited_to_para_ids: Some(para_ids), + mode: ProfileMode::Bootnode, + }; + + let caller = create_funded_user::("caller", 1, 1_000_000_000u32); + + Pallet::::create_profile(RawOrigin::Signed(caller.clone()).into(), profile) + .expect("to create profile"); + + // x: url len, y: para ids len + let url = BoundedVec::try_from(vec![b'B'; x as usize]).unwrap(); + let para_ids = BoundedVec::try_from(vec![ParaId::from(43); y as usize]).unwrap(); + + let profile = Profile { + url, + limited_to_para_ids: Some(para_ids), + mode: ProfileMode::Bootnode, + }; + + let deposit = T::ProfileDeposit::profile_deposit(&profile).expect("deposit to be computed"); + + #[extrinsic_call] + Pallet::::update_profile(RawOrigin::Signed(caller.clone()), 0, profile.clone()); + + assert_eq!( + Profiles::::get(0), + Some(RegisteredProfile { + account: caller, + deposit, + profile + }) + ); + } + + #[benchmark] + fn force_update_profile(x: Linear<1, 200>, y: Linear<1, 10>) { + let url = BoundedVec::try_from(vec![b'A'; 10]).unwrap(); + let para_ids = BoundedVec::try_from(vec![ParaId::from(42); 2]).unwrap(); + + let profile = Profile { + url, + limited_to_para_ids: Some(para_ids), + mode: ProfileMode::Bootnode, + }; + + let caller = create_funded_user::("caller", 1, 1_000_000_000u32); + + Pallet::::create_profile(RawOrigin::Signed(caller.clone()).into(), profile) + .expect("to create profile"); + + // x: url len, y: para ids len + let url = BoundedVec::try_from(vec![b'B'; x as usize]).unwrap(); + let para_ids = BoundedVec::try_from(vec![ParaId::from(43); y as usize]).unwrap(); + + let profile = Profile { + url, + limited_to_para_ids: Some(para_ids), + mode: ProfileMode::Bootnode, + }; + + let origin_force = T::ForceSetProfileOrigin::try_successful_origin() + .expect("failed to create ForceSetProfileOrigin"); + + #[extrinsic_call] + Pallet::::force_update_profile(origin_force as T::RuntimeOrigin, 0, profile.clone()); + + assert_eq!( + Profiles::::get(0), + Some(RegisteredProfile { + account: caller, + deposit: 0u32.into(), + profile + }) + ); + } + + #[benchmark] + fn delete_profile() { + let url = BoundedVec::try_from(vec![b'A'; 10]).unwrap(); + let para_ids = BoundedVec::try_from(vec![ParaId::from(42); 2]).unwrap(); + + let profile = Profile { + url, + limited_to_para_ids: Some(para_ids), + mode: ProfileMode::Bootnode, + }; + + let caller = create_funded_user::("caller", 1, 1_000_000_000u32); + + Pallet::::create_profile(RawOrigin::Signed(caller.clone()).into(), profile) + .expect("to create profile"); + + #[extrinsic_call] + Pallet::::delete_profile(RawOrigin::Signed(caller.clone()), 0); + + assert_eq!(Profiles::::get(0), None); + } + + #[benchmark] + fn force_delete_profile() { + let url = BoundedVec::try_from(vec![b'A'; 10]).unwrap(); + let para_ids = BoundedVec::try_from(vec![ParaId::from(42); 2]).unwrap(); + + let profile = Profile { + url, + limited_to_para_ids: Some(para_ids), + mode: ProfileMode::Bootnode, + }; + + let caller = create_funded_user::("caller", 1, 1_000_000_000u32); + + Pallet::::create_profile(RawOrigin::Signed(caller.clone()).into(), profile) + .expect("to create profile"); + + let origin_force = T::ForceSetProfileOrigin::try_successful_origin() + .expect("failed to create ForceSetProfileOrigin"); + + #[extrinsic_call] + Pallet::::force_delete_profile(origin_force as T::RuntimeOrigin, 0); + + assert_eq!(Profiles::::get(0), None); + } + impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test); } diff --git a/pallets/data-preservers/src/lib.rs b/pallets/data-preservers/src/lib.rs index 4f4186421..c1c447bec 100644 --- a/pallets/data-preservers/src/lib.rs +++ b/pallets/data-preservers/src/lib.rs @@ -273,8 +273,10 @@ pub mod pallet { } #[pallet::call_index(1)] - // TODO: Benchmark - #[pallet::weight(0)] + #[pallet::weight(T::WeightInfo::create_profile( + profile.url.len() as u32, + profile.limited_to_para_ids.as_ref().map(|v| v.len() as u32).unwrap_or(0) + ))] pub fn create_profile( origin: OriginFor, profile: Profile, @@ -288,7 +290,7 @@ pub mod pallet { NextProfileId::::set(id.checked_add(1).ok_or(ArithmeticError::Overflow)?); ensure!( - !Profiles::::contains_key(&id), + !Profiles::::contains_key(id), Error::::NextProfileIdShouldBeAvailable ); @@ -311,8 +313,10 @@ pub mod pallet { } #[pallet::call_index(2)] - // TODO: Benchmark - #[pallet::weight(0)] + #[pallet::weight(T::WeightInfo::update_profile( + profile.url.len() as u32, + profile.limited_to_para_ids.as_ref().map(|v| v.len() as u32).unwrap_or(0) + ))] pub fn update_profile( origin: OriginFor, profile_id: ProfileId, @@ -320,7 +324,7 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { let account = ensure_signed(origin)?; - let Some(existing_profile) = Profiles::::get(&profile_id) else { + let Some(existing_profile) = Profiles::::get(profile_id) else { Err(Error::::UnknownProfileId)? }; @@ -359,22 +363,21 @@ pub mod pallet { Self::deposit_event(Event::ProfileUpdated { profile_id, old_deposit: existing_profile.deposit, - new_deposit: new_deposit, + new_deposit, }); Ok(().into()) } #[pallet::call_index(3)] - // TODO: Benchmark - #[pallet::weight(0)] + #[pallet::weight(T::WeightInfo::delete_profile())] pub fn delete_profile( origin: OriginFor, profile_id: ProfileId, ) -> DispatchResultWithPostInfo { let account = ensure_signed(origin)?; - let Some(profile) = Profiles::::get(&profile_id) else { + let Some(profile) = Profiles::::get(profile_id) else { Err(Error::::UnknownProfileId)? }; @@ -390,7 +393,7 @@ pub mod pallet { Precision::Exact, )?; - Profiles::::remove(&profile_id); + Profiles::::remove(profile_id); Self::deposit_event(Event::ProfileDeleted { profile_id, @@ -401,8 +404,10 @@ pub mod pallet { } #[pallet::call_index(4)] - // TODO: Benchmark - #[pallet::weight(0)] + #[pallet::weight(T::WeightInfo::force_create_profile( + profile.url.len() as u32, + profile.limited_to_para_ids.as_ref().map(|v| v.len() as u32).unwrap_or(0) + ))] pub fn force_create_profile( origin: OriginFor, profile: Profile, @@ -414,7 +419,7 @@ pub mod pallet { NextProfileId::::set(id.checked_add(1).ok_or(ArithmeticError::Overflow)?); ensure!( - !Profiles::::contains_key(&id), + !Profiles::::contains_key(id), Error::::NextProfileIdShouldBeAvailable ); @@ -437,8 +442,10 @@ pub mod pallet { } #[pallet::call_index(5)] - // TODO: Benchmark - #[pallet::weight(0)] + #[pallet::weight(T::WeightInfo::force_update_profile( + profile.url.len() as u32, + profile.limited_to_para_ids.as_ref().map(|v| v.len() as u32).unwrap_or(0) + ))] pub fn force_update_profile( origin: OriginFor, profile_id: ProfileId, @@ -446,7 +453,7 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { T::ForceSetProfileOrigin::ensure_origin(origin)?; - let Some(existing_profile) = Profiles::::get(&profile_id) else { + let Some(existing_profile) = Profiles::::get(profile_id) else { Err(Error::::UnknownProfileId)? }; @@ -477,15 +484,14 @@ pub mod pallet { } #[pallet::call_index(6)] - // TODO: Benchmark - #[pallet::weight(0)] + #[pallet::weight(T::WeightInfo::force_delete_profile())] pub fn force_delete_profile( origin: OriginFor, profile_id: ProfileId, ) -> DispatchResultWithPostInfo { T::ForceSetProfileOrigin::ensure_origin(origin)?; - let Some(profile) = Profiles::::get(&profile_id) else { + let Some(profile) = Profiles::::get(profile_id) else { Err(Error::::UnknownProfileId)? }; @@ -496,7 +502,7 @@ pub mod pallet { Precision::Exact, )?; - Profiles::::remove(&profile_id); + Profiles::::remove(profile_id); Self::deposit_event(Event::ProfileDeleted { profile_id, diff --git a/pallets/data-preservers/src/weights.rs b/pallets/data-preservers/src/weights.rs index b93d57d1a..9e282966b 100644 --- a/pallets/data-preservers/src/weights.rs +++ b/pallets/data-preservers/src/weights.rs @@ -18,10 +18,10 @@ //! Autogenerated weights for pallet_data_preservers //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-11, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-05-17, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `tomasz-XPS-15-9520`, CPU: `12th Gen Intel(R) Core(TM) i7-12700H` -//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024 +//! HOSTNAME: `pop-os`, CPU: `12th Gen Intel(R) Core(TM) i7-1260P` +//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: // ./target/release/tanssi-node @@ -33,15 +33,16 @@ // pallet_data_preservers // --extrinsic // * +// --chain=dev // --steps // 50 // --repeat // 20 -// --template=./benchmarking/frame-weight-template.hbs +// --template=./benchmarking/frame-weight-pallet-template.hbs // --json-file // raw.json // --output -// weights.rs +// tmp/pallet_data_preservers.rs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -53,6 +54,12 @@ use sp_std::marker::PhantomData; /// Weight functions needed for pallet_data_preservers. pub trait WeightInfo { fn set_boot_nodes(x: u32, y: u32, ) -> Weight; + fn create_profile(x: u32, y: u32, ) -> Weight; + fn force_create_profile(x: u32, y: u32, ) -> Weight; + fn update_profile(x: u32, y: u32, ) -> Weight; + fn force_update_profile(x: u32, y: u32, ) -> Weight; + fn delete_profile() -> Weight; + fn force_delete_profile() -> Weight; } /// Weights for pallet_data_preservers using the Substrate node and recommended hardware. @@ -68,15 +75,113 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `195` // Estimated: `3660` - // Minimum execution time: 10_703_000 picoseconds. - Weight::from_parts(9_788_229, 3660) - // Standard Error: 170 - .saturating_add(Weight::from_parts(7_964, 0).saturating_mul(x.into())) - // Standard Error: 3_552 - .saturating_add(Weight::from_parts(334_296, 0).saturating_mul(y.into())) + // Minimum execution time: 10_063_000 picoseconds. + Weight::from_parts(10_198_905, 3660) + // Standard Error: 739 + .saturating_add(Weight::from_parts(2_403, 0).saturating_mul(x.into())) + // Standard Error: 15_425 + .saturating_add(Weight::from_parts(258_908, 0).saturating_mul(y.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) + /// Storage: `DataPreservers::NextProfileId` (r:1 w:1) + /// Proof: `DataPreservers::NextProfileId` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 200]`. + /// The range of component `y` is `[1, 10]`. + fn create_profile(_x: u32, _y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `182` + // Estimated: `3694` + // Minimum execution time: 34_210_000 picoseconds. + Weight::from_parts(43_239_265, 3694) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: `DataPreservers::NextProfileId` (r:1 w:1) + /// Proof: `DataPreservers::NextProfileId` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 200]`. + /// The range of component `y` is `[1, 10]`. + fn force_create_profile(_x: u32, _y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `79` + // Estimated: `3544` + // Minimum execution time: 9_075_000 picoseconds. + Weight::from_parts(11_443_644, 3544) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) + /// The range of component `x` is `[1, 200]`. + /// The range of component `y` is `[1, 10]`. + fn update_profile(_x: u32, _y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `319` + // Estimated: `3784` + // Minimum execution time: 33_842_000 picoseconds. + Weight::from_parts(42_067_126, 3784) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) + /// The range of component `x` is `[1, 200]`. + /// The range of component `y` is `[1, 10]`. + fn force_update_profile(_x: u32, _y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `319` + // Estimated: `3784` + // Minimum execution time: 29_757_000 picoseconds. + Weight::from_parts(34_984_806, 3784) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) + fn delete_profile() -> Weight { + // Proof Size summary in bytes: + // Measured: `319` + // Estimated: `3784` + // Minimum execution time: 32_125_000 picoseconds. + Weight::from_parts(35_384_000, 3784) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) + fn force_delete_profile() -> Weight { + // Proof Size summary in bytes: + // Measured: `319` + // Estimated: `3784` + // Minimum execution time: 35_189_000 picoseconds. + Weight::from_parts(36_883_000, 3784) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } } // For backwards compatibility and tests @@ -91,13 +196,111 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `195` // Estimated: `3660` - // Minimum execution time: 10_703_000 picoseconds. - Weight::from_parts(9_788_229, 3660) - // Standard Error: 170 - .saturating_add(Weight::from_parts(7_964, 0).saturating_mul(x.into())) - // Standard Error: 3_552 - .saturating_add(Weight::from_parts(334_296, 0).saturating_mul(y.into())) + // Minimum execution time: 10_063_000 picoseconds. + Weight::from_parts(10_198_905, 3660) + // Standard Error: 739 + .saturating_add(Weight::from_parts(2_403, 0).saturating_mul(x.into())) + // Standard Error: 15_425 + .saturating_add(Weight::from_parts(258_908, 0).saturating_mul(y.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) + /// Storage: `DataPreservers::NextProfileId` (r:1 w:1) + /// Proof: `DataPreservers::NextProfileId` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 200]`. + /// The range of component `y` is `[1, 10]`. + fn create_profile(_x: u32, _y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `182` + // Estimated: `3694` + // Minimum execution time: 34_210_000 picoseconds. + Weight::from_parts(43_239_265, 3694) + .saturating_add(RocksDbWeight::get().reads(4_u64)) + .saturating_add(RocksDbWeight::get().writes(4_u64)) + } + /// Storage: `DataPreservers::NextProfileId` (r:1 w:1) + /// Proof: `DataPreservers::NextProfileId` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 200]`. + /// The range of component `y` is `[1, 10]`. + fn force_create_profile(_x: u32, _y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `79` + // Estimated: `3544` + // Minimum execution time: 9_075_000 picoseconds. + Weight::from_parts(11_443_644, 3544) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) + /// The range of component `x` is `[1, 200]`. + /// The range of component `y` is `[1, 10]`. + fn update_profile(_x: u32, _y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `319` + // Estimated: `3784` + // Minimum execution time: 33_842_000 picoseconds. + Weight::from_parts(42_067_126, 3784) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) + /// The range of component `x` is `[1, 200]`. + /// The range of component `y` is `[1, 10]`. + fn force_update_profile(_x: u32, _y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `319` + // Estimated: `3784` + // Minimum execution time: 29_757_000 picoseconds. + Weight::from_parts(34_984_806, 3784) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) + fn delete_profile() -> Weight { + // Proof Size summary in bytes: + // Measured: `319` + // Estimated: `3784` + // Minimum execution time: 32_125_000 picoseconds. + Weight::from_parts(35_384_000, 3784) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) + fn force_delete_profile() -> Weight { + // Proof Size summary in bytes: + // Measured: `319` + // Estimated: `3784` + // Minimum execution time: 35_189_000 picoseconds. + Weight::from_parts(36_883_000, 3784) + .saturating_add(RocksDbWeight::get().reads(3_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } } diff --git a/runtime/dancebox/src/lib.rs b/runtime/dancebox/src/lib.rs index a37f658d9..15bec6c00 100644 --- a/runtime/dancebox/src/lib.rs +++ b/runtime/dancebox/src/lib.rs @@ -68,6 +68,7 @@ use { nimbus_primitives::{NimbusId, SlotBeacon}, pallet_balances::NegativeImbalance, pallet_collator_assignment::{GetRandomnessForNextBlock, RotateCollatorsEveryNSessions}, + pallet_data_preservers::BytesProfileDeposit, pallet_invulnerables::InvulnerableRewardDistribution, pallet_pooled_staking::traits::{IsCandidateEligible, Timer}, pallet_registrar::RegistrarHooks, @@ -156,9 +157,10 @@ pub mod currency { pub const KILODANCE: Balance = 1_000_000_000_000_000; pub const STORAGE_BYTE_FEE: Balance = 100 * MICRODANCE * SUPPLY_FACTOR; + pub const STORAGE_ITEM_FEE: Balance = 100 * MILLIDANCE * SUPPLY_FACTOR; pub const fn deposit(items: u32, bytes: u32) -> Balance { - items as Balance * 100 * MILLIDANCE * SUPPLY_FACTOR + (bytes as Balance) * STORAGE_BYTE_FEE + items as Balance * STORAGE_ITEM_FEE + (bytes as Balance) * STORAGE_BYTE_FEE } } @@ -924,14 +926,26 @@ impl pallet_services_payment::Config for Runtime { type WeightInfo = weights::pallet_services_payment::SubstrateWeight; } +parameter_types! { + pub const ProfileDepositBaseFee: Balance = currency::STORAGE_ITEM_FEE; + pub const ProfileDepositByteFee: Balance = currency::STORAGE_BYTE_FEE; +} + impl pallet_data_preservers::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type RuntimeHoldReason = RuntimeHoldReason; type Currency = Balances; + type WeightInfo = weights::pallet_data_preservers::SubstrateWeight; + + type ProfileDeposit = BytesProfileDeposit; + type SetBootNodesOrigin = EitherOfDiverse, EnsureRoot>; + type ForceSetProfileOrigin = EnsureRoot; + type MaxBootNodes = MaxBootNodes; type MaxBootNodeUrlLen = MaxBootNodeUrlLen; - type WeightInfo = weights::pallet_data_preservers::SubstrateWeight; + type MaxParaIdsVecLen = MaxLengthParaIds; } impl pallet_author_noting::Config for Runtime { diff --git a/runtime/dancebox/src/weights/pallet_data_preservers.rs b/runtime/dancebox/src/weights/pallet_data_preservers.rs index a9ebb563f..aea5b9995 100644 --- a/runtime/dancebox/src/weights/pallet_data_preservers.rs +++ b/runtime/dancebox/src/weights/pallet_data_preservers.rs @@ -73,4 +73,28 @@ impl pallet_data_preservers::WeightInfo for SubstrateWe .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } + + fn create_profile(x: u32, y: u32, ) -> Weight { + todo!() + } + + fn force_create_profile(x: u32, y: u32, ) -> Weight { + todo!() + } + + fn update_profile(x: u32, y: u32, ) -> Weight { + todo!() + } + + fn force_update_profile(x: u32, y: u32, ) -> Weight { + todo!() + } + + fn delete_profile() -> Weight { + todo!() + } + + fn force_delete_profile() -> Weight { + todo!() + } } \ No newline at end of file diff --git a/runtime/flashbox/src/lib.rs b/runtime/flashbox/src/lib.rs index 0f6cb7b16..d85c07b3d 100644 --- a/runtime/flashbox/src/lib.rs +++ b/runtime/flashbox/src/lib.rs @@ -65,6 +65,7 @@ use { }, nimbus_primitives::{NimbusId, SlotBeacon}, pallet_balances::NegativeImbalance, + pallet_data_preservers::BytesProfileDeposit, pallet_invulnerables::InvulnerableRewardDistribution, pallet_registrar::RegistrarHooks, pallet_registrar_runtime_api::ContainerChainGenesisData, @@ -150,9 +151,10 @@ pub mod currency { pub const KILODANCE: Balance = 1_000_000_000_000_000; pub const STORAGE_BYTE_FEE: Balance = 100 * MICRODANCE * SUPPLY_FACTOR; + pub const STORAGE_ITEM_FEE: Balance = 100 * MILLIDANCE * SUPPLY_FACTOR; pub const fn deposit(items: u32, bytes: u32) -> Balance { - items as Balance * 100 * MILLIDANCE * SUPPLY_FACTOR + (bytes as Balance) * STORAGE_BYTE_FEE + items as Balance * STORAGE_ITEM_FEE + (bytes as Balance) * STORAGE_BYTE_FEE } } @@ -782,14 +784,27 @@ impl pallet_services_payment::Config for Runtime { EitherOfDiverse, EnsureRoot>; type WeightInfo = weights::pallet_services_payment::SubstrateWeight; } + +parameter_types! { + pub const ProfileDepositBaseFee: Balance = currency::STORAGE_ITEM_FEE; + pub const ProfileDepositByteFee: Balance = currency::STORAGE_BYTE_FEE; +} + impl pallet_data_preservers::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type RuntimeHoldReason = RuntimeHoldReason; type Currency = Balances; + type WeightInfo = weights::pallet_data_preservers::SubstrateWeight; + + type ProfileDeposit = BytesProfileDeposit; + type SetBootNodesOrigin = EitherOfDiverse, EnsureRoot>; + type ForceSetProfileOrigin = EnsureRoot; + type MaxBootNodes = MaxBootNodes; type MaxBootNodeUrlLen = MaxBootNodeUrlLen; - type WeightInfo = weights::pallet_data_preservers::SubstrateWeight; + type MaxParaIdsVecLen = MaxLengthParaIds; } impl pallet_author_noting::Config for Runtime { diff --git a/runtime/flashbox/src/weights/pallet_data_preservers.rs b/runtime/flashbox/src/weights/pallet_data_preservers.rs index c906acb2d..2f9be3f9a 100644 --- a/runtime/flashbox/src/weights/pallet_data_preservers.rs +++ b/runtime/flashbox/src/weights/pallet_data_preservers.rs @@ -73,4 +73,28 @@ impl pallet_data_preservers::WeightInfo for SubstrateWe .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } + + fn create_profile(x: u32, y: u32, ) -> Weight { + todo!() + } + + fn force_create_profile(x: u32, y: u32, ) -> Weight { + todo!() + } + + fn update_profile(x: u32, y: u32, ) -> Weight { + todo!() + } + + fn force_update_profile(x: u32, y: u32, ) -> Weight { + todo!() + } + + fn delete_profile() -> Weight { + todo!() + } + + fn force_delete_profile() -> Weight { + todo!() + } } \ No newline at end of file From a1972588c439804b637cb68329e5a13fcd7284da Mon Sep 17 00:00:00 2001 From: nanocryk <6422796+nanocryk@users.noreply.github.com> Date: Tue, 21 May 2024 12:45:16 +0200 Subject: [PATCH 06/13] real benchmarks --- .../src/weights/pallet_data_preservers.rs | 128 +++++++++++++++--- .../src/weights/pallet_data_preservers.rs | 126 ++++++++++++++--- 2 files changed, 211 insertions(+), 43 deletions(-) diff --git a/runtime/dancebox/src/weights/pallet_data_preservers.rs b/runtime/dancebox/src/weights/pallet_data_preservers.rs index aea5b9995..9c42a0160 100644 --- a/runtime/dancebox/src/weights/pallet_data_preservers.rs +++ b/runtime/dancebox/src/weights/pallet_data_preservers.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for pallet_data_preservers //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-04-12, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-05-21, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `benchmark-1`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` //! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 @@ -64,37 +64,123 @@ impl pallet_data_preservers::WeightInfo for SubstrateWe // Proof Size summary in bytes: // Measured: `195` // Estimated: `3660` - // Minimum execution time: 17_362_000 picoseconds. - Weight::from_parts(15_414_530, 3660) - // Standard Error: 144 - .saturating_add(Weight::from_parts(11_706, 0).saturating_mul(x.into())) - // Standard Error: 3_020 - .saturating_add(Weight::from_parts(455_376, 0).saturating_mul(y.into())) + // Minimum execution time: 17_579_000 picoseconds. + Weight::from_parts(15_512_474, 3660) + // Standard Error: 155 + .saturating_add(Weight::from_parts(12_145, 0).saturating_mul(x.into())) + // Standard Error: 3_245 + .saturating_add(Weight::from_parts(444_028, 0).saturating_mul(y.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } - - fn create_profile(x: u32, y: u32, ) -> Weight { - todo!() + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) + /// Storage: `DataPreservers::NextProfileId` (r:1 w:1) + /// Proof: `DataPreservers::NextProfileId` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 200]`. + /// The range of component `y` is `[1, 10]`. + fn create_profile(x: u32, _y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `182` + // Estimated: `3694` + // Minimum execution time: 60_338_000 picoseconds. + Weight::from_parts(61_745_449, 3694) + // Standard Error: 237 + .saturating_add(Weight::from_parts(43, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } - + /// Storage: `DataPreservers::NextProfileId` (r:1 w:1) + /// Proof: `DataPreservers::NextProfileId` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 200]`. + /// The range of component `y` is `[1, 10]`. fn force_create_profile(x: u32, y: u32, ) -> Weight { - todo!() + // Proof Size summary in bytes: + // Measured: `79` + // Estimated: `3544` + // Minimum execution time: 17_167_000 picoseconds. + Weight::from_parts(17_704_087, 3544) + // Standard Error: 98 + .saturating_add(Weight::from_parts(221, 0).saturating_mul(x.into())) + // Standard Error: 2_053 + .saturating_add(Weight::from_parts(5_369, 0).saturating_mul(y.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } - - fn update_profile(x: u32, y: u32, ) -> Weight { - todo!() + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) + /// The range of component `x` is `[1, 200]`. + /// The range of component `y` is `[1, 10]`. + fn update_profile(x: u32, _y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `319` + // Estimated: `3784` + // Minimum execution time: 59_285_000 picoseconds. + Weight::from_parts(60_566_202, 3784) + // Standard Error: 172 + .saturating_add(Weight::from_parts(336, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } - + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) + /// The range of component `x` is `[1, 200]`. + /// The range of component `y` is `[1, 10]`. fn force_update_profile(x: u32, y: u32, ) -> Weight { - todo!() + // Proof Size summary in bytes: + // Measured: `319` + // Estimated: `3784` + // Minimum execution time: 51_519_000 picoseconds. + Weight::from_parts(53_016_751, 3784) + // Standard Error: 202 + .saturating_add(Weight::from_parts(224, 0).saturating_mul(x.into())) + // Standard Error: 4_224 + .saturating_add(Weight::from_parts(17, 0).saturating_mul(y.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } - + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) fn delete_profile() -> Weight { - todo!() + // Proof Size summary in bytes: + // Measured: `319` + // Estimated: `3784` + // Minimum execution time: 50_942_000 picoseconds. + Weight::from_parts(51_642_000, 3784) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } - + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) fn force_delete_profile() -> Weight { - todo!() + // Proof Size summary in bytes: + // Measured: `319` + // Estimated: `3784` + // Minimum execution time: 50_872_000 picoseconds. + Weight::from_parts(51_956_000, 3784) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } } \ No newline at end of file diff --git a/runtime/flashbox/src/weights/pallet_data_preservers.rs b/runtime/flashbox/src/weights/pallet_data_preservers.rs index 2f9be3f9a..27c1f78a7 100644 --- a/runtime/flashbox/src/weights/pallet_data_preservers.rs +++ b/runtime/flashbox/src/weights/pallet_data_preservers.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for pallet_data_preservers //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-04-12, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-05-21, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `benchmark-1`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` //! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("flashbox_dev"), DB CACHE: 1024 @@ -64,37 +64,119 @@ impl pallet_data_preservers::WeightInfo for SubstrateWe // Proof Size summary in bytes: // Measured: `195` // Estimated: `3660` - // Minimum execution time: 16_473_000 picoseconds. - Weight::from_parts(14_542_746, 3660) + // Minimum execution time: 16_267_000 picoseconds. + Weight::from_parts(14_208_199, 3660) // Standard Error: 159 - .saturating_add(Weight::from_parts(12_051, 0).saturating_mul(x.into())) - // Standard Error: 3_325 - .saturating_add(Weight::from_parts(452_868, 0).saturating_mul(y.into())) + .saturating_add(Weight::from_parts(11_989, 0).saturating_mul(x.into())) + // Standard Error: 3_322 + .saturating_add(Weight::from_parts(452_756, 0).saturating_mul(y.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } - - fn create_profile(x: u32, y: u32, ) -> Weight { - todo!() + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) + /// Storage: `DataPreservers::NextProfileId` (r:1 w:1) + /// Proof: `DataPreservers::NextProfileId` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 200]`. + /// The range of component `y` is `[1, 10]`. + fn create_profile(x: u32, _y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `182` + // Estimated: `3694` + // Minimum execution time: 59_513_000 picoseconds. + Weight::from_parts(60_845_441, 3694) + // Standard Error: 269 + .saturating_add(Weight::from_parts(1_122, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) } - - fn force_create_profile(x: u32, y: u32, ) -> Weight { - todo!() + /// Storage: `DataPreservers::NextProfileId` (r:1 w:1) + /// Proof: `DataPreservers::NextProfileId` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 200]`. + /// The range of component `y` is `[1, 10]`. + fn force_create_profile(x: u32, _y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `79` + // Estimated: `3544` + // Minimum execution time: 15_994_000 picoseconds. + Weight::from_parts(16_661_778, 3544) + // Standard Error: 116 + .saturating_add(Weight::from_parts(1_112, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } - - fn update_profile(x: u32, y: u32, ) -> Weight { - todo!() + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) + /// The range of component `x` is `[1, 200]`. + /// The range of component `y` is `[1, 10]`. + fn update_profile(x: u32, _y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `319` + // Estimated: `3784` + // Minimum execution time: 58_515_000 picoseconds. + Weight::from_parts(59_596_525, 3784) + // Standard Error: 181 + .saturating_add(Weight::from_parts(1_609, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } - - fn force_update_profile(x: u32, y: u32, ) -> Weight { - todo!() + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) + /// The range of component `x` is `[1, 200]`. + /// The range of component `y` is `[1, 10]`. + fn force_update_profile(x: u32, _y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `319` + // Estimated: `3784` + // Minimum execution time: 50_727_000 picoseconds. + Weight::from_parts(52_180_969, 3784) + // Standard Error: 179 + .saturating_add(Weight::from_parts(1_243, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } - + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) fn delete_profile() -> Weight { - todo!() + // Proof Size summary in bytes: + // Measured: `319` + // Estimated: `3784` + // Minimum execution time: 50_322_000 picoseconds. + Weight::from_parts(51_297_000, 3784) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } - + /// Storage: `DataPreservers::Profiles` (r:1 w:1) + /// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(229), added: 2704, mode: `MaxEncodedLen`) fn force_delete_profile() -> Weight { - todo!() + // Proof Size summary in bytes: + // Measured: `319` + // Estimated: `3784` + // Minimum execution time: 49_809_000 picoseconds. + Weight::from_parts(50_842_000, 3784) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) } } \ No newline at end of file From 8e42a75fddd176c1a0e622ed8ae853addfc390f4 Mon Sep 17 00:00:00 2001 From: nanocryk <6422796+nanocryk@users.noreply.github.com> Date: Tue, 21 May 2024 13:37:51 +0200 Subject: [PATCH 07/13] typescript api --- .../dancebox/interfaces/augment-api-consts.ts | 14 +- .../dancebox/interfaces/augment-api-errors.ts | 10 +- .../dancebox/interfaces/augment-api-events.ts | 31 +- .../dancebox/interfaces/augment-api-query.ts | 39 +- .../interfaces/augment-api-runtime.ts | 31 +- .../src/dancebox/interfaces/augment-api-tx.ts | 88 ++- .../src/dancebox/interfaces/lookup.ts | 471 ++++++++-------- .../src/dancebox/interfaces/registry.ts | 10 +- .../src/dancebox/interfaces/types-lookup.ts | 528 ++++++++++-------- .../flashbox/interfaces/augment-api-consts.ts | 1 + .../flashbox/interfaces/augment-api-errors.ts | 2 + .../flashbox/interfaces/augment-api-events.ts | 15 + .../flashbox/interfaces/augment-api-query.ts | 16 +- .../interfaces/augment-api-runtime.ts | 31 +- .../src/flashbox/interfaces/augment-api-tx.ts | 58 ++ .../src/flashbox/interfaces/lookup.ts | 207 ++++--- .../src/flashbox/interfaces/registry.ts | 8 + .../src/flashbox/interfaces/types-lookup.ts | 223 +++++--- 18 files changed, 1078 insertions(+), 705 deletions(-) diff --git a/typescript-api/src/dancebox/interfaces/augment-api-consts.ts b/typescript-api/src/dancebox/interfaces/augment-api-consts.ts index 983e22c32..158a7a8a8 100644 --- a/typescript-api/src/dancebox/interfaces/augment-api-consts.ts +++ b/typescript-api/src/dancebox/interfaces/augment-api-consts.ts @@ -16,7 +16,6 @@ import type { SpVersionRuntimeVersion, SpWeightsRuntimeDbWeight, SpWeightsWeightV2Weight, - XcmV3Junctions, } from "@polkadot/types/lookup"; export type __AugmentedConst = AugmentedConst; @@ -64,6 +63,7 @@ declare module "@polkadot/api-base/types/consts" { dataPreservers: { maxBootNodes: u32 & AugmentedConst; maxBootNodeUrlLen: u32 & AugmentedConst; + maxParaIdsVecLen: u32 & AugmentedConst; /** Generic const */ [key: string]: Codec; }; @@ -373,16 +373,8 @@ declare module "@polkadot/api-base/types/consts" { [key: string]: Codec; }; xcmCoreBuyer: { - /** - * Additional ttl for in flight orders (total would be CoreBuyingXCMQueryTtl + AdditionalTtlForInflightOrders) - * after which the in flight orders can be cleaned up by anyone. - */ - additionalTtlForInflightOrders: u32 & AugmentedConst; - /** TTL to be used in xcm's notify query */ - coreBuyingXCMQueryTtl: u32 & AugmentedConst; - /** TTL for pending blocks entry, which prevents anyone to submit another core buying xcm. */ - pendingBlocksTtl: u32 & AugmentedConst; - universalLocation: XcmV3Junctions & AugmentedConst; + /** Limit how many in-flight XCM requests can be sent to the relay chain in one block. */ + maxParathreads: u32 & AugmentedConst; /** * A configuration for base priority of unsigned transactions. * diff --git a/typescript-api/src/dancebox/interfaces/augment-api-errors.ts b/typescript-api/src/dancebox/interfaces/augment-api-errors.ts index caaaa9ff8..8a01c5514 100644 --- a/typescript-api/src/dancebox/interfaces/augment-api-errors.ts +++ b/typescript-api/src/dancebox/interfaces/augment-api-errors.ts @@ -74,8 +74,10 @@ declare module "@polkadot/api-base/types/errors" { [key: string]: AugmentedError; }; dataPreservers: { + NextProfileIdShouldBeAvailable: AugmentedError; /** This container chain does not have any boot nodes */ NoBootNodes: AugmentedError; + UnknownProfileId: AugmentedError; /** Generic error */ [key: string]: AugmentedError; }; @@ -543,8 +545,6 @@ declare module "@polkadot/api-base/types/errors" { [key: string]: AugmentedError; }; xcmCoreBuyer: { - /** Block production is pending for para id with successfully placed order */ - BlockProductionPending: AugmentedError; /** This collator is not assigned to this parathread */ CollatorNotAssigned: AugmentedError; ErrorDeliveringXCM: AugmentedError; @@ -552,8 +552,6 @@ declare module "@polkadot/api-base/types/errors" { /** There are too many in-flight orders, buying cores will not work until some of those orders finish. */ InFlightLimitReached: AugmentedError; InvalidProof: AugmentedError; - /** Inverting location from destination point of view failed */ - LocationInversionFailed: AugmentedError; /** There are no collators assigned to this parathread, so no point in buying a core */ NoAssignedCollators: AugmentedError; /** The para id is not a parathread */ @@ -562,10 +560,6 @@ declare module "@polkadot/api-base/types/errors" { OrderAlreadyExists: AugmentedError; /** Converting a multilocation into a relay relative multilocation failed */ ReanchorFailed: AugmentedError; - /** Modifying XCM to report the result of XCM failed */ - ReportNotifyingSetupFailed: AugmentedError; - /** Unexpected XCM response */ - UnexpectedXCMResponse: AugmentedError; /** * The `XcmWeights` storage has not been set. This must have been set by root with the value of the relay chain * xcm call weight and extrinsic weight diff --git a/typescript-api/src/dancebox/interfaces/augment-api-events.ts b/typescript-api/src/dancebox/interfaces/augment-api-events.ts index f652da67f..6a61e7eab 100644 --- a/typescript-api/src/dancebox/interfaces/augment-api-events.ts +++ b/typescript-api/src/dancebox/interfaces/augment-api-events.ts @@ -156,6 +156,21 @@ declare module "@polkadot/api-base/types/events" { dataPreservers: { /** The list of boot_nodes changed. */ BootNodesChanged: AugmentedEvent; + ProfileCreated: AugmentedEvent< + ApiType, + [account: AccountId32, profileId: u64, deposit: u128], + { account: AccountId32; profileId: u64; deposit: u128 } + >; + ProfileDeleted: AugmentedEvent< + ApiType, + [profileId: u64, releasedDeposit: u128], + { profileId: u64; releasedDeposit: u128 } + >; + ProfileUpdated: AugmentedEvent< + ApiType, + [profileId: u64, oldDeposit: u128, newDeposit: u128], + { profileId: u64; oldDeposit: u128; newDeposit: u128 } + >; /** Generic event */ [key: string]: AugmentedEvent; }; @@ -1303,21 +1318,7 @@ declare module "@polkadot/api-base/types/events" { }; xcmCoreBuyer: { /** An XCM message to buy a core for this parathread has been sent to the relay chain. */ - BuyCoreXcmSent: AugmentedEvent< - ApiType, - [paraId: u32, transactionStatusQueryId: u64], - { paraId: u32; transactionStatusQueryId: u64 } - >; - /** We cleaned up expired in flight orders entries. */ - CleanedUpExpiredInFlightOrderEntries: AugmentedEvent], { paraIds: Vec }>; - /** We cleaned up expired pending blocks entries. */ - CleanedUpExpiredPendingBlocksEntries: AugmentedEvent], { paraIds: Vec }>; - /** We received response for xcm */ - ReceivedBuyCoreXCMResult: AugmentedEvent< - ApiType, - [paraId: u32, response: XcmV3Response], - { paraId: u32; response: XcmV3Response } - >; + BuyCoreXcmSent: AugmentedEvent; /** Generic event */ [key: string]: AugmentedEvent; }; diff --git a/typescript-api/src/dancebox/interfaces/augment-api-query.ts b/typescript-api/src/dancebox/interfaces/augment-api-query.ts index 28172c474..77ec32b49 100644 --- a/typescript-api/src/dancebox/interfaces/augment-api-query.ts +++ b/typescript-api/src/dancebox/interfaces/augment-api-query.ts @@ -53,6 +53,7 @@ import type { PalletBalancesIdAmountRuntimeHoldReason, PalletBalancesReserveData, PalletConfigurationHostConfiguration, + PalletDataPreserversRegisteredProfile, PalletIdentityAuthorityProperties, PalletIdentityRegistrarInfo, PalletIdentityRegistration, @@ -70,7 +71,6 @@ import type { PalletTransactionPaymentReleases, PalletTreasuryProposal, PalletTreasurySpendStatus, - PalletXcmCoreBuyerInFlightCoreBuyingOrder, PalletXcmCoreBuyerRelayXcmWeightConfigInner, PalletXcmQueryStatus, PalletXcmRemoteLockedFungibleRecord, @@ -294,6 +294,13 @@ declare module "@polkadot/api-base/types/storage" { dataPreservers: { bootNodes: AugmentedQuery Observable>, [u32]> & QueryableStorageEntry; + nextProfileId: AugmentedQuery Observable, []> & QueryableStorageEntry; + profiles: AugmentedQuery< + ApiType, + (arg: u64 | AnyNumber | Uint8Array) => Observable>, + [u64] + > & + QueryableStorageEntry; /** Generic query */ [key: string]: QueryableStorageEntry; }; @@ -959,12 +966,8 @@ declare module "@polkadot/api-base/types/storage" { QueryableStorageEntry; pendingToRemove: AugmentedQuery Observable]>>>, []> & QueryableStorageEntry; - pendingVerification: AugmentedQuery< - ApiType, - (arg: u32 | AnyNumber | Uint8Array) => Observable>, - [u32] - > & - QueryableStorageEntry; + pendingVerification: AugmentedQuery Observable>, []> & + QueryableStorageEntry; registeredParaIds: AugmentedQuery Observable>, []> & QueryableStorageEntry; /** @@ -1277,26 +1280,8 @@ declare module "@polkadot/api-base/types/storage" { * Set of parathreads that have already sent an XCM message to buy a core recently. Used to avoid 2 collators * buying a core at the same time, because it is only possible to buy 1 core in 1 relay block for the same parathread. */ - inFlightOrders: AugmentedQuery< - ApiType, - (arg: u32 | AnyNumber | Uint8Array) => Observable>, - [u32] - > & - QueryableStorageEntry; - /** Number of pending blocks */ - pendingBlocks: AugmentedQuery< - ApiType, - (arg: u32 | AnyNumber | Uint8Array) => Observable>, - [u32] - > & - QueryableStorageEntry; - /** Mapping of QueryId to ParaId */ - queryIdToParaId: AugmentedQuery< - ApiType, - (arg: u64 | AnyNumber | Uint8Array) => Observable>, - [u64] - > & - QueryableStorageEntry; + inFlightOrders: AugmentedQuery Observable>, []> & + QueryableStorageEntry; /** * This must be set by root with the value of the relay chain xcm call weight and extrinsic weight limit. This is * a storage item because relay chain weights can change, so we need to be able to adjust them without doing a diff --git a/typescript-api/src/dancebox/interfaces/augment-api-runtime.ts b/typescript-api/src/dancebox/interfaces/augment-api-runtime.ts index dd2fc6f57..efcd5afc0 100644 --- a/typescript-api/src/dancebox/interfaces/augment-api-runtime.ts +++ b/typescript-api/src/dancebox/interfaces/augment-api-runtime.ts @@ -6,8 +6,9 @@ import "@polkadot/api-base/types/calls"; import type { ApiTypes, AugmentedCall, DecoratedCallBase } from "@polkadot/api-base/types"; -import type { Bytes, Null, Option, Vec, u32 } from "@polkadot/types-codec"; +import type { Bytes, Null, Option, Result, Text, Vec, bool, u32 } from "@polkadot/types-codec"; import type { AnyNumber, ITuple } from "@polkadot/types-codec/types"; +import type { BenchmarkBatch, BenchmarkConfig, BenchmarkList } from "@polkadot/types/interfaces/benchmark"; import type { CheckInherentsResult, InherentData } from "@polkadot/types/interfaces/blockbuilder"; import type { BlockHash } from "@polkadot/types/interfaces/chain"; import type { AuthorityId } from "@polkadot/types/interfaces/consensus"; @@ -23,6 +24,7 @@ import type { Index, KeyTypeId, SlotDuration, + StorageInfo, Weight, } from "@polkadot/types/interfaces/runtime"; import type { RuntimeVersion } from "@polkadot/types/interfaces/state"; @@ -51,6 +53,33 @@ declare module "@polkadot/api-base/types/calls" { /** Generic call */ [key: string]: DecoratedCallBase; }; + /** 0x67f4b8fba858782a/1 */ + benchmark: { + /** Get the benchmark metadata available for this runtime. */ + benchmarkMetadata: AugmentedCall< + ApiType, + (extra: bool | boolean | Uint8Array) => Observable, Vec]>> + >; + /** Dispatch the given benchmark. */ + dispatchBenchmark: AugmentedCall< + ApiType, + ( + config: + | BenchmarkConfig + | { + pallet?: any; + benchmark?: any; + selectedComponents?: any; + verify?: any; + internalRepeats?: any; + } + | string + | Uint8Array + ) => Observable, Text>> + >; + /** Generic call */ + [key: string]: DecoratedCallBase; + }; /** 0x40fe3ad401f8959a/6 */ blockBuilder: { /** Apply the given extrinsic. */ diff --git a/typescript-api/src/dancebox/interfaces/augment-api-tx.ts b/typescript-api/src/dancebox/interfaces/augment-api-tx.ts index b1d285434..0ab71c28c 100644 --- a/typescript-api/src/dancebox/interfaces/augment-api-tx.ts +++ b/typescript-api/src/dancebox/interfaces/augment-api-tx.ts @@ -23,6 +23,7 @@ import type { DanceboxRuntimeSessionKeys, DanceboxRuntimeStreamPaymentAssetId, DanceboxRuntimeXcmConfigRelayChain, + PalletDataPreserversProfile, PalletIdentityJudgement, PalletIdentityLegacyIdentityInfo, PalletMultisigTimepoint, @@ -41,7 +42,6 @@ import type { TpAuthorNotingInherentOwnParachainInherentData, TpContainerChainGenesisDataContainerChainGenesisData, TpTraitsSlotFrequency, - XcmV3Response, XcmV3WeightLimit, XcmVersionedMultiAssets, XcmVersionedMultiLocation, @@ -287,6 +287,51 @@ declare module "@polkadot/api-base/types/submittable" { [key: string]: SubmittableExtrinsicFunction; }; dataPreservers: { + /** See [`Pallet::create_profile`]. */ + createProfile: AugmentedSubmittable< + ( + profile: + | PalletDataPreserversProfile + | { url?: any; limitedToParaIds?: any; mode?: any } + | string + | Uint8Array + ) => SubmittableExtrinsic, + [PalletDataPreserversProfile] + >; + /** See [`Pallet::delete_profile`]. */ + deleteProfile: AugmentedSubmittable< + (profileId: u64 | AnyNumber | Uint8Array) => SubmittableExtrinsic, + [u64] + >; + /** See [`Pallet::force_create_profile`]. */ + forceCreateProfile: AugmentedSubmittable< + ( + profile: + | PalletDataPreserversProfile + | { url?: any; limitedToParaIds?: any; mode?: any } + | string + | Uint8Array, + forAccount: AccountId32 | string | Uint8Array + ) => SubmittableExtrinsic, + [PalletDataPreserversProfile, AccountId32] + >; + /** See [`Pallet::force_delete_profile`]. */ + forceDeleteProfile: AugmentedSubmittable< + (profileId: u64 | AnyNumber | Uint8Array) => SubmittableExtrinsic, + [u64] + >; + /** See [`Pallet::force_update_profile`]. */ + forceUpdateProfile: AugmentedSubmittable< + ( + profileId: u64 | AnyNumber | Uint8Array, + profile: + | PalletDataPreserversProfile + | { url?: any; limitedToParaIds?: any; mode?: any } + | string + | Uint8Array + ) => SubmittableExtrinsic, + [u64, PalletDataPreserversProfile] + >; /** See [`Pallet::set_boot_nodes`]. */ setBootNodes: AugmentedSubmittable< ( @@ -295,6 +340,18 @@ declare module "@polkadot/api-base/types/submittable" { ) => SubmittableExtrinsic, [u32, Vec] >; + /** See [`Pallet::update_profile`]. */ + updateProfile: AugmentedSubmittable< + ( + profileId: u64 | AnyNumber | Uint8Array, + profile: + | PalletDataPreserversProfile + | { url?: any; limitedToParaIds?: any; mode?: any } + | string + | Uint8Array + ) => SubmittableExtrinsic, + [u64, PalletDataPreserversProfile] + >; /** Generic tx */ [key: string]: SubmittableExtrinsicFunction; }; @@ -2189,40 +2246,11 @@ declare module "@polkadot/api-base/types/submittable" { ) => SubmittableExtrinsic, [u32, PalletXcmCoreBuyerBuyCoreCollatorProof] >; - /** See [`Pallet::clean_up_expired_in_flight_orders`]. */ - cleanUpExpiredInFlightOrders: AugmentedSubmittable< - (expiredInFlightOrders: Vec | (u32 | AnyNumber | Uint8Array)[]) => SubmittableExtrinsic, - [Vec] - >; - /** See [`Pallet::clean_up_expired_pending_blocks`]. */ - cleanUpExpiredPendingBlocks: AugmentedSubmittable< - ( - expiredPendingBlocksParaId: Vec | (u32 | AnyNumber | Uint8Array)[] - ) => SubmittableExtrinsic, - [Vec] - >; /** See [`Pallet::force_buy_core`]. */ forceBuyCore: AugmentedSubmittable< (paraId: u32 | AnyNumber | Uint8Array) => SubmittableExtrinsic, [u32] >; - /** See [`Pallet::query_response`]. */ - queryResponse: AugmentedSubmittable< - ( - queryId: u64 | AnyNumber | Uint8Array, - response: - | XcmV3Response - | { Null: any } - | { Assets: any } - | { ExecutionResult: any } - | { Version: any } - | { PalletsInfo: any } - | { DispatchResult: any } - | string - | Uint8Array - ) => SubmittableExtrinsic, - [u64, XcmV3Response] - >; /** See [`Pallet::set_relay_chain`]. */ setRelayChain: AugmentedSubmittable< ( diff --git a/typescript-api/src/dancebox/interfaces/lookup.ts b/typescript-api/src/dancebox/interfaces/lookup.ts index 3c583e4ce..51f16bacf 100644 --- a/typescript-api/src/dancebox/interfaces/lookup.ts +++ b/typescript-api/src/dancebox/interfaces/lookup.ts @@ -655,6 +655,20 @@ export default { BootNodesChanged: { paraId: "u32", }, + ProfileCreated: { + account: "AccountId32", + profileId: "u64", + deposit: "u128", + }, + ProfileUpdated: { + profileId: "u64", + oldDeposit: "u128", + newDeposit: "u128", + }, + ProfileDeleted: { + profileId: "u64", + releasedDeposit: "u128", + }, }, }, /** Lookup68: pallet_invulnerables::pallet::Event */ @@ -1773,25 +1787,14 @@ export default { _enum: { BuyCoreXcmSent: { paraId: "u32", - transactionStatusQueryId: "u64", - }, - ReceivedBuyCoreXCMResult: { - paraId: "u32", - response: "XcmV3Response", - }, - CleanedUpExpiredPendingBlocksEntries: { - paraIds: "Vec", - }, - CleanedUpExpiredInFlightOrderEntries: { - paraIds: "Vec", }, }, }, - /** Lookup144: pallet_root_testing::pallet::Event */ + /** Lookup143: pallet_root_testing::pallet::Event */ PalletRootTestingEvent: { _enum: ["DefensiveTestCall"], }, - /** Lookup145: frame_system::Phase */ + /** Lookup144: frame_system::Phase */ FrameSystemPhase: { _enum: { ApplyExtrinsic: "u32", @@ -1799,17 +1802,17 @@ export default { Initialization: "Null", }, }, - /** Lookup149: frame_system::LastRuntimeUpgradeInfo */ + /** Lookup148: frame_system::LastRuntimeUpgradeInfo */ FrameSystemLastRuntimeUpgradeInfo: { specVersion: "Compact", specName: "Text", }, - /** Lookup151: frame_system::CodeUpgradeAuthorization */ + /** Lookup150: frame_system::CodeUpgradeAuthorization */ FrameSystemCodeUpgradeAuthorization: { codeHash: "H256", checkVersion: "bool", }, - /** Lookup152: frame_system::pallet::Call */ + /** Lookup151: frame_system::pallet::Call */ FrameSystemCall: { _enum: { remark: { @@ -1852,41 +1855,41 @@ export default { }, }, }, - /** Lookup156: frame_system::limits::BlockWeights */ + /** Lookup155: frame_system::limits::BlockWeights */ FrameSystemLimitsBlockWeights: { baseBlock: "SpWeightsWeightV2Weight", maxBlock: "SpWeightsWeightV2Weight", perClass: "FrameSupportDispatchPerDispatchClassWeightsPerClass", }, - /** Lookup157: frame_support::dispatch::PerDispatchClass */ + /** Lookup156: frame_support::dispatch::PerDispatchClass */ FrameSupportDispatchPerDispatchClassWeightsPerClass: { normal: "FrameSystemLimitsWeightsPerClass", operational: "FrameSystemLimitsWeightsPerClass", mandatory: "FrameSystemLimitsWeightsPerClass", }, - /** Lookup158: frame_system::limits::WeightsPerClass */ + /** Lookup157: frame_system::limits::WeightsPerClass */ FrameSystemLimitsWeightsPerClass: { baseExtrinsic: "SpWeightsWeightV2Weight", maxExtrinsic: "Option", maxTotal: "Option", reserved: "Option", }, - /** Lookup160: frame_system::limits::BlockLength */ + /** Lookup159: frame_system::limits::BlockLength */ FrameSystemLimitsBlockLength: { max: "FrameSupportDispatchPerDispatchClassU32", }, - /** Lookup161: frame_support::dispatch::PerDispatchClass */ + /** Lookup160: frame_support::dispatch::PerDispatchClass */ FrameSupportDispatchPerDispatchClassU32: { normal: "u32", operational: "u32", mandatory: "u32", }, - /** Lookup162: sp_weights::RuntimeDbWeight */ + /** Lookup161: sp_weights::RuntimeDbWeight */ SpWeightsRuntimeDbWeight: { read: "u64", write: "u64", }, - /** Lookup163: sp_version::RuntimeVersion */ + /** Lookup162: sp_version::RuntimeVersion */ SpVersionRuntimeVersion: { specName: "Text", implName: "Text", @@ -1897,7 +1900,7 @@ export default { transactionVersion: "u32", stateVersion: "u8", }, - /** Lookup167: frame_system::pallet::Error */ + /** Lookup166: frame_system::pallet::Error */ FrameSystemError: { _enum: [ "InvalidSpecName", @@ -1910,49 +1913,49 @@ export default { "Unauthorized", ], }, - /** Lookup169: cumulus_pallet_parachain_system::unincluded_segment::Ancestor */ + /** Lookup168: cumulus_pallet_parachain_system::unincluded_segment::Ancestor */ CumulusPalletParachainSystemUnincludedSegmentAncestor: { usedBandwidth: "CumulusPalletParachainSystemUnincludedSegmentUsedBandwidth", paraHeadHash: "Option", consumedGoAheadSignal: "Option", }, - /** Lookup170: cumulus_pallet_parachain_system::unincluded_segment::UsedBandwidth */ + /** Lookup169: cumulus_pallet_parachain_system::unincluded_segment::UsedBandwidth */ CumulusPalletParachainSystemUnincludedSegmentUsedBandwidth: { umpMsgCount: "u32", umpTotalBytes: "u32", hrmpOutgoing: "BTreeMap", }, - /** Lookup172: cumulus_pallet_parachain_system::unincluded_segment::HrmpChannelUpdate */ + /** Lookup171: cumulus_pallet_parachain_system::unincluded_segment::HrmpChannelUpdate */ CumulusPalletParachainSystemUnincludedSegmentHrmpChannelUpdate: { msgCount: "u32", totalBytes: "u32", }, - /** Lookup177: polkadot_primitives::v6::UpgradeGoAhead */ + /** Lookup176: polkadot_primitives::v6::UpgradeGoAhead */ PolkadotPrimitivesV6UpgradeGoAhead: { _enum: ["Abort", "GoAhead"], }, - /** Lookup178: cumulus_pallet_parachain_system::unincluded_segment::SegmentTracker */ + /** Lookup177: cumulus_pallet_parachain_system::unincluded_segment::SegmentTracker */ CumulusPalletParachainSystemUnincludedSegmentSegmentTracker: { usedBandwidth: "CumulusPalletParachainSystemUnincludedSegmentUsedBandwidth", hrmpWatermark: "Option", consumedGoAheadSignal: "Option", }, - /** Lookup179: polkadot_primitives::v6::PersistedValidationData */ + /** Lookup178: polkadot_primitives::v6::PersistedValidationData */ PolkadotPrimitivesV6PersistedValidationData: { parentHead: "Bytes", relayParentNumber: "u32", relayParentStorageRoot: "H256", maxPovSize: "u32", }, - /** Lookup182: polkadot_primitives::v6::UpgradeRestriction */ + /** Lookup181: polkadot_primitives::v6::UpgradeRestriction */ PolkadotPrimitivesV6UpgradeRestriction: { _enum: ["Present"], }, - /** Lookup183: sp_trie::storage_proof::StorageProof */ + /** Lookup182: sp_trie::storage_proof::StorageProof */ SpTrieStorageProof: { trieNodes: "BTreeSet", }, - /** Lookup185: cumulus_pallet_parachain_system::relay_state_snapshot::MessagingStateSnapshot */ + /** Lookup184: cumulus_pallet_parachain_system::relay_state_snapshot::MessagingStateSnapshot */ CumulusPalletParachainSystemRelayStateSnapshotMessagingStateSnapshot: { dmqMqcHead: "H256", relayDispatchQueueRemainingCapacity: @@ -1960,12 +1963,12 @@ export default { ingressChannels: "Vec<(u32,PolkadotPrimitivesV6AbridgedHrmpChannel)>", egressChannels: "Vec<(u32,PolkadotPrimitivesV6AbridgedHrmpChannel)>", }, - /** Lookup186: cumulus_pallet_parachain_system::relay_state_snapshot::RelayDispatchQueueRemainingCapacity */ + /** Lookup185: cumulus_pallet_parachain_system::relay_state_snapshot::RelayDispatchQueueRemainingCapacity */ CumulusPalletParachainSystemRelayStateSnapshotRelayDispatchQueueRemainingCapacity: { remainingCount: "u32", remainingSize: "u32", }, - /** Lookup189: polkadot_primitives::v6::AbridgedHrmpChannel */ + /** Lookup188: polkadot_primitives::v6::AbridgedHrmpChannel */ PolkadotPrimitivesV6AbridgedHrmpChannel: { maxCapacity: "u32", maxTotalSize: "u32", @@ -1974,7 +1977,7 @@ export default { totalSize: "u32", mqcHead: "Option", }, - /** Lookup190: polkadot_primitives::v6::AbridgedHostConfiguration */ + /** Lookup189: polkadot_primitives::v6::AbridgedHostConfiguration */ PolkadotPrimitivesV6AbridgedHostConfiguration: { maxCodeSize: "u32", maxHeadDataSize: "u32", @@ -1987,17 +1990,17 @@ export default { validationUpgradeDelay: "u32", asyncBackingParams: "PolkadotPrimitivesV6AsyncBackingAsyncBackingParams", }, - /** Lookup191: polkadot_primitives::v6::async_backing::AsyncBackingParams */ + /** Lookup190: polkadot_primitives::v6::async_backing::AsyncBackingParams */ PolkadotPrimitivesV6AsyncBackingAsyncBackingParams: { maxCandidateDepth: "u32", allowedAncestryLen: "u32", }, - /** Lookup197: polkadot_core_primitives::OutboundHrmpMessage */ + /** Lookup196: polkadot_core_primitives::OutboundHrmpMessage */ PolkadotCorePrimitivesOutboundHrmpMessage: { recipient: "u32", data: "Bytes", }, - /** Lookup198: cumulus_pallet_parachain_system::pallet::Call */ + /** Lookup197: cumulus_pallet_parachain_system::pallet::Call */ CumulusPalletParachainSystemCall: { _enum: { set_validation_data: { @@ -2015,24 +2018,24 @@ export default { }, }, }, - /** Lookup199: cumulus_primitives_parachain_inherent::ParachainInherentData */ + /** Lookup198: cumulus_primitives_parachain_inherent::ParachainInherentData */ CumulusPrimitivesParachainInherentParachainInherentData: { validationData: "PolkadotPrimitivesV6PersistedValidationData", relayChainState: "SpTrieStorageProof", downwardMessages: "Vec", horizontalMessages: "BTreeMap>", }, - /** Lookup201: polkadot_core_primitives::InboundDownwardMessage */ + /** Lookup200: polkadot_core_primitives::InboundDownwardMessage */ PolkadotCorePrimitivesInboundDownwardMessage: { sentAt: "u32", msg: "Bytes", }, - /** Lookup204: polkadot_core_primitives::InboundHrmpMessage */ + /** Lookup203: polkadot_core_primitives::InboundHrmpMessage */ PolkadotCorePrimitivesInboundHrmpMessage: { sentAt: "u32", data: "Bytes", }, - /** Lookup207: cumulus_pallet_parachain_system::pallet::Error */ + /** Lookup206: cumulus_pallet_parachain_system::pallet::Error */ CumulusPalletParachainSystemError: { _enum: [ "OverlappingUpgrades", @@ -2045,7 +2048,7 @@ export default { "Unauthorized", ], }, - /** Lookup208: pallet_timestamp::pallet::Call */ + /** Lookup207: pallet_timestamp::pallet::Call */ PalletTimestampCall: { _enum: { set: { @@ -2053,9 +2056,9 @@ export default { }, }, }, - /** Lookup209: staging_parachain_info::pallet::Call */ + /** Lookup208: staging_parachain_info::pallet::Call */ StagingParachainInfoCall: "Null", - /** Lookup210: pallet_sudo::pallet::Call */ + /** Lookup209: pallet_sudo::pallet::Call */ PalletSudoCall: { _enum: { sudo: { @@ -2078,7 +2081,7 @@ export default { remove_key: "Null", }, }, - /** Lookup212: pallet_utility::pallet::Call */ + /** Lookup211: pallet_utility::pallet::Call */ PalletUtilityCall: { _enum: { batch: { @@ -2104,7 +2107,7 @@ export default { }, }, }, - /** Lookup214: dancebox_runtime::OriginCaller */ + /** Lookup213: dancebox_runtime::OriginCaller */ DanceboxRuntimeOriginCaller: { _enum: { system: "FrameSupportDispatchRawOrigin", @@ -2163,7 +2166,7 @@ export default { PolkadotXcm: "PalletXcmOrigin", }, }, - /** Lookup215: frame_support::dispatch::RawOrigin */ + /** Lookup214: frame_support::dispatch::RawOrigin */ FrameSupportDispatchRawOrigin: { _enum: { Root: "Null", @@ -2171,23 +2174,23 @@ export default { None: "Null", }, }, - /** Lookup216: cumulus_pallet_xcm::pallet::Origin */ + /** Lookup215: cumulus_pallet_xcm::pallet::Origin */ CumulusPalletXcmOrigin: { _enum: { Relay: "Null", SiblingParachain: "u32", }, }, - /** Lookup217: pallet_xcm::pallet::Origin */ + /** Lookup216: pallet_xcm::pallet::Origin */ PalletXcmOrigin: { _enum: { Xcm: "StagingXcmV3MultiLocation", Response: "StagingXcmV3MultiLocation", }, }, - /** Lookup218: sp_core::Void */ + /** Lookup217: sp_core::Void */ SpCoreVoid: "Null", - /** Lookup219: pallet_proxy::pallet::Call */ + /** Lookup218: pallet_proxy::pallet::Call */ PalletProxyCall: { _enum: { proxy: { @@ -2238,11 +2241,11 @@ export default { }, }, }, - /** Lookup223: pallet_maintenance_mode::pallet::Call */ + /** Lookup222: pallet_maintenance_mode::pallet::Call */ PalletMaintenanceModeCall: { _enum: ["enter_maintenance_mode", "resume_normal_operation"], }, - /** Lookup224: pallet_tx_pause::pallet::Call */ + /** Lookup223: pallet_tx_pause::pallet::Call */ PalletTxPauseCall: { _enum: { pause: { @@ -2253,7 +2256,7 @@ export default { }, }, }, - /** Lookup225: pallet_balances::pallet::Call */ + /** Lookup224: pallet_balances::pallet::Call */ PalletBalancesCall: { _enum: { transfer_allow_death: { @@ -2288,7 +2291,7 @@ export default { }, }, }, - /** Lookup226: pallet_stream_payment::pallet::Call */ + /** Lookup225: pallet_stream_payment::pallet::Call */ PalletStreamPaymentCall: { _enum: { open_stream: { @@ -2323,7 +2326,7 @@ export default { }, }, }, - /** Lookup227: pallet_stream_payment::pallet::ChangeKind