Skip to content

Commit d787269

Browse files
gavofyorkggwpezfranciscoaguirrekianenigma
authored
FRAME: Revamp Preimage pallet to use Consideration (#1363)
Make Preimage pallet use Consideration instead of handling deposits directly. Other half of paritytech/substrate#13666. Depends/based on #1361. Script for the lazy migration that should be run manually once: [migrate-preimage-lazy.py](https://github.com/ggwpez/substrate-scripts/blob/master/migrate-preimage-lazy.py). ## TODO - [x] Migration code. --------- Signed-off-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: command-bot <> Co-authored-by: Francisco Aguirre <[email protected]> Co-authored-by: Kian Paimani <[email protected]>
1 parent 11d1a39 commit d787269

File tree

25 files changed

+787
-346
lines changed

25 files changed

+787
-346
lines changed

cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ use frame_support::{
6767
construct_runtime,
6868
dispatch::DispatchClass,
6969
parameter_types,
70-
traits::{ConstBool, ConstU16, ConstU32, ConstU64, ConstU8, EitherOfDiverse, InstanceFilter},
70+
traits::{
71+
fungible::HoldConsideration, ConstBool, ConstU16, ConstU32, ConstU64, ConstU8,
72+
EitherOfDiverse, InstanceFilter, LinearStoragePrice,
73+
},
7174
weights::{ConstantMultiplier, Weight},
7275
PalletId,
7376
};
@@ -209,7 +212,7 @@ impl pallet_balances::Config for Runtime {
209212
type ReserveIdentifier = [u8; 8];
210213
type RuntimeHoldReason = RuntimeHoldReason;
211214
type FreezeIdentifier = ();
212-
type MaxHolds = ConstU32<0>;
215+
type MaxHolds = ConstU32<1>;
213216
type MaxFreezes = ConstU32<0>;
214217
}
215218

@@ -545,15 +548,20 @@ impl pallet_scheduler::Config for Runtime {
545548
parameter_types! {
546549
pub const PreimageBaseDeposit: Balance = deposit(2, 64);
547550
pub const PreimageByteDeposit: Balance = deposit(0, 1);
551+
pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);
548552
}
549553

550554
impl pallet_preimage::Config for Runtime {
551555
type WeightInfo = weights::pallet_preimage::WeightInfo<Runtime>;
552556
type RuntimeEvent = RuntimeEvent;
553557
type Currency = Balances;
554558
type ManagerOrigin = EnsureRoot<AccountId>;
555-
type BaseDeposit = PreimageBaseDeposit;
556-
type ByteDeposit = PreimageByteDeposit;
559+
type Consideration = HoldConsideration<
560+
AccountId,
561+
Balances,
562+
PreimageHoldReason,
563+
LinearStoragePrice<PreimageBaseDeposit, PreimageByteDeposit, Balance>,
564+
>;
557565
}
558566

559567
// Create the runtime by composing the FRAME pallets that were previously configured.
@@ -589,7 +597,7 @@ construct_runtime!(
589597
Utility: pallet_utility::{Pallet, Call, Event} = 40,
590598
Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 41,
591599
Proxy: pallet_proxy::{Pallet, Call, Storage, Event<T>} = 42,
592-
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>} = 43,
600+
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>, HoldReason} = 43,
593601
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 44,
594602

595603
// The main stage.

cumulus/parachains/runtimes/collectives/collectives-polkadot/src/weights/pallet_preimage.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ use core::marker::PhantomData;
5050
/// Weight functions for `pallet_preimage`.
5151
pub struct WeightInfo<T>(PhantomData<T>);
5252
impl<T: frame_system::Config> pallet_preimage::WeightInfo for WeightInfo<T> {
53+
fn ensure_updated(n: u32, ) -> Weight {
54+
// Proof Size summary in bytes:
55+
// Measured: `193 + n * (91 ±0)`
56+
// Estimated: `3593 + n * (2566 ±0)`
57+
// Minimum execution time: 2_000_000 picoseconds.
58+
Weight::from_parts(2_000_000, 3593)
59+
// Standard Error: 13_720
60+
.saturating_add(Weight::from_parts(17_309_199, 0).saturating_mul(n.into()))
61+
.saturating_add(T::DbWeight::get().reads(1_u64))
62+
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into())))
63+
.saturating_add(T::DbWeight::get().writes(1_u64))
64+
.saturating_add(T::DbWeight::get().writes((2_u64).saturating_mul(n.into())))
65+
.saturating_add(Weight::from_parts(0, 2566).saturating_mul(n.into()))
66+
}
67+
5368
/// Storage: `Preimage::StatusFor` (r:1 w:1)
5469
/// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`)
5570
/// Storage: `Preimage::PreimageFor` (r:0 w:1)

