From 5e6a9f8366fceab14536de0486c6292ec3cce5a7 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Tue, 12 Nov 2024 14:04:29 +0800 Subject: [PATCH 1/7] Make pallet-recovery supports `BlockNumberProvider` --- polkadot/runtime/rococo/src/lib.rs | 1 + polkadot/runtime/westend/src/lib.rs | 1 + substrate/bin/node/runtime/src/lib.rs | 1 + substrate/frame/recovery/src/lib.rs | 12 +++++++++--- substrate/frame/recovery/src/mock.rs | 1 + 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 96a97faa4750d..4dc6f4f9ee482 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -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; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 993010cbce661..ec3acb0df4bc9 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -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; diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 5a2ff3ceb7f6a..cb60f3cdeb4ff 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1650,6 +1650,7 @@ impl pallet_recovery::Config for Runtime { type RuntimeEvent = RuntimeEvent; type WeightInfo = pallet_recovery::weights::SubstrateWeight; type RuntimeCall = RuntimeCall; + type BlockNumberProvider = System; type Currency = Balances; type ConfigDepositBase = ConfigDepositBase; type FriendDepositFactor = FriendDepositFactor; diff --git a/substrate/frame/recovery/src/lib.rs b/substrate/frame/recovery/src/lib.rs index f8622880538ef..f52ef4a1192f3 100644 --- a/substrate/frame/recovery/src/lib.rs +++ b/substrate/frame/recovery/src/lib.rs @@ -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, }; @@ -236,6 +239,9 @@ pub mod pallet { + GetDispatchInfo + From>; + /// Provider for the block number. Normally this is the `frame_system` pallet. + type BlockNumberProvider: BlockNumberProvider>; + /// The currency mechanism. type Currency: ReservableCurrency; @@ -511,7 +517,7 @@ pub mod pallet { T::Currency::reserve(&who, recovery_deposit)?; // Create an active recovery status let recovery_status = ActiveRecovery { - created: >::block_number(), + created: T::BlockNumberProvider::current_block_number(), deposit: recovery_deposit, friends: Default::default(), }; @@ -596,7 +602,7 @@ pub mod pallet { Self::active_recovery(&account, &who).ok_or(Error::::NotStarted)?; ensure!(!Proxy::::contains_key(&who), Error::::AlreadyProxy); // Make sure the delay period has passed - let current_block_number = >::block_number(); + let current_block_number = T::BlockNumberProvider::current_block_number(); let recoverable_block_number = active_recovery .created .checked_add(&recovery_config.delay_period) diff --git a/substrate/frame/recovery/src/mock.rs b/substrate/frame/recovery/src/mock.rs index 8e30cbe997e17..3930db82d6c77 100644 --- a/substrate/frame/recovery/src/mock.rs +++ b/substrate/frame/recovery/src/mock.rs @@ -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; From 976443e40ce89d4ca763b065b1e5284ecf7bab75 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Wed, 13 Nov 2024 14:16:28 +0800 Subject: [PATCH 2/7] Update lib.rs Co-authored-by: Guillaume Thiolliere --- substrate/frame/recovery/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/recovery/src/lib.rs b/substrate/frame/recovery/src/lib.rs index f52ef4a1192f3..dbc62bf1196d8 100644 --- a/substrate/frame/recovery/src/lib.rs +++ b/substrate/frame/recovery/src/lib.rs @@ -240,7 +240,7 @@ pub mod pallet { + From>; /// Provider for the block number. Normally this is the `frame_system` pallet. - type BlockNumberProvider: BlockNumberProvider>; + type BlockNumberProvider: BlockNumberProvider; /// The currency mechanism. type Currency: ReservableCurrency; From e12fef8ae6b8794ccb3c2b7489ce0e929e29000b Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 15 Nov 2024 17:18:32 +0800 Subject: [PATCH 3/7] Fix --- substrate/frame/recovery/src/lib.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/substrate/frame/recovery/src/lib.rs b/substrate/frame/recovery/src/lib.rs index dbc62bf1196d8..8e350ade25fef 100644 --- a/substrate/frame/recovery/src/lib.rs +++ b/substrate/frame/recovery/src/lib.rs @@ -181,11 +181,12 @@ mod mock; mod tests; pub mod weights; +type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; - +type BlockNumberFromProvider = + <::BlockNumberProvider as BlockNumberProvider>::BlockNumber; type FriendsOf = BoundedVec<::AccountId, ::MaxFriends>; -type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; /// An active recovery process. #[derive(Clone, Eq, PartialEq, Encode, Decode, Default, RuntimeDebug, TypeInfo, MaxEncodedLen)] @@ -193,7 +194,7 @@ pub struct ActiveRecovery { /// 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, @@ -345,7 +346,7 @@ pub mod pallet { _, Twox64Concat, T::AccountId, - RecoveryConfig, BalanceOf, FriendsOf>, + RecoveryConfig, BalanceOf, FriendsOf>, >; /// Active recovery attempts. @@ -360,7 +361,7 @@ pub mod pallet { T::AccountId, Twox64Concat, T::AccountId, - ActiveRecovery, BalanceOf, FriendsOf>, + ActiveRecovery, BalanceOf, FriendsOf>, >; /// The list of allowed proxy accounts. @@ -451,7 +452,7 @@ pub mod pallet { origin: OriginFor, friends: Vec, threshold: u16, - delay_period: BlockNumberFor, + delay_period: BlockNumberFromProvider, ) -> DispatchResult { let who = ensure_signed(origin)?; // Check account is not already set up for recovery From 614098a40ce881c1350e643f98941cafa3231384 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 15 Nov 2024 09:24:52 +0000 Subject: [PATCH 4/7] Update from gui1117 running command 'prdoc --audience runtime_dev --bump major' --- prdoc/pr_6446.prdoc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 prdoc/pr_6446.prdoc diff --git a/prdoc/pr_6446.prdoc b/prdoc/pr_6446.prdoc new file mode 100644 index 0000000000000..31e14e7140e4c --- /dev/null +++ b/prdoc/pr_6446.prdoc @@ -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 From 39a380f05d9bc1ea2ce1d27f89c4a8519fcbda30 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Thu, 5 Dec 2024 21:57:46 +0800 Subject: [PATCH 5/7] Update prdoc --- Cargo.lock | 8 ++++---- prdoc/pr_6446.prdoc | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 775a7fe99e1ee..182d8f6bacad4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10194,9 +10194,9 @@ dependencies = [ [[package]] name = "litep2p" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7286b1971f85d1d60be40ef49e81c1f3b5a0d8b83cfa02ab53591cdacae22901" +checksum = "5b67484b8ac41e1cfdf012f65fa81e88c2ef5f8a7d6dec0e2678c2d06dc04530" dependencies = [ "async-trait", "bs58", @@ -20402,7 +20402,7 @@ checksum = "f8650aabb6c35b860610e9cff5dc1af886c9e25073b7b1712a68972af4281302" dependencies = [ "bytes", "heck 0.5.0", - "itertools 0.12.1", + "itertools 0.13.0", "log", "multimap", "once_cell", @@ -20448,7 +20448,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acf0c195eebb4af52c752bec4f52f645da98b6e92077a04110c7f349477ae5ac" dependencies = [ "anyhow", - "itertools 0.12.1", + "itertools 0.13.0", "proc-macro2 1.0.86", "quote 1.0.37", "syn 2.0.87", diff --git a/prdoc/pr_6446.prdoc b/prdoc/pr_6446.prdoc index 31e14e7140e4c..8bfeb06bd33ba 100644 --- a/prdoc/pr_6446.prdoc +++ b/prdoc/pr_6446.prdoc @@ -2,9 +2,9 @@ title: Make pallet-recovery supports `BlockNumberProvider` doc: - audience: Runtime Dev description: |- - Make pallet-recovery supports `BlockNumberProvider`. + This PR enhances the recovery pallet by enabling it to define the source of the block number. - Part of #6297. + A migration is required for `Recoverable` and `ActiveRecoveries` storage items in cases where this pallet has been deployed on a parachain, and its block number type differs from that of the relaychain. crates: - name: rococo-runtime bump: major From aa865455abecca944b081a7bc3579d7e841a761e Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Sat, 7 Dec 2024 19:20:22 +0800 Subject: [PATCH 6/7] Update prdoc --- prdoc/pr_6446.prdoc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/prdoc/pr_6446.prdoc b/prdoc/pr_6446.prdoc index 8bfeb06bd33ba..3bfe7d0c7a60b 100644 --- a/prdoc/pr_6446.prdoc +++ b/prdoc/pr_6446.prdoc @@ -2,9 +2,11 @@ title: Make pallet-recovery supports `BlockNumberProvider` doc: - audience: Runtime Dev description: |- - This PR enhances the recovery pallet by enabling it to define the source of the block number. + 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 migration is required for `Recoverable` and `ActiveRecoveries` storage items in cases where this pallet has been deployed on a parachain, and its block number type differs from that of the relaychain. + 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 From 3a1ce05b16ab3c228eff015dd3973192bfbdbf94 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Thu, 12 Dec 2024 23:08:39 +0800 Subject: [PATCH 7/7] Rename --- substrate/frame/recovery/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/substrate/frame/recovery/src/lib.rs b/substrate/frame/recovery/src/lib.rs index 8e350ade25fef..d8f3c33fbea9f 100644 --- a/substrate/frame/recovery/src/lib.rs +++ b/substrate/frame/recovery/src/lib.rs @@ -184,7 +184,7 @@ pub mod weights; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; -type BlockNumberFromProvider = +type BlockNumberFromProviderOf = <::BlockNumberProvider as BlockNumberProvider>::BlockNumber; type FriendsOf = BoundedVec<::AccountId, ::MaxFriends>; @@ -346,7 +346,7 @@ pub mod pallet { _, Twox64Concat, T::AccountId, - RecoveryConfig, BalanceOf, FriendsOf>, + RecoveryConfig, BalanceOf, FriendsOf>, >; /// Active recovery attempts. @@ -361,7 +361,7 @@ pub mod pallet { T::AccountId, Twox64Concat, T::AccountId, - ActiveRecovery, BalanceOf, FriendsOf>, + ActiveRecovery, BalanceOf, FriendsOf>, >; /// The list of allowed proxy accounts. @@ -452,7 +452,7 @@ pub mod pallet { origin: OriginFor, friends: Vec, threshold: u16, - delay_period: BlockNumberFromProvider, + delay_period: BlockNumberFromProviderOf, ) -> DispatchResult { let who = ensure_signed(origin)?; // Check account is not already set up for recovery