From 56850bc49cc3d408c881b9fa2c01e97f17b36f0c Mon Sep 17 00:00:00 2001 From: "R.RajeshKumar" Date: Wed, 1 Dec 2021 15:45:08 +0530 Subject: [PATCH] pallet grants BlockNumberProvider integration Signed-off-by: R.RajeshKumar --- Cargo.lock | 2 +- pallets/grants/src/lib.rs | 8 +++++--- pallets/grants/src/mock.rs | 1 + runtimes/eden/Cargo.toml | 2 +- runtimes/eden/src/implementations.rs | 17 ++++++++++++++++- runtimes/eden/src/pallets_util.rs | 6 +++++- runtimes/main/src/pallets_util.rs | 1 + 7 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d153346e3e..46dd75b08a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7487,7 +7487,7 @@ dependencies = [ [[package]] name = "runtime-eden" -version = "2.0.13" +version = "2.0.14" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/pallets/grants/src/lib.rs b/pallets/grants/src/lib.rs index 19a76461e2e..eb0a745e263 100644 --- a/pallets/grants/src/lib.rs +++ b/pallets/grants/src/lib.rs @@ -32,7 +32,7 @@ use frame_support::{ }; use parity_scale_codec::{Decode, Encode}; use sp_runtime::{ - traits::{AtLeast32Bit, CheckedAdd, Saturating, StaticLookup, Zero}, + traits::{AtLeast32Bit, BlockNumberProvider, CheckedAdd, Saturating, StaticLookup, Zero}, DispatchResult, RuntimeDebug, }; use sp_std::{ @@ -123,6 +123,8 @@ pub mod pallet { type ForceOrigin: EnsureOrigin; /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; + // The block number provider + type BlockNumberProvider: BlockNumberProvider; } #[pallet::pallet] @@ -231,7 +233,7 @@ pub mod pallet { let target = T::Lookup::lookup(who)?; VestingSchedules::::insert(target.clone(), new_schedules.clone()); - let now = >::block_number(); + let now = T::BlockNumberProvider::current_block_number(); let new_lock: BalanceOf = new_schedules .iter() .fold(Zero::zero(), |acc, s| { @@ -374,7 +376,7 @@ impl Pallet { /// Returns locked balance based on current block number. fn locked_balance(who: &T::AccountId) -> BalanceOf { - let now = >::block_number(); + let now = T::BlockNumberProvider::current_block_number(); Self::vesting_schedules(who) .iter() .fold(Zero::zero(), |acc, s| { diff --git a/pallets/grants/src/mock.rs b/pallets/grants/src/mock.rs index 700d0fa7d46..6c1bdc37b7f 100644 --- a/pallets/grants/src/mock.rs +++ b/pallets/grants/src/mock.rs @@ -86,6 +86,7 @@ impl Config for Test { type CancelOrigin = EnsureSignedBy; type ForceOrigin = EnsureSignedBy; type WeightInfo = (); + type BlockNumberProvider = frame_system::Pallet; } pub const ALICE: AccountId = 1; diff --git a/runtimes/eden/Cargo.toml b/runtimes/eden/Cargo.toml index 5d4191ec85e..85b3c4ceba1 100644 --- a/runtimes/eden/Cargo.toml +++ b/runtimes/eden/Cargo.toml @@ -2,7 +2,7 @@ authors = ["Eliott Teissonniere "] edition = "2018" name = "runtime-eden" -version = "2.0.13" +version = "2.0.14" [features] default = ["std"] diff --git a/runtimes/eden/src/implementations.rs b/runtimes/eden/src/implementations.rs index 004f0c63f3b..3fdef128e50 100644 --- a/runtimes/eden/src/implementations.rs +++ b/runtimes/eden/src/implementations.rs @@ -21,7 +21,8 @@ use crate::{Authorship, Balances, CompanyReserve}; use frame_support::traits::{Currency, Imbalance, OnUnbalanced}; -use primitives::AccountId; +use primitives::{AccountId, BlockNumber}; +use sp_runtime::traits::BlockNumberProvider; /// Logic for the author to get a portion of fees. pub struct Author; @@ -49,3 +50,17 @@ impl OnUnbalanced for DealWithFees { } } } + +pub struct RelayChainBlockNumberProvider(sp_std::marker::PhantomData); + +impl BlockNumberProvider + for RelayChainBlockNumberProvider +{ + type BlockNumber = BlockNumber; + + fn current_block_number() -> Self::BlockNumber { + cumulus_pallet_parachain_system::Pallet::::validation_data() + .map(|d| d.relay_parent_number) + .unwrap_or_default() + } +} diff --git a/runtimes/eden/src/pallets_util.rs b/runtimes/eden/src/pallets_util.rs index 60d1dae47be..3e4bf0bfb16 100644 --- a/runtimes/eden/src/pallets_util.rs +++ b/runtimes/eden/src/pallets_util.rs @@ -15,7 +15,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -use crate::{constants, Balances, Call, Event, Origin, OriginCaller, Runtime}; +use crate::{ + constants, implementations::RelayChainBlockNumberProvider, Balances, Call, Event, Origin, + OriginCaller, Runtime, +}; use frame_support::{parameter_types, weights::Weight}; use primitives::{AccountId, Balance}; use sp_runtime::Perbill; @@ -26,6 +29,7 @@ impl pallet_grants::Config for Runtime { type CancelOrigin = frame_system::EnsureRoot; type ForceOrigin = frame_system::EnsureRoot; type WeightInfo = pallet_grants::weights::SubstrateWeight; + type BlockNumberProvider = RelayChainBlockNumberProvider; } impl pallet_utility::Config for Runtime { diff --git a/runtimes/main/src/pallets_util.rs b/runtimes/main/src/pallets_util.rs index c15232a9d03..d305ba1c438 100644 --- a/runtimes/main/src/pallets_util.rs +++ b/runtimes/main/src/pallets_util.rs @@ -37,6 +37,7 @@ impl pallet_grants::Config for Runtime { type ForceOrigin = pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, FinancialCollective>; type WeightInfo = pallet_grants::weights::SubstrateWeight; + type BlockNumberProvider = frame_system::Pallet; } impl pallet_utility::Config for Runtime {