polkadot/runtime/kusama/src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ use frame_election_provider_support::{
6363
use frame_support::{
6464
construct_runtime, parameter_types,
6565
traits::{
66-
ConstU32, Contains, EitherOf, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem,
67-
PrivilegeCmp, ProcessMessage, ProcessMessageError, StorageMapShim, WithdrawReasons,
66+
fungible::HoldConsideration, ConstU32, Contains, EitherOf, EitherOfDiverse, InstanceFilter,
67+
KeyOwnerProofSystem, LinearStoragePrice, PrivilegeCmp, ProcessMessage, ProcessMessageError,
68+
StorageMapShim, WithdrawReasons,
6869
},
6970
weights::{ConstantMultiplier, WeightMeter},
7071
PalletId,
@@ -239,15 +240,20 @@ impl pallet_scheduler::Config for Runtime {
239240
parameter_types! {
240241
pub const PreimageBaseDeposit: Balance = deposit(2, 64);
241242
pub const PreimageByteDeposit: Balance = deposit(0, 1);
243+
pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);
242244
}
243245

244246
impl pallet_preimage::Config for Runtime {
245247
type WeightInfo = weights::pallet_preimage::WeightInfo<Runtime>;
246248
type RuntimeEvent = RuntimeEvent;
247249
type Currency = Balances;
248250
type ManagerOrigin = EnsureRoot<AccountId>;
249-
type BaseDeposit = PreimageBaseDeposit;
250-
type ByteDeposit = PreimageByteDeposit;
251+
type Consideration = HoldConsideration<
252+
AccountId,
253+
Balances,
254+
PreimageHoldReason,
255+
LinearStoragePrice<PreimageBaseDeposit, PreimageByteDeposit, Balance>,
256+
>;
251257
}
252258

253259
parameter_types! {
@@ -1560,7 +1566,7 @@ construct_runtime! {
15601566
Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 31,
15611567

15621568
// Preimage registrar.
1563-
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>} = 32,
1569+
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>, HoldReason} = 32,
15641570

15651571
// Bounties modules.
15661572
Bounties: pallet_bounties::{Pallet, Call, Storage, Event<T>} = 35,

polkadot/runtime/kusama/src/weights/pallet_preimage.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ use core::marker::PhantomData;
5050
/// Weight functions for `pallet_preimage`.
5151
pub struct WeightInfo<T>(PhantomData<T>);
5252
impl<T: frame_system::Config> pallet_preimage::WeightInfo for WeightInfo<T> {
53+
fn ensure_updated(n: u32, ) -> Weight {
54+
// Proof Size summary in bytes:
55+
// Measured: `193 + n * (91 ±0)`
56+
// Estimated: `3593 + n * (2566 ±0)`
57+
// Minimum execution time: 2_000_000 picoseconds.
58+
Weight::from_parts(2_000_000, 3593)
59+
// Standard Error: 13_720
60+
.saturating_add(Weight::from_parts(17_309_199, 0).saturating_mul(n.into()))
61+
.saturating_add(T::DbWeight::get().reads(1_u64))
62+
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into())))
63+
.saturating_add(T::DbWeight::get().writes(1_u64))
64+
.saturating_add(T::DbWeight::get().writes((2_u64).saturating_mul(n.into())))
65+
.saturating_add(Weight::from_parts(0, 2566).saturating_mul(n.into()))
66+
}
67+
5368
/// Storage: Preimage StatusFor (r:1 w:1)
5469
/// Proof: Preimage StatusFor (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen)
5570
/// Storage: Preimage PreimageFor (r:0 w:1)

