Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ impl pallet_recovery::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type RuntimeCall = RuntimeCall;
type BlockNumberProvider = System;
type Currency = Balances;
type ConfigDepositBase = ConfigDepositBase;
type FriendDepositFactor = FriendDepositFactor;
Expand Down
1 change: 1 addition & 0 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,7 @@ impl pallet_recovery::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type RuntimeCall = RuntimeCall;
type BlockNumberProvider = System;
type Currency = Balances;
type ConfigDepositBase = ConfigDepositBase;
type FriendDepositFactor = FriendDepositFactor;
Expand Down
16 changes: 16 additions & 0 deletions prdoc/pr_6446.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
title: Make pallet-recovery supports `BlockNumberProvider`
doc:
- audience: Runtime Dev
description: |-
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.

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`.

If the block provider is configured with a value different from `System`, a migration will be necessary for the `Recoverable` and `ActiveRecoveries` storage items.
crates:
- name: rococo-runtime
bump: major
- name: westend-runtime
bump: major
- name: pallet-recovery
bump: major
1 change: 1 addition & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,7 @@ impl pallet_recovery::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_recovery::weights::SubstrateWeight<Runtime>;
type RuntimeCall = RuntimeCall;
type BlockNumberProvider = System;
type Currency = Balances;
type ConfigDepositBase = ConfigDepositBase;
type FriendDepositFactor = FriendDepositFactor;
Expand Down
25 changes: 16 additions & 9 deletions substrate/frame/recovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ use alloc::{boxed::Box, vec::Vec};
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{CheckedAdd, CheckedMul, Dispatchable, SaturatedConversion, StaticLookup},
traits::{
BlockNumberProvider, CheckedAdd, CheckedMul, Dispatchable, SaturatedConversion,
StaticLookup,
},
RuntimeDebug,
};

Expand All @@ -178,19 +181,20 @@ mod mock;
mod tests;
pub mod weights;

type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;

type BlockNumberFromProviderOf<T> =
<<T as Config>::BlockNumberProvider as BlockNumberProvider>::BlockNumber;
type FriendsOf<T> = BoundedVec<<T as frame_system::Config>::AccountId, <T as Config>::MaxFriends>;
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;

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

/// Provider for the block number. Normally this is the `frame_system` pallet.
type BlockNumberProvider: BlockNumberProvider;

/// The currency mechanism.
type Currency: ReservableCurrency<Self::AccountId>;

Expand Down Expand Up @@ -339,7 +346,7 @@ pub mod pallet {
_,
Twox64Concat,
T::AccountId,
RecoveryConfig<BlockNumberFor<T>, BalanceOf<T>, FriendsOf<T>>,
RecoveryConfig<BlockNumberFromProviderOf<T>, BalanceOf<T>, FriendsOf<T>>,
>;

/// Active recovery attempts.
Expand All @@ -354,7 +361,7 @@ pub mod pallet {
T::AccountId,
Twox64Concat,
T::AccountId,
ActiveRecovery<BlockNumberFor<T>, BalanceOf<T>, FriendsOf<T>>,
ActiveRecovery<BlockNumberFromProviderOf<T>, BalanceOf<T>, FriendsOf<T>>,
>;

/// The list of allowed proxy accounts.
Expand Down Expand Up @@ -445,7 +452,7 @@ pub mod pallet {
origin: OriginFor<T>,
friends: Vec<T::AccountId>,
threshold: u16,
delay_period: BlockNumberFor<T>,
delay_period: BlockNumberFromProviderOf<T>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
// Check account is not already set up for recovery
Expand Down Expand Up @@ -511,7 +518,7 @@ pub mod pallet {
T::Currency::reserve(&who, recovery_deposit)?;
// Create an active recovery status
let recovery_status = ActiveRecovery {
created: <frame_system::Pallet<T>>::block_number(),
created: T::BlockNumberProvider::current_block_number(),
deposit: recovery_deposit,
friends: Default::default(),
};
Expand Down Expand Up @@ -596,7 +603,7 @@ pub mod pallet {
Self::active_recovery(&account, &who).ok_or(Error::<T>::NotStarted)?;
ensure!(!Proxy::<T>::contains_key(&who), Error::<T>::AlreadyProxy);
// Make sure the delay period has passed
let current_block_number = <frame_system::Pallet<T>>::block_number();
let current_block_number = T::BlockNumberProvider::current_block_number();
let recoverable_block_number = active_recovery
.created
.checked_add(&recovery_config.delay_period)
Expand Down
1 change: 1 addition & 0 deletions substrate/frame/recovery/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl Config for Test {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type RuntimeCall = RuntimeCall;
type BlockNumberProvider = System;
type Currency = Balances;
type ConfigDepositBase = ConfigDepositBase;
type FriendDepositFactor = FriendDepositFactor;
Expand Down