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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Change AtLeastOneStoragePrice to ZeroFootprintOr
David Kazlauskas committed Sep 2, 2024
commit 9ca8487a8aed029c6fb37b3bb4856c6225136528
16 changes: 11 additions & 5 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -60,9 +60,9 @@ use frame_support::{
genesis_builder_helper::{build_state, get_preset},
ord_parameter_types, parameter_types,
traits::{
fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg,
AtLeastOneLinearStoragePrice, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8,
EitherOfDiverse, Equals, InstanceFilter, TransformOrigin,
fungible, fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool,
ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Equals, InstanceFilter,
LinearStoragePrice, TransformOrigin, ZeroFootprintOr,
},
weights::{ConstantMultiplier, Weight, WeightToFee as _},
BoundedVec, PalletId,
@@ -648,13 +648,19 @@ impl pallet_proxy::Config for Runtime {
AccountId,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
ZeroFootprintOr<
LinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
Balance,
>,
>;
type AnnouncementConsideration = fungible::HoldConsideration<
AccountId,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
ZeroFootprintOr<
LinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
Balance,
>,
>;
}

14 changes: 10 additions & 4 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -45,8 +45,8 @@ use frame_support::{
traits::{
fungible, fungibles,
tokens::{imbalance::ResolveAssetTo, nonfungibles_v2::Inspect},
AsEnsureOriginWithArg, AtLeastOneLinearStoragePrice, ConstBool, ConstU128, ConstU32,
ConstU64, ConstU8, Equals, InstanceFilter, TransformOrigin,
AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, Equals,
InstanceFilter, LinearStoragePrice, TransformOrigin, ZeroFootprintOr,
},
weights::{ConstantMultiplier, Weight, WeightToFee as _},
BoundedVec, PalletId,
@@ -646,13 +646,19 @@ impl pallet_proxy::Config for Runtime {
AccountId,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
ZeroFootprintOr<
LinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
Balance,
>,
>;
type AnnouncementConsideration = fungible::HoldConsideration<
AccountId,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
ZeroFootprintOr<
LinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
Balance,
>,
>;
}

Original file line number Diff line number Diff line change
@@ -73,8 +73,8 @@ use frame_support::{
genesis_builder_helper::{build_state, get_preset},
parameter_types,
traits::{
fungible::HoldConsideration, AtLeastOneLinearStoragePrice, ConstBool, ConstU32, ConstU64,
ConstU8, EitherOfDiverse, InstanceFilter, LinearStoragePrice, TransformOrigin,
fungible::HoldConsideration, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse,
InstanceFilter, LinearStoragePrice, TransformOrigin, ZeroFootprintOr,
},
weights::{ConstantMultiplier, Weight, WeightToFee as _},
PalletId,
@@ -378,13 +378,19 @@ impl pallet_proxy::Config for Runtime {
AccountId,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
ZeroFootprintOr<
LinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
Balance,
>,
>;
type AnnouncementConsideration = HoldConsideration<
AccountId,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
ZeroFootprintOr<
LinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
Balance,
>,
>;
}

18 changes: 12 additions & 6 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -82,10 +82,10 @@ use frame_support::{
genesis_builder_helper::{build_state, get_preset},
parameter_types,
traits::{
fungible::HoldConsideration, tokens::UnityOrOuterConversion, AtLeastOneLinearStoragePrice,
Contains, EitherOf, EitherOfDiverse, EnsureOrigin, EnsureOriginWithArg, EverythingBut,
InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, PrivilegeCmp, ProcessMessage,
ProcessMessageError, StorageMapShim, WithdrawReasons,
fungible::HoldConsideration, tokens::UnityOrOuterConversion, Contains, EitherOf,
EitherOfDiverse, EnsureOrigin, EnsureOriginWithArg, EverythingBut, InstanceFilter,
KeyOwnerProofSystem, LinearStoragePrice, PrivilegeCmp, ProcessMessage, ProcessMessageError,
StorageMapShim, WithdrawReasons, ZeroFootprintOr,
},
weights::{ConstantMultiplier, WeightMeter, WeightToFee as _},
PalletId,
@@ -936,13 +936,19 @@ impl pallet_proxy::Config for Runtime {
AccountId,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
ZeroFootprintOr<
LinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
Balance,
>,
>;
type AnnouncementConsideration = HoldConsideration<
AccountId,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
ZeroFootprintOr<
LinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
Balance,
>,
>;
}

18 changes: 12 additions & 6 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -35,10 +35,10 @@ use frame_support::{
genesis_builder_helper::{build_state, get_preset},
parameter_types,
traits::{
fungible::HoldConsideration, tokens::UnityOrOuterConversion, AtLeastOneLinearStoragePrice,
ConstU32, Contains, EitherOf, EitherOfDiverse, EnsureOriginWithArg, EverythingBut,
FromContains, InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, ProcessMessage,
ProcessMessageError, VariantCountOf, WithdrawReasons,
fungible::HoldConsideration, tokens::UnityOrOuterConversion, ConstU32, Contains, EitherOf,
EitherOfDiverse, EnsureOriginWithArg, EverythingBut, FromContains, InstanceFilter,
KeyOwnerProofSystem, LinearStoragePrice, ProcessMessage, ProcessMessageError,
VariantCountOf, WithdrawReasons, ZeroFootprintOr,
},
weights::{ConstantMultiplier, WeightMeter, WeightToFee as _},
PalletId,
@@ -1170,13 +1170,19 @@ impl pallet_proxy::Config for Runtime {
AccountId,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
ZeroFootprintOr<
LinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
Balance,
>,
>;
type AnnouncementConsideration = HoldConsideration<
AccountId,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
ZeroFootprintOr<
LinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
Balance,
>,
>;
type MaxProxies = MaxProxies;
type WeightInfo = weights::pallet_proxy::WeightInfo<Runtime>;
4 changes: 2 additions & 2 deletions prdoc/pr_5336.prdoc
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@ doc:
trait simplifies the implementation, although users now need to refactor their
configuration of proxy pallet.

Adds new AtLeastOneLinearStoragePrice storage trait that implements `proxy-pallet`
balance reservation of reserving no balance if there are no items and reserving
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
18 changes: 12 additions & 6 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -49,10 +49,10 @@ use frame_support::{
imbalance::ResolveAssetTo, nonfungibles_v2::Inspect, pay::PayAssetFromAccount,
GetSalary, PayFromAccount,
},
AsEnsureOriginWithArg, AtLeastOneLinearStoragePrice, ConstBool, ConstU128, ConstU16,
ConstU32, Contains, Currency, EitherOfDiverse, EnsureOriginWithArg, EqualPrivilegeOnly,
Imbalance, InsideBoth, InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice,
LockIdentifier, Nothing, OnUnbalanced, VariantCountOf, WithdrawReasons,
AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU16, ConstU32, Contains, Currency,
EitherOfDiverse, EnsureOriginWithArg, EqualPrivilegeOnly, Imbalance, InsideBoth,
InstanceFilter, KeyOwnerProofSystem, LinearStoragePrice, LockIdentifier, Nothing,
OnUnbalanced, VariantCountOf, WithdrawReasons, ZeroFootprintOr,
},
weights::{
constants::{
@@ -441,13 +441,19 @@ impl pallet_proxy::Config for Runtime {
AccountId,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
ZeroFootprintOr<
LinearStoragePrice<ProxyDepositBase, ProxyDepositPerByte, Balance>,
Balance,
>,
>;
type AnnouncementConsideration = HoldConsideration<
AccountId,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
ZeroFootprintOr<
LinearStoragePrice<AnnouncementDepositBase, AnnouncementDepositPerByte, Balance>,
Balance,
>,
>;
}

8 changes: 4 additions & 4 deletions substrate/frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
@@ -51,8 +51,8 @@ use frame_support::{
traits::{
fungible::{BalancedHold, HoldConsideration, Inspect, Mutate, MutateHold},
tokens::Preservation,
AtLeastOneLinearStoragePrice, ConstU32, ConstU64, Contains, OnIdle, OnInitialize,
StorageVersion,
ConstU32, ConstU64, Contains, LinearStoragePrice, OnIdle, OnInitialize, StorageVersion,
ZeroFootprintOr,
},
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight, WeightMeter},
};
@@ -402,13 +402,13 @@ impl pallet_proxy::Config for Test {
AccountId32,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<ConstU64<1>, ConstU64<1>, u64>,
ZeroFootprintOr<LinearStoragePrice<ConstU64<1>, ConstU64<1>, u64>, u64>,
>;
type AnnouncementConsideration = HoldConsideration<
AccountId32,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<ConstU64<1>, ConstU64<1>, u64>,
ZeroFootprintOr<LinearStoragePrice<ConstU64<1>, ConstU64<1>, u64>, u64>,
>;
}

8 changes: 4 additions & 4 deletions substrate/frame/revive/src/tests.rs
Original file line number Diff line number Diff line change
@@ -55,8 +55,8 @@ use frame_support::{
traits::{
fungible::{BalancedHold, HoldConsideration, Inspect, Mutate, MutateHold},
tokens::Preservation,
AtLeastOneLinearStoragePrice, ConstU32, ConstU64, Contains, OnIdle, OnInitialize,
StorageVersion,
ConstU32, ConstU64, Contains, LinearStoragePrice, OnIdle, OnInitialize, StorageVersion,
ZeroFootprintOr,
},
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight, WeightMeter},
};
@@ -400,13 +400,13 @@ impl pallet_proxy::Config for Test {
<Test as frame_system::Config>::AccountId,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<ConstU64<1>, ConstU64<1>, u64>,
ZeroFootprintOr<LinearStoragePrice<ConstU64<1>, ConstU64<1>, u64>, u64>,
>;
type AnnouncementConsideration = HoldConsideration<
<Test as frame_system::Config>::AccountId,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<ConstU64<1>, ConstU64<1>, u64>,
ZeroFootprintOr<LinearStoragePrice<ConstU64<1>, ConstU64<1>, u64>, u64>,
>;
}

8 changes: 4 additions & 4 deletions substrate/frame/safe-mode/src/mock.rs
Original file line number Diff line number Diff line change
@@ -25,8 +25,8 @@ use crate as pallet_safe_mode;
use frame_support::{
derive_impl, parameter_types,
traits::{
AtLeastOneLinearStoragePrice, ConstU64, Everything, InsideBoth, InstanceFilter, IsInVec,
SafeModeNotify,
ConstU64, Everything, InsideBoth, InstanceFilter, IsInVec, LinearStoragePrice,
SafeModeNotify, ZeroFootprintOr,
},
};
use frame_system::EnsureSignedBy;
@@ -143,13 +143,13 @@ impl pallet_proxy::Config for Test {
u64,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<ConstU64<1>, ConstU64<1>, u64>,
ZeroFootprintOr<LinearStoragePrice<ConstU64<1>, ConstU64<1>, u64>, u64>,
>;
type AnnouncementConsideration = HoldConsideration<
u64,
Balances,
AnnouncementHoldReason,
AtLeastOneLinearStoragePrice<ConstU64<1>, ConstU64<1>, u64>,
ZeroFootprintOr<LinearStoragePrice<ConstU64<1>, ConstU64<1>, u64>, u64>,
>;
type MaxProxies = ConstU32<4>;
type WeightInfo = ();
6 changes: 3 additions & 3 deletions substrate/frame/support/src/traits.rs
Original file line number Diff line number Diff line change
@@ -95,9 +95,9 @@ mod storage;
#[cfg(feature = "experimental")]
pub use storage::MaybeConsideration;
pub use storage::{
AtLeastOneLinearStoragePrice, Consideration, Footprint, Incrementable, Instance,
LinearStoragePrice, PartialStorageInfoTrait, StorageInfo, StorageInfoTrait, StorageInstance,
TrackedStorageKey, WhitelistedStorageKeys,
Consideration, Footprint, Incrementable, Instance, LinearStoragePrice, PartialStorageInfoTrait,
StorageInfo, StorageInfoTrait, StorageInstance, TrackedStorageKey, WhitelistedStorageKeys,
ZeroFootprintOr,
};

mod dispatch;
21 changes: 9 additions & 12 deletions substrate/frame/support/src/traits/storage.rs
Original file line number Diff line number Diff line change
@@ -200,20 +200,17 @@ where
}
}

/// A storage price that increases linearly with the number of elements and their size,
/// but there must be at least one element in footprint or the price is zero
pub struct AtLeastOneLinearStoragePrice<Base, Slope, Balance>(PhantomData<(Base, Slope, Balance)>);
impl<Base, Slope, Balance> Convert<Footprint, Balance>
for AtLeastOneLinearStoragePrice<Base, Slope, Balance>
/// A storage price modifier that returns zero if number of elements is zero,
Copy link
Member

Choose a reason for hiding this comment

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

Where is this useful? Couldn't there still be a base deposit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the behaviour of Proxy pallet before Consideration, there's no base deposit, if items in footprint is zero then storage price is 0. This is to keep Proxy pallet backwards compatible with this behaviour not to break existing runtimes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed ZeroFootprintOr, not it calculates based on size only

/// otherwise uses a configured [`Convert`] parameter
pub struct ZeroFootprintOr<I: Convert<Footprint, Balance>, Balance>(PhantomData<(Balance, I)>);
impl<I, Balance> Convert<Footprint, Balance> for ZeroFootprintOr<I, Balance>
where
Base: Get<Balance>,
Slope: Get<Balance>,
Balance: From<u64> + sp_runtime::Saturating,
I: Convert<Footprint, Balance>,
Balance: From<u32>,
{
fn convert(a: Footprint) -> Balance {
if a.count > 0 {
let s: Balance = (a.count.saturating_mul(a.size)).into();
s.saturating_mul(Slope::get()).saturating_add(Base::get())
I::convert(a)
} else {
0.into()
}
@@ -357,8 +354,8 @@ mod tests {
}

#[test]
fn at_least_one_linear_storage_price_works() {
type Linear = AtLeastOneLinearStoragePrice<ConstU64<7>, ConstU64<3>, u64>;
fn zero_footprint_or_linear_storage_price_works() {
type Linear = ZeroFootprintOr<LinearStoragePrice<ConstU64<7>, ConstU64<3>, u64>, u64>;
let p = |count, size| Linear::convert(Footprint { count, size });

assert_eq!(p(0, 0), 0);
8 changes: 4 additions & 4 deletions substrate/frame/tx-pause/src/mock.rs
Original file line number Diff line number Diff line change
@@ -25,8 +25,8 @@ use crate as pallet_tx_pause;
use frame_support::{
derive_impl, parameter_types,
traits::{
fungible::HoldConsideration, AtLeastOneLinearStoragePrice, ConstU64, Everything,
InsideBoth, InstanceFilter,
fungible::HoldConsideration, ConstU64, Everything, InsideBoth, InstanceFilter,
LinearStoragePrice, ZeroFootprintOr,
},
};
use frame_system::EnsureSignedBy;
@@ -108,13 +108,13 @@ impl pallet_proxy::Config for Test {
u64,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<ConstU64<1>, ConstU64<1>, u64>,
ZeroFootprintOr<LinearStoragePrice<ConstU64<1>, ConstU64<1>, u64>, u64>,
>;
type AnnouncementConsideration = HoldConsideration<
u64,
Balances,
ProxyHoldReason,
AtLeastOneLinearStoragePrice<ConstU64<1>, ConstU64<1>, u64>,
ZeroFootprintOr<LinearStoragePrice<ConstU64<1>, ConstU64<1>, u64>, u64>,
>;
}