polkadot/runtime/polkadot/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ use frame_election_provider_support::{
4747
use frame_support::{
4848
construct_runtime, parameter_types,
4949
traits::{
50-
ConstU32, Contains, EitherOf, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem,
51-
PrivilegeCmp, ProcessMessage, ProcessMessageError, WithdrawReasons,
50+
fungible::HoldConsideration, ConstU32, Contains, EitherOf, EitherOfDiverse, InstanceFilter,
51+
KeyOwnerProofSystem, LinearStoragePrice, PrivilegeCmp, ProcessMessage, ProcessMessageError,
52+
WithdrawReasons,
5253
},
5354
weights::{ConstantMultiplier, WeightMeter},
5455
PalletId,
@@ -221,18 +222,22 @@ impl pallet_scheduler::Config for Runtime {
221222
}
222223

223224
parameter_types! {
224-
pub const PreimageMaxSize: u32 = 4096 * 1024;
225225
pub const PreimageBaseDeposit: Balance = deposit(2, 64);
226226
pub const PreimageByteDeposit: Balance = deposit(0, 1);
227+
pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);
227228
}
228229

229230
impl pallet_preimage::Config for Runtime {
230231
type WeightInfo = weights::pallet_preimage::WeightInfo<Runtime>;
231232
type RuntimeEvent = RuntimeEvent;
232233
type Currency = Balances;
233234
type ManagerOrigin = EnsureRoot<AccountId>;
234-
type BaseDeposit = PreimageBaseDeposit;
235-
type ByteDeposit = PreimageByteDeposit;
235+
type Consideration = HoldConsideration<
236+
AccountId,
237+
Balances,
238+
PreimageHoldReason,
239+
LinearStoragePrice<PreimageBaseDeposit, PreimageByteDeposit, Balance>,
240+
>;
236241
}
237242

238243
parameter_types! {
@@ -297,7 +302,7 @@ impl pallet_balances::Config for Runtime {
297302
type WeightInfo = weights::pallet_balances::WeightInfo<Runtime>;
298303
type RuntimeHoldReason = RuntimeHoldReason;
299304
type FreezeIdentifier = ();
300-
type MaxHolds = ConstU32<0>;
305+
type MaxHolds = ConstU32<1>;
301306
type MaxFreezes = ConstU32<0>;
302307
}
303308

@@ -1326,7 +1331,7 @@ construct_runtime! {
13261331
// Basic stuff; balances is uncallable initially.
13271332
System: frame_system::{Pallet, Call, Storage, Config<T>, Event<T>} = 0,
13281333
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 1,
1329-
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>} = 10,
1334+
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>, HoldReason} = 10,
13301335

13311336
// Babe must be before session.
13321337
Babe: pallet_babe::{Pallet, Call, Storage, Config<T>, ValidateUnsigned} = 2,

polkadot/runtime/polkadot/src/weights/pallet_preimage.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ use core::marker::PhantomData;
5050
/// Weight functions for `pallet_preimage`.
5151
pub struct WeightInfo<T>(PhantomData<T>);
5252
impl<T: frame_system::Config> pallet_preimage::WeightInfo for WeightInfo<T> {
53+
fn ensure_updated(n: u32, ) -> Weight {
54+
// Proof Size summary in bytes:
55+
// Measured: `193 + n * (91 ±0)`
56+
// Estimated: `3593 + n * (2566 ±0)`
57+
// Minimum execution time: 2_000_000 picoseconds.
58+
Weight::from_parts(2_000_000, 3593)
59+
// Standard Error: 13_720
60+
.saturating_add(Weight::from_parts(17_309_199, 0).saturating_mul(n.into()))
61+
.saturating_add(T::DbWeight::get().reads(1_u64))
62+
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into())))
63+
.saturating_add(T::DbWeight::get().writes(1_u64))
64+
.saturating_add(T::DbWeight::get().writes((2_u64).saturating_mul(n.into())))
65+
.saturating_add(Weight::from_parts(0, 2566).saturating_mul(n.into()))
66+
}
67+
5368
/// Storage: Preimage StatusFor (r:1 w:1)
5469
/// Proof: Preimage StatusFor (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen)
5570
/// Storage: Preimage PreimageFor (r:0 w:1)

