From 8efe5221348960c2eba1411e05f9802859745ca1 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 6 Oct 2023 01:18:02 +0200 Subject: [PATCH 01/31] Replace `Currency` with funginle traits --- substrate/frame/nicks/src/lib.rs | 65 +++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/substrate/frame/nicks/src/lib.rs b/substrate/frame/nicks/src/lib.rs index 0a68f7d7142d..ead492d77b28 100644 --- a/substrate/frame/nicks/src/lib.rs +++ b/substrate/frame/nicks/src/lib.rs @@ -39,15 +39,18 @@ #![deny(missing_docs)] #![cfg_attr(not(feature = "std"), no_std)] -use frame_support::traits::{Currency, OnUnbalanced, ReservableCurrency}; +use frame_support::traits::{ + fungible::{hold::Balanced as FnBalanced, Inspect as FnInspect, MutateHold as FnMutateHold}, + tokens::{fungible::Credit, Precision}, + OnUnbalanced, +}; pub use pallet::*; -use sp_runtime::traits::{StaticLookup, Zero}; +use sp_runtime::traits::{Saturating, StaticLookup, Zero}; use sp_std::prelude::*; type AccountIdOf = ::AccountId; -type BalanceOf = <::Currency as Currency>>::Balance; -type NegativeImbalanceOf = - <::Currency as Currency>>::NegativeImbalance; +type BalanceOf = <::Currency as FnInspect>>::Balance; +type CreditOf = Credit<::AccountId, ::Currency>; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; #[frame_support::pallet] @@ -56,20 +59,32 @@ pub mod pallet { use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; + /// A reason for this pallet placing a hold on funds. + #[pallet::composite_enum] + pub enum HoldReason { + /// The funds are held as deposit to start the referendum's decision phase. + /// The funds are held as deposit for doing a system-sponsored fast unstake. + Nicks, + } + #[pallet::config] pub trait Config: frame_system::Config { /// The overarching event type. type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// The currency trait. - type Currency: ReservableCurrency; + type Currency: FnMutateHold + + FnBalanced; + + /// The overarching runtime hold reason. + type RuntimeHoldReason: From; /// Reservation fee. #[pallet::constant] type ReservationFee: Get>; /// What to do with slashed funds. - type Slashed: OnUnbalanced>; + type OnSlash: OnUnbalanced>; /// The origin which may forcibly set or remove a name. Root can always do this. type ForceOrigin: EnsureOrigin; @@ -164,7 +179,7 @@ pub mod pallet { deposit } else { let deposit = T::ReservationFee::get(); - T::Currency::reserve(&sender, deposit)?; + T::Currency::hold(&HoldReason::Nicks.into(), &sender, deposit)?; Self::deposit_event(Event::::NameSet { who: sender.clone() }); deposit }; @@ -186,10 +201,14 @@ pub mod pallet { let deposit = >::take(&sender).ok_or(Error::::Unnamed)?.1; - let err_amount = T::Currency::unreserve(&sender, deposit); - debug_assert!(err_amount.is_zero()); + let released_deposit = T::Currency::release( + &HoldReason::Nicks.into(), + &sender, + deposit, + Precision::Exact, + )?; - Self::deposit_event(Event::::NameCleared { who: sender, deposit }); + Self::deposit_event(Event::::NameCleared { who: sender, deposit: released_deposit }); Ok(()) } @@ -212,9 +231,18 @@ pub mod pallet { // Grab their deposit (and check that they have one). let deposit = >::take(&target).ok_or(Error::::Unnamed)?.1; // Slash their deposit from them. - T::Slashed::on_unbalanced(T::Currency::slash_reserved(&target, deposit).0); + let (imbalance, non_slashed) = >::slash( + &HoldReason::Nicks.into(), + &target, + deposit, + ); + // Handle slashed amount. + T::OnSlash::on_unbalanced(imbalance); - Self::deposit_event(Event::::NameKilled { target, deposit }); + Self::deposit_event(Event::::NameKilled { + target, + deposit: deposit.saturating_sub(non_slashed), + }); Ok(()) } @@ -261,6 +289,8 @@ mod tests { use sp_runtime::{ traits::{BadOrigin, BlakeTwo256, IdentityLookup}, BuildStorage, + DispatchError::Token, + TokenError::FundsUnavailable, }; type Block = frame_system::mocking::MockBlock; @@ -312,8 +342,8 @@ mod tests { type WeightInfo = (); type FreezeIdentifier = (); type MaxFreezes = (); - type RuntimeHoldReason = (); - type MaxHolds = (); + type RuntimeHoldReason = RuntimeHoldReason; + type MaxHolds = ConstU32<1>; } ord_parameter_types! { @@ -322,8 +352,9 @@ mod tests { impl Config for Test { type RuntimeEvent = RuntimeEvent; type Currency = Balances; + type RuntimeHoldReason = RuntimeHoldReason; type ReservationFee = ConstU64<2>; - type Slashed = (); + type OnSlash = (); type ForceOrigin = EnsureSignedBy; type MinLength = ConstU32<3>; type MaxLength = ConstU32<16>; @@ -400,7 +431,7 @@ mod tests { assert_noop!( Nicks::set_name(RuntimeOrigin::signed(3), b"Dave".to_vec()), - pallet_balances::Error::::InsufficientBalance + Token(FundsUnavailable) ); assert_noop!( From 63a99fef9ed33e22d741ae482eca073fa058bb97 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 6 Oct 2023 10:31:43 +0200 Subject: [PATCH 02/31] Use TestDefaultConfig --- Cargo.lock | 1 - substrate/frame/nicks/Cargo.toml | 4 ---- substrate/frame/nicks/src/lib.rs | 39 ++++---------------------------- 3 files changed, 5 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 340587d268d7..a2751d87f849 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9836,7 +9836,6 @@ dependencies = [ "pallet-balances", "parity-scale-codec", "scale-info", - "sp-core", "sp-io", "sp-runtime", "sp-std", diff --git a/substrate/frame/nicks/Cargo.toml b/substrate/frame/nicks/Cargo.toml index c8e8fa0467a5..c8324496cab5 100644 --- a/substrate/frame/nicks/Cargo.toml +++ b/substrate/frame/nicks/Cargo.toml @@ -23,7 +23,6 @@ sp-std = { path = "../../primitives/std", default-features = false} [dev-dependencies] pallet-balances = { path = "../balances" } -sp-core = { path = "../../primitives/core" } [features] default = [ "std" ] @@ -31,9 +30,7 @@ std = [ "codec/std", "frame-support/std", "frame-system/std", - "pallet-balances/std", "scale-info/std", - "sp-core/std", "sp-io/std", "sp-runtime/std", "sp-std/std", @@ -41,6 +38,5 @@ std = [ try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", - "pallet-balances/try-runtime", "sp-runtime/try-runtime", ] diff --git a/substrate/frame/nicks/src/lib.rs b/substrate/frame/nicks/src/lib.rs index ead492d77b28..315593dbe0d7 100644 --- a/substrate/frame/nicks/src/lib.rs +++ b/substrate/frame/nicks/src/lib.rs @@ -281,13 +281,12 @@ mod tests { use crate as pallet_nicks; use frame_support::{ - assert_noop, assert_ok, ord_parameter_types, + assert_noop, assert_ok, ord_parameter_types, derive_impl, traits::{ConstU32, ConstU64}, }; use frame_system::EnsureSignedBy; - use sp_core::H256; use sp_runtime::{ - traits::{BadOrigin, BlakeTwo256, IdentityLookup}, + traits::BadOrigin, BuildStorage, DispatchError::Token, TokenError::FundsUnavailable, @@ -304,51 +303,23 @@ mod tests { } ); + #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type Nonce = u64; - type Hash = H256; - type RuntimeCall = RuntimeCall; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } + #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); type ReserveIdentifier = [u8; 8]; - type Balance = u64; - type RuntimeEvent = RuntimeEvent; - type DustRemoval = (); - type ExistentialDeposit = ConstU64<1>; type AccountStore = System; - type WeightInfo = (); - type FreezeIdentifier = (); - type MaxFreezes = (); - type RuntimeHoldReason = RuntimeHoldReason; type MaxHolds = ConstU32<1>; } ord_parameter_types! { pub const One: u64 = 1; } + impl Config for Test { type RuntimeEvent = RuntimeEvent; type Currency = Balances; From de57c658400b5723a49c579484ae9afeaf279542 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 6 Oct 2023 10:35:46 +0200 Subject: [PATCH 03/31] Fix --- substrate/frame/nicks/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/frame/nicks/Cargo.toml b/substrate/frame/nicks/Cargo.toml index c8324496cab5..c739611cb85c 100644 --- a/substrate/frame/nicks/Cargo.toml +++ b/substrate/frame/nicks/Cargo.toml @@ -38,5 +38,6 @@ std = [ try-runtime = [ "frame-support/try-runtime", "frame-system/try-runtime", + "pallet-balances/try-runtime", "sp-runtime/try-runtime", ] From ff2aa2f787db83b0665f206fa9c8f57b9207617f Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 6 Oct 2023 10:40:46 +0200 Subject: [PATCH 04/31] Fmt --- substrate/frame/nicks/src/lib.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/substrate/frame/nicks/src/lib.rs b/substrate/frame/nicks/src/lib.rs index 315593dbe0d7..6282a37f2347 100644 --- a/substrate/frame/nicks/src/lib.rs +++ b/substrate/frame/nicks/src/lib.rs @@ -281,15 +281,12 @@ mod tests { use crate as pallet_nicks; use frame_support::{ - assert_noop, assert_ok, ord_parameter_types, derive_impl, + assert_noop, assert_ok, derive_impl, ord_parameter_types, traits::{ConstU32, ConstU64}, }; use frame_system::EnsureSignedBy; use sp_runtime::{ - traits::BadOrigin, - BuildStorage, - DispatchError::Token, - TokenError::FundsUnavailable, + traits::BadOrigin, BuildStorage, DispatchError::Token, TokenError::FundsUnavailable, }; type Block = frame_system::mocking::MockBlock; From 546c532a376303dbf083aa78c13f03260263caba Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 9 Oct 2023 12:52:13 +0200 Subject: [PATCH 05/31] Fix for `pallet_alliance` --- substrate/frame/alliance/src/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index 82dbbe9c0bb9..6cca209fba38 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -49,7 +49,7 @@ parameter_types! { #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Test { type Block = Block; - type AccountData = pallet_balances::AccountData; + type AccountData = pallet_balances::AccountData; } parameter_types! { From 9fb54cf5f9b4bbeaec43997ef62a6cb298a9d48f Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 9 Oct 2023 13:04:57 +0200 Subject: [PATCH 06/31] Use TestDefaultConfig in `pallet_society` mock --- substrate/frame/society/src/mock.rs | 39 ++++------------------------- 1 file changed, 5 insertions(+), 34 deletions(-) diff --git a/substrate/frame/society/src/mock.rs b/substrate/frame/society/src/mock.rs index a318c2e794b7..05b5b63ae0fe 100644 --- a/substrate/frame/society/src/mock.rs +++ b/substrate/frame/society/src/mock.rs @@ -21,14 +21,13 @@ use super::*; use crate as pallet_society; use frame_support::{ - assert_noop, assert_ok, ord_parameter_types, parameter_types, + assert_noop, assert_ok, ord_parameter_types, parameter_types, derive_impl, traits::{ConstU32, ConstU64}, }; use frame_support_test::TestRandomness; use frame_system::EnsureSignedBy; -use sp_core::H256; use sp_runtime::{ - traits::{BlakeTwo256, IdentityLookup}, + traits::IdentityLookup, BuildStorage, }; @@ -58,46 +57,18 @@ ord_parameter_types! { pub const MaxBids: u32 = 10; } +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type RuntimeOrigin = RuntimeOrigin; - type Nonce = u64; - type Hash = H256; - type RuntimeCall = RuntimeCall; - type Hashing = BlakeTwo256; type AccountId = u128; - type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = ConstU64<250>; - type Version = (); - type PalletInfo = PalletInfo; - type OnNewAccount = (); - type OnKilledAccount = (); type AccountData = pallet_balances::AccountData; - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; + type Lookup = IdentityLookup; } +#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] impl pallet_balances::Config for Test { - type MaxLocks = (); - type MaxReserves = (); type ReserveIdentifier = [u8; 8]; - type Balance = u64; - type RuntimeEvent = RuntimeEvent; - type DustRemoval = (); - type ExistentialDeposit = ConstU64<1>; type AccountStore = System; - type WeightInfo = (); - type FreezeIdentifier = (); - type MaxFreezes = (); - type RuntimeHoldReason = (); - type MaxHolds = (); } impl Config for Test { From 2d6e04235e0b34f2f4917563454768741a30081e Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Tue, 10 Oct 2023 00:12:34 +0200 Subject: [PATCH 07/31] Use TestDefaultConfig in `pallet_state_trie_migration` mock --- substrate/frame/society/src/mock.rs | 7 +- .../frame/state-trie-migration/src/lib.rs | 75 +++++++++---------- 2 files changed, 36 insertions(+), 46 deletions(-) diff --git a/substrate/frame/society/src/mock.rs b/substrate/frame/society/src/mock.rs index 05b5b63ae0fe..3cdfe2dfddb2 100644 --- a/substrate/frame/society/src/mock.rs +++ b/substrate/frame/society/src/mock.rs @@ -21,15 +21,12 @@ use super::*; use crate as pallet_society; use frame_support::{ - assert_noop, assert_ok, ord_parameter_types, parameter_types, derive_impl, + assert_noop, assert_ok, derive_impl, ord_parameter_types, parameter_types, traits::{ConstU32, ConstU64}, }; use frame_support_test::TestRandomness; use frame_system::EnsureSignedBy; -use sp_runtime::{ - traits::IdentityLookup, - BuildStorage, -}; +use sp_runtime::{traits::IdentityLookup, BuildStorage}; use RuntimeOrigin as Origin; diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index 3e69b219bb52..94bdbdac38fe 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -441,19 +441,41 @@ pub mod pallet { #[pallet::pallet] pub struct Pallet(_); + /// Default implementations of [`DefaultConfig`], which can be used to implement [`Config`]. + pub mod config_preludes { + use super::*; + use frame_support::derive_impl; + + pub struct TestDefaultConfig; + + #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig, no_aggregated_types)] + impl frame_system::DefaultConfig for TestDefaultConfig {} + + #[frame_support::register_default_impl(TestDefaultConfig)] + impl DefaultConfig for TestDefaultConfig { + #[inject_runtime_type] + type RuntimeEvent = (); + type WeightInfo = (); + } + } + /// Configurations of this pallet. - #[pallet::config] + #[pallet::config(with_default)] pub trait Config: frame_system::Config { /// Origin that can control the configurations of this pallet. - type ControlOrigin: frame_support::traits::EnsureOrigin; + #[pallet::no_default] + type ControlOrigin: EnsureOrigin; /// Filter on which origin that trigger the manual migrations. + #[pallet::no_default] type SignedFilter: EnsureOrigin; /// The overarching event type. + #[pallet::no_default_bounds] type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// The currency provider type. + #[pallet::no_default] type Currency: Currency; /// Maximal number of bytes that a key can have. @@ -479,16 +501,19 @@ pub mod pallet { /// #[pallet::constant] + #[pallet::no_default] type MaxKeyLen: Get; /// The amount of deposit collected per item in advance, for signed migrations. /// /// This should reflect the average storage value size in the worse case. + #[pallet::no_default] type SignedDepositPerItem: Get>; /// The base value of [`Config::SignedDepositPerItem`]. /// /// Final deposit is `items * SignedDepositPerItem + SignedDepositBase`. + #[pallet::no_default] type SignedDepositBase: Get>; /// The weight information of this pallet. @@ -1051,8 +1076,8 @@ mod mock { use super::*; use crate as pallet_state_trie_migration; use frame_support::{ - parameter_types, - traits::{ConstU32, ConstU64, Hooks}, + derive_impl, parameter_types, + traits::{ConstU32, Hooks}, weights::Weight, }; use frame_system::{EnsureRoot, EnsureSigned}; @@ -1060,10 +1085,7 @@ mod mock { storage::{ChildInfo, StateVersion}, H256, }; - use sp_runtime::{ - traits::{BlakeTwo256, Header as _, IdentityLookup}, - BuildStorage, StorageChild, - }; + use sp_runtime::{traits::Header as _, BuildStorage, StorageChild}; type Block = frame_system::mocking::MockBlockU32; @@ -1081,30 +1103,11 @@ mod mock { pub const SS58Prefix: u8 = 42; } + #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; type Block = Block; - type RuntimeEvent = RuntimeEvent; type BlockHashCount = ConstU32<250>; - type DbWeight = (); - type Version = (); - type PalletInfo = PalletInfo; type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = SS58Prefix; - type OnSetCode = (); - type MaxConsumers = ConstU32<16>; } parameter_types! { @@ -1113,20 +1116,10 @@ mod mock { pub const MigrationMaxKeyLen: u32 = 512; } + #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] impl pallet_balances::Config for Test { - type Balance = u64; - type RuntimeEvent = RuntimeEvent; - type DustRemoval = (); - type ExistentialDeposit = ConstU64<1>; - type AccountStore = System; - type MaxLocks = (); - type MaxReserves = (); type ReserveIdentifier = [u8; 8]; - type WeightInfo = (); - type FreezeIdentifier = (); - type MaxFreezes = (); - type RuntimeHoldReason = (); - type MaxHolds = (); + type AccountStore = System; } /// Test only Weights for state migration. @@ -1156,8 +1149,8 @@ mod mock { } } + #[derive_impl(super::config_preludes::TestDefaultConfig as pallet_state_trie_migration::DefaultConfig)] impl pallet_state_trie_migration::Config for Test { - type RuntimeEvent = RuntimeEvent; type ControlOrigin = EnsureRoot; type Currency = Balances; type MaxKeyLen = MigrationMaxKeyLen; From 5abfa6c197d67629410edf98b0a1f8b3f7bd4752 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 22 Nov 2023 14:00:12 +0100 Subject: [PATCH 08/31] Change `Currency` to `fungible` traits --- substrate/frame/nicks/src/lib.rs | 17 +-- .../frame/state-trie-migration/src/lib.rs | 141 ++++++++++++------ .../frame/transaction-storage/src/mock.rs | 5 - 3 files changed, 105 insertions(+), 58 deletions(-) diff --git a/substrate/frame/nicks/src/lib.rs b/substrate/frame/nicks/src/lib.rs index 0ce8b65fae27..793d1f3230d7 100644 --- a/substrate/frame/nicks/src/lib.rs +++ b/substrate/frame/nicks/src/lib.rs @@ -40,16 +40,16 @@ #![cfg_attr(not(feature = "std"), no_std)] use frame_support::traits::{ - fungible::{hold::Balanced as FnBalanced, Inspect as FnInspect, MutateHold as FnMutateHold}, + fungible::{hold::Balanced as FunBalanced, Inspect as FunInspect, MutateHold as FunMutateHold}, tokens::{fungible::Credit, Precision}, OnUnbalanced, }; -pub use pallet::*; +use pallet::*; use sp_runtime::traits::{Saturating, StaticLookup, Zero}; use sp_std::prelude::*; type AccountIdOf = ::AccountId; -type BalanceOf = <::Currency as FnInspect>>::Balance; +type BalanceOf = <::Currency as FunInspect>>::Balance; type CreditOf = Credit<::AccountId, ::Currency>; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; @@ -73,8 +73,8 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// The currency trait. - type Currency: FnMutateHold - + FnBalanced; + type Currency: FunMutateHold + + FunBalanced; /// The overarching runtime hold reason. type RuntimeHoldReason: From; @@ -231,11 +231,8 @@ pub mod pallet { // Grab their deposit (and check that they have one). let deposit = >::take(&target).ok_or(Error::::Unnamed)?.1; // Slash their deposit from them. - let (imbalance, non_slashed) = >::slash( - &HoldReason::Nicks.into(), - &target, - deposit, - ); + let (imbalance, non_slashed) = + T::Currency::slash(&HoldReason::Nicks.into(), &target, deposit); // Handle slashed amount. T::OnSlash::on_unbalanced(imbalance); diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index 94bdbdac38fe..8b9b67ac129d 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -79,7 +79,14 @@ pub mod pallet { dispatch::{DispatchErrorWithPostInfo, PostDispatchInfo}, ensure, pallet_prelude::*, - traits::{Currency, Get}, + traits::{ + fungible::{ + hold::Balanced as FunBalanced, Inspect as FunInspect, + InspectHold as FunInspectHold, Mutate as FunMutate, MutateHold as FunMutateHold, + }, + tokens::{Fortitude, Preservation}, + Get, + }, }; use frame_system::{self, pallet_prelude::*}; use sp_core::{ @@ -92,7 +99,7 @@ pub mod pallet { use sp_std::{ops::Deref, prelude::*}; pub(crate) type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; + <::Currency as FunInspect<::AccountId>>::Balance; /// The progress of either the top or child keys. #[derive( @@ -455,10 +462,25 @@ pub mod pallet { impl DefaultConfig for TestDefaultConfig { #[inject_runtime_type] type RuntimeEvent = (); - type WeightInfo = (); + #[inject_runtime_type] + type RuntimeHoldReason = (); } } + /// A reason for this pallet placing a hold on funds. + #[pallet::composite_enum] + pub enum HoldReason { + /// The funds are held as deposit for slashing for `continue_migrate`. + #[codec(index = 0)] + SlashForContinueMigrate, + /// The funds are held as deposit for slashing for `migrate_custom_top`. + #[codec(index = 1)] + SlashForMigrateCustomTop, + /// The funds are held as deposit for slashing for `migrate_custom_child`. + #[codec(index = 2)] + SlashForMigrateCustomChild, + } + /// Configurations of this pallet. #[pallet::config(with_default)] pub trait Config: frame_system::Config { @@ -476,7 +498,14 @@ pub mod pallet { /// The currency provider type. #[pallet::no_default] - type Currency: Currency; + type Currency: FunInspectHold + + FunMutate + + FunMutateHold + + FunBalanced; + + /// The overarching runtime hold reason. + #[pallet::no_default_bounds] + type RuntimeHoldReason: From; /// Maximal number of bytes that a key can have. /// @@ -517,6 +546,7 @@ pub mod pallet { type SignedDepositBase: Get>; /// The weight information of this pallet. + #[pallet::no_default] type WeightInfo: WeightInfo; } @@ -626,7 +656,13 @@ pub mod pallet { // ensure they can pay more than the fee. let deposit = T::SignedDepositPerItem::get().saturating_mul(limits.item.into()); - ensure!(T::Currency::can_slash(&who, deposit), Error::::NotEnoughFunds); + sp_std::if_std! { + println!("+ {:?} / {:?} / {:?}", who, deposit, T::Currency::reducible_balance(&who, Preservation::Protect, Fortitude::Force)); + } + ensure!( + T::Currency::can_hold(&HoldReason::SlashForContinueMigrate.into(), &who, deposit), + Error::::NotEnoughFunds + ); let mut task = Self::migration_process(); ensure!( @@ -643,8 +679,10 @@ pub mod pallet { // ensure that the migration witness data was correct. if real_size_upper < task.dyn_size { + T::Currency::hold(&HoldReason::SlashForContinueMigrate.into(), &who, deposit)?; // let the imbalance burn. - let (_imbalance, _remainder) = T::Currency::slash(&who, deposit); + let (_imbalance, _remainder) = + T::Currency::slash(&HoldReason::SlashForContinueMigrate.into(), &who, deposit); Self::deposit_event(Event::::Slashed { who, amount: deposit }); debug_assert!(_remainder.is_zero()); return Ok(().into()) @@ -693,7 +731,13 @@ pub mod pallet { let deposit = T::SignedDepositBase::get().saturating_add( T::SignedDepositPerItem::get().saturating_mul((keys.len() as u32).into()), ); - ensure!(T::Currency::can_slash(&who, deposit), "not enough funds"); + sp_std::if_std! { + println!("+ {:?} / {:?} / {:?}", who, deposit, T::Currency::reducible_balance(&who, Preservation::Protect, Fortitude::Force)); + } + ensure!( + T::Currency::can_hold(&HoldReason::SlashForMigrateCustomTop.into(), &who, deposit), + Error::::NotEnoughFunds + ); let mut dyn_size = 0u32; for key in &keys { @@ -704,7 +748,9 @@ pub mod pallet { } if dyn_size > witness_size { - let (_imbalance, _remainder) = T::Currency::slash(&who, deposit); + T::Currency::hold(&HoldReason::SlashForMigrateCustomTop.into(), &who, deposit)?; + let (_imbalance, _remainder) = + T::Currency::slash(&HoldReason::SlashForMigrateCustomTop.into(), &who, deposit); Self::deposit_event(Event::::Slashed { who, amount: deposit }); debug_assert!(_remainder.is_zero()); Ok(().into()) @@ -753,9 +799,16 @@ pub mod pallet { T::SignedDepositPerItem::get().saturating_mul((child_keys.len() as u32).into()), ); sp_std::if_std! { - println!("+ {:?} / {:?} / {:?}", who, deposit, T::Currency::free_balance(&who)); + println!("+ {:?} / {:?} / {:?}", who, deposit, T::Currency::reducible_balance(&who, Preservation::Protect, Fortitude::Force)); } - ensure!(T::Currency::can_slash(&who, deposit), "not enough funds"); + ensure!( + T::Currency::can_hold( + &HoldReason::SlashForMigrateCustomChild.into(), + &who, + deposit + ), + Error::::NotEnoughFunds + ); let mut dyn_size = 0u32; let transformed_child_key = Self::transform_child_key(&root).ok_or("bad child key")?; @@ -767,7 +820,12 @@ pub mod pallet { } if dyn_size != total_size { - let (_imbalance, _remainder) = T::Currency::slash(&who, deposit); + T::Currency::hold(&HoldReason::SlashForMigrateCustomChild.into(), &who, deposit)?; + let (_imbalance, _remainder) = T::Currency::slash( + &HoldReason::SlashForMigrateCustomChild.into(), + &who, + deposit, + ); debug_assert!(_remainder.is_zero()); Self::deposit_event(Event::::Slashed { who, amount: deposit }); Ok(PostDispatchInfo { @@ -918,7 +976,10 @@ pub mod pallet { #[cfg(feature = "runtime-benchmarks")] mod benchmarks { use super::{pallet::Pallet as StateTrieMigration, *}; - use frame_support::traits::{Currency, Get}; + use frame_support::traits::{ + fungible::{Inspect as FunInspect, Mutate as FunMutate}, + Get, + }; use sp_runtime::traits::Saturating; use sp_std::prelude::*; @@ -926,6 +987,14 @@ mod benchmarks { // constant. const KEY: &[u8] = b"key"; + fn set_balance_for_deposit(caller: &T::AccountId, item: u32) -> BalanceOf { + let deposit = T::SignedDepositBase::get() + .saturating_add(T::SignedDepositPerItem::get().saturating_mul(item.into())); + let stash = T::Currency::minimum_balance() * BalanceOf::::from(1000u32) + deposit; + T::Currency::set_balance(caller, stash); + stash + } + frame_benchmarking::benchmarks! { continue_migrate { // note that this benchmark should migrate nothing, as we only want the overhead weight @@ -933,11 +1002,13 @@ mod benchmarks { // function. let null = MigrationLimits::default(); let caller = frame_benchmarking::whitelisted_caller(); + let stash = set_balance_for_deposit::(&caller, null.item); // Allow signed migrations. SignedMigrationMaxLimits::::put(MigrationLimits { size: 1024, item: 5 }); - }: _(frame_system::RawOrigin::Signed(caller), null, 0, StateTrieMigration::::migration_process()) + }: _(frame_system::RawOrigin::Signed(caller.clone()), null, 0, StateTrieMigration::::migration_process()) verify { - assert_eq!(StateTrieMigration::::migration_process(), Default::default()) + assert_eq!(StateTrieMigration::::migration_process(), Default::default()); + assert_eq!(T::Currency::balance(&caller), stash) } continue_migrate_wrong_witness { @@ -961,26 +1032,18 @@ mod benchmarks { migrate_custom_top_success { let null = MigrationLimits::default(); - let caller = frame_benchmarking::whitelisted_caller(); - let deposit = T::SignedDepositBase::get().saturating_add( - T::SignedDepositPerItem::get().saturating_mul(1u32.into()), - ); - let stash = T::Currency::minimum_balance() * BalanceOf::::from(1000u32) + deposit; - T::Currency::make_free_balance_be(&caller, stash); + let caller: T::AccountId = frame_benchmarking::whitelisted_caller(); + let stash = set_balance_for_deposit::(&caller, null.item); }: migrate_custom_top(frame_system::RawOrigin::Signed(caller.clone()), Default::default(), 0) verify { assert_eq!(StateTrieMigration::::migration_process(), Default::default()); - assert_eq!(T::Currency::free_balance(&caller), stash) + assert_eq!(T::Currency::balance(&caller), stash) } migrate_custom_top_fail { let null = MigrationLimits::default(); - let caller = frame_benchmarking::whitelisted_caller(); - let deposit = T::SignedDepositBase::get().saturating_add( - T::SignedDepositPerItem::get().saturating_mul(1u32.into()), - ); - let stash = T::Currency::minimum_balance() * BalanceOf::::from(1000u32) + deposit; - T::Currency::make_free_balance_be(&caller, stash); + let caller: T::AccountId = frame_benchmarking::whitelisted_caller(); + let stash = set_balance_for_deposit::(&caller, null.item); // for tests, we need to make sure there is _something_ in storage that is being // migrated. sp_io::storage::set(b"foo", vec![1u8;33].as_ref()); @@ -1004,16 +1067,12 @@ mod benchmarks { verify { assert_eq!(StateTrieMigration::::migration_process(), Default::default()); // must have gotten slashed - assert!(T::Currency::free_balance(&caller) < stash) + assert!(T::Currency::balance(&caller) < stash) } migrate_custom_child_success { - let caller = frame_benchmarking::whitelisted_caller(); - let deposit = T::SignedDepositBase::get().saturating_add( - T::SignedDepositPerItem::get().saturating_mul(1u32.into()), - ); - let stash = T::Currency::minimum_balance() * BalanceOf::::from(1000u32) + deposit; - T::Currency::make_free_balance_be(&caller, stash); + let caller: T::AccountId = frame_benchmarking::whitelisted_caller(); + let stash = set_balance_for_deposit::(&caller, 0); }: migrate_custom_child( frame_system::RawOrigin::Signed(caller.clone()), StateTrieMigration::::childify(Default::default()), @@ -1022,16 +1081,12 @@ mod benchmarks { ) verify { assert_eq!(StateTrieMigration::::migration_process(), Default::default()); - assert_eq!(T::Currency::free_balance(&caller), stash); + assert_eq!(T::Currency::balance(&caller), stash); } migrate_custom_child_fail { - let caller = frame_benchmarking::whitelisted_caller(); - let deposit = T::SignedDepositBase::get().saturating_add( - T::SignedDepositPerItem::get().saturating_mul(1u32.into()), - ); - let stash = T::Currency::minimum_balance() * BalanceOf::::from(1000u32) + deposit; - T::Currency::make_free_balance_be(&caller, stash); + let caller: T::AccountId = frame_benchmarking::whitelisted_caller(); + let stash = set_balance_for_deposit::(&caller, 1); // for tests, we need to make sure there is _something_ in storage that is being // migrated. sp_io::default_child_storage::set(b"top", b"foo", vec![1u8;33].as_ref()); @@ -1048,7 +1103,7 @@ mod benchmarks { verify { assert_eq!(StateTrieMigration::::migration_process(), Default::default()); // must have gotten slashed - assert!(T::Currency::free_balance(&caller) < stash) + assert!(T::Currency::balance(&caller) < stash) } process_top_key { @@ -1095,7 +1150,7 @@ mod mock { { System: frame_system::{Pallet, Call, Config, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Config, Storage, Event}, - StateTrieMigration: pallet_state_trie_migration::{Pallet, Call, Storage, Event}, + StateTrieMigration: pallet_state_trie_migration, } ); diff --git a/substrate/frame/transaction-storage/src/mock.rs b/substrate/frame/transaction-storage/src/mock.rs index a8da19a382df..942f8405bdc3 100644 --- a/substrate/frame/transaction-storage/src/mock.rs +++ b/substrate/frame/transaction-storage/src/mock.rs @@ -52,12 +52,7 @@ impl frame_system::Config for Test { #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] impl pallet_balances::Config for Test { - type Balance = u64; - type ExistentialDeposit = ConstU64<1>; type AccountStore = System; - type RuntimeHoldReason = RuntimeHoldReason; - type RuntimeFreezeReason = RuntimeFreezeReason; - type MaxHolds = ConstU32<128>; } impl pallet_transaction_storage::Config for Test { From a65a107b8a2fd7363b58dd3fce87b70ebff179d8 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 22 Nov 2023 14:09:11 +0100 Subject: [PATCH 09/31] Fix --- cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs | 1 + cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs | 1 + polkadot/runtime/rococo/src/lib.rs | 1 + substrate/bin/node/runtime/src/lib.rs | 1 + 4 files changed, 4 insertions(+) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index af0116d7014a..dcdfaf61a710 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -1453,6 +1453,7 @@ parameter_types! { impl pallet_state_trie_migration::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; + type RuntimeHoldReason = RuntimeHoldReason; type SignedDepositPerItem = MigrationSignedDepositPerItem; type SignedDepositBase = MigrationSignedDepositBase; // An origin that can control the whole pallet: should be Root, or a part of your council. diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index b274f45877b3..d2bda6767f9d 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -1575,6 +1575,7 @@ parameter_types! { impl pallet_state_trie_migration::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; + type RuntimeHoldReason = RuntimeHoldReason; type SignedDepositPerItem = MigrationSignedDepositPerItem; type SignedDepositBase = MigrationSignedDepositBase; // An origin that can control the whole pallet: should be Root, or a part of your council. diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 675e0a20b2b0..74efc0fecb05 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1552,6 +1552,7 @@ parameter_types! { impl pallet_state_trie_migration::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; + type RuntimeHoldReason = RuntimeHoldReason; type SignedDepositPerItem = MigrationSignedDepositPerItem; type SignedDepositBase = MigrationSignedDepositBase; type ControlOrigin = EnsureRoot; diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index d7beb29becf4..9b59a6472303 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1872,6 +1872,7 @@ impl pallet_state_trie_migration::Config for Runtime { type RuntimeEvent = RuntimeEvent; type ControlOrigin = EnsureRoot; type Currency = Balances; + type RuntimeHoldReason = RuntimeHoldReason; type MaxKeyLen = MigrationMaxKeyLen; type SignedDepositPerItem = MigrationSignedDepositPerItem; type SignedDepositBase = MigrationSignedDepositBase; From a763f29a847360e0f65a0e535361a7a087158e6d Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 22 Nov 2023 14:21:07 +0100 Subject: [PATCH 10/31] Fix imports --- substrate/frame/state-trie-migration/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index 8b9b67ac129d..ce27ff78e518 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -84,7 +84,6 @@ pub mod pallet { hold::Balanced as FunBalanced, Inspect as FunInspect, InspectHold as FunInspectHold, Mutate as FunMutate, MutateHold as FunMutateHold, }, - tokens::{Fortitude, Preservation}, Get, }, }; @@ -657,6 +656,7 @@ pub mod pallet { // ensure they can pay more than the fee. let deposit = T::SignedDepositPerItem::get().saturating_mul(limits.item.into()); sp_std::if_std! { + use frame_support::traits::tokens::{Fortitude, Preservation}; println!("+ {:?} / {:?} / {:?}", who, deposit, T::Currency::reducible_balance(&who, Preservation::Protect, Fortitude::Force)); } ensure!( @@ -732,6 +732,7 @@ pub mod pallet { T::SignedDepositPerItem::get().saturating_mul((keys.len() as u32).into()), ); sp_std::if_std! { + use frame_support::traits::tokens::{Fortitude, Preservation}; println!("+ {:?} / {:?} / {:?}", who, deposit, T::Currency::reducible_balance(&who, Preservation::Protect, Fortitude::Force)); } ensure!( @@ -799,6 +800,7 @@ pub mod pallet { T::SignedDepositPerItem::get().saturating_mul((child_keys.len() as u32).into()), ); sp_std::if_std! { + use frame_support::traits::tokens::{Fortitude, Preservation}; println!("+ {:?} / {:?} / {:?}", who, deposit, T::Currency::reducible_balance(&who, Preservation::Protect, Fortitude::Force)); } ensure!( From 728855649578eec7421ad2366fd305ec27612e17 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 22 Nov 2023 15:18:33 +0100 Subject: [PATCH 11/31] Increase `MaxHolds` --- cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs | 3 ++- cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs | 3 ++- polkadot/runtime/rococo/src/lib.rs | 2 +- substrate/bin/node/runtime/src/lib.rs | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index dcdfaf61a710..6c78c11b3c01 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -229,7 +229,8 @@ impl pallet_balances::Config for Runtime { type FreezeIdentifier = (); // We allow each account to have holds on it from: // - `NftFractionalization`: 1 - type MaxHolds = ConstU32<1>; + // - `StateTrieMigration`: 3 + type MaxHolds = ConstU32<4>; type MaxFreezes = ConstU32<0>; } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index d2bda6767f9d..a70206c68502 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -226,7 +226,8 @@ impl pallet_balances::Config for Runtime { type FreezeIdentifier = (); // We allow each account to have holds on it from: // - `NftFractionalization`: 1 - type MaxHolds = ConstU32<1>; + // - `StateTrieMigration`: 3 + type MaxHolds = ConstU32<4>; type MaxFreezes = ConstU32<0>; } diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 74efc0fecb05..8511e77af077 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -323,7 +323,7 @@ impl pallet_balances::Config for Runtime { type MaxFreezes = ConstU32<1>; type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; - type MaxHolds = ConstU32<2>; + type MaxHolds = ConstU32<5>; } parameter_types! { diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 9b59a6472303..f0985c3fc891 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -526,7 +526,7 @@ impl pallet_balances::Config for Runtime { type WeightInfo = pallet_balances::weights::SubstrateWeight; type FreezeIdentifier = RuntimeFreezeReason; type MaxFreezes = ConstU32<1>; - type MaxHolds = ConstU32<6>; + type MaxHolds = ConstU32<9>; } parameter_types! { From 6e86f4b0c6ea93c68b32cc22e1487b8781a0a30a Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 22 Nov 2023 15:19:48 +0100 Subject: [PATCH 12/31] git apply patch from: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/4435437 --- .../frame/state-trie-migration/src/weights.rs | 207 ++++++++++-------- 1 file changed, 114 insertions(+), 93 deletions(-) diff --git a/substrate/frame/state-trie-migration/src/weights.rs b/substrate/frame/state-trie-migration/src/weights.rs index df3338fdc17d..2e972327434d 100644 --- a/substrate/frame/state-trie-migration/src/weights.rs +++ b/substrate/frame/state-trie-migration/src/weights.rs @@ -15,32 +15,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Autogenerated weights for pallet_state_trie_migration +//! Autogenerated weights for `pallet_state_trie_migration` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-06-16, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2023-11-22, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-e8ezs4ez-project-145-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 +//! HOSTNAME: `runner-yprdrvc7-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` // Executed Command: -// ./target/production/substrate +// target/production/substrate-node // benchmark // pallet -// --chain=dev // --steps=50 // --repeat=20 -// --pallet=pallet_state_trie_migration -// --no-storage-info -// --no-median-slopes -// --no-min-squares // --extrinsic=* -// --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --output=./frame/state-trie-migration/src/weights.rs -// --header=./HEADER-APACHE2 -// --template=./.maintain/frame-weight-template.hbs +// --json-file=/builds/parity/mirrors/polkadot-sdk/.git/.artifacts/bench.json +// --pallet=pallet_state_trie_migration +// --chain=dev +// --header=./substrate/HEADER-APACHE2 +// --output=./substrate/frame/state-trie-migration/src/weights.rs +// --template=./substrate/.maintain/frame-weight-template.hbs #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -50,7 +47,7 @@ use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; use core::marker::PhantomData; -/// Weight functions needed for pallet_state_trie_migration. +/// Weight functions needed for `pallet_state_trie_migration`. pub trait WeightInfo { fn continue_migrate() -> Weight; fn continue_migrate_wrong_witness() -> Weight; @@ -61,157 +58,181 @@ pub trait WeightInfo { fn process_top_key(v: u32, ) -> Weight; } -/// Weights for pallet_state_trie_migration using the Substrate node and recommended hardware. +/// Weights for `pallet_state_trie_migration` using the Substrate node and recommended hardware. pub struct SubstrateWeight(PhantomData); impl WeightInfo for SubstrateWeight { - /// Storage: StateTrieMigration SignedMigrationMaxLimits (r:1 w:0) - /// Proof: StateTrieMigration SignedMigrationMaxLimits (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) - /// Storage: StateTrieMigration MigrationProcess (r:1 w:1) - /// Proof: StateTrieMigration MigrationProcess (max_values: Some(1), max_size: Some(1042), added: 1537, mode: MaxEncodedLen) + /// Storage: `StateTrieMigration::SignedMigrationMaxLimits` (r:1 w:0) + /// Proof: `StateTrieMigration::SignedMigrationMaxLimits` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:0) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Storage: `StateTrieMigration::MigrationProcess` (r:1 w:1) + /// Proof: `StateTrieMigration::MigrationProcess` (`max_values`: Some(1), `max_size`: Some(1042), added: 1537, mode: `MaxEncodedLen`) fn continue_migrate() -> Weight { // Proof Size summary in bytes: // Measured: `108` - // Estimated: `2527` - // Minimum execution time: 14_297_000 picoseconds. - Weight::from_parts(14_832_000, 2527) - .saturating_add(T::DbWeight::get().reads(2_u64)) + // Estimated: `3622` + // Minimum execution time: 18_335_000 picoseconds. + Weight::from_parts(19_046_000, 3622) + .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } - /// Storage: StateTrieMigration SignedMigrationMaxLimits (r:1 w:0) - /// Proof: StateTrieMigration SignedMigrationMaxLimits (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) + /// Storage: `StateTrieMigration::SignedMigrationMaxLimits` (r:1 w:0) + /// Proof: `StateTrieMigration::SignedMigrationMaxLimits` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) fn continue_migrate_wrong_witness() -> Weight { // Proof Size summary in bytes: // Measured: `76` // Estimated: `1493` - // Minimum execution time: 4_237_000 picoseconds. - Weight::from_parts(4_646_000, 1493) + // Minimum execution time: 4_006_000 picoseconds. + Weight::from_parts(4_280_000, 1493) .saturating_add(T::DbWeight::get().reads(1_u64)) } + /// Storage: `Balances::Holds` (r:1 w:0) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) fn migrate_custom_top_success() -> Weight { // Proof Size summary in bytes: // Measured: `0` - // Estimated: `0` - // Minimum execution time: 8_898_000 picoseconds. - Weight::from_parts(9_237_000, 0) + // Estimated: `3622` + // Minimum execution time: 11_410_000 picoseconds. + Weight::from_parts(11_654_000, 3622) + .saturating_add(T::DbWeight::get().reads(1_u64)) } - /// Storage: unknown `0x666f6f` (r:1 w:1) - /// Proof Skipped: unknown `0x666f6f` (r:1 w:1) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Storage: UNKNOWN KEY `0x666f6f` (r:1 w:1) + /// Proof: UNKNOWN KEY `0x666f6f` (r:1 w:1) fn migrate_custom_top_fail() -> Weight { // Proof Size summary in bytes: // Measured: `113` - // Estimated: `3578` - // Minimum execution time: 29_291_000 picoseconds. - Weight::from_parts(30_424_000, 3578) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Estimated: `3622` + // Minimum execution time: 59_377_000 picoseconds. + Weight::from_parts(60_532_000, 3622) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } + /// Storage: `Balances::Holds` (r:1 w:0) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) fn migrate_custom_child_success() -> Weight { // Proof Size summary in bytes: // Measured: `0` - // Estimated: `0` - // Minimum execution time: 9_094_000 picoseconds. - Weight::from_parts(9_544_000, 0) + // Estimated: `3622` + // Minimum execution time: 11_515_000 picoseconds. + Weight::from_parts(11_811_000, 3622) + .saturating_add(T::DbWeight::get().reads(1_u64)) } - /// Storage: unknown `0x666f6f` (r:1 w:1) - /// Proof Skipped: unknown `0x666f6f` (r:1 w:1) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Storage: UNKNOWN KEY `0x666f6f` (r:1 w:1) + /// Proof: UNKNOWN KEY `0x666f6f` (r:1 w:1) fn migrate_custom_child_fail() -> Weight { // Proof Size summary in bytes: - // Measured: `105` - // Estimated: `3570` - // Minimum execution time: 30_286_000 picoseconds. - Weight::from_parts(30_948_000, 3570) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Measured: `106` + // Estimated: `3622` + // Minimum execution time: 61_399_000 picoseconds. + Weight::from_parts(62_394_000, 3622) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) } - /// Storage: unknown `0x6b6579` (r:1 w:1) - /// Proof Skipped: unknown `0x6b6579` (r:1 w:1) + /// Storage: UNKNOWN KEY `0x6b6579` (r:1 w:1) + /// Proof: UNKNOWN KEY `0x6b6579` (r:1 w:1) /// The range of component `v` is `[1, 4194304]`. fn process_top_key(v: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `197 + v * (1 ±0)` // Estimated: `3662 + v * (1 ±0)` - // Minimum execution time: 5_420_000 picoseconds. - Weight::from_parts(5_560_000, 3662) + // Minimum execution time: 5_320_000 picoseconds. + Weight::from_parts(5_435_000, 3662) // Standard Error: 1 - .saturating_add(Weight::from_parts(1_139, 0).saturating_mul(v.into())) + .saturating_add(Weight::from_parts(1_138, 0).saturating_mul(v.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(v.into())) } } -// For backwards compatibility and tests +// For backwards compatibility and tests. impl WeightInfo for () { - /// Storage: StateTrieMigration SignedMigrationMaxLimits (r:1 w:0) - /// Proof: StateTrieMigration SignedMigrationMaxLimits (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) - /// Storage: StateTrieMigration MigrationProcess (r:1 w:1) - /// Proof: StateTrieMigration MigrationProcess (max_values: Some(1), max_size: Some(1042), added: 1537, mode: MaxEncodedLen) + /// Storage: `StateTrieMigration::SignedMigrationMaxLimits` (r:1 w:0) + /// Proof: `StateTrieMigration::SignedMigrationMaxLimits` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:0) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Storage: `StateTrieMigration::MigrationProcess` (r:1 w:1) + /// Proof: `StateTrieMigration::MigrationProcess` (`max_values`: Some(1), `max_size`: Some(1042), added: 1537, mode: `MaxEncodedLen`) fn continue_migrate() -> Weight { // Proof Size summary in bytes: // Measured: `108` - // Estimated: `2527` - // Minimum execution time: 14_297_000 picoseconds. - Weight::from_parts(14_832_000, 2527) - .saturating_add(RocksDbWeight::get().reads(2_u64)) + // Estimated: `3622` + // Minimum execution time: 18_335_000 picoseconds. + Weight::from_parts(19_046_000, 3622) + .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } - /// Storage: StateTrieMigration SignedMigrationMaxLimits (r:1 w:0) - /// Proof: StateTrieMigration SignedMigrationMaxLimits (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) + /// Storage: `StateTrieMigration::SignedMigrationMaxLimits` (r:1 w:0) + /// Proof: `StateTrieMigration::SignedMigrationMaxLimits` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) fn continue_migrate_wrong_witness() -> Weight { // Proof Size summary in bytes: // Measured: `76` // Estimated: `1493` - // Minimum execution time: 4_237_000 picoseconds. - Weight::from_parts(4_646_000, 1493) + // Minimum execution time: 4_006_000 picoseconds. + Weight::from_parts(4_280_000, 1493) .saturating_add(RocksDbWeight::get().reads(1_u64)) } + /// Storage: `Balances::Holds` (r:1 w:0) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) fn migrate_custom_top_success() -> Weight { // Proof Size summary in bytes: // Measured: `0` - // Estimated: `0` - // Minimum execution time: 8_898_000 picoseconds. - Weight::from_parts(9_237_000, 0) + // Estimated: `3622` + // Minimum execution time: 11_410_000 picoseconds. + Weight::from_parts(11_654_000, 3622) + .saturating_add(RocksDbWeight::get().reads(1_u64)) } - /// Storage: unknown `0x666f6f` (r:1 w:1) - /// Proof Skipped: unknown `0x666f6f` (r:1 w:1) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Storage: UNKNOWN KEY `0x666f6f` (r:1 w:1) + /// Proof: UNKNOWN KEY `0x666f6f` (r:1 w:1) fn migrate_custom_top_fail() -> Weight { // Proof Size summary in bytes: // Measured: `113` - // Estimated: `3578` - // Minimum execution time: 29_291_000 picoseconds. - Weight::from_parts(30_424_000, 3578) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Estimated: `3622` + // Minimum execution time: 59_377_000 picoseconds. + Weight::from_parts(60_532_000, 3622) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } + /// Storage: `Balances::Holds` (r:1 w:0) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) fn migrate_custom_child_success() -> Weight { // Proof Size summary in bytes: // Measured: `0` - // Estimated: `0` - // Minimum execution time: 9_094_000 picoseconds. - Weight::from_parts(9_544_000, 0) + // Estimated: `3622` + // Minimum execution time: 11_515_000 picoseconds. + Weight::from_parts(11_811_000, 3622) + .saturating_add(RocksDbWeight::get().reads(1_u64)) } - /// Storage: unknown `0x666f6f` (r:1 w:1) - /// Proof Skipped: unknown `0x666f6f` (r:1 w:1) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Storage: UNKNOWN KEY `0x666f6f` (r:1 w:1) + /// Proof: UNKNOWN KEY `0x666f6f` (r:1 w:1) fn migrate_custom_child_fail() -> Weight { // Proof Size summary in bytes: - // Measured: `105` - // Estimated: `3570` - // Minimum execution time: 30_286_000 picoseconds. - Weight::from_parts(30_948_000, 3570) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Measured: `106` + // Estimated: `3622` + // Minimum execution time: 61_399_000 picoseconds. + Weight::from_parts(62_394_000, 3622) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) } - /// Storage: unknown `0x6b6579` (r:1 w:1) - /// Proof Skipped: unknown `0x6b6579` (r:1 w:1) + /// Storage: UNKNOWN KEY `0x6b6579` (r:1 w:1) + /// Proof: UNKNOWN KEY `0x6b6579` (r:1 w:1) /// The range of component `v` is `[1, 4194304]`. fn process_top_key(v: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `197 + v * (1 ±0)` // Estimated: `3662 + v * (1 ±0)` - // Minimum execution time: 5_420_000 picoseconds. - Weight::from_parts(5_560_000, 3662) + // Minimum execution time: 5_320_000 picoseconds. + Weight::from_parts(5_435_000, 3662) // Standard Error: 1 - .saturating_add(Weight::from_parts(1_139, 0).saturating_mul(v.into())) + .saturating_add(Weight::from_parts(1_138, 0).saturating_mul(v.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(v.into())) From 1e03e3d8c750071e17d7003e9dc67ba425565ddb Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 22 Nov 2023 16:04:14 +0100 Subject: [PATCH 13/31] Fix `MaxHolds` --- .../parachains/runtimes/assets/asset-hub-kusama/src/lib.rs | 4 ++-- .../parachains/runtimes/assets/asset-hub-rococo/src/lib.rs | 4 ++-- polkadot/runtime/rococo/src/lib.rs | 4 ++-- substrate/bin/node/runtime/src/lib.rs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index 6c78c11b3c01..488719cd69ae 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -229,8 +229,8 @@ impl pallet_balances::Config for Runtime { type FreezeIdentifier = (); // We allow each account to have holds on it from: // - `NftFractionalization`: 1 - // - `StateTrieMigration`: 3 - type MaxHolds = ConstU32<4>; + // - `StateTrieMigration`: 1 + type MaxHolds = ConstU32<2>; type MaxFreezes = ConstU32<0>; } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index a70206c68502..9705147283eb 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -226,8 +226,8 @@ impl pallet_balances::Config for Runtime { type FreezeIdentifier = (); // We allow each account to have holds on it from: // - `NftFractionalization`: 1 - // - `StateTrieMigration`: 3 - type MaxHolds = ConstU32<4>; + // - `StateTrieMigration`: 1 + type MaxHolds = ConstU32<2>; type MaxFreezes = ConstU32<0>; } diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 8511e77af077..d09dbacf7d5a 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -323,7 +323,7 @@ impl pallet_balances::Config for Runtime { type MaxFreezes = ConstU32<1>; type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; - type MaxHolds = ConstU32<5>; + type MaxHolds = ConstU32<3>; } parameter_types! { @@ -1120,7 +1120,7 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<2>; + type MaxHolds = ConstU32<3>; type MaxFreezes = ConstU32<1>; } diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index f0985c3fc891..8a7dd10e045a 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -526,7 +526,7 @@ impl pallet_balances::Config for Runtime { type WeightInfo = pallet_balances::weights::SubstrateWeight; type FreezeIdentifier = RuntimeFreezeReason; type MaxFreezes = ConstU32<1>; - type MaxHolds = ConstU32<9>; + type MaxHolds = ConstU32<7>; } parameter_types! { From b371db3d3de2a8e37606219a9e85efb0f88ab755 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Thu, 23 Nov 2023 14:38:58 +0100 Subject: [PATCH 14/31] Based on element discussion removing `pallet-nicks` (R.I.P.) --- Cargo.lock | 14 -- Cargo.toml | 1 - substrate/frame/nicks/Cargo.toml | 43 ---- substrate/frame/nicks/README.md | 25 -- substrate/frame/nicks/src/lib.rs | 417 ------------------------------- 5 files changed, 500 deletions(-) delete mode 100644 substrate/frame/nicks/Cargo.toml delete mode 100644 substrate/frame/nicks/README.md delete mode 100644 substrate/frame/nicks/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index ce2b07481951..838d81a3485f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10425,20 +10425,6 @@ dependencies = [ "sp-api", ] -[[package]] -name = "pallet-nicks" -version = "4.0.0-dev" -dependencies = [ - "frame-support", - "frame-system", - "pallet-balances", - "parity-scale-codec", - "scale-info", - "sp-io", - "sp-runtime", - "sp-std 8.0.0", -] - [[package]] name = "pallet-nis" version = "4.0.0-dev" diff --git a/Cargo.toml b/Cargo.toml index 57079aa4d03d..3b20f1db0aa2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -325,7 +325,6 @@ members = [ "substrate/frame/nft-fractionalization", "substrate/frame/nfts", "substrate/frame/nfts/runtime-api", - "substrate/frame/nicks", "substrate/frame/nis", "substrate/frame/node-authorization", "substrate/frame/nomination-pools", diff --git a/substrate/frame/nicks/Cargo.toml b/substrate/frame/nicks/Cargo.toml deleted file mode 100644 index aac4e24571bb..000000000000 --- a/substrate/frame/nicks/Cargo.toml +++ /dev/null @@ -1,43 +0,0 @@ -[package] -name = "pallet-nicks" -version = "4.0.0-dev" -authors.workspace = true -edition.workspace = true -license = "Apache-2.0" -homepage = "https://substrate.io" -repository.workspace = true -description = "FRAME pallet for nick management" -readme = "README.md" - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] } -scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } -frame-support = { path = "../support", default-features = false} -frame-system = { path = "../system", default-features = false} -sp-io = { path = "../../primitives/io", default-features = false} -sp-runtime = { path = "../../primitives/runtime", default-features = false} -sp-std = { path = "../../primitives/std", default-features = false} - -[dev-dependencies] -pallet-balances = { path = "../balances" } - -[features] -default = [ "std" ] -std = [ - "codec/std", - "frame-support/std", - "frame-system/std", - "scale-info/std", - "sp-io/std", - "sp-runtime/std", - "sp-std/std", -] -try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "pallet-balances/try-runtime", - "sp-runtime/try-runtime", -] diff --git a/substrate/frame/nicks/README.md b/substrate/frame/nicks/README.md deleted file mode 100644 index 2b05f32d3344..000000000000 --- a/substrate/frame/nicks/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# Nicks Module - -- [`Config`](https://docs.rs/pallet-nicks/latest/pallet_nicks/pallet/trait.Config.html) -- [`Call`](https://docs.rs/pallet-nicks/latest/pallet_nicks/pallet/enum.Call.html) - -## Overview - -Nicks is an example module for keeping track of account names on-chain. It makes no effort to -create a name hierarchy, be a DNS replacement or provide reverse lookups. Furthermore, the -weights attached to this module's dispatchable functions are for demonstration purposes only and -have not been designed to be economically secure. Do not use this pallet as-is in production. - -## Interface - -### Dispatchable Functions - -- `set_name` - Set the associated name of an account; a small deposit is reserved if not already - taken. -- `clear_name` - Remove an account's associated name; the deposit is returned. -- `kill_name` - Forcibly remove the associated name; the deposit is lost. - -[`Call`]: ./enum.Call.html -[`Config`]: ./trait.Config.html - -License: Apache-2.0 diff --git a/substrate/frame/nicks/src/lib.rs b/substrate/frame/nicks/src/lib.rs deleted file mode 100644 index 793d1f3230d7..000000000000 --- a/substrate/frame/nicks/src/lib.rs +++ /dev/null @@ -1,417 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! # Nicks Pallet -//! -//! - [`Config`] -//! - [`Call`] -//! -//! ## Overview -//! -//! Nicks is an example pallet for keeping track of account names on-chain. It makes no effort to -//! create a name hierarchy, be a DNS replacement or provide reverse lookups. Furthermore, the -//! weights attached to this pallet's dispatchable functions are for demonstration purposes only and -//! have not been designed to be economically secure. Do not use this pallet as-is in production. -//! -//! ## Interface -//! -//! ### Dispatchable Functions -//! -//! * `set_name` - Set the associated name of an account; a small deposit is reserved if not already -//! taken. -//! * `clear_name` - Remove an account's associated name; the deposit is returned. -//! * `kill_name` - Forcibly remove the associated name; the deposit is lost. - -#![deny(missing_docs)] -#![cfg_attr(not(feature = "std"), no_std)] - -use frame_support::traits::{ - fungible::{hold::Balanced as FunBalanced, Inspect as FunInspect, MutateHold as FunMutateHold}, - tokens::{fungible::Credit, Precision}, - OnUnbalanced, -}; -use pallet::*; -use sp_runtime::traits::{Saturating, StaticLookup, Zero}; -use sp_std::prelude::*; - -type AccountIdOf = ::AccountId; -type BalanceOf = <::Currency as FunInspect>>::Balance; -type CreditOf = Credit<::AccountId, ::Currency>; -type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; - -#[frame_support::pallet] -pub mod pallet { - use super::*; - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; - - /// A reason for this pallet placing a hold on funds. - #[pallet::composite_enum] - pub enum HoldReason { - /// The funds are held as deposit to start the referendum's decision phase. - /// The funds are held as deposit for doing a system-sponsored fast unstake. - Nicks, - } - - #[pallet::config] - pub trait Config: frame_system::Config { - /// The overarching event type. - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - - /// The currency trait. - type Currency: FunMutateHold - + FunBalanced; - - /// The overarching runtime hold reason. - type RuntimeHoldReason: From; - - /// Reservation fee. - #[pallet::constant] - type ReservationFee: Get>; - - /// What to do with slashed funds. - type OnSlash: OnUnbalanced>; - - /// The origin which may forcibly set or remove a name. Root can always do this. - type ForceOrigin: EnsureOrigin; - - /// The minimum length a name may be. - #[pallet::constant] - type MinLength: Get; - - /// The maximum length a name may be. - #[pallet::constant] - type MaxLength: Get; - } - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - /// A name was set. - NameSet { - /// The account for which the name was set. - who: T::AccountId, - }, - /// A name was forcibly set. - NameForced { - /// The account whose name was forcibly set. - target: T::AccountId, - }, - /// A name was changed. - NameChanged { - /// The account for which the name was changed. - who: T::AccountId, - }, - /// A name was cleared, and the given balance returned. - NameCleared { - /// The account for which the name was cleared. - who: T::AccountId, - /// The deposit returned. - deposit: BalanceOf, - }, - /// A name was removed and the given balance slashed. - NameKilled { - /// The account for which the name was removed. - target: T::AccountId, - /// The deposit returned. - deposit: BalanceOf, - }, - } - - /// Error for the Nicks pallet. - #[pallet::error] - pub enum Error { - /// A name is too short. - TooShort, - /// A name is too long. - TooLong, - /// An account isn't named. - Unnamed, - } - - /// The lookup table for names. - #[pallet::storage] - pub(super) type NameOf = - StorageMap<_, Twox64Concat, T::AccountId, (BoundedVec, BalanceOf)>; - - #[pallet::pallet] - pub struct Pallet(_); - - #[pallet::call] - impl Pallet { - /// Set an account's name. The name should be a UTF-8-encoded string by convention, though - /// we don't check it. - /// - /// The name may not be more than `T::MaxLength` bytes, nor less than `T::MinLength` bytes. - /// - /// If the account doesn't already have a name, then a fee of `ReservationFee` is reserved - /// in the account. - /// - /// The dispatch origin for this call must be _Signed_. - /// - /// ## Complexity - /// - O(1). - #[pallet::call_index(0)] - #[pallet::weight({50_000_000})] - pub fn set_name(origin: OriginFor, name: Vec) -> DispatchResult { - let sender = ensure_signed(origin)?; - - let bounded_name: BoundedVec<_, _> = - name.try_into().map_err(|_| Error::::TooLong)?; - ensure!(bounded_name.len() >= T::MinLength::get() as usize, Error::::TooShort); - - let deposit = if let Some((_, deposit)) = >::get(&sender) { - Self::deposit_event(Event::::NameChanged { who: sender.clone() }); - deposit - } else { - let deposit = T::ReservationFee::get(); - T::Currency::hold(&HoldReason::Nicks.into(), &sender, deposit)?; - Self::deposit_event(Event::::NameSet { who: sender.clone() }); - deposit - }; - - >::insert(&sender, (bounded_name, deposit)); - Ok(()) - } - - /// Clear an account's name and return the deposit. Fails if the account was not named. - /// - /// The dispatch origin for this call must be _Signed_. - /// - /// ## Complexity - /// - O(1). - #[pallet::call_index(1)] - #[pallet::weight({70_000_000})] - pub fn clear_name(origin: OriginFor) -> DispatchResult { - let sender = ensure_signed(origin)?; - - let deposit = >::take(&sender).ok_or(Error::::Unnamed)?.1; - - let released_deposit = T::Currency::release( - &HoldReason::Nicks.into(), - &sender, - deposit, - Precision::Exact, - )?; - - Self::deposit_event(Event::::NameCleared { who: sender, deposit: released_deposit }); - Ok(()) - } - - /// Remove an account's name and take charge of the deposit. - /// - /// Fails if `target` has not been named. The deposit is dealt with through `T::Slashed` - /// imbalance handler. - /// - /// The dispatch origin for this call must match `T::ForceOrigin`. - /// - /// ## Complexity - /// - O(1). - #[pallet::call_index(2)] - #[pallet::weight({70_000_000})] - pub fn kill_name(origin: OriginFor, target: AccountIdLookupOf) -> DispatchResult { - T::ForceOrigin::ensure_origin(origin)?; - - // Figure out who we're meant to be clearing. - let target = T::Lookup::lookup(target)?; - // Grab their deposit (and check that they have one). - let deposit = >::take(&target).ok_or(Error::::Unnamed)?.1; - // Slash their deposit from them. - let (imbalance, non_slashed) = - T::Currency::slash(&HoldReason::Nicks.into(), &target, deposit); - // Handle slashed amount. - T::OnSlash::on_unbalanced(imbalance); - - Self::deposit_event(Event::::NameKilled { - target, - deposit: deposit.saturating_sub(non_slashed), - }); - Ok(()) - } - - /// Set a third-party account's name with no deposit. - /// - /// No length checking is done on the name. - /// - /// The dispatch origin for this call must match `T::ForceOrigin`. - /// - /// ## Complexity - /// - O(1). - #[pallet::call_index(3)] - #[pallet::weight({70_000_000})] - pub fn force_name( - origin: OriginFor, - target: AccountIdLookupOf, - name: Vec, - ) -> DispatchResult { - T::ForceOrigin::ensure_origin(origin)?; - - let bounded_name: BoundedVec<_, _> = - name.try_into().map_err(|_| Error::::TooLong)?; - let target = T::Lookup::lookup(target)?; - let deposit = >::get(&target).map(|x| x.1).unwrap_or_else(Zero::zero); - >::insert(&target, (bounded_name, deposit)); - - Self::deposit_event(Event::::NameForced { target }); - Ok(()) - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate as pallet_nicks; - - use frame_support::{ - assert_noop, assert_ok, derive_impl, ord_parameter_types, - traits::{ConstU32, ConstU64}, - }; - use frame_system::EnsureSignedBy; - use sp_runtime::{ - traits::BadOrigin, BuildStorage, DispatchError::Token, TokenError::FundsUnavailable, - }; - - type Block = frame_system::mocking::MockBlock; - - frame_support::construct_runtime!( - pub enum Test - { - System: frame_system, - Balances: pallet_balances, - Nicks: pallet_nicks, - } - ); - - #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] - impl frame_system::Config for Test { - type Block = Block; - type AccountData = pallet_balances::AccountData; - } - - #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] - impl pallet_balances::Config for Test { - type ReserveIdentifier = [u8; 8]; - type AccountStore = System; - } - - ord_parameter_types! { - pub const One: u64 = 1; - } - - impl Config for Test { - type RuntimeEvent = RuntimeEvent; - type Currency = Balances; - type RuntimeHoldReason = RuntimeHoldReason; - type ReservationFee = ConstU64<2>; - type OnSlash = (); - type ForceOrigin = EnsureSignedBy; - type MinLength = ConstU32<3>; - type MaxLength = ConstU32<16>; - } - - fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - pallet_balances::GenesisConfig:: { balances: vec![(1, 10), (2, 10)] } - .assimilate_storage(&mut t) - .unwrap(); - t.into() - } - - #[test] - fn kill_name_should_work() { - new_test_ext().execute_with(|| { - assert_ok!(Nicks::set_name(RuntimeOrigin::signed(2), b"Dave".to_vec())); - assert_eq!(Balances::total_balance(&2), 10); - assert_ok!(Nicks::kill_name(RuntimeOrigin::signed(1), 2)); - assert_eq!(Balances::total_balance(&2), 8); - assert_eq!(>::get(2), None); - }); - } - - #[test] - fn force_name_should_work() { - new_test_ext().execute_with(|| { - assert_noop!( - Nicks::set_name(RuntimeOrigin::signed(2), b"Dr. David Brubeck, III".to_vec()), - Error::::TooLong, - ); - - assert_ok!(Nicks::set_name(RuntimeOrigin::signed(2), b"Dave".to_vec())); - assert_eq!(Balances::reserved_balance(2), 2); - assert_noop!( - Nicks::force_name(RuntimeOrigin::signed(1), 2, b"Dr. David Brubeck, III".to_vec()), - Error::::TooLong, - ); - assert_ok!(Nicks::force_name( - RuntimeOrigin::signed(1), - 2, - b"Dr. Brubeck, III".to_vec() - )); - assert_eq!(Balances::reserved_balance(2), 2); - let (name, amount) = >::get(2).unwrap(); - assert_eq!(name, b"Dr. Brubeck, III".to_vec()); - assert_eq!(amount, 2); - }); - } - - #[test] - fn normal_operation_should_work() { - new_test_ext().execute_with(|| { - assert_ok!(Nicks::set_name(RuntimeOrigin::signed(1), b"Gav".to_vec())); - assert_eq!(Balances::reserved_balance(1), 2); - assert_eq!(Balances::free_balance(1), 8); - assert_eq!(>::get(1).unwrap().0, b"Gav".to_vec()); - - assert_ok!(Nicks::set_name(RuntimeOrigin::signed(1), b"Gavin".to_vec())); - assert_eq!(Balances::reserved_balance(1), 2); - assert_eq!(Balances::free_balance(1), 8); - assert_eq!(>::get(1).unwrap().0, b"Gavin".to_vec()); - - assert_ok!(Nicks::clear_name(RuntimeOrigin::signed(1))); - assert_eq!(Balances::reserved_balance(1), 0); - assert_eq!(Balances::free_balance(1), 10); - }); - } - - #[test] - fn error_catching_should_work() { - new_test_ext().execute_with(|| { - assert_noop!(Nicks::clear_name(RuntimeOrigin::signed(1)), Error::::Unnamed); - - assert_noop!( - Nicks::set_name(RuntimeOrigin::signed(3), b"Dave".to_vec()), - Token(FundsUnavailable) - ); - - assert_noop!( - Nicks::set_name(RuntimeOrigin::signed(1), b"Ga".to_vec()), - Error::::TooShort - ); - assert_noop!( - Nicks::set_name(RuntimeOrigin::signed(1), b"Gavin James Wood, Esquire".to_vec()), - Error::::TooLong - ); - assert_ok!(Nicks::set_name(RuntimeOrigin::signed(1), b"Dave".to_vec())); - assert_noop!(Nicks::kill_name(RuntimeOrigin::signed(2), 1), BadOrigin); - assert_noop!( - Nicks::force_name(RuntimeOrigin::signed(2), 1, b"Whatever".to_vec()), - BadOrigin - ); - }); - } -} From 07ef547bc51ae1d057fa676ed38bc03f8b922f73 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Thu, 30 Nov 2023 11:15:29 +0100 Subject: [PATCH 15/31] Update substrate/frame/state-trie-migration/src/lib.rs Co-authored-by: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> --- substrate/frame/state-trie-migration/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index ce27ff78e518..450dd864199e 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -466,7 +466,7 @@ pub mod pallet { } } - /// A reason for this pallet placing a hold on funds. + /// The reason for this pallet placing a hold on funds. #[pallet::composite_enum] pub enum HoldReason { /// The funds are held as deposit for slashing for `continue_migrate`. From 5ab4b1b29695e2fa0d1b4e5c46ad4c0daec2c4bd Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Thu, 30 Nov 2023 11:15:40 +0100 Subject: [PATCH 16/31] Update substrate/frame/state-trie-migration/src/lib.rs Co-authored-by: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> --- substrate/frame/state-trie-migration/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index 450dd864199e..c860ccd850e9 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -469,7 +469,7 @@ pub mod pallet { /// The reason for this pallet placing a hold on funds. #[pallet::composite_enum] pub enum HoldReason { - /// The funds are held as deposit for slashing for `continue_migrate`. + /// The funds are held as a deposit to slash for `continue_migrate`. #[codec(index = 0)] SlashForContinueMigrate, /// The funds are held as deposit for slashing for `migrate_custom_top`. From 43efe43a8d9b6d38e2201d96777f54e2d2ab7968 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Thu, 30 Nov 2023 11:15:47 +0100 Subject: [PATCH 17/31] Update substrate/frame/state-trie-migration/src/lib.rs Co-authored-by: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> --- substrate/frame/state-trie-migration/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index c860ccd850e9..f51d4982349a 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -472,7 +472,7 @@ pub mod pallet { /// The funds are held as a deposit to slash for `continue_migrate`. #[codec(index = 0)] SlashForContinueMigrate, - /// The funds are held as deposit for slashing for `migrate_custom_top`. + /// The funds are held as a deposit to slash for `migrate_custom_top`. #[codec(index = 1)] SlashForMigrateCustomTop, /// The funds are held as deposit for slashing for `migrate_custom_child`. From c9c40cb56375623175e968f705467af60262b9ed Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Thu, 30 Nov 2023 11:15:55 +0100 Subject: [PATCH 18/31] Update substrate/frame/state-trie-migration/src/lib.rs Co-authored-by: Richard Melkonian <35300528+0xmovses@users.noreply.github.com> --- substrate/frame/state-trie-migration/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index f51d4982349a..d0d7d618b6aa 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -475,7 +475,7 @@ pub mod pallet { /// The funds are held as a deposit to slash for `migrate_custom_top`. #[codec(index = 1)] SlashForMigrateCustomTop, - /// The funds are held as deposit for slashing for `migrate_custom_child`. + /// The funds are held as a deposit to slash for `migrate_custom_child`. #[codec(index = 2)] SlashForMigrateCustomChild, } From ad6c8874fa440d130f7cf9d93ec30b41e4c1c571 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Thu, 7 Dec 2023 12:49:55 +0100 Subject: [PATCH 19/31] Removed `println!` for `sp_std::if_std!` --- substrate/frame/state-trie-migration/src/lib.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index d0d7d618b6aa..967aaa5853a3 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -655,10 +655,6 @@ pub mod pallet { // ensure they can pay more than the fee. let deposit = T::SignedDepositPerItem::get().saturating_mul(limits.item.into()); - sp_std::if_std! { - use frame_support::traits::tokens::{Fortitude, Preservation}; - println!("+ {:?} / {:?} / {:?}", who, deposit, T::Currency::reducible_balance(&who, Preservation::Protect, Fortitude::Force)); - } ensure!( T::Currency::can_hold(&HoldReason::SlashForContinueMigrate.into(), &who, deposit), Error::::NotEnoughFunds @@ -731,10 +727,6 @@ pub mod pallet { let deposit = T::SignedDepositBase::get().saturating_add( T::SignedDepositPerItem::get().saturating_mul((keys.len() as u32).into()), ); - sp_std::if_std! { - use frame_support::traits::tokens::{Fortitude, Preservation}; - println!("+ {:?} / {:?} / {:?}", who, deposit, T::Currency::reducible_balance(&who, Preservation::Protect, Fortitude::Force)); - } ensure!( T::Currency::can_hold(&HoldReason::SlashForMigrateCustomTop.into(), &who, deposit), Error::::NotEnoughFunds @@ -799,10 +791,6 @@ pub mod pallet { let deposit = T::SignedDepositBase::get().saturating_add( T::SignedDepositPerItem::get().saturating_mul((child_keys.len() as u32).into()), ); - sp_std::if_std! { - use frame_support::traits::tokens::{Fortitude, Preservation}; - println!("+ {:?} / {:?} / {:?}", who, deposit, T::Currency::reducible_balance(&who, Preservation::Protect, Fortitude::Force)); - } ensure!( T::Currency::can_hold( &HoldReason::SlashForMigrateCustomChild.into(), From 12fdb1d79db8b06fa1930d6554a25a379e6efc22 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 8 Dec 2023 15:37:03 +0100 Subject: [PATCH 20/31] Added test for `continue_migrate` slashing scenario --- .../frame/state-trie-migration/src/lib.rs | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index 967aaa5853a3..5108aef7b304 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -1306,6 +1306,7 @@ mod mock { #[cfg(test)] mod test { use super::{mock::*, *}; + use frame_support::assert_ok; use sp_runtime::{bounded_vec, traits::Bounded, StateVersion}; #[test] @@ -1535,10 +1536,9 @@ mod test { while !MigrationProcess::::get().finished() { // first we compute the task to get the accurate consumption. let mut task = StateTrieMigration::migration_process(); - let result = task.migrate_until_exhaustion( + assert_ok!(task.migrate_until_exhaustion( StateTrieMigration::signed_migration_max_limits().unwrap(), - ); - assert!(result.is_ok()); + )); frame_support::assert_ok!(StateTrieMigration::continue_migrate( RuntimeOrigin::signed(1), @@ -1549,6 +1549,7 @@ mod test { // no funds should remain reserved. assert_eq!(Balances::reserved_balance(&1), 0); + assert_eq!(Balances::free_balance(&1), 1000); // and the task should be updated assert!(matches!( @@ -1559,6 +1560,37 @@ mod test { }); } + #[test] + fn continue_migrate_slashing_works() { + new_test_ext(StateVersion::V0, true, None, None).execute_with(|| { + assert_eq!(MigrationProcess::::get(), Default::default()); + + // Allow signed migrations. + SignedMigrationMaxLimits::::put(MigrationLimits { size: 1024, item: 5 }); + + // first we compute the task to get the accurate consumption. + let mut task = StateTrieMigration::migration_process(); + assert_ok!(task.migrate_until_exhaustion( + StateTrieMigration::signed_migration_max_limits().unwrap(), + )); + + // can't submit with `real_size_upper` < `task.dyn_size` expect slashing + frame_support::assert_ok!(StateTrieMigration::continue_migrate( + RuntimeOrigin::signed(1), + StateTrieMigration::signed_migration_max_limits().unwrap(), + task.dyn_size - 1, + MigrationProcess::::get() + )); + // no funds should remain reserved. + assert_eq!(Balances::reserved_balance(&1), 0); + // user was slashed + assert_eq!( + Balances::free_balance(&1), + 1000 - (5 * SignedDepositPerItem::get()) + ); + }); + } + #[test] fn custom_migrate_top_works() { let correct_witness = 3 + sp_core::storage::TRIE_VALUE_NODE_THRESHOLD * 3 + 1 + 2 + 3; From cc076a3b7c5590cef6e4f7b696ee6f74a840b04a Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 8 Dec 2023 16:01:10 +0100 Subject: [PATCH 21/31] Changed `slash` to `burn_all_held` --- .../frame/state-trie-migration/src/lib.rs | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index 5108aef7b304..f622d1b523f1 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -84,6 +84,7 @@ pub mod pallet { hold::Balanced as FunBalanced, Inspect as FunInspect, InspectHold as FunInspectHold, Mutate as FunMutate, MutateHold as FunMutateHold, }, + tokens::{Fortitude, Precision}, Get, }, }; @@ -677,10 +678,14 @@ pub mod pallet { if real_size_upper < task.dyn_size { T::Currency::hold(&HoldReason::SlashForContinueMigrate.into(), &who, deposit)?; // let the imbalance burn. - let (_imbalance, _remainder) = - T::Currency::slash(&HoldReason::SlashForContinueMigrate.into(), &who, deposit); + let _burned = T::Currency::burn_all_held( + &HoldReason::SlashForContinueMigrate.into(), + &who, + Precision::BestEffort, + Fortitude::Force, + )?; + debug_assert!(deposit.saturating_sub(_burned).is_zero()); Self::deposit_event(Event::::Slashed { who, amount: deposit }); - debug_assert!(_remainder.is_zero()); return Ok(().into()) } @@ -742,10 +747,14 @@ pub mod pallet { if dyn_size > witness_size { T::Currency::hold(&HoldReason::SlashForMigrateCustomTop.into(), &who, deposit)?; - let (_imbalance, _remainder) = - T::Currency::slash(&HoldReason::SlashForMigrateCustomTop.into(), &who, deposit); + let _burned = T::Currency::burn_all_held( + &HoldReason::SlashForMigrateCustomTop.into(), + &who, + Precision::BestEffort, + Fortitude::Force, + )?; + debug_assert!(deposit.saturating_sub(_burned).is_zero()); Self::deposit_event(Event::::Slashed { who, amount: deposit }); - debug_assert!(_remainder.is_zero()); Ok(().into()) } else { Self::deposit_event(Event::::Migrated { @@ -811,12 +820,13 @@ pub mod pallet { if dyn_size != total_size { T::Currency::hold(&HoldReason::SlashForMigrateCustomChild.into(), &who, deposit)?; - let (_imbalance, _remainder) = T::Currency::slash( + let _burned = T::Currency::burn_all_held( &HoldReason::SlashForMigrateCustomChild.into(), &who, - deposit, - ); - debug_assert!(_remainder.is_zero()); + Precision::BestEffort, + Fortitude::Force, + )?; + debug_assert!(deposit.saturating_sub(_burned).is_zero()); Self::deposit_event(Event::::Slashed { who, amount: deposit }); Ok(PostDispatchInfo { actual_weight: Some(T::WeightInfo::migrate_custom_child_fail()), @@ -1571,23 +1581,20 @@ mod test { // first we compute the task to get the accurate consumption. let mut task = StateTrieMigration::migration_process(); assert_ok!(task.migrate_until_exhaustion( - StateTrieMigration::signed_migration_max_limits().unwrap(), - )); + StateTrieMigration::signed_migration_max_limits().unwrap(), + )); // can't submit with `real_size_upper` < `task.dyn_size` expect slashing frame_support::assert_ok!(StateTrieMigration::continue_migrate( - RuntimeOrigin::signed(1), - StateTrieMigration::signed_migration_max_limits().unwrap(), - task.dyn_size - 1, - MigrationProcess::::get() + RuntimeOrigin::signed(1), + StateTrieMigration::signed_migration_max_limits().unwrap(), + task.dyn_size - 1, + MigrationProcess::::get() )); // no funds should remain reserved. assert_eq!(Balances::reserved_balance(&1), 0); // user was slashed - assert_eq!( - Balances::free_balance(&1), - 1000 - (5 * SignedDepositPerItem::get()) - ); + assert_eq!(Balances::free_balance(&1), 1000 - (5 * SignedDepositPerItem::get())); }); } From 69588b556c6f01ae69994778c2b52ef3fc480ef1 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 8 Dec 2023 16:04:56 +0100 Subject: [PATCH 22/31] Removed `as Fun*` stuff --- substrate/frame/state-trie-migration/src/lib.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index f622d1b523f1..a95ed14e43e5 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -80,10 +80,7 @@ pub mod pallet { ensure, pallet_prelude::*, traits::{ - fungible::{ - hold::Balanced as FunBalanced, Inspect as FunInspect, - InspectHold as FunInspectHold, Mutate as FunMutate, MutateHold as FunMutateHold, - }, + fungible::{hold::Balanced, Inspect, InspectHold, Mutate, MutateHold}, tokens::{Fortitude, Precision}, Get, }, @@ -99,7 +96,7 @@ pub mod pallet { use sp_std::{ops::Deref, prelude::*}; pub(crate) type BalanceOf = - <::Currency as FunInspect<::AccountId>>::Balance; + <::Currency as Inspect<::AccountId>>::Balance; /// The progress of either the top or child keys. #[derive( @@ -498,10 +495,10 @@ pub mod pallet { /// The currency provider type. #[pallet::no_default] - type Currency: FunInspectHold - + FunMutate - + FunMutateHold - + FunBalanced; + type Currency: InspectHold + + Mutate + + MutateHold + + Balanced; /// The overarching runtime hold reason. #[pallet::no_default_bounds] From 5eb2d8cb3df80ba9399b2e9109a0b7c333b19358 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 8 Dec 2023 16:08:52 +0100 Subject: [PATCH 23/31] One more --- substrate/frame/state-trie-migration/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index a95ed14e43e5..76fb3674e2ea 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -974,7 +974,7 @@ pub mod pallet { mod benchmarks { use super::{pallet::Pallet as StateTrieMigration, *}; use frame_support::traits::{ - fungible::{Inspect as FunInspect, Mutate as FunMutate}, + fungible::{Inspect, Mutate}, Get, }; use sp_runtime::traits::Saturating; From 57e3bea8c9c49626bef4ef01efd619a9cad55a8a Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 19 Jan 2024 14:45:31 +0100 Subject: [PATCH 24/31] `fungible` remove `as Fn` (https://github.com/paritytech/polkadot-sdk/issues/226#issuecomment-1822861445) --- substrate/frame/transaction-storage/src/lib.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/substrate/frame/transaction-storage/src/lib.rs b/substrate/frame/transaction-storage/src/lib.rs index fb8ada0f5f99..d32cfe169ce0 100644 --- a/substrate/frame/transaction-storage/src/lib.rs +++ b/substrate/frame/transaction-storage/src/lib.rs @@ -32,10 +32,7 @@ use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::{ dispatch::GetDispatchInfo, traits::{ - fungible::{ - hold::Balanced as FnBalanced, Inspect as FnInspect, Mutate as FnMutate, - MutateHold as FnMutateHold, - }, + fungible::{hold::Balanced, Inspect, Mutate, MutateHold}, tokens::fungible::Credit, OnUnbalanced, }, @@ -49,7 +46,7 @@ use sp_transaction_storage_proof::{ /// A type alias for the balance type from this pallet's point of view. type BalanceOf = - <::Currency as FnInspect<::AccountId>>::Balance; + <::Currency as Inspect<::AccountId>>::Balance; pub type CreditOf = Credit<::AccountId, ::Currency>; // Re-export pallet items so that they can be accessed from the crate namespace. @@ -111,9 +108,9 @@ pub mod pallet { + GetDispatchInfo + From>; /// The fungible type for this pallet. - type Currency: FnMutate - + FnMutateHold - + FnBalanced; + type Currency: Mutate + + MutateHold + + Balanced; /// The overarching runtime hold reason. type RuntimeHoldReason: From; /// Handler for the unbalanced decrease when fees are burned. From 1b9822559e86c1fa90f9193b1eaf1baa86a69ac7 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 19 Jan 2024 15:08:06 +0100 Subject: [PATCH 25/31] `fungible` remove `as Fun` (https://github.com/paritytech/polkadot-sdk/issues/226#issuecomment-1822861445) --- substrate/frame/nomination-pools/src/lib.rs | 11 ++++------- substrate/frame/safe-mode/src/benchmarking.rs | 4 ++-- substrate/frame/safe-mode/src/lib.rs | 10 +++++----- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/substrate/frame/nomination-pools/src/lib.rs b/substrate/frame/nomination-pools/src/lib.rs index c538f12e20bf..c4e5ad1f700a 100644 --- a/substrate/frame/nomination-pools/src/lib.rs +++ b/substrate/frame/nomination-pools/src/lib.rs @@ -357,10 +357,7 @@ use frame_support::{ pallet_prelude::{MaxEncodedLen, *}, storage::bounded_btree_map::BoundedBTreeMap, traits::{ - fungible::{ - Inspect as FunInspect, InspectFreeze, Mutate as FunMutate, - MutateFreeze as FunMutateFreeze, - }, + fungible::{Inspect, InspectFreeze, Mutate, MutateFreeze}, tokens::{Fortitude, Preservation}, Defensive, DefensiveOption, DefensiveResult, DefensiveSaturating, Get, }, @@ -408,7 +405,7 @@ pub use weights::WeightInfo; /// The balance type used by the currency system. pub type BalanceOf = - <::Currency as FunInspect<::AccountId>>::Balance; + <::Currency as Inspect<::AccountId>>::Balance; /// Type used for unique identifier of each pool. pub type PoolId = u32; @@ -1608,8 +1605,8 @@ pub mod pallet { type WeightInfo: weights::WeightInfo; /// The currency type used for nomination pool. - type Currency: FunMutate - + FunMutateFreeze; + type Currency: Mutate + + MutateFreeze; /// The overarching freeze reason. type RuntimeFreezeReason: From; diff --git a/substrate/frame/safe-mode/src/benchmarking.rs b/substrate/frame/safe-mode/src/benchmarking.rs index 566150e982af..ccfb33b92b17 100644 --- a/substrate/frame/safe-mode/src/benchmarking.rs +++ b/substrate/frame/safe-mode/src/benchmarking.rs @@ -20,11 +20,11 @@ use super::{Pallet as SafeMode, *}; use frame_benchmarking::v2::*; -use frame_support::traits::{fungible::Mutate as FunMutate, UnfilteredDispatchable}; +use frame_support::traits::{fungible::Mutate, UnfilteredDispatchable}; use frame_system::{Pallet as System, RawOrigin}; use sp_runtime::traits::{Bounded, One, Zero}; -#[benchmarks(where T::Currency: FunMutate)] +#[benchmarks(where T::Currency: Mutate)] mod benchmarks { use super::*; diff --git a/substrate/frame/safe-mode/src/lib.rs b/substrate/frame/safe-mode/src/lib.rs index 554f509db63e..325d751e17f6 100644 --- a/substrate/frame/safe-mode/src/lib.rs +++ b/substrate/frame/safe-mode/src/lib.rs @@ -84,8 +84,8 @@ use frame_support::{ pallet_prelude::*, traits::{ fungible::{ - hold::{Inspect as FunHoldInspect, Mutate as FunHoldMutate}, - Inspect as FunInspect, + self, + hold::{Inspect, Mutate}, }, tokens::{Fortitude, Precision}, CallMetadata, Contains, Defensive, GetCallMetadata, PalletInfoAccess, SafeModeNotify, @@ -102,7 +102,7 @@ pub use pallet::*; pub use weights::*; type BalanceOf = - <::Currency as FunInspect<::AccountId>>::Balance; + <::Currency as fungible::Inspect<::AccountId>>::Balance; #[frame_support::pallet] pub mod pallet { @@ -117,8 +117,8 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// Currency type for this pallet, used for Deposits. - type Currency: FunHoldInspect - + FunHoldMutate; + type Currency: Inspect + + Mutate; /// The hold reason when reserving funds for entering or extending the safe-mode. type RuntimeHoldReason: From; From c933c8946e36a0bc88351bfa6c18a679573d558a Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 19 Jan 2024 15:28:52 +0100 Subject: [PATCH 26/31] fix --- substrate/frame/safe-mode/src/benchmarking.rs | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/substrate/frame/safe-mode/src/benchmarking.rs b/substrate/frame/safe-mode/src/benchmarking.rs index ccfb33b92b17..7561cf305f45 100644 --- a/substrate/frame/safe-mode/src/benchmarking.rs +++ b/substrate/frame/safe-mode/src/benchmarking.rs @@ -20,11 +20,11 @@ use super::{Pallet as SafeMode, *}; use frame_benchmarking::v2::*; -use frame_support::traits::{fungible::Mutate, UnfilteredDispatchable}; +use frame_support::traits::{fungible, UnfilteredDispatchable}; use frame_system::{Pallet as System, RawOrigin}; use sp_runtime::traits::{Bounded, One, Zero}; -#[benchmarks(where T::Currency: Mutate)] +#[benchmarks(where T::Currency: fungible::Mutate)] mod benchmarks { use super::*; @@ -58,7 +58,7 @@ mod benchmarks { let caller: T::AccountId = whitelisted_caller(); let origin = RawOrigin::Signed(caller.clone()); - T::Currency::set_balance(&caller, init_bal::()); + >::set_balance(&caller, init_bal::()); #[extrinsic_call] _(origin); @@ -91,7 +91,7 @@ mod benchmarks { T::ExtendDepositAmount::get().ok_or_else(|| BenchmarkError::Weightless)?; let alice: T::AccountId = whitelisted_caller(); - T::Currency::set_balance(&alice, init_bal::()); + >::set_balance(&alice, init_bal::()); System::::set_block_number(1u32.into()); assert!(SafeMode::::do_enter(None, 1u32.into()).is_ok()); @@ -152,7 +152,7 @@ mod benchmarks { let alice: T::AccountId = whitelisted_caller(); let origin = RawOrigin::Signed(alice.clone()); - T::Currency::set_balance(&alice, init_bal::()); + >::set_balance(&alice, init_bal::()); // Mock the storage. This is needed in case the `EnterDepositAmount` is zero. let block: BlockNumberFor = 1u32.into(); let bal: BalanceOf = 1u32.into(); @@ -169,7 +169,7 @@ mod benchmarks { _(origin, alice.clone(), 1u32.into()); assert!(!Deposits::::contains_key(&alice, &block)); - assert_eq!(T::Currency::balance(&alice), init_bal::()); + assert_eq!(>::balance(&alice), init_bal::()); Ok(()) } @@ -180,7 +180,7 @@ mod benchmarks { .map_err(|_| BenchmarkError::Weightless)?; let alice: T::AccountId = whitelisted_caller(); - T::Currency::set_balance(&alice, init_bal::()); + >::set_balance(&alice, init_bal::()); // Mock the storage. This is needed in case the `EnterDepositAmount` is zero. let block: BlockNumberFor = 1u32.into(); @@ -189,7 +189,10 @@ mod benchmarks { T::Currency::hold(&&HoldReason::EnterOrExtend.into(), &alice, bal)?; EnteredUntil::::put(&block); - assert_eq!(T::Currency::balance(&alice), init_bal::() - 1u32.into()); + assert_eq!( + >::balance(&alice), + init_bal::() - 1u32.into() + ); assert!(SafeMode::::do_exit(ExitReason::Force).is_ok()); System::::set_block_number(System::::block_number() + One::one()); @@ -200,7 +203,7 @@ mod benchmarks { _(force_origin as T::RuntimeOrigin, alice.clone(), block); assert!(!Deposits::::contains_key(&alice, block)); - assert_eq!(T::Currency::balance(&alice), init_bal::()); + assert_eq!(>::balance(&alice), init_bal::()); Ok(()) } @@ -210,7 +213,7 @@ mod benchmarks { .map_err(|_| BenchmarkError::Weightless)?; let alice: T::AccountId = whitelisted_caller(); - T::Currency::set_balance(&alice, init_bal::()); + >::set_balance(&alice, init_bal::()); // Mock the storage. This is needed in case the `EnterDepositAmount` is zero. let block: BlockNumberFor = 1u32.into(); @@ -224,7 +227,10 @@ mod benchmarks { _(force_origin as T::RuntimeOrigin, alice.clone(), block); assert!(!Deposits::::contains_key(&alice, block)); - assert_eq!(T::Currency::balance(&alice), init_bal::() - 1u32.into()); + assert_eq!( + >::balance(&alice), + init_bal::() - 1u32.into() + ); Ok(()) } From 6f8fedad48f76d220711d40dc1c7cb7f51e234a9 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 19 Jan 2024 15:04:32 +0000 Subject: [PATCH 27/31] ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --pallet=pallet_state_trie_migration --- .../frame/state-trie-migration/src/weights.rs | 104 +++++++++--------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/substrate/frame/state-trie-migration/src/weights.rs b/substrate/frame/state-trie-migration/src/weights.rs index 2e972327434d..2be785fc99fe 100644 --- a/substrate/frame/state-trie-migration/src/weights.rs +++ b/substrate/frame/state-trie-migration/src/weights.rs @@ -18,9 +18,9 @@ //! Autogenerated weights for `pallet_state_trie_migration` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-11-22, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-01-19, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-yprdrvc7-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `runner-j8vvqcjr-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` // Executed Command: @@ -64,15 +64,15 @@ impl WeightInfo for SubstrateWeight { /// Storage: `StateTrieMigration::SignedMigrationMaxLimits` (r:1 w:0) /// Proof: `StateTrieMigration::SignedMigrationMaxLimits` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) /// Storage: `Balances::Holds` (r:1 w:0) - /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) /// Storage: `StateTrieMigration::MigrationProcess` (r:1 w:1) /// Proof: `StateTrieMigration::MigrationProcess` (`max_values`: Some(1), `max_size`: Some(1042), added: 1537, mode: `MaxEncodedLen`) fn continue_migrate() -> Weight { // Proof Size summary in bytes: // Measured: `108` - // Estimated: `3622` - // Minimum execution time: 18_335_000 picoseconds. - Weight::from_parts(19_046_000, 3622) + // Estimated: `3640` + // Minimum execution time: 18_692_000 picoseconds. + Weight::from_parts(19_391_000, 3640) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -82,53 +82,53 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `76` // Estimated: `1493` - // Minimum execution time: 4_006_000 picoseconds. - Weight::from_parts(4_280_000, 1493) + // Minimum execution time: 3_886_000 picoseconds. + Weight::from_parts(4_136_000, 1493) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: `Balances::Holds` (r:1 w:0) - /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) fn migrate_custom_top_success() -> Weight { // Proof Size summary in bytes: // Measured: `0` - // Estimated: `3622` - // Minimum execution time: 11_410_000 picoseconds. - Weight::from_parts(11_654_000, 3622) + // Estimated: `3640` + // Minimum execution time: 11_232_000 picoseconds. + Weight::from_parts(11_641_000, 3640) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: `Balances::Holds` (r:1 w:1) - /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) /// Storage: UNKNOWN KEY `0x666f6f` (r:1 w:1) /// Proof: UNKNOWN KEY `0x666f6f` (r:1 w:1) fn migrate_custom_top_fail() -> Weight { // Proof Size summary in bytes: // Measured: `113` - // Estimated: `3622` - // Minimum execution time: 59_377_000 picoseconds. - Weight::from_parts(60_532_000, 3622) + // Estimated: `3640` + // Minimum execution time: 61_149_000 picoseconds. + Weight::from_parts(62_082_000, 3640) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } /// Storage: `Balances::Holds` (r:1 w:0) - /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) fn migrate_custom_child_success() -> Weight { // Proof Size summary in bytes: // Measured: `0` - // Estimated: `3622` - // Minimum execution time: 11_515_000 picoseconds. - Weight::from_parts(11_811_000, 3622) + // Estimated: `3640` + // Minimum execution time: 11_372_000 picoseconds. + Weight::from_parts(11_769_000, 3640) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: `Balances::Holds` (r:1 w:1) - /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) /// Storage: UNKNOWN KEY `0x666f6f` (r:1 w:1) /// Proof: UNKNOWN KEY `0x666f6f` (r:1 w:1) fn migrate_custom_child_fail() -> Weight { // Proof Size summary in bytes: // Measured: `106` - // Estimated: `3622` - // Minimum execution time: 61_399_000 picoseconds. - Weight::from_parts(62_394_000, 3622) + // Estimated: `3640` + // Minimum execution time: 62_713_000 picoseconds. + Weight::from_parts(64_210_000, 3640) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -139,10 +139,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `197 + v * (1 ±0)` // Estimated: `3662 + v * (1 ±0)` - // Minimum execution time: 5_320_000 picoseconds. - Weight::from_parts(5_435_000, 3662) + // Minimum execution time: 5_370_000 picoseconds. + Weight::from_parts(5_525_000, 3662) // Standard Error: 1 - .saturating_add(Weight::from_parts(1_138, 0).saturating_mul(v.into())) + .saturating_add(Weight::from_parts(1_149, 0).saturating_mul(v.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(v.into())) @@ -154,15 +154,15 @@ impl WeightInfo for () { /// Storage: `StateTrieMigration::SignedMigrationMaxLimits` (r:1 w:0) /// Proof: `StateTrieMigration::SignedMigrationMaxLimits` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) /// Storage: `Balances::Holds` (r:1 w:0) - /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) /// Storage: `StateTrieMigration::MigrationProcess` (r:1 w:1) /// Proof: `StateTrieMigration::MigrationProcess` (`max_values`: Some(1), `max_size`: Some(1042), added: 1537, mode: `MaxEncodedLen`) fn continue_migrate() -> Weight { // Proof Size summary in bytes: // Measured: `108` - // Estimated: `3622` - // Minimum execution time: 18_335_000 picoseconds. - Weight::from_parts(19_046_000, 3622) + // Estimated: `3640` + // Minimum execution time: 18_692_000 picoseconds. + Weight::from_parts(19_391_000, 3640) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -172,53 +172,53 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `76` // Estimated: `1493` - // Minimum execution time: 4_006_000 picoseconds. - Weight::from_parts(4_280_000, 1493) + // Minimum execution time: 3_886_000 picoseconds. + Weight::from_parts(4_136_000, 1493) .saturating_add(RocksDbWeight::get().reads(1_u64)) } /// Storage: `Balances::Holds` (r:1 w:0) - /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) fn migrate_custom_top_success() -> Weight { // Proof Size summary in bytes: // Measured: `0` - // Estimated: `3622` - // Minimum execution time: 11_410_000 picoseconds. - Weight::from_parts(11_654_000, 3622) + // Estimated: `3640` + // Minimum execution time: 11_232_000 picoseconds. + Weight::from_parts(11_641_000, 3640) .saturating_add(RocksDbWeight::get().reads(1_u64)) } /// Storage: `Balances::Holds` (r:1 w:1) - /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) /// Storage: UNKNOWN KEY `0x666f6f` (r:1 w:1) /// Proof: UNKNOWN KEY `0x666f6f` (r:1 w:1) fn migrate_custom_top_fail() -> Weight { // Proof Size summary in bytes: // Measured: `113` - // Estimated: `3622` - // Minimum execution time: 59_377_000 picoseconds. - Weight::from_parts(60_532_000, 3622) + // Estimated: `3640` + // Minimum execution time: 61_149_000 picoseconds. + Weight::from_parts(62_082_000, 3640) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } /// Storage: `Balances::Holds` (r:1 w:0) - /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) fn migrate_custom_child_success() -> Weight { // Proof Size summary in bytes: // Measured: `0` - // Estimated: `3622` - // Minimum execution time: 11_515_000 picoseconds. - Weight::from_parts(11_811_000, 3622) + // Estimated: `3640` + // Minimum execution time: 11_372_000 picoseconds. + Weight::from_parts(11_769_000, 3640) .saturating_add(RocksDbWeight::get().reads(1_u64)) } /// Storage: `Balances::Holds` (r:1 w:1) - /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(157), added: 2632, mode: `MaxEncodedLen`) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(175), added: 2650, mode: `MaxEncodedLen`) /// Storage: UNKNOWN KEY `0x666f6f` (r:1 w:1) /// Proof: UNKNOWN KEY `0x666f6f` (r:1 w:1) fn migrate_custom_child_fail() -> Weight { // Proof Size summary in bytes: // Measured: `106` - // Estimated: `3622` - // Minimum execution time: 61_399_000 picoseconds. - Weight::from_parts(62_394_000, 3622) + // Estimated: `3640` + // Minimum execution time: 62_713_000 picoseconds. + Weight::from_parts(64_210_000, 3640) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -229,10 +229,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `197 + v * (1 ±0)` // Estimated: `3662 + v * (1 ±0)` - // Minimum execution time: 5_320_000 picoseconds. - Weight::from_parts(5_435_000, 3662) + // Minimum execution time: 5_370_000 picoseconds. + Weight::from_parts(5_525_000, 3662) // Standard Error: 1 - .saturating_add(Weight::from_parts(1_138, 0).saturating_mul(v.into())) + .saturating_add(Weight::from_parts(1_149, 0).saturating_mul(v.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(v.into())) From 338a494c4b945dbda0aa9cf103dd5218b22d626b Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 24 Jan 2024 12:07:21 +0100 Subject: [PATCH 28/31] Fix deposit stuff --- .../frame/state-trie-migration/src/lib.rs | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index e4da7afcddf6..9ad5ef8b08ba 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -652,7 +652,7 @@ pub mod pallet { ); // ensure they can pay more than the fee. - let deposit = T::SignedDepositPerItem::get().saturating_mul(limits.item.into()); + let deposit = Self::calculate_deposit_for(limits.item); ensure!( T::Currency::can_hold(&HoldReason::SlashForContinueMigrate.into(), &who, deposit), Error::::NotEnoughFunds @@ -726,9 +726,7 @@ pub mod pallet { let who = T::SignedFilter::ensure_origin(origin)?; // ensure they can pay more than the fee. - let deposit = T::SignedDepositBase::get().saturating_add( - T::SignedDepositPerItem::get().saturating_mul((keys.len() as u32).into()), - ); + let deposit = Self::calculate_deposit_for(keys.len() as u32); ensure!( T::Currency::can_hold(&HoldReason::SlashForMigrateCustomTop.into(), &who, deposit), Error::::NotEnoughFunds @@ -794,9 +792,7 @@ pub mod pallet { let who = T::SignedFilter::ensure_origin(origin)?; // ensure they can pay more than the fee. - let deposit = T::SignedDepositBase::get().saturating_add( - T::SignedDepositPerItem::get().saturating_mul((child_keys.len() as u32).into()), - ); + let deposit = Self::calculate_deposit_for(child_keys.len() as u32); ensure!( T::Currency::can_hold( &HoldReason::SlashForMigrateCustomChild.into(), @@ -967,6 +963,12 @@ pub mod pallet { string.extend_from_slice(root.as_ref()); string } + + /// Calculate the deposit required for migrating a specific number of keys. + pub fn calculate_deposit_for(keys_count: u32) -> BalanceOf { + T::SignedDepositBase::get() + .saturating_add(T::SignedDepositPerItem::get().saturating_mul(keys_count.into())) + } } } @@ -985,8 +987,7 @@ mod benchmarks { const KEY: &[u8] = b"key"; fn set_balance_for_deposit(caller: &T::AccountId, item: u32) -> BalanceOf { - let deposit = T::SignedDepositBase::get() - .saturating_add(T::SignedDepositPerItem::get().saturating_mul(item.into())); + let deposit = StateTrieMigration::::calculate_deposit_for(item); let stash = T::Currency::minimum_balance() * BalanceOf::::from(1000u32) + deposit; T::Currency::set_balance(caller, stash); stash @@ -1056,8 +1057,7 @@ mod benchmarks { frame_system::Pallet::::assert_last_event( ::RuntimeEvent::from(crate::Event::Slashed { who: caller.clone(), - amount: T::SignedDepositBase::get() - .saturating_add(T::SignedDepositPerItem::get().saturating_mul(1u32.into())), + amount: StateTrieMigration::::calculate_deposit_for(1u32), }).into(), ); } @@ -1591,7 +1591,10 @@ mod test { // no funds should remain reserved. assert_eq!(Balances::reserved_balance(&1), 0); // user was slashed - assert_eq!(Balances::free_balance(&1), 1000 - (5 * SignedDepositPerItem::get())); + assert_eq!( + Balances::free_balance(&1), + 1000 - StateTrieMigration::calculate_deposit_for(5) + ); }); } @@ -1637,7 +1640,7 @@ mod test { assert_eq!(Balances::reserved_balance(&1), 0); assert_eq!( Balances::free_balance(&1), - 1000 - (3 * SignedDepositPerItem::get() + SignedDepositBase::get()) + 1000 - StateTrieMigration::calculate_deposit_for(3) ); }); } @@ -1672,7 +1675,7 @@ mod test { assert_eq!(Balances::reserved_balance(&1), 0); assert_eq!( Balances::free_balance(&1), - 1000 - (2 * SignedDepositPerItem::get() + SignedDepositBase::get()) + 1000 - StateTrieMigration::calculate_deposit_for(2) ); }); } From 9f2c695c86d4879fb3f7419fc26e3aa8e03d9911 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 24 Jan 2024 12:18:28 +0100 Subject: [PATCH 29/31] Single reason is enough --- .../frame/state-trie-migration/src/lib.rs | 32 +++++++------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index 9ad5ef8b08ba..2f3076dd0701 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -467,15 +467,9 @@ pub mod pallet { /// The reason for this pallet placing a hold on funds. #[pallet::composite_enum] pub enum HoldReason { - /// The funds are held as a deposit to slash for `continue_migrate`. + /// The funds are held as a deposit for slashing. #[codec(index = 0)] - SlashForContinueMigrate, - /// The funds are held as a deposit to slash for `migrate_custom_top`. - #[codec(index = 1)] - SlashForMigrateCustomTop, - /// The funds are held as a deposit to slash for `migrate_custom_child`. - #[codec(index = 2)] - SlashForMigrateCustomChild, + SlashForMigrate, } /// Configurations of this pallet. @@ -654,7 +648,7 @@ pub mod pallet { // ensure they can pay more than the fee. let deposit = Self::calculate_deposit_for(limits.item); ensure!( - T::Currency::can_hold(&HoldReason::SlashForContinueMigrate.into(), &who, deposit), + T::Currency::can_hold(&HoldReason::SlashForMigrate.into(), &who, deposit), Error::::NotEnoughFunds ); @@ -673,10 +667,10 @@ pub mod pallet { // ensure that the migration witness data was correct. if real_size_upper < task.dyn_size { - T::Currency::hold(&HoldReason::SlashForContinueMigrate.into(), &who, deposit)?; + T::Currency::hold(&HoldReason::SlashForMigrate.into(), &who, deposit)?; // let the imbalance burn. let _burned = T::Currency::burn_all_held( - &HoldReason::SlashForContinueMigrate.into(), + &HoldReason::SlashForMigrate.into(), &who, Precision::BestEffort, Fortitude::Force, @@ -728,7 +722,7 @@ pub mod pallet { // ensure they can pay more than the fee. let deposit = Self::calculate_deposit_for(keys.len() as u32); ensure!( - T::Currency::can_hold(&HoldReason::SlashForMigrateCustomTop.into(), &who, deposit), + T::Currency::can_hold(&HoldReason::SlashForMigrate.into(), &who, deposit), Error::::NotEnoughFunds ); @@ -741,9 +735,9 @@ pub mod pallet { } if dyn_size > witness_size { - T::Currency::hold(&HoldReason::SlashForMigrateCustomTop.into(), &who, deposit)?; + T::Currency::hold(&HoldReason::SlashForMigrate.into(), &who, deposit)?; let _burned = T::Currency::burn_all_held( - &HoldReason::SlashForMigrateCustomTop.into(), + &HoldReason::SlashForMigrate.into(), &who, Precision::BestEffort, Fortitude::Force, @@ -794,11 +788,7 @@ pub mod pallet { // ensure they can pay more than the fee. let deposit = Self::calculate_deposit_for(child_keys.len() as u32); ensure!( - T::Currency::can_hold( - &HoldReason::SlashForMigrateCustomChild.into(), - &who, - deposit - ), + T::Currency::can_hold(&HoldReason::SlashForMigrate.into(), &who, deposit), Error::::NotEnoughFunds ); @@ -812,9 +802,9 @@ pub mod pallet { } if dyn_size != total_size { - T::Currency::hold(&HoldReason::SlashForMigrateCustomChild.into(), &who, deposit)?; + T::Currency::hold(&HoldReason::SlashForMigrate.into(), &who, deposit)?; let _burned = T::Currency::burn_all_held( - &HoldReason::SlashForMigrateCustomChild.into(), + &HoldReason::SlashForMigrate.into(), &who, Precision::BestEffort, Fortitude::Force, From c07b5b58efa23e00c66e0bfb31c3dc5531716284 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 24 Jan 2024 12:31:53 +0100 Subject: [PATCH 30/31] Hide away `hold + slash_all_held` to `fn slash` --- .../frame/state-trie-migration/src/lib.rs | 54 +++++++------------ 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/substrate/frame/state-trie-migration/src/lib.rs b/substrate/frame/state-trie-migration/src/lib.rs index 2f3076dd0701..6b3aa9934e07 100644 --- a/substrate/frame/state-trie-migration/src/lib.rs +++ b/substrate/frame/state-trie-migration/src/lib.rs @@ -667,16 +667,7 @@ pub mod pallet { // ensure that the migration witness data was correct. if real_size_upper < task.dyn_size { - T::Currency::hold(&HoldReason::SlashForMigrate.into(), &who, deposit)?; - // let the imbalance burn. - let _burned = T::Currency::burn_all_held( - &HoldReason::SlashForMigrate.into(), - &who, - Precision::BestEffort, - Fortitude::Force, - )?; - debug_assert!(deposit.saturating_sub(_burned).is_zero()); - Self::deposit_event(Event::::Slashed { who, amount: deposit }); + Self::slash(who, deposit)?; return Ok(().into()) } @@ -735,15 +726,7 @@ pub mod pallet { } if dyn_size > witness_size { - T::Currency::hold(&HoldReason::SlashForMigrate.into(), &who, deposit)?; - let _burned = T::Currency::burn_all_held( - &HoldReason::SlashForMigrate.into(), - &who, - Precision::BestEffort, - Fortitude::Force, - )?; - debug_assert!(deposit.saturating_sub(_burned).is_zero()); - Self::deposit_event(Event::::Slashed { who, amount: deposit }); + Self::slash(who, deposit)?; Ok(().into()) } else { Self::deposit_event(Event::::Migrated { @@ -802,15 +785,7 @@ pub mod pallet { } if dyn_size != total_size { - T::Currency::hold(&HoldReason::SlashForMigrate.into(), &who, deposit)?; - let _burned = T::Currency::burn_all_held( - &HoldReason::SlashForMigrate.into(), - &who, - Precision::BestEffort, - Fortitude::Force, - )?; - debug_assert!(deposit.saturating_sub(_burned).is_zero()); - Self::deposit_event(Event::::Slashed { who, amount: deposit }); + Self::slash(who, deposit)?; Ok(PostDispatchInfo { actual_weight: Some(T::WeightInfo::migrate_custom_child_fail()), pays_fee: Pays::Yes, @@ -955,21 +930,32 @@ pub mod pallet { } /// Calculate the deposit required for migrating a specific number of keys. - pub fn calculate_deposit_for(keys_count: u32) -> BalanceOf { + pub(crate) fn calculate_deposit_for(keys_count: u32) -> BalanceOf { T::SignedDepositBase::get() .saturating_add(T::SignedDepositPerItem::get().saturating_mul(keys_count.into())) } + + /// Slash an account for migration. + fn slash(who: T::AccountId, amount: BalanceOf) -> Result<(), DispatchError> { + T::Currency::hold(&HoldReason::SlashForMigrate.into(), &who, amount)?; + // let the imbalance burn. + let _burned = T::Currency::burn_all_held( + &HoldReason::SlashForMigrate.into(), + &who, + Precision::BestEffort, + Fortitude::Force, + )?; + debug_assert!(amount.saturating_sub(_burned).is_zero()); + Self::deposit_event(Event::::Slashed { who, amount }); + Ok(()) + } } } #[cfg(feature = "runtime-benchmarks")] mod benchmarks { use super::{pallet::Pallet as StateTrieMigration, *}; - use frame_support::traits::{ - fungible::{Inspect, Mutate}, - Get, - }; - use sp_runtime::traits::Saturating; + use frame_support::traits::fungible::{Inspect, Mutate}; use sp_std::prelude::*; // The size of the key seemingly makes no difference in the read/write time, so we make it From 5b03bf2a6440de254b99a52603dda4b4fb14e965 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 24 Jan 2024 12:11:26 +0000 Subject: [PATCH 31/31] ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=dev --target_dir=substrate --pallet=pallet_state_trie_migration --- .../frame/state-trie-migration/src/weights.rs | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/substrate/frame/state-trie-migration/src/weights.rs b/substrate/frame/state-trie-migration/src/weights.rs index 2be785fc99fe..8fa80b38957d 100644 --- a/substrate/frame/state-trie-migration/src/weights.rs +++ b/substrate/frame/state-trie-migration/src/weights.rs @@ -18,9 +18,9 @@ //! Autogenerated weights for `pallet_state_trie_migration` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-01-19, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-01-24, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-j8vvqcjr-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `runner-grjcggob-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` // Executed Command: @@ -71,8 +71,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `108` // Estimated: `3640` - // Minimum execution time: 18_692_000 picoseconds. - Weight::from_parts(19_391_000, 3640) + // Minimum execution time: 18_520_000 picoseconds. + Weight::from_parts(19_171_000, 3640) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -82,8 +82,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `76` // Estimated: `1493` - // Minimum execution time: 3_886_000 picoseconds. - Weight::from_parts(4_136_000, 1493) + // Minimum execution time: 3_786_000 picoseconds. + Weight::from_parts(4_038_000, 1493) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: `Balances::Holds` (r:1 w:0) @@ -92,8 +92,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3640` - // Minimum execution time: 11_232_000 picoseconds. - Weight::from_parts(11_641_000, 3640) + // Minimum execution time: 11_144_000 picoseconds. + Weight::from_parts(11_556_000, 3640) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: `Balances::Holds` (r:1 w:1) @@ -104,8 +104,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `113` // Estimated: `3640` - // Minimum execution time: 61_149_000 picoseconds. - Weight::from_parts(62_082_000, 3640) + // Minimum execution time: 59_288_000 picoseconds. + Weight::from_parts(60_276_000, 3640) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -115,8 +115,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3640` - // Minimum execution time: 11_372_000 picoseconds. - Weight::from_parts(11_769_000, 3640) + // Minimum execution time: 11_258_000 picoseconds. + Weight::from_parts(11_626_000, 3640) .saturating_add(T::DbWeight::get().reads(1_u64)) } /// Storage: `Balances::Holds` (r:1 w:1) @@ -127,8 +127,8 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `106` // Estimated: `3640` - // Minimum execution time: 62_713_000 picoseconds. - Weight::from_parts(64_210_000, 3640) + // Minimum execution time: 61_575_000 picoseconds. + Weight::from_parts(63_454_000, 3640) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } @@ -139,10 +139,10 @@ impl WeightInfo for SubstrateWeight { // Proof Size summary in bytes: // Measured: `197 + v * (1 ±0)` // Estimated: `3662 + v * (1 ±0)` - // Minimum execution time: 5_370_000 picoseconds. - Weight::from_parts(5_525_000, 3662) + // Minimum execution time: 5_259_000 picoseconds. + Weight::from_parts(5_433_000, 3662) // Standard Error: 1 - .saturating_add(Weight::from_parts(1_149, 0).saturating_mul(v.into())) + .saturating_add(Weight::from_parts(1_159, 0).saturating_mul(v.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(v.into())) @@ -161,8 +161,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `108` // Estimated: `3640` - // Minimum execution time: 18_692_000 picoseconds. - Weight::from_parts(19_391_000, 3640) + // Minimum execution time: 18_520_000 picoseconds. + Weight::from_parts(19_171_000, 3640) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -172,8 +172,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `76` // Estimated: `1493` - // Minimum execution time: 3_886_000 picoseconds. - Weight::from_parts(4_136_000, 1493) + // Minimum execution time: 3_786_000 picoseconds. + Weight::from_parts(4_038_000, 1493) .saturating_add(RocksDbWeight::get().reads(1_u64)) } /// Storage: `Balances::Holds` (r:1 w:0) @@ -182,8 +182,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3640` - // Minimum execution time: 11_232_000 picoseconds. - Weight::from_parts(11_641_000, 3640) + // Minimum execution time: 11_144_000 picoseconds. + Weight::from_parts(11_556_000, 3640) .saturating_add(RocksDbWeight::get().reads(1_u64)) } /// Storage: `Balances::Holds` (r:1 w:1) @@ -194,8 +194,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `113` // Estimated: `3640` - // Minimum execution time: 61_149_000 picoseconds. - Weight::from_parts(62_082_000, 3640) + // Minimum execution time: 59_288_000 picoseconds. + Weight::from_parts(60_276_000, 3640) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -205,8 +205,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3640` - // Minimum execution time: 11_372_000 picoseconds. - Weight::from_parts(11_769_000, 3640) + // Minimum execution time: 11_258_000 picoseconds. + Weight::from_parts(11_626_000, 3640) .saturating_add(RocksDbWeight::get().reads(1_u64)) } /// Storage: `Balances::Holds` (r:1 w:1) @@ -217,8 +217,8 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `106` // Estimated: `3640` - // Minimum execution time: 62_713_000 picoseconds. - Weight::from_parts(64_210_000, 3640) + // Minimum execution time: 61_575_000 picoseconds. + Weight::from_parts(63_454_000, 3640) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } @@ -229,10 +229,10 @@ impl WeightInfo for () { // Proof Size summary in bytes: // Measured: `197 + v * (1 ±0)` // Estimated: `3662 + v * (1 ±0)` - // Minimum execution time: 5_370_000 picoseconds. - Weight::from_parts(5_525_000, 3662) + // Minimum execution time: 5_259_000 picoseconds. + Weight::from_parts(5_433_000, 3662) // Standard Error: 1 - .saturating_add(Weight::from_parts(1_149, 0).saturating_mul(v.into())) + .saturating_add(Weight::from_parts(1_159, 0).saturating_mul(v.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(v.into()))