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 efe4a4052a99..355e830d1f37 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -63,7 +63,8 @@ use frame_support::{ ord_parameter_types, parameter_types, traits::{ fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool, - ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, InstanceFilter, TransformOrigin, + ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, InstanceFilter, + LinearStoragePrice, TransformOrigin, }, weights::{ConstantMultiplier, Weight, WeightToFee as _}, BoundedVec, PalletId, @@ -476,13 +477,14 @@ impl pallet_utility::Config for Runtime { parameter_types! { // One storage item; key size 32, value size 8; . pub const ProxyDepositBase: Balance = deposit(1, 40); - // Additional storage item size of 33 bytes. - pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const ProxyDepositPerByte: Balance = deposit(0, 1); pub const MaxProxies: u16 = 32; // One storage item; key size 32, value size 16 pub const AnnouncementDepositBase: Balance = deposit(1, 48); - pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + pub const AnnouncementDepositPerByte: Balance = deposit(0, 1); pub const MaxPending: u16 = 32; + pub const ProxyHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Proxy); + pub const AnnouncementHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Announcement); } /// The type used to represent the kinds of proxying allowed. @@ -638,16 +640,23 @@ impl InstanceFilter for ProxyType { impl pallet_proxy::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; - type Currency = Balances; type ProxyType = ProxyType; - type ProxyDepositBase = ProxyDepositBase; - type ProxyDepositFactor = ProxyDepositFactor; type MaxProxies = MaxProxies; type WeightInfo = weights::pallet_proxy::WeightInfo; type MaxPending = MaxPending; type CallHasher = BlakeTwo256; - type AnnouncementDepositBase = AnnouncementDepositBase; - type AnnouncementDepositFactor = AnnouncementDepositFactor; + type ProxyConsideration = fungible::HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; + type AnnouncementConsideration = fungible::HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; } parameter_types! { diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 712b5c0ada94..1f58046289ac 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -46,7 +46,7 @@ use frame_support::{ fungible, fungibles, tokens::{imbalance::ResolveAssetTo, nonfungibles_v2::Inspect}, AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, InstanceFilter, - TransformOrigin, + LinearStoragePrice, TransformOrigin, }, weights::{ConstantMultiplier, Weight, WeightToFee as _}, BoundedVec, PalletId, @@ -472,13 +472,14 @@ impl pallet_utility::Config for Runtime { parameter_types! { // One storage item; key size 32, value size 8; . pub const ProxyDepositBase: Balance = deposit(1, 40); - // Additional storage item size of 33 bytes. - pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const ProxyDepositPerByte: Balance = deposit(0, 1); pub const MaxProxies: u16 = 32; // One storage item; key size 32, value size 16 pub const AnnouncementDepositBase: Balance = deposit(1, 48); - pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + pub const AnnouncementDepositPerByte: Balance = deposit(0, 1); pub const MaxPending: u16 = 32; + pub const ProxyHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Proxy); + pub const AnnouncementHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Announcement); } /// The type used to represent the kinds of proxying allowed. @@ -634,16 +635,23 @@ impl InstanceFilter for ProxyType { impl pallet_proxy::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; - type Currency = Balances; type ProxyType = ProxyType; - type ProxyDepositBase = ProxyDepositBase; - type ProxyDepositFactor = ProxyDepositFactor; type MaxProxies = MaxProxies; type WeightInfo = weights::pallet_proxy::WeightInfo; type MaxPending = MaxPending; type CallHasher = BlakeTwo256; - type AnnouncementDepositBase = AnnouncementDepositBase; - type AnnouncementDepositFactor = AnnouncementDepositFactor; + type ProxyConsideration = fungible::HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; + type AnnouncementConsideration = fungible::HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; } parameter_types! { diff --git a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs index f22feb70382a..d846e9b1a20a 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-westend/src/lib.rs @@ -266,11 +266,11 @@ impl pallet_utility::Config for Runtime { parameter_types! { // One storage item; key size 32, value size 8; . pub const ProxyDepositBase: Balance = deposit(1, 40); - // Additional storage item size of 33 bytes. - pub const ProxyDepositFactor: Balance = deposit(0, 33); - // One storage item; key size 32, value size 16 + pub const ProxyDepositPerByte: Balance = deposit(0, 1); pub const AnnouncementDepositBase: Balance = deposit(1, 48); - pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + pub const AnnouncementDepositPerByte: Balance = deposit(0, 1); + pub const ProxyHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Proxy); + pub const AnnouncementHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Announcement); } /// The type used to represent the kinds of proxying allowed. @@ -368,16 +368,23 @@ impl InstanceFilter for ProxyType { impl pallet_proxy::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; - type Currency = Balances; type ProxyType = ProxyType; - type ProxyDepositBase = ProxyDepositBase; - type ProxyDepositFactor = ProxyDepositFactor; type MaxProxies = ConstU32<32>; type WeightInfo = weights::pallet_proxy::WeightInfo; type MaxPending = ConstU32<32>; type CallHasher = BlakeTwo256; - type AnnouncementDepositBase = AnnouncementDepositBase; - type AnnouncementDepositFactor = AnnouncementDepositFactor; + type ProxyConsideration = HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; + type AnnouncementConsideration = HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; } parameter_types! { diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 0c9f9461f7f4..51c1610a17d9 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -45,7 +45,8 @@ use frame_support::{ genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ - ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, InstanceFilter, TransformOrigin, + fungible::HoldConsideration, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, + InstanceFilter, LinearStoragePrice, TransformOrigin, }, weights::{ConstantMultiplier, Weight, WeightToFee as _}, PalletId, @@ -549,28 +550,35 @@ impl InstanceFilter for ProxyType { parameter_types! { // One storage item; key size 32, value size 8; . pub const ProxyDepositBase: Balance = deposit(1, 40); - // Additional storage item size of 33 bytes. - pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const ProxyDepositPerByte: Balance = deposit(0, 1); pub const MaxProxies: u16 = 32; - // One storage item; key size 32, value size 16 pub const AnnouncementDepositBase: Balance = deposit(1, 48); - pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + pub const AnnouncementDepositPerByte: Balance = deposit(0, 1); pub const MaxPending: u16 = 32; + pub const ProxyHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Proxy); + pub const AnnouncementHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Announcement); } impl pallet_proxy::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; - type Currency = Balances; type ProxyType = ProxyType; - type ProxyDepositBase = ProxyDepositBase; - type ProxyDepositFactor = ProxyDepositFactor; type MaxProxies = MaxProxies; type WeightInfo = weights::pallet_proxy::WeightInfo; type MaxPending = MaxPending; type CallHasher = BlakeTwo256; - type AnnouncementDepositBase = AnnouncementDepositBase; - type AnnouncementDepositFactor = AnnouncementDepositFactor; + type ProxyConsideration = HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; + type AnnouncementConsideration = HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; } impl pallet_utility::Config for Runtime { diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 614eae895a74..eba8aab52ffb 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -45,7 +45,8 @@ use frame_support::{ genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ - ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, InstanceFilter, TransformOrigin, + fungible::HoldConsideration, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, + InstanceFilter, LinearStoragePrice, TransformOrigin, }, weights::{ConstantMultiplier, Weight, WeightToFee as _}, PalletId, @@ -549,28 +550,36 @@ impl InstanceFilter for ProxyType { parameter_types! { // One storage item; key size 32, value size 8; . pub const ProxyDepositBase: Balance = deposit(1, 40); - // Additional storage item size of 33 bytes. - pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const ProxyDepositPerByte: Balance = deposit(0, 1); pub const MaxProxies: u16 = 32; // One storage item; key size 32, value size 16 pub const AnnouncementDepositBase: Balance = deposit(1, 48); - pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + pub const AnnouncementDepositPerByte: Balance = deposit(0, 1); pub const MaxPending: u16 = 32; + pub const ProxyHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Proxy); + pub const AnnouncementHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Announcement); } impl pallet_proxy::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; - type Currency = Balances; type ProxyType = ProxyType; - type ProxyDepositBase = ProxyDepositBase; - type ProxyDepositFactor = ProxyDepositFactor; type MaxProxies = MaxProxies; type WeightInfo = weights::pallet_proxy::WeightInfo; type MaxPending = MaxPending; type CallHasher = BlakeTwo256; - type AnnouncementDepositBase = AnnouncementDepositBase; - type AnnouncementDepositFactor = AnnouncementDepositFactor; + type ProxyConsideration = HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; + type AnnouncementConsideration = HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; } impl pallet_utility::Config for Runtime { diff --git a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs index 9b251a90d678..0c8a8fc4237e 100644 --- a/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-rococo/src/lib.rs @@ -34,8 +34,8 @@ use frame_support::{ genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ - ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, InstanceFilter, - TransformOrigin, + fungible::HoldConsideration, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, + Everything, InstanceFilter, LinearStoragePrice, TransformOrigin, }, weights::{ConstantMultiplier, Weight, WeightToFee as _}, PalletId, @@ -492,28 +492,36 @@ impl InstanceFilter for ProxyType { parameter_types! { // One storage item; key size 32, value size 8. pub const ProxyDepositBase: Balance = deposit(1, 40); - // Additional storage item size of 33 bytes. - pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const ProxyDepositPerByte: Balance = deposit(0, 1); pub const MaxProxies: u16 = 32; // One storage item; key size 32, value size 16. pub const AnnouncementDepositBase: Balance = deposit(1, 48); - pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + pub const AnnouncementDepositPerByte: Balance = deposit(0, 1); pub const MaxPending: u16 = 32; + pub const ProxyHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Proxy); + pub const AnnouncementHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Announcement); } impl pallet_proxy::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; - type Currency = Balances; type ProxyType = ProxyType; - type ProxyDepositBase = ProxyDepositBase; - type ProxyDepositFactor = ProxyDepositFactor; type MaxProxies = MaxProxies; type WeightInfo = weights::pallet_proxy::WeightInfo; type MaxPending = MaxPending; type CallHasher = BlakeTwo256; - type AnnouncementDepositBase = AnnouncementDepositBase; - type AnnouncementDepositFactor = AnnouncementDepositFactor; + type ProxyConsideration = HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; + type AnnouncementConsideration = HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; } impl pallet_utility::Config for Runtime { diff --git a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs index 07bfba92c933..59d76c4ef36a 100644 --- a/cumulus/parachains/runtimes/people/people-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/people/people-westend/src/lib.rs @@ -34,8 +34,8 @@ use frame_support::{ genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ - ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, InstanceFilter, - TransformOrigin, + fungible::HoldConsideration, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, + Everything, InstanceFilter, LinearStoragePrice, TransformOrigin, }, weights::{ConstantMultiplier, Weight, WeightToFee as _}, PalletId, @@ -493,27 +493,36 @@ parameter_types! { // One storage item; key size 32, value size 8. pub const ProxyDepositBase: Balance = deposit(1, 40); // Additional storage item size of 33 bytes. - pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const ProxyDepositPerByte: Balance = deposit(0, 1); pub const MaxProxies: u16 = 32; // One storage item; key size 32, value size 16. pub const AnnouncementDepositBase: Balance = deposit(1, 48); - pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + pub const AnnouncementDepositPerByte: Balance = deposit(0, 1); pub const MaxPending: u16 = 32; + pub const ProxyHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Proxy); + pub const AnnouncementHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Announcement); } impl pallet_proxy::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; - type Currency = Balances; type ProxyType = ProxyType; - type ProxyDepositBase = ProxyDepositBase; - type ProxyDepositFactor = ProxyDepositFactor; type MaxProxies = MaxProxies; type WeightInfo = weights::pallet_proxy::WeightInfo; type MaxPending = MaxPending; type CallHasher = BlakeTwo256; - type AnnouncementDepositBase = AnnouncementDepositBase; - type AnnouncementDepositFactor = AnnouncementDepositFactor; + type ProxyConsideration = HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; + type AnnouncementConsideration = HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; } impl pallet_utility::Config for Runtime { diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 6ec49c5830f7..5a43f724615b 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -796,12 +796,13 @@ impl pallet_vesting::Config for Runtime { parameter_types! { // One storage item; key size 32, value size 8; . pub const ProxyDepositBase: Balance = deposit(1, 8); - // Additional storage item size of 33 bytes. - pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const ProxyDepositPerByte: Balance = deposit(0, 1); pub const MaxProxies: u16 = 32; pub const AnnouncementDepositBase: Balance = deposit(1, 8); - pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + pub const AnnouncementDepositPerByte: Balance = deposit(0, 1); pub const MaxPending: u16 = 32; + pub const ProxyHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Proxy); + pub const AnnouncementHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Announcement); } /// The type used to represent the kinds of proxying allowed. @@ -929,16 +930,23 @@ impl InstanceFilter for ProxyType { impl pallet_proxy::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; - type Currency = Balances; type ProxyType = ProxyType; - type ProxyDepositBase = ProxyDepositBase; - type ProxyDepositFactor = ProxyDepositFactor; type MaxProxies = MaxProxies; type WeightInfo = weights::pallet_proxy::WeightInfo; type MaxPending = MaxPending; type CallHasher = BlakeTwo256; - type AnnouncementDepositBase = AnnouncementDepositBase; - type AnnouncementDepositFactor = AnnouncementDepositFactor; + type ProxyConsideration = HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; + type AnnouncementConsideration = HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; } impl parachains_origin::Config for Runtime {} diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index d0c1cd89de32..369fbc503750 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1024,12 +1024,13 @@ impl pallet_sudo::Config for Runtime { parameter_types! { // One storage item; key size 32, value size 8; . pub const ProxyDepositBase: Balance = deposit(1, 8); - // Additional storage item size of 33 bytes. - pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const ProxyDepositPerByte: Balance = deposit(0, 1); pub const MaxProxies: u16 = 32; pub const AnnouncementDepositBase: Balance = deposit(1, 8); - pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + pub const AnnouncementDepositPerByte: Balance = deposit(0, 1); pub const MaxPending: u16 = 32; + pub const ProxyHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Proxy); + pub const AnnouncementHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Announcement); } /// The type used to represent the kinds of proxying allowed. @@ -1167,16 +1168,23 @@ impl InstanceFilter for ProxyType { impl pallet_proxy::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; - type Currency = Balances; type ProxyType = ProxyType; - type ProxyDepositBase = ProxyDepositBase; - type ProxyDepositFactor = ProxyDepositFactor; + type ProxyConsideration = HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; + type AnnouncementConsideration = HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; type MaxProxies = MaxProxies; type WeightInfo = weights::pallet_proxy::WeightInfo; type MaxPending = MaxPending; type CallHasher = BlakeTwo256; - type AnnouncementDepositBase = AnnouncementDepositBase; - type AnnouncementDepositFactor = AnnouncementDepositFactor; } impl parachains_origin::Config for Runtime {} diff --git a/prdoc/pr_5336.prdoc b/prdoc/pr_5336.prdoc new file mode 100644 index 000000000000..fc2f49516887 --- /dev/null +++ b/prdoc/pr_5336.prdoc @@ -0,0 +1,36 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: Refactor proxy pallet to use Consideration trait + +doc: + - audience: Runtime Dev + description: | + Before this pallet would reserve its storage value manually, `Consideration` + trait simplifies the implementation, although users now need to refactor their + configuration of proxy pallet. + + Refactors the rest of the dependent crates to use the new proxy pallet with + Consideration. + +crates: + - name: pallet-proxy + bump: major + - name: frame-support + bump: patch + - name: rococo-runtime + bump: major + - name: westend-runtime + bump: major + - name: pallet-contracts + bump: patch + - name: pallet-safe-mode + bump: patch + - name: pallet-tx-pause + bump: patch + - name: asset-hub-rococo-runtime + bump: major + - name: asset-hub-westend-runtime + bump: major + - name: collectives-westend-runtime + bump: major diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index c8409078af57..fedda4c3a9da 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -358,10 +358,11 @@ impl pallet_multisig::Config for Runtime { parameter_types! { // One storage item; key size 32, value size 8; . pub const ProxyDepositBase: Balance = deposit(1, 8); - // Additional storage item size of 33 bytes. - pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const ProxyDepositPerByte: Balance = deposit(0, 1); pub const AnnouncementDepositBase: Balance = deposit(1, 8); - pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + pub const AnnouncementDepositPerByte: Balance = deposit(0, 1); + pub const ProxyHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Proxy); + pub const AnnouncementHoldReason: RuntimeHoldReason = RuntimeHoldReason::Proxy(pallet_proxy::HoldReason::Announcement); } /// The type used to represent the kinds of proxying allowed. @@ -430,16 +431,23 @@ impl InstanceFilter for ProxyType { impl pallet_proxy::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; - type Currency = Balances; type ProxyType = ProxyType; - type ProxyDepositBase = ProxyDepositBase; - type ProxyDepositFactor = ProxyDepositFactor; type MaxProxies = ConstU32<32>; type WeightInfo = pallet_proxy::weights::SubstrateWeight; type MaxPending = ConstU32<32>; type CallHasher = BlakeTwo256; - type AnnouncementDepositBase = AnnouncementDepositBase; - type AnnouncementDepositFactor = AnnouncementDepositFactor; + type ProxyConsideration = HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; + type AnnouncementConsideration = HoldConsideration< + AccountId, + Balances, + ProxyHoldReason, + LinearStoragePrice, + >; } parameter_types! { diff --git a/substrate/frame/contracts/src/tests.rs b/substrate/frame/contracts/src/tests.rs index c3b6e3273f34..c1f7033f83d0 100644 --- a/substrate/frame/contracts/src/tests.rs +++ b/substrate/frame/contracts/src/tests.rs @@ -51,7 +51,7 @@ use frame_support::{ traits::{ fungible::{BalancedHold, Inspect, Mutate, MutateHold}, tokens::Preservation, - ConstU32, ConstU64, Contains, OnIdle, OnInitialize, StorageVersion, + Contains, OnIdle, OnInitialize, StorageVersion, }, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight, WeightMeter}, }; @@ -63,7 +63,7 @@ use sp_io::hashing::blake2_256; use sp_keystore::{testing::MemoryKeystore, KeystoreExt}; use sp_runtime::{ testing::H256, - traits::{BlakeTwo256, Convert, IdentityLookup}, + traits::{Convert, IdentityLookup}, AccountId32, BuildStorage, DispatchError, Perbill, TokenError, }; @@ -386,20 +386,8 @@ impl pallet_utility::Config for Test { type WeightInfo = (); } -impl pallet_proxy::Config for Test { - type RuntimeEvent = RuntimeEvent; - type RuntimeCall = RuntimeCall; - type Currency = Balances; - type ProxyType = (); - type ProxyDepositBase = ConstU64<1>; - type ProxyDepositFactor = ConstU64<1>; - type MaxProxies = ConstU32<32>; - type WeightInfo = (); - type MaxPending = ConstU32<32>; - type CallHasher = BlakeTwo256; - type AnnouncementDepositBase = ConstU64<1>; - type AnnouncementDepositFactor = ConstU64<1>; -} +#[derive_impl(pallet_proxy::config_preludes::TestDefaultConfig)] +impl pallet_proxy::Config for Test {} impl pallet_dummy::Config for Test {} diff --git a/substrate/frame/proxy/Cargo.toml b/substrate/frame/proxy/Cargo.toml index 40c1c9750614..a8095831b46e 100644 --- a/substrate/frame/proxy/Cargo.toml +++ b/substrate/frame/proxy/Cargo.toml @@ -19,13 +19,13 @@ targets = ["x86_64-unknown-linux-gnu"] codec = { features = ["max-encoded-len"], workspace = true } scale-info = { features = ["derive"], workspace = true } frame-benchmarking = { optional = true, workspace = true } +pallet-balances = { optional = true, workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } sp-io = { workspace = true } sp-runtime = { workspace = true } [dev-dependencies] -pallet-balances = { workspace = true, default-features = true } pallet-utility = { workspace = true, default-features = true } sp-core = { workspace = true, default-features = true } diff --git a/substrate/frame/proxy/src/benchmarking.rs b/substrate/frame/proxy/src/benchmarking.rs index 4081af49c243..980700c98a49 100644 --- a/substrate/frame/proxy/src/benchmarking.rs +++ b/substrate/frame/proxy/src/benchmarking.rs @@ -24,7 +24,6 @@ use crate::Pallet as Proxy; use alloc::{boxed::Box, vec}; use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller}; use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; -use sp_runtime::traits::Bounded; const SEED: u32 = 0; @@ -34,10 +33,12 @@ fn assert_last_event(generic_event: ::RuntimeEvent) { fn add_proxies(n: u32, maybe_who: Option) -> Result<(), &'static str> { let caller = maybe_who.unwrap_or_else(whitelisted_caller); - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value() / 2u32.into()); for i in 0..n { let real = T::Lookup::unlookup(account("target", i, SEED)); - + T::ProxyConsideration::ensure_successful( + &caller, + Footprint::from_mel::<(ProxiesVec, ProxyTicketOf)>(), + ); Proxy::::add_proxy( RawOrigin::Signed(caller.clone()).into(), real, @@ -55,12 +56,14 @@ fn add_announcements( ) -> Result<(), &'static str> { let caller = maybe_who.unwrap_or_else(|| account("caller", 0, SEED)); let caller_lookup = T::Lookup::unlookup(caller.clone()); - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value() / 2u32.into()); let real = if let Some(real) = maybe_real { real } else { - let real = account("real", 0, SEED); - T::Currency::make_free_balance_be(&real, BalanceOf::::max_value() / 2u32.into()); + let real: T::AccountId = account("real", 0, SEED); + T::ProxyConsideration::ensure_successful( + &real, + Footprint::from_mel::<(ProxiesVec, ProxyTicketOf)>(), + ); Proxy::::add_proxy( RawOrigin::Signed(real.clone()).into(), caller_lookup, @@ -71,6 +74,10 @@ fn add_announcements( }; let real_lookup = T::Lookup::unlookup(real); for _ in 0..n { + T::AnnouncementConsideration::ensure_successful( + &caller, + Footprint::from_mel::<(AnnouncementsVec, AnnouncementTicketOf)>(), + ); Proxy::::announce( RawOrigin::Signed(caller.clone()).into(), real_lookup.clone(), @@ -81,11 +88,12 @@ fn add_announcements( } benchmarks! { + where_clause { where T: Config } + proxy { let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("target", p - 1, SEED); - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value() / 2u32.into()); // ... and "real" is the traditional caller. This is not a typo. let real: T::AccountId = whitelisted_caller(); let real_lookup = T::Lookup::unlookup(real); @@ -102,11 +110,11 @@ benchmarks! { let caller: T::AccountId = account("pure", 0, SEED); let delegate: T::AccountId = account("target", p - 1, SEED); let delegate_lookup = T::Lookup::unlookup(delegate.clone()); - T::Currency::make_free_balance_be(&delegate, BalanceOf::::max_value() / 2u32.into()); // ... and "real" is the traditional caller. This is not a typo. let real: T::AccountId = whitelisted_caller(); let real_lookup = T::Lookup::unlookup(real); let call: ::RuntimeCall = frame_system::Call::::remark { remark: vec![] }.into(); + T::AnnouncementConsideration::ensure_successful(&delegate, Footprint::from_mel::<(AnnouncementsVec, AnnouncementTicketOf)>()); Proxy::::announce( RawOrigin::Signed(delegate.clone()).into(), real_lookup.clone(), @@ -123,11 +131,11 @@ benchmarks! { let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("target", p - 1, SEED); - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value() / 2u32.into()); // ... and "real" is the traditional caller. This is not a typo. let real: T::AccountId = whitelisted_caller(); let real_lookup = T::Lookup::unlookup(real); let call: ::RuntimeCall = frame_system::Call::::remark { remark: vec![] }.into(); + T::AnnouncementConsideration::ensure_successful(&caller, Footprint::from_mel::<(AnnouncementsVec, AnnouncementTicketOf)>()); Proxy::::announce( RawOrigin::Signed(caller.clone()).into(), real_lookup.clone(), @@ -136,7 +144,7 @@ benchmarks! { add_announcements::(a, Some(caller.clone()), None)?; }: _(RawOrigin::Signed(caller.clone()), real_lookup, T::CallHasher::hash_of(&call)) verify { - let (announcements, _) = Announcements::::get(&caller); + let (announcements, _) = Announcements::::get(&caller).unwrap(); assert_eq!(announcements.len() as u32, a); } @@ -146,11 +154,11 @@ benchmarks! { // In this case the caller is the "target" proxy let caller: T::AccountId = account("target", p - 1, SEED); let caller_lookup = T::Lookup::unlookup(caller.clone()); - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value() / 2u32.into()); // ... and "real" is the traditional caller. This is not a typo. let real: T::AccountId = whitelisted_caller(); let real_lookup = T::Lookup::unlookup(real.clone()); let call: ::RuntimeCall = frame_system::Call::::remark { remark: vec![] }.into(); + T::AnnouncementConsideration::ensure_successful(&caller, Footprint::from_mel::<(AnnouncementsVec, AnnouncementTicketOf)>()); Proxy::::announce( RawOrigin::Signed(caller.clone()).into(), real_lookup, @@ -159,7 +167,7 @@ benchmarks! { add_announcements::(a, Some(caller.clone()), None)?; }: _(RawOrigin::Signed(real), caller_lookup, T::CallHasher::hash_of(&call)) verify { - let (announcements, _) = Announcements::::get(&caller); + let (announcements, _) = Announcements::::get(&caller).unwrap(); assert_eq!(announcements.len() as u32, a); } @@ -168,13 +176,13 @@ benchmarks! { let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::(p, None)?; // In this case the caller is the "target" proxy let caller: T::AccountId = account("target", p - 1, SEED); - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value() / 2u32.into()); // ... and "real" is the traditional caller. This is not a typo. let real: T::AccountId = whitelisted_caller(); let real_lookup = T::Lookup::unlookup(real.clone()); add_announcements::(a, Some(caller.clone()), None)?; let call: ::RuntimeCall = frame_system::Call::::remark { remark: vec![] }.into(); let call_hash = T::CallHasher::hash_of(&call); + T::AnnouncementConsideration::ensure_successful(&caller, Footprint::from_mel::<(AnnouncementsVec, AnnouncementTicketOf)>()); }: _(RawOrigin::Signed(caller.clone()), real_lookup, call_hash) verify { assert_last_event::(Event::Announced { real, proxy: caller, call_hash }.into()); @@ -184,6 +192,7 @@ benchmarks! { let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::(p, None)?; let caller: T::AccountId = whitelisted_caller(); let real = T::Lookup::unlookup(account("target", T::MaxProxies::get(), SEED)); + T::ProxyConsideration::ensure_successful(&caller, Footprint::from_mel::<(ProxiesVec, ProxyTicketOf)>()); }: _( RawOrigin::Signed(caller.clone()), real, @@ -191,7 +200,7 @@ benchmarks! { BlockNumberFor::::zero() ) verify { - let (proxies, _) = Proxies::::get(caller); + let (proxies, _) = Proxies::::get(caller).unwrap(); assert_eq!(proxies.len() as u32, p + 1); } @@ -206,8 +215,8 @@ benchmarks! { BlockNumberFor::::zero() ) verify { - let (proxies, _) = Proxies::::get(caller); - assert_eq!(proxies.len() as u32, p - 1); + let len = Proxies::::get(caller).map(|x| x.0.len()).unwrap_or(0); + assert_eq!(len as u32, p - 1); } remove_proxies { @@ -215,13 +224,14 @@ benchmarks! { let caller: T::AccountId = whitelisted_caller(); }: _(RawOrigin::Signed(caller.clone())) verify { - let (proxies, _) = Proxies::::get(caller); - assert_eq!(proxies.len() as u32, 0); + let len = Proxies::::get(caller).map(|x| x.0.len()).unwrap_or(0); + assert_eq!(len as u32, 0); } create_pure { let p in 1 .. (T::MaxProxies::get() - 1) => add_proxies::(p, None)?; let caller: T::AccountId = whitelisted_caller(); + T::ProxyConsideration::ensure_successful(&caller, Footprint::from_mel::<(ProxiesVec, ProxyTicketOf)>()); }: _( RawOrigin::Signed(caller.clone()), T::ProxyType::default(), @@ -243,9 +253,9 @@ benchmarks! { let caller: T::AccountId = whitelisted_caller(); let caller_lookup = T::Lookup::unlookup(caller.clone()); - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); + T::ProxyConsideration::ensure_successful(&caller, Footprint::from_mel::<(ProxiesVec, ProxyTicketOf)>()); Pallet::::create_pure( - RawOrigin::Signed(whitelisted_caller()).into(), + RawOrigin::Signed(caller.clone()).into(), T::ProxyType::default(), BlockNumberFor::::zero(), 0 diff --git a/substrate/frame/proxy/src/lib.rs b/substrate/frame/proxy/src/lib.rs index 016f2cf225e0..035ee6cc3502 100644 --- a/substrate/frame/proxy/src/lib.rs +++ b/substrate/frame/proxy/src/lib.rs @@ -38,9 +38,10 @@ extern crate alloc; use alloc::{boxed::Box, vec}; use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::{ + defensive, dispatch::GetDispatchInfo, ensure, - traits::{Currency, Get, InstanceFilter, IsSubType, IsType, OriginTrait, ReservableCurrency}, + traits::{Consideration, Footprint, Get, InstanceFilter, IsSubType, IsType, OriginTrait}, BoundedVec, }; use frame_system::{self as system, ensure_signed, pallet_prelude::BlockNumberFor}; @@ -48,18 +49,33 @@ pub use pallet::*; use scale_info::TypeInfo; use sp_io::hashing::blake2_256; use sp_runtime::{ - traits::{Dispatchable, Hash, Saturating, StaticLookup, TrailingZeroInput, Zero}, + traits::{BlakeTwo256, Dispatchable, Hash, Saturating, StaticLookup, TrailingZeroInput, Zero}, DispatchError, DispatchResult, RuntimeDebug, }; pub use weights::WeightInfo; type CallHashOf = <::CallHasher as Hash>::Output; -type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; +type AnnouncementTicketOf = ::AnnouncementConsideration; + +type ProxyTicketOf = ::ProxyConsideration; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; +type ProxiesVec = BoundedVec< + ProxyDefinition< + ::AccountId, + ::ProxyType, + BlockNumberFor, + >, + ::MaxProxies, +>; + +type AnnouncementsVec = BoundedVec< + Announcement<::AccountId, CallHashOf, BlockNumberFor>, + ::MaxPending, +>; + /// The parameters under which a particular account has a proxy relationship with some other /// account. #[derive( @@ -99,19 +115,49 @@ pub struct Announcement { #[frame_support::pallet] pub mod pallet { use super::{DispatchResult, *}; - use frame_support::pallet_prelude::*; + use frame_support::{ + pallet_prelude::{OptionQuery, *}, + traits::Footprint, + }; use frame_system::pallet_prelude::*; #[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, no_aggregated_types)] + impl frame_system::DefaultConfig for TestDefaultConfig {} + + #[frame_support::register_default_impl(TestDefaultConfig)] + impl DefaultConfig for TestDefaultConfig { + #[inject_runtime_type] + type RuntimeEvent = (); + #[inject_runtime_type] + type RuntimeCall = (); + type ProxyType = (); + type MaxProxies = ConstU32<4>; + type MaxPending = ConstU32<2>; + type WeightInfo = (); + type CallHasher = BlakeTwo256; + type ProxyConsideration = (); + type AnnouncementConsideration = (); + } + } + /// Configuration trait. - #[pallet::config] + #[pallet::config(with_default)] pub trait Config: frame_system::Config { /// The overarching event type. + #[pallet::no_default_bounds] type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// The overarching call type. + #[pallet::no_default_bounds] type RuntimeCall: Parameter + Dispatchable + GetDispatchInfo @@ -119,13 +165,11 @@ pub mod pallet { + IsSubType> + IsType<::RuntimeCall>; - /// The currency mechanism. - type Currency: ReservableCurrency; - /// A kind of proxy; specified with the proxy and passed in to the `IsProxyable` filter. /// The instance filter determines whether a given call may be proxied under this type. /// /// IMPORTANT: `Default` must be provided and MUST BE the the *most permissive* value. + #[pallet::no_default_bounds] type ProxyType: Parameter + Member + Ord @@ -134,20 +178,11 @@ pub mod pallet { + Default + MaxEncodedLen; - /// The base amount of currency needed to reserve for creating a proxy. - /// - /// This is held for an additional storage item whose value size is - /// `sizeof(Balance)` bytes and whose key size is `sizeof(AccountId)` bytes. - #[pallet::constant] - type ProxyDepositBase: Get>; + /// A means of providing some cost for storing announcement data on-chain. + type AnnouncementConsideration: Consideration; - /// The amount of currency needed per proxy added. - /// - /// This is held for adding 32 bytes plus an instance of `ProxyType` more into a - /// pre-existing storage value. Thus, when configuring `ProxyDepositFactor` one should take - /// into account `32 + proxy_type.encode().len()` bytes of data. - #[pallet::constant] - type ProxyDepositFactor: Get>; + /// A means of providing some cost for storing proxy data on-chain. + type ProxyConsideration: Consideration; /// The maximum amount of proxies allowed for a single account. #[pallet::constant] @@ -162,20 +197,15 @@ pub mod pallet { /// The type of hash used for hashing the call. type CallHasher: Hash; + } - /// The base amount of currency needed to reserve for creating an announcement. - /// - /// This is held when a new storage item holding a `Balance` is created (typically 16 - /// bytes). - #[pallet::constant] - type AnnouncementDepositBase: Get>; - - /// The amount of currency needed per announcement made. - /// - /// This is held for adding an `AccountId`, `Hash` and `BlockNumber` (typically 68 bytes) - /// into a pre-existing storage value. - #[pallet::constant] - type AnnouncementDepositFactor: Get>; + /// Reasons the pallet may place funds on hold. + #[pallet::composite_enum] + pub enum HoldReason { + /// The funds are held as storage deposit for a pure Proxy. + Proxy, + /// The funds are held as storage deposit for an announcement. + Announcement, } #[pallet::call] @@ -303,13 +333,13 @@ pub mod pallet { let proxy_def = ProxyDefinition { delegate: who.clone(), proxy_type: proxy_type.clone(), delay }; - let bounded_proxies: BoundedVec<_, T::MaxProxies> = + let bounded_proxies: ProxiesVec = vec![proxy_def].try_into().map_err(|_| Error::::TooMany)?; - let deposit = T::ProxyDepositBase::get() + T::ProxyDepositFactor::get(); - T::Currency::reserve(&who, deposit)?; + let ticket = + T::ProxyConsideration::new(&who, Footprint::from_encodable(&bounded_proxies))?; + Proxies::::insert(&pure, (bounded_proxies, ticket)); - Proxies::::insert(&pure, (bounded_proxies, deposit)); Self::deposit_event(Event::PureCreated { pure, who, @@ -353,8 +383,14 @@ pub mod pallet { let proxy = Self::pure_account(&spawner, &proxy_type, index, Some(when)); ensure!(proxy == who, Error::::NoPermission); - let (_, deposit) = Proxies::::take(&who); - T::Currency::unreserve(&spawner, deposit); + if let Some((_, ticket)) = Proxies::::take(&who) { + if let Err(e) = ticket.drop(&spawner) { + defensive!( + "Failed to drop proxy consideration ticket for account {:?}", + (&who, e) + ); + } + } Ok(()) } @@ -383,9 +419,11 @@ pub mod pallet { ) -> DispatchResult { let who = ensure_signed(origin)?; let real = T::Lookup::lookup(real)?; - Proxies::::get(&real) - .0 - .into_iter() + + Proxies::::try_get(&real) + .map(|i| i.0) + .iter() + .flatten() .find(|x| x.delegate == who) .ok_or(Error::::NotProxy)?; @@ -395,20 +433,38 @@ pub mod pallet { height: system::Pallet::::block_number(), }; - Announcements::::try_mutate(&who, |(ref mut pending, ref mut deposit)| { - pending.try_push(announcement).map_err(|_| Error::::TooMany)?; - Self::rejig_deposit( - &who, - *deposit, - T::AnnouncementDepositBase::get(), - T::AnnouncementDepositFactor::get(), - pending.len(), - ) - .map(|d| { - d.expect("Just pushed; pending.len() > 0; rejig_deposit returns Some; qed") - }) - .map(|d| *deposit = d) - })?; + Announcements::::mutate( + &who, + |value: &mut Option<( + AnnouncementsVec, + AnnouncementTicketOf, + )>| + -> Result<(), DispatchError> { + let result = match value.take() { + Some((mut pending, ticket)) => { + pending.try_push(announcement).map_err(|_| Error::::TooMany)?; + let new_ticket = ticket.update( + &who, + Footprint::from_encodable(&pending), + )?; + (pending, new_ticket) + } + None => { + let default: AnnouncementsVec = vec![announcement].try_into().map_err(|_| Error::::TooMany)?; + let footprint = Footprint::from_encodable(&default); + ( + default, + T::AnnouncementConsideration::new( + &who, + footprint, + )?, + ) + } + }; + *value = Some(result); + Ok::<(), DispatchError>(()) + }, + )?; Self::deposit_event(Event::Announced { real, proxy: who, call_hash }); Ok(()) @@ -571,19 +627,8 @@ pub mod pallet { /// The set of account proxies. Maps the account which has delegated to the accounts /// which are being delegated to, together with the amount held on deposit. #[pallet::storage] - pub type Proxies = StorageMap< - _, - Twox64Concat, - T::AccountId, - ( - BoundedVec< - ProxyDefinition>, - T::MaxProxies, - >, - BalanceOf, - ), - ValueQuery, - >; + pub type Proxies = + StorageMap<_, Twox64Concat, T::AccountId, (ProxiesVec, ProxyTicketOf), OptionQuery>; /// The announcements made by the proxy (key). #[pallet::storage] @@ -591,32 +636,21 @@ pub mod pallet { _, Twox64Concat, T::AccountId, - ( - BoundedVec, BlockNumberFor>, T::MaxPending>, - BalanceOf, - ), - ValueQuery, + (AnnouncementsVec, AnnouncementTicketOf), + OptionQuery, >; } impl Pallet { /// Public function to proxies storage. - pub fn proxies( - account: T::AccountId, - ) -> ( - BoundedVec>, T::MaxProxies>, - BalanceOf, - ) { + pub fn proxies(account: T::AccountId) -> Option<(ProxiesVec, ProxyTicketOf)> { Proxies::::get(account) } /// Public function to announcements storage. pub fn announcements( account: T::AccountId, - ) -> ( - BoundedVec, BlockNumberFor>, T::MaxPending>, - BalanceOf, - ) { + ) -> Option<(AnnouncementsVec, AnnouncementTicketOf)> { Announcements::::get(account) } @@ -664,7 +698,15 @@ impl Pallet { delay: BlockNumberFor, ) -> DispatchResult { ensure!(delegator != &delegatee, Error::::NoSelfProxy); - Proxies::::try_mutate(delegator, |(ref mut proxies, ref mut deposit)| { + Proxies::::mutate_exists(delegator, |value| { + let (mut proxies, ticket) = if let Some(v) = value.take() { + v + } else { + let default_proxies: ProxiesVec = Default::default(); + let footprint = Footprint::from_encodable(&default_proxies); + (default_proxies, T::ProxyConsideration::new(delegator, footprint)?) + }; + let proxy_def = ProxyDefinition { delegate: delegatee.clone(), proxy_type: proxy_type.clone(), @@ -672,13 +714,11 @@ impl Pallet { }; let i = proxies.binary_search(&proxy_def).err().ok_or(Error::::Duplicate)?; proxies.try_insert(i, proxy_def).map_err(|_| Error::::TooMany)?; - let new_deposit = Self::deposit(proxies.len() as u32); - if new_deposit > *deposit { - T::Currency::reserve(delegator, new_deposit - *deposit)?; - } else if new_deposit < *deposit { - T::Currency::unreserve(delegator, *deposit - new_deposit); - } - *deposit = new_deposit; + + let new_ticket = ticket.update(delegator, Footprint::from_encodable(&proxies))?; + + *value = Some((proxies, new_ticket)); + Self::deposit_event(Event::::ProxyAdded { delegator: delegator.clone(), delegatee, @@ -704,7 +744,7 @@ impl Pallet { delay: BlockNumberFor, ) -> DispatchResult { Proxies::::try_mutate_exists(delegator, |x| { - let (mut proxies, old_deposit) = x.take().ok_or(Error::::NotFound)?; + let (mut proxies, ticket) = x.take().ok_or(Error::::NotFound)?; let proxy_def = ProxyDefinition { delegate: delegatee.clone(), proxy_type: proxy_type.clone(), @@ -712,14 +752,10 @@ impl Pallet { }; let i = proxies.binary_search(&proxy_def).ok().ok_or(Error::::NotFound)?; proxies.remove(i); - let new_deposit = Self::deposit(proxies.len() as u32); - if new_deposit > old_deposit { - T::Currency::reserve(delegator, new_deposit - old_deposit)?; - } else if new_deposit < old_deposit { - T::Currency::unreserve(delegator, old_deposit - new_deposit); - } + // If this was the last proxy, the ticket will be updated to 0. + let new_ticket = ticket.update(delegator, Footprint::from_encodable(&proxies))?; if !proxies.is_empty() { - *x = Some((proxies, new_deposit)) + *x = Some((proxies, new_ticket)) } Self::deposit_event(Event::::ProxyRemoved { delegator: delegator.clone(), @@ -731,31 +767,6 @@ impl Pallet { }) } - pub fn deposit(num_proxies: u32) -> BalanceOf { - if num_proxies == 0 { - Zero::zero() - } else { - T::ProxyDepositBase::get() + T::ProxyDepositFactor::get() * num_proxies.into() - } - } - - fn rejig_deposit( - who: &T::AccountId, - old_deposit: BalanceOf, - base: BalanceOf, - factor: BalanceOf, - len: usize, - ) -> Result>, DispatchError> { - let new_deposit = - if len == 0 { BalanceOf::::zero() } else { base + factor * (len as u32).into() }; - if new_deposit > old_deposit { - T::Currency::reserve(who, new_deposit - old_deposit)?; - } else if new_deposit < old_deposit { - T::Currency::unreserve(who, old_deposit - new_deposit); - } - Ok(if len == 0 { None } else { Some(new_deposit) }) - } - fn edit_announcements< F: FnMut(&Announcement, BlockNumberFor>) -> bool, >( @@ -763,18 +774,12 @@ impl Pallet { f: F, ) -> DispatchResult { Announcements::::try_mutate_exists(delegate, |x| { - let (mut pending, old_deposit) = x.take().ok_or(Error::::NotFound)?; + let (mut pending, ticket) = x.take().ok_or(Error::::NotFound)?; let orig_pending_len = pending.len(); pending.retain(f); ensure!(orig_pending_len > pending.len(), Error::::NotFound); - *x = Self::rejig_deposit( - delegate, - old_deposit, - T::AnnouncementDepositBase::get(), - T::AnnouncementDepositFactor::get(), - pending.len(), - )? - .map(|deposit| (pending, deposit)); + let new_ticket = ticket.update(delegate, Footprint::from_encodable(&pending))?; + *x = Some((pending, new_ticket)); Ok(()) }) } @@ -788,7 +793,8 @@ impl Pallet { &x.delegate == delegate && force_proxy_type.as_ref().map_or(true, |y| &x.proxy_type == y) }; - Ok(Proxies::::get(real).0.into_iter().find(f).ok_or(Error::::NotProxy)?) + let (proxy, _) = Proxies::::get(real).ok_or(Error::::NotProxy)?; + Ok(proxy.into_iter().find(f).ok_or(Error::::NotProxy)?) } fn do_proxy( @@ -825,7 +831,13 @@ impl Pallet { /// Parameters: /// - `delegator`: The delegator account. pub fn remove_all_proxy_delegates(delegator: &T::AccountId) { - let (_, old_deposit) = Proxies::::take(&delegator); - T::Currency::unreserve(&delegator, old_deposit); + if let Some((_, ticket)) = Proxies::::take(&delegator) { + if let Err(e) = ticket.drop(&delegator) { + defensive!( + "Failed to drop proxy consideration ticket for account {:?}", + (delegator, e) + ); + } + } } } diff --git a/substrate/frame/proxy/src/tests.rs b/substrate/frame/proxy/src/tests.rs index 3edb96026a82..5a9ba3d88df2 100644 --- a/substrate/frame/proxy/src/tests.rs +++ b/substrate/frame/proxy/src/tests.rs @@ -26,7 +26,7 @@ use alloc::{vec, vec::Vec}; use codec::{Decode, Encode}; use frame_support::{ assert_noop, assert_ok, derive_impl, - traits::{ConstU32, ConstU64, Contains}, + traits::{Contains, Currency}, }; use sp_core::H256; use sp_runtime::{traits::BlakeTwo256, BuildStorage, DispatchError, RuntimeDebug}; @@ -114,24 +114,15 @@ impl Contains for BaseFilter { } } } + +#[derive_impl(crate::config_preludes::TestDefaultConfig)] impl Config for Test { - type RuntimeEvent = RuntimeEvent; - type RuntimeCall = RuntimeCall; - type Currency = Balances; type ProxyType = ProxyType; - type ProxyDepositBase = ConstU64<1>; - type ProxyDepositFactor = ConstU64<1>; - type MaxProxies = ConstU32<4>; - type WeightInfo = (); - type CallHasher = BlakeTwo256; - type MaxPending = ConstU32<2>; - type AnnouncementDepositBase = ConstU64<1>; - type AnnouncementDepositFactor = ConstU64<1>; } use super::{Call as ProxyCall, Event as ProxyEvent}; use frame_system::Call as SystemCall; -use pallet_balances::{Call as BalancesCall, Event as BalancesEvent}; +use pallet_balances::Call as BalancesCall; use pallet_utility::{Call as UtilityCall, Event as UtilityEvent}; type SystemError = frame_system::Error; @@ -180,18 +171,16 @@ fn announcement_works() { .into(), ); assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(2), 3, ProxyType::Any, 1)); - assert_eq!(Balances::reserved_balance(3), 0); assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 1, [1; 32].into())); - let announcements = Announcements::::get(3); + let announcements = Announcements::::get(3).unwrap(); assert_eq!( announcements.0, vec![Announcement { real: 1, call_hash: [1; 32].into(), height: 1 }] ); - assert_eq!(Balances::reserved_balance(3), announcements.1); assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 2, [2; 32].into())); - let announcements = Announcements::::get(3); + let announcements = Announcements::::get(3).unwrap(); assert_eq!( announcements.0, vec![ @@ -199,7 +188,6 @@ fn announcement_works() { Announcement { real: 2, call_hash: [2; 32].into(), height: 1 }, ] ); - assert_eq!(Balances::reserved_balance(3), announcements.1); assert_noop!( Proxy::announce(RuntimeOrigin::signed(3), 2, [3; 32].into()), @@ -218,12 +206,11 @@ fn remove_announcement_works() { let e = Error::::NotFound; assert_noop!(Proxy::remove_announcement(RuntimeOrigin::signed(3), 1, [0; 32].into()), e); assert_ok!(Proxy::remove_announcement(RuntimeOrigin::signed(3), 1, [1; 32].into())); - let announcements = Announcements::::get(3); + let announcements = Announcements::::get(3).unwrap(); assert_eq!( announcements.0, vec![Announcement { real: 2, call_hash: [2; 32].into(), height: 1 }] ); - assert_eq!(Balances::reserved_balance(3), announcements.1); }); } @@ -239,12 +226,11 @@ fn reject_announcement_works() { let e = Error::::NotFound; assert_noop!(Proxy::reject_announcement(RuntimeOrigin::signed(4), 3, [1; 32].into()), e); assert_ok!(Proxy::reject_announcement(RuntimeOrigin::signed(1), 3, [1; 32].into())); - let announcements = Announcements::::get(3); + let announcements = Announcements::::get(3).unwrap(); assert_eq!( announcements.0, vec![Announcement { real: 2, call_hash: [2; 32].into(), height: 1 }] ); - assert_eq!(Balances::reserved_balance(3), announcements.1); }); } @@ -270,7 +256,7 @@ fn calling_proxy_doesnt_remove_announcement() { assert_ok!(Proxy::proxy(RuntimeOrigin::signed(2), 1, None, call)); // The announcement is not removed by calling proxy. - let announcements = Announcements::::get(2); + let announcements = Announcements::::get(2).unwrap(); assert_eq!(announcements.0, vec![Announcement { real: 1, call_hash, height: 1 }]); }); } @@ -306,9 +292,8 @@ fn proxy_announced_removes_announcement_and_returns_deposit() { system::Pallet::::set_block_number(2); assert_ok!(Proxy::proxy_announced(RuntimeOrigin::signed(0), 3, 1, None, call.clone())); - let announcements = Announcements::::get(3); + let announcements = Announcements::::get(3).unwrap(); assert_eq!(announcements.0, vec![Announcement { real: 2, call_hash, height: 1 }]); - assert_eq!(Balances::reserved_balance(3), announcements.1); }); } @@ -398,10 +383,7 @@ fn filtering_works() { ProxyEvent::ProxyExecuted { result: Err(SystemError::CallFiltered.into()) }.into(), ); assert_ok!(Proxy::proxy(RuntimeOrigin::signed(2), 1, None, call.clone())); - expect_events(vec![ - BalancesEvent::::Unreserved { who: 1, amount: 5 }.into(), - ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), - ]); + expect_events(vec![ProxyEvent::ProxyExecuted { result: Ok(()) }.into()]); }); } @@ -413,13 +395,9 @@ fn add_remove_proxies_works() { Proxy::add_proxy(RuntimeOrigin::signed(1), 2, ProxyType::Any, 0), Error::::Duplicate ); - assert_eq!(Balances::reserved_balance(1), 2); assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 2, ProxyType::JustTransfer, 0)); - assert_eq!(Balances::reserved_balance(1), 3); assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 3, ProxyType::Any, 0)); - assert_eq!(Balances::reserved_balance(1), 4); assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(1), 4, ProxyType::JustUtility, 0)); - assert_eq!(Balances::reserved_balance(1), 5); assert_noop!( Proxy::add_proxy(RuntimeOrigin::signed(1), 4, ProxyType::Any, 0), Error::::TooMany @@ -438,9 +416,7 @@ fn add_remove_proxies_works() { } .into(), ); - assert_eq!(Balances::reserved_balance(1), 4); assert_ok!(Proxy::remove_proxy(RuntimeOrigin::signed(1), 3, ProxyType::Any, 0)); - assert_eq!(Balances::reserved_balance(1), 3); System::assert_last_event( ProxyEvent::ProxyRemoved { delegator: 1, @@ -451,7 +427,6 @@ fn add_remove_proxies_works() { .into(), ); assert_ok!(Proxy::remove_proxy(RuntimeOrigin::signed(1), 2, ProxyType::Any, 0)); - assert_eq!(Balances::reserved_balance(1), 2); System::assert_last_event( ProxyEvent::ProxyRemoved { delegator: 1, @@ -462,7 +437,6 @@ fn add_remove_proxies_works() { .into(), ); assert_ok!(Proxy::remove_proxy(RuntimeOrigin::signed(1), 2, ProxyType::JustTransfer, 0)); - assert_eq!(Balances::reserved_balance(1), 0); System::assert_last_event( ProxyEvent::ProxyRemoved { delegator: 1, @@ -480,14 +454,11 @@ fn add_remove_proxies_works() { } #[test] -fn cannot_add_proxy_without_balance() { +fn can_add_proxy_without_balance() { + // if proxy consideration is configured empty creating proxy without balance is possible new_test_ext().execute_with(|| { assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(5), 3, ProxyType::Any, 0)); - assert_eq!(Balances::reserved_balance(5), 2); - assert_noop!( - Proxy::add_proxy(RuntimeOrigin::signed(5), 4, ProxyType::Any, 0), - DispatchError::ConsumerRemaining, - ); + assert_ok!(Proxy::add_proxy(RuntimeOrigin::signed(5), 4, ProxyType::Any, 0)); }); } @@ -508,7 +479,6 @@ fn proxying_works() { ); assert_ok!(Proxy::proxy(RuntimeOrigin::signed(2), 1, None, call.clone())); System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into()); - assert_eq!(Balances::free_balance(6), 1); let call = Box::new(RuntimeCall::System(SystemCall::set_code { code: vec![] })); assert_ok!(Proxy::proxy(RuntimeOrigin::signed(3), 1, None, call.clone())); @@ -527,7 +497,6 @@ fn proxying_works() { ); assert_ok!(Proxy::proxy(RuntimeOrigin::signed(3), 1, None, call.clone())); System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into()); - assert_eq!(Balances::free_balance(6), 2); }); } @@ -566,7 +535,6 @@ fn pure_works() { assert_ok!(Balances::transfer_allow_death(RuntimeOrigin::signed(3), anon, 5)); assert_ok!(Proxy::proxy(RuntimeOrigin::signed(1), anon, None, call)); System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into()); - assert_eq!(Balances::free_balance(6), 1); let call = Box::new(RuntimeCall::Proxy(ProxyCall::new_call_variant_kill_pure( 1, @@ -582,9 +550,7 @@ fn pure_works() { Proxy::kill_pure(RuntimeOrigin::signed(1), 1, ProxyType::Any, 0, 1, 0), Error::::NoPermission ); - assert_eq!(Balances::free_balance(1), 1); assert_ok!(Proxy::proxy(RuntimeOrigin::signed(1), anon, None, call.clone())); - assert_eq!(Balances::free_balance(1), 3); assert_noop!( Proxy::proxy(RuntimeOrigin::signed(1), anon, None, call.clone()), Error::::NotProxy diff --git a/substrate/frame/revive/src/tests.rs b/substrate/frame/revive/src/tests.rs index c7185caf0efb..eb0c375f10ff 100644 --- a/substrate/frame/revive/src/tests.rs +++ b/substrate/frame/revive/src/tests.rs @@ -56,7 +56,7 @@ use frame_support::{ traits::{ fungible::{BalancedHold, Inspect, Mutate, MutateHold}, tokens::Preservation, - ConstU32, ConstU64, Contains, OnIdle, OnInitialize, StorageVersion, + Contains, OnIdle, OnInitialize, StorageVersion, }, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight, WeightMeter}, }; @@ -67,7 +67,7 @@ use sp_io::hashing::blake2_256; use sp_keystore::{testing::MemoryKeystore, KeystoreExt}; use sp_runtime::{ testing::H256, - traits::{BlakeTwo256, Convert, IdentityLookup}, + traits::{Convert, IdentityLookup}, AccountId32, BuildStorage, DispatchError, Perbill, TokenError, }; @@ -391,20 +391,8 @@ impl pallet_utility::Config for Test { type WeightInfo = (); } -impl pallet_proxy::Config for Test { - type RuntimeEvent = RuntimeEvent; - type RuntimeCall = RuntimeCall; - type Currency = Balances; - type ProxyType = (); - type ProxyDepositBase = ConstU64<1>; - type ProxyDepositFactor = ConstU64<1>; - type MaxProxies = ConstU32<32>; - type WeightInfo = (); - type MaxPending = ConstU32<32>; - type CallHasher = BlakeTwo256; - type AnnouncementDepositBase = ConstU64<1>; - type AnnouncementDepositFactor = ConstU64<1>; -} +#[derive_impl(pallet_proxy::config_preludes::TestDefaultConfig)] +impl pallet_proxy::Config for Test {} impl pallet_dummy::Config for Test {} diff --git a/substrate/frame/safe-mode/src/mock.rs b/substrate/frame/safe-mode/src/mock.rs index ec1ad8249514..9b8b17f52ce6 100644 --- a/substrate/frame/safe-mode/src/mock.rs +++ b/substrate/frame/safe-mode/src/mock.rs @@ -125,19 +125,9 @@ impl InstanceFilter for ProxyType { } } +#[derive_impl(pallet_proxy::config_preludes::TestDefaultConfig)] impl pallet_proxy::Config for Test { - type RuntimeEvent = RuntimeEvent; - type RuntimeCall = RuntimeCall; - type Currency = Balances; type ProxyType = ProxyType; - type ProxyDepositBase = ConstU64<1>; - type ProxyDepositFactor = ConstU64<1>; - type MaxProxies = ConstU32<4>; - type WeightInfo = (); - type CallHasher = BlakeTwo256; - type MaxPending = ConstU32<2>; - type AnnouncementDepositBase = ConstU64<1>; - type AnnouncementDepositFactor = ConstU64<1>; } /// The calls that can always bypass safe-mode. diff --git a/substrate/frame/tx-pause/src/mock.rs b/substrate/frame/tx-pause/src/mock.rs index 84ce45e83528..aad5e9074830 100644 --- a/substrate/frame/tx-pause/src/mock.rs +++ b/substrate/frame/tx-pause/src/mock.rs @@ -24,10 +24,10 @@ use crate as pallet_tx_pause; use frame_support::{ derive_impl, parameter_types, - traits::{ConstU64, Everything, InsideBoth, InstanceFilter}, + traits::{Everything, InsideBoth, InstanceFilter}, }; use frame_system::EnsureSignedBy; -use sp_runtime::{traits::BlakeTwo256, BuildStorage}; +use sp_runtime::BuildStorage; #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { @@ -92,19 +92,9 @@ impl InstanceFilter for ProxyType { } } +#[derive_impl(pallet_proxy::config_preludes::TestDefaultConfig)] impl pallet_proxy::Config for Test { - type RuntimeEvent = RuntimeEvent; - type RuntimeCall = RuntimeCall; - type Currency = Balances; type ProxyType = ProxyType; - type ProxyDepositBase = ConstU64<1>; - type ProxyDepositFactor = ConstU64<1>; - type MaxProxies = ConstU32<4>; - type WeightInfo = (); - type CallHasher = BlakeTwo256; - type MaxPending = ConstU32<2>; - type AnnouncementDepositBase = ConstU64<1>; - type AnnouncementDepositFactor = ConstU64<1>; } parameter_types! {