polkadot/runtime/rococo/src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ use beefy_primitives::{
6060
use frame_support::{
6161
construct_runtime, parameter_types,
6262
traits::{
63-
Contains, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem, LockIdentifier,
64-
PrivilegeCmp, ProcessMessage, ProcessMessageError, StorageMapShim, WithdrawReasons,
63+
fungible::HoldConsideration, Contains, EitherOfDiverse, InstanceFilter,
64+
KeyOwnerProofSystem, LinearStoragePrice, LockIdentifier, PrivilegeCmp, ProcessMessage,
65+
ProcessMessageError, StorageMapShim, WithdrawReasons,
6566
},
6667
weights::{ConstantMultiplier, WeightMeter},
6768
PalletId,
@@ -224,15 +225,20 @@ impl pallet_scheduler::Config for Runtime {
224225
parameter_types! {
225226
pub const PreimageBaseDeposit: Balance = deposit(2, 64);
226227
pub const PreimageByteDeposit: Balance = deposit(0, 1);
228+
pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);
227229
}
228230

229231
impl pallet_preimage::Config for Runtime {
230232
type WeightInfo = weights::pallet_preimage::WeightInfo<Runtime>;
231233
type RuntimeEvent = RuntimeEvent;
232234
type Currency = Balances;
233235
type ManagerOrigin = EnsureRoot<AccountId>;
234-
type BaseDeposit = PreimageBaseDeposit;
235-
type ByteDeposit = PreimageByteDeposit;
236+
type Consideration = HoldConsideration<
237+
AccountId,
238+
Balances,
239+
PreimageHoldReason,
240+
LinearStoragePrice<PreimageBaseDeposit, PreimageByteDeposit, Balance>,
241+
>;
236242
}
237243

238244
parameter_types! {
@@ -1449,7 +1455,7 @@ construct_runtime! {
14491455
Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 31,
14501456

14511457
// Preimage registrar.
1452-
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>} = 32,
1458+
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>, HoldReason} = 32,
14531459

14541460
// Bounties modules.
14551461
Bounties: pallet_bounties::{Pallet, Call, Storage, Event<T>} = 35,

polkadot/runtime/rococo/src/weights/pallet_preimage.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ use core::marker::PhantomData;
4747
/// Weight functions for `pallet_preimage`.
4848
pub struct WeightInfo<T>(PhantomData<T>);
4949
impl<T: frame_system::Config> pallet_preimage::WeightInfo for WeightInfo<T> {
50+
fn ensure_updated(n: u32, ) -> Weight {
51+
// Proof Size summary in bytes:
52+
// Measured: `193 + n * (91 ±0)`
53+
// Estimated: `3593 + n * (2566 ±0)`
54+
// Minimum execution time: 2_000_000 picoseconds.
55+
Weight::from_parts(2_000_000, 3593)
56+
// Standard Error: 13_720
57+
.saturating_add(Weight::from_parts(17_309_199, 0).saturating_mul(n.into()))
58+
.saturating_add(T::DbWeight::get().reads(1_u64))
59+
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into())))
60+
.saturating_add(T::DbWeight::get().writes(1_u64))
61+
.saturating_add(T::DbWeight::get().writes((2_u64).saturating_mul(n.into())))
62+
.saturating_add(Weight::from_parts(0, 2566).saturating_mul(n.into()))
63+
}
64+
5065
/// Storage: Preimage StatusFor (r:1 w:1)
5166
/// Proof: Preimage StatusFor (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen)
5267
/// Storage: Preimage PreimageFor (r:0 w:1)

polkadot/runtime/westend/src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use frame_election_provider_support::{bounds::ElectionBoundsBuilder, onchain, Se
2929
use frame_support::{
3030
construct_runtime, parameter_types,
3131
traits::{
32-
ConstU32, InstanceFilter, KeyOwnerProofSystem, ProcessMessage, ProcessMessageError,
33-
WithdrawReasons,
32+
fungible::HoldConsideration, ConstU32, InstanceFilter, KeyOwnerProofSystem,
33+
LinearStoragePrice, ProcessMessage, ProcessMessageError, WithdrawReasons,
3434
},
3535
weights::{ConstantMultiplier, WeightMeter},
3636
PalletId,
@@ -193,18 +193,22 @@ impl pallet_scheduler::Config for Runtime {
193193
}
194194

195195
parameter_types! {
196-
pub const PreimageMaxSize: u32 = 4096 * 1024;
197196
pub const PreimageBaseDeposit: Balance = deposit(2, 64);
198197
pub const PreimageByteDeposit: Balance = deposit(0, 1);
198+
pub const PreimageHoldReason: RuntimeHoldReason = RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage);
199199
}
200200

201201
impl pallet_preimage::Config for Runtime {
202202
type WeightInfo = weights::pallet_preimage::WeightInfo<Runtime>;
203203
type RuntimeEvent = RuntimeEvent;
204204
type Currency = Balances;
205205
type ManagerOrigin = EnsureRoot<AccountId>;
206-
type BaseDeposit = PreimageBaseDeposit;
207-
type ByteDeposit = PreimageByteDeposit;
206+
type Consideration = HoldConsideration<
207+
AccountId,
208+
Balances,
209+
PreimageHoldReason,
210+
LinearStoragePrice<PreimageBaseDeposit, PreimageByteDeposit, Balance>,
211+
>;
208212
}
209213

210214
parameter_types! {
@@ -268,7 +272,7 @@ impl pallet_balances::Config for Runtime {
268272
type WeightInfo = weights::pallet_balances::WeightInfo<Runtime>;
269273
type RuntimeHoldReason = RuntimeHoldReason;
270274
type FreezeIdentifier = ();
271-
type MaxHolds = ConstU32<0>;
275+
type MaxHolds = ConstU32<1>;
272276
type MaxFreezes = ConstU32<0>;
273277
}
274278

@@ -1311,7 +1315,7 @@ construct_runtime! {
13111315
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 20,
13121316

13131317
// Preimage registrar.
1314-
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>} = 28,
1318+
Preimage: pallet_preimage::{Pallet, Call, Storage, Event<T>, HoldReason} = 28,
13151319

13161320
// Sudo.
13171321
Sudo: pallet_sudo::{Pallet, Call, Storage, Event<T>, Config<T>} = 21,

polkadot/runtime/westend/src/weights/pallet_preimage.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ use core::marker::PhantomData;
5050
/// Weight functions for `pallet_preimage`.
5151
pub struct WeightInfo<T>(PhantomData<T>);
5252
impl<T: frame_system::Config> pallet_preimage::WeightInfo for WeightInfo<T> {
53+
fn ensure_updated(n: u32, ) -> Weight {
54+
// Proof Size summary in bytes:
55+
// Measured: `193 + n * (91 ±0)`
56+
// Estimated: `3593 + n * (2566 ±0)`
57+
// Minimum execution time: 2_000_000 picoseconds.
58+
Weight::from_parts(2_000_000, 3593)
59+
// Standard Error: 13_720
60+
.saturating_add(Weight::from_parts(17_309_199, 0).saturating_mul(n.into()))
61+
.saturating_add(T::DbWeight::get().reads(1_u64))
62+
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into())))
63+
.saturating_add(T::DbWeight::get().writes(1_u64))
64+
.saturating_add(T::DbWeight::get().writes((2_u64).saturating_mul(n.into())))
65+
.saturating_add(Weight::from_parts(0, 2566).saturating_mul(n.into()))
66+
}
67+
5368
/// Storage: Preimage StatusFor (r:1 w:1)
5469
/// Proof: Preimage StatusFor (max_values: None, max_size: Some(91), added: 2566, mode: MaxEncodedLen)
5570
/// Storage: Preimage PreimageFor (r:0 w:1)

0 commit comments

Comments
 (0)