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

Make pallet-recovery supports BlockNumberProvider #6446

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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 @@ -780,6 +780,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 @@ -1017,6 +1017,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
14 changes: 14 additions & 0 deletions prdoc/pr_6446.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
title: Make pallet-recovery supports `BlockNumberProvider`
doc:
- audience: Runtime Dev
description: |-
Make pallet-recovery supports `BlockNumberProvider`.

Part of #6297.
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 @@ -1650,6 +1650,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 BlockNumberFromProvider<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<BlockNumberFromProvider<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<BlockNumberFromProvider<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: BlockNumberFromProvider<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