Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor proxy pallet to use Consideration instead #5336

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ae5bbc7
Refactor proxy pallet to use Consideration trait
Aug 13, 2024
a11865a
Rust fmt
Aug 21, 2024
19dd381
Taplo format
Aug 21, 2024
479c15d
Manual changes for rust formatter
Aug 21, 2024
adb53a0
Additional prdoc
Aug 21, 2024
6463236
Remove dispatch result in infallible function
Aug 22, 2024
ad31477
Fix typos, comments, remove unneded type annotations
Aug 23, 2024
48a0f36
Refactor deposits per byte
Aug 29, 2024
cd4ae27
Merge branch 'master' into davidk/refactor-proxy-pallet-to-use-consid…
davidk-pt Aug 29, 2024
13636eb
Migrate revive pallet to use new proxy version
Aug 29, 2024
dbd416e
Fix revive test formatting
Aug 29, 2024
1d8256b
Remove redundant clone
Aug 30, 2024
3b14812
Syntax sugar to proxy find
Aug 30, 2024
9ca8487
Change AtLeastOneStoragePrice to ZeroFootprintOr
Sep 2, 2024
c6fba2d
Merge branch 'master' into davidk/refactor-proxy-pallet-to-use-consid…
davidk-pt Sep 2, 2024
7214145
Remove Currency from Proxy configuration
Sep 3, 2024
d98d39f
Merge branch 'master' into davidk/refactor-proxy-pallet-to-use-consid…
davidk-pt Sep 3, 2024
b9991f4
Create default test config for proxy pallet
Sep 4, 2024
a9e95d4
Formatting fixes
Sep 4, 2024
7cd10a6
Use scale encoding size for proxy/announcement
Sep 5, 2024
6f2a372
ProxiesVec/AnnouncementsVec type aliases
Sep 17, 2024
9d0c627
Replace log error with defensive! macro
Sep 17, 2024
03ecaf1
Remove balance checks from tests/benchmarks
Sep 17, 2024
4e76c2e
Merge branch 'master' into davidk/refactor-proxy-pallet-to-use-consid…
davidk-pt Sep 17, 2024
0332ab4
Update new runtimes to use new proxy pallet config
Sep 17, 2024
c680f8d
Add Consideration::ensure_successful calls to benchmarks
Sep 18, 2024
fc3fa68
Fix proxy benchmarks
Sep 20, 2024
379f80b
Correct footprint calculation for proxies/announcements vec
Sep 20, 2024
4c48256
Rewrite updating announcements ticket
Sep 20, 2024
0e9e2e8
Add ensure_successful before every consideration creation
Sep 20, 2024
e19ef78
Remove ZeroFootprintOr converter
Sep 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 24 additions & 9 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, ZeroFootprintOr,
},
weights::{ConstantMultiplier, Weight, WeightToFee as _},
BoundedVec, PalletId,
Expand Down Expand Up @@ -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);
davidk-pt marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down Expand Up @@ -638,16 +640,29 @@ impl InstanceFilter<RuntimeCall> 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<Runtime>;
type MaxPending = MaxPending;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type ProxyConsideration = fungible::HoldConsideration<
AccountId,
Balances,
ProxyHoldReason,
ZeroFootprintOr<
LinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
Balance,
>,
>;
type AnnouncementConsideration = fungible::HoldConsideration<
AccountId,
Balances,
ProxyHoldReason,
ZeroFootprintOr<
LinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
Balance,
>,
>;
}

parameter_types! {
Expand Down
32 changes: 23 additions & 9 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, ZeroFootprintOr,
},
weights::{ConstantMultiplier, Weight, WeightToFee as _},
BoundedVec, PalletId,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -634,16 +635,29 @@ impl InstanceFilter<RuntimeCall> 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<Runtime>;
type MaxPending = MaxPending;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type ProxyConsideration = fungible::HoldConsideration<
AccountId,
Balances,
ProxyHoldReason,
ZeroFootprintOr<
LinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
Balance,
>,
>;
type AnnouncementConsideration = fungible::HoldConsideration<
AccountId,
Balances,
ProxyHoldReason,
ZeroFootprintOr<
LinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
Balance,
>,
>;
}

parameter_types! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ use frame_support::{
parameter_types,
traits::{
fungible::HoldConsideration, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse,
InstanceFilter, LinearStoragePrice, TransformOrigin,
InstanceFilter, LinearStoragePrice, TransformOrigin, ZeroFootprintOr,
},
weights::{ConstantMultiplier, Weight, WeightToFee as _},
PalletId,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -368,16 +368,29 @@ impl InstanceFilter<RuntimeCall> 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<Runtime>;
type MaxPending = ConstU32<32>;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type ProxyConsideration = HoldConsideration<
AccountId,
Balances,
ProxyHoldReason,
ZeroFootprintOr<
LinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
Balance,
>,
>;
type AnnouncementConsideration = HoldConsideration<
AccountId,
Balances,
ProxyHoldReason,
ZeroFootprintOr<
LinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
Balance,
>,
>;
}

parameter_types! {
Expand Down
32 changes: 23 additions & 9 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ use frame_support::{
fungible::HoldConsideration, tokens::UnityOrOuterConversion, Contains, EitherOf,
EitherOfDiverse, EnsureOrigin, EnsureOriginWithArg, EverythingBut, InstanceFilter,
KeyOwnerProofSystem, LinearStoragePrice, PrivilegeCmp, ProcessMessage, ProcessMessageError,
StorageMapShim, WithdrawReasons,
StorageMapShim, WithdrawReasons, ZeroFootprintOr,
},
weights::{ConstantMultiplier, WeightMeter, WeightToFee as _},
PalletId,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -929,16 +930,29 @@ impl InstanceFilter<RuntimeCall> 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<Runtime>;
type MaxPending = MaxPending;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type ProxyConsideration = HoldConsideration<
AccountId,
Balances,
ProxyHoldReason,
ZeroFootprintOr<
LinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
Balance,
>,
>;
type AnnouncementConsideration = HoldConsideration<
AccountId,
Balances,
ProxyHoldReason,
ZeroFootprintOr<
LinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
Balance,
>,
>;
}

impl parachains_origin::Config for Runtime {}
Expand Down
32 changes: 23 additions & 9 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use frame_support::{
fungible::HoldConsideration, tokens::UnityOrOuterConversion, ConstU32, Contains, EitherOf,
EitherOfDiverse, EnsureOriginWithArg, EverythingBut, FromContains, InstanceFilter,
KeyOwnerProofSystem, LinearStoragePrice, ProcessMessage, ProcessMessageError,
VariantCountOf, WithdrawReasons,
VariantCountOf, WithdrawReasons, ZeroFootprintOr,
},
weights::{ConstantMultiplier, WeightMeter, WeightToFee as _},
PalletId,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1167,16 +1168,29 @@ impl InstanceFilter<RuntimeCall> 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,
ZeroFootprintOr<
LinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
Balance,
>,
>;
type AnnouncementConsideration = HoldConsideration<
AccountId,
Balances,
ProxyHoldReason,
ZeroFootprintOr<
LinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
Balance,
>,
>;
type MaxProxies = MaxProxies;
type WeightInfo = weights::pallet_proxy::WeightInfo<Runtime>;
type MaxPending = MaxPending;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
}

impl parachains_origin::Config for Runtime {}
Expand Down
40 changes: 40 additions & 0 deletions prdoc/pr_5336.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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.

Adds new ZeroFootprintOr storage trait that which is needed to implement previous
`proxy-pallet` balance reservation of reserving no balance if there are no items and reserving
`base + size * factor` balance if there's at least one item.

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
Loading
Loading