Skip to content

Commit 88d900a

Browse files
aurexavgui1117actions-user
authored
Make pallet-recovery supports BlockNumberProvider (#6446)
Make pallet-recovery supports `BlockNumberProvider`. Part of #6297. --- Polkadot address: 156HGo9setPcU2qhFMVWLkcmtCEGySLwNqa3DaEiYSWtte4Y --------- Co-authored-by: Guillaume Thiolliere <[email protected]> Co-authored-by: GitHub Action <[email protected]>
1 parent f9cdf41 commit 88d900a

File tree

6 files changed

+36
-9
lines changed

6 files changed

+36
-9
lines changed

polkadot/runtime/rococo/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ impl pallet_recovery::Config for Runtime {
792792
type RuntimeEvent = RuntimeEvent;
793793
type WeightInfo = ();
794794
type RuntimeCall = RuntimeCall;
795+
type BlockNumberProvider = System;
795796
type Currency = Balances;
796797
type ConfigDepositBase = ConfigDepositBase;
797798
type FriendDepositFactor = FriendDepositFactor;

polkadot/runtime/westend/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,7 @@ impl pallet_recovery::Config for Runtime {
10181018
type RuntimeEvent = RuntimeEvent;
10191019
type WeightInfo = ();
10201020
type RuntimeCall = RuntimeCall;
1021+
type BlockNumberProvider = System;
10211022
type Currency = Balances;
10221023
type ConfigDepositBase = ConfigDepositBase;
10231024
type FriendDepositFactor = FriendDepositFactor;

prdoc/pr_6446.prdoc

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
title: Make pallet-recovery supports `BlockNumberProvider`
2+
doc:
3+
- audience: Runtime Dev
4+
description: |-
5+
pallet-recovery now allows configuring the block provider to be utilized within this pallet. This block is employed for the delay in the recovery process.
6+
7+
A new associated type has been introduced in the `Config` trait: `BlockNumberProvider`. This can be assigned to `System` to maintain the previous behavior, or it can be set to another block number provider, such as `RelayChain`.
8+
9+
If the block provider is configured with a value different from `System`, a migration will be necessary for the `Recoverable` and `ActiveRecoveries` storage items.
10+
crates:
11+
- name: rococo-runtime
12+
bump: major
13+
- name: westend-runtime
14+
bump: major
15+
- name: pallet-recovery
16+
bump: major

substrate/bin/node/runtime/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,7 @@ impl pallet_recovery::Config for Runtime {
16531653
type RuntimeEvent = RuntimeEvent;
16541654
type WeightInfo = pallet_recovery::weights::SubstrateWeight<Runtime>;
16551655
type RuntimeCall = RuntimeCall;
1656+
type BlockNumberProvider = System;
16561657
type Currency = Balances;
16571658
type ConfigDepositBase = ConfigDepositBase;
16581659
type FriendDepositFactor = FriendDepositFactor;

substrate/frame/recovery/src/lib.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ use alloc::{boxed::Box, vec::Vec};
156156
use codec::{Decode, Encode, MaxEncodedLen};
157157
use scale_info::TypeInfo;
158158
use sp_runtime::{
159-
traits::{CheckedAdd, CheckedMul, Dispatchable, SaturatedConversion, StaticLookup},
159+
traits::{
160+
BlockNumberProvider, CheckedAdd, CheckedMul, Dispatchable, SaturatedConversion,
161+
StaticLookup,
162+
},
160163
RuntimeDebug,
161164
};
162165

@@ -178,19 +181,20 @@ mod mock;
178181
mod tests;
179182
pub mod weights;
180183

184+
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
181185
type BalanceOf<T> =
182186
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
183-
187+
type BlockNumberFromProviderOf<T> =
188+
<<T as Config>::BlockNumberProvider as BlockNumberProvider>::BlockNumber;
184189
type FriendsOf<T> = BoundedVec<<T as frame_system::Config>::AccountId, <T as Config>::MaxFriends>;
185-
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
186190

187191
/// An active recovery process.
188192
#[derive(Clone, Eq, PartialEq, Encode, Decode, Default, RuntimeDebug, TypeInfo, MaxEncodedLen)]
189193
pub struct ActiveRecovery<BlockNumber, Balance, Friends> {
190194
/// The block number when the recovery process started.
191195
created: BlockNumber,
192196
/// The amount held in reserve of the `depositor`,
193-
/// To be returned once this recovery process is closed.
197+
/// to be returned once this recovery process is closed.
194198
deposit: Balance,
195199
/// The friends which have vouched so far. Always sorted.
196200
friends: Friends,
@@ -236,6 +240,9 @@ pub mod pallet {
236240
+ GetDispatchInfo
237241
+ From<frame_system::Call<Self>>;
238242

243+
/// Provider for the block number. Normally this is the `frame_system` pallet.
244+
type BlockNumberProvider: BlockNumberProvider;
245+
239246
/// The currency mechanism.
240247
type Currency: ReservableCurrency<Self::AccountId>;
241248

@@ -339,7 +346,7 @@ pub mod pallet {
339346
_,
340347
Twox64Concat,
341348
T::AccountId,
342-
RecoveryConfig<BlockNumberFor<T>, BalanceOf<T>, FriendsOf<T>>,
349+
RecoveryConfig<BlockNumberFromProviderOf<T>, BalanceOf<T>, FriendsOf<T>>,
343350
>;
344351

345352
/// Active recovery attempts.
@@ -354,7 +361,7 @@ pub mod pallet {
354361
T::AccountId,
355362
Twox64Concat,
356363
T::AccountId,
357-
ActiveRecovery<BlockNumberFor<T>, BalanceOf<T>, FriendsOf<T>>,
364+
ActiveRecovery<BlockNumberFromProviderOf<T>, BalanceOf<T>, FriendsOf<T>>,
358365
>;
359366

360367
/// The list of allowed proxy accounts.
@@ -445,7 +452,7 @@ pub mod pallet {
445452
origin: OriginFor<T>,
446453
friends: Vec<T::AccountId>,
447454
threshold: u16,
448-
delay_period: BlockNumberFor<T>,
455+
delay_period: BlockNumberFromProviderOf<T>,
449456
) -> DispatchResult {
450457
let who = ensure_signed(origin)?;
451458
// Check account is not already set up for recovery
@@ -511,7 +518,7 @@ pub mod pallet {
511518
T::Currency::reserve(&who, recovery_deposit)?;
512519
// Create an active recovery status
513520
let recovery_status = ActiveRecovery {
514-
created: <frame_system::Pallet<T>>::block_number(),
521+
created: T::BlockNumberProvider::current_block_number(),
515522
deposit: recovery_deposit,
516523
friends: Default::default(),
517524
};
@@ -596,7 +603,7 @@ pub mod pallet {
596603
Self::active_recovery(&account, &who).ok_or(Error::<T>::NotStarted)?;
597604
ensure!(!Proxy::<T>::contains_key(&who), Error::<T>::AlreadyProxy);
598605
// Make sure the delay period has passed
599-
let current_block_number = <frame_system::Pallet<T>>::block_number();
606+
let current_block_number = T::BlockNumberProvider::current_block_number();
600607
let recoverable_block_number = active_recovery
601608
.created
602609
.checked_add(&recovery_config.delay_period)

substrate/frame/recovery/src/mock.rs

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl Config for Test {
6666
type RuntimeEvent = RuntimeEvent;
6767
type WeightInfo = ();
6868
type RuntimeCall = RuntimeCall;
69+
type BlockNumberProvider = System;
6970
type Currency = Balances;
7071
type ConfigDepositBase = ConfigDepositBase;
7172
type FriendDepositFactor = FriendDepositFactor;

0 commit comments

Comments
 (0)