Skip to content

Commit e07c1a9

Browse files
committed
Prepare pallets for async backing
1 parent 0ca5002 commit e07c1a9

File tree

35 files changed

+161
-58
lines changed

35 files changed

+161
-58
lines changed

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pallet-elections-phragmen.workspace = true
5151
pallet-message-queue.workspace = true
5252
cumulus-primitives-core.workspace = true
5353
cumulus-pallet-xcm.workspace = true
54+
cumulus-pallet-parachain-system.workspace = true
5455

5556
parachain-info.workspace = true
5657
parachains-common.workspace = true

integration-tests/src/tests/e2e.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ fn e2e_test() {
583583
assert_close_enough!(sub_account_held_plmc, plmc_balance, Perquintill::from_float(0.999));
584584

585585
let otm_duration = Multiplier::force_new(5).calculate_vesting_duration::<PolimecRuntime>();
586-
let now = PolimecSystem::block_number();
586+
let now = PolkadotSystem::block_number();
587587
inst.jump_to_block(now + otm_duration);
588588

589589
let treasury_account = <PolimecRuntime as pallet_proxy_bonding::Config>::Treasury::get();

pallets/democracy/src/lib.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ use frame_support::{
163163
},
164164
weights::Weight,
165165
};
166-
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
166+
use frame_system::pallet_prelude::OriginFor;
167167
use parity_scale_codec::{Decode, Encode};
168168
use sp_runtime::{
169-
traits::{Bounded as ArithBounded, One, Saturating, StaticLookup, Zero},
169+
traits::{BlockNumberProvider, Bounded as ArithBounded, One, Saturating, StaticLookup, Zero},
170170
ArithmeticError, DispatchError, DispatchResult,
171171
};
172172

@@ -199,11 +199,12 @@ pub type CreditOf<T> = Credit<<T as frame_system::Config>::AccountId, <T as Conf
199199

200200
pub type CallOf<T> = <T as frame_system::Config>::RuntimeCall;
201201
pub type BoundedCallOf<T> = Bounded<CallOf<T>, <T as frame_system::Config>::Hashing>;
202+
pub type BlockNumberFor<T> = <<T as Config>::BlockNumberProvider as BlockNumberProvider>::BlockNumber;
202203
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
203204

204205
#[frame_support::pallet]
205206
pub mod pallet {
206-
use super::{DispatchResult, *};
207+
use super::{BlockNumberFor, DispatchResult, *};
207208
use frame_support::{
208209
pallet_prelude::*,
209210
traits::{
@@ -212,6 +213,7 @@ pub mod pallet {
212213
},
213214
};
214215
use frame_system::pallet_prelude::*;
216+
use sp_runtime::traits::BlockNumberProvider;
215217
/// The current storage version.
216218
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
217219

@@ -350,6 +352,9 @@ pub mod pallet {
350352

351353
/// Type returning the total electorate.
352354
type Electorate: GetElectorate<BalanceOf<Self>>;
355+
356+
/// Block number provider.
357+
type BlockNumberProvider: BlockNumberProvider<BlockNumber = frame_system::pallet_prelude::BlockNumberFor<Self>>;
353358
}
354359

355360
/// The number of (public) proposals that have been made so far.
@@ -610,7 +615,7 @@ pub mod pallet {
610615
let proposal_hash = proposal.hash();
611616

612617
if let Some((until, _)) = <Blacklist<T>>::get(proposal_hash) {
613-
ensure!(<frame_system::Pallet<T>>::block_number() >= until, Error::<T>::ProposalBlacklisted,);
618+
ensure!(T::BlockNumberProvider::current_block_number() >= until, Error::<T>::ProposalBlacklisted,);
614619
}
615620

616621
T::Fungible::hold(&HoldReason::Proposal.into(), &who, value)?;
@@ -700,7 +705,7 @@ pub mod pallet {
700705
T::ExternalOrigin::ensure_origin(origin)?;
701706
ensure!(!<NextExternal<T>>::exists(), Error::<T>::DuplicateProposal);
702707
if let Some((until, _)) = <Blacklist<T>>::get(proposal.hash()) {
703-
ensure!(<frame_system::Pallet<T>>::block_number() >= until, Error::<T>::ProposalBlacklisted,);
708+
ensure!(T::BlockNumberProvider::current_block_number() >= until, Error::<T>::ProposalBlacklisted,);
704709
}
705710
<NextExternal<T>>::put((proposal, VoteThreshold::SuperMajorityApprove));
706711
Ok(())
@@ -790,7 +795,7 @@ pub mod pallet {
790795
ensure!(proposal_hash == ext_proposal.hash(), Error::<T>::InvalidHash);
791796

792797
<NextExternal<T>>::kill();
793-
let now = <frame_system::Pallet<T>>::block_number();
798+
let now = T::BlockNumberProvider::current_block_number();
794799
let ref_index = Self::inject_referendum(now.saturating_add(voting_period), ext_proposal, threshold, delay);
795800
Self::transfer_metadata(MetadataOwner::External, MetadataOwner::Referendum(ref_index));
796801
Ok(())
@@ -820,7 +825,7 @@ pub mod pallet {
820825
let insert_position = existing_vetoers.binary_search(&who).err().ok_or(Error::<T>::AlreadyVetoed)?;
821826
existing_vetoers.try_insert(insert_position, who.clone()).map_err(|_| Error::<T>::TooMany)?;
822827

823-
let until = <frame_system::Pallet<T>>::block_number().saturating_add(T::CooloffPeriod::get());
828+
let until = T::BlockNumberProvider::current_block_number().saturating_add(T::CooloffPeriod::get());
824829
<Blacklist<T>>::insert(&proposal_hash, (until, existing_vetoers));
825830

826831
Self::deposit_event(Event::<T>::Vetoed { who, proposal_hash, until });
@@ -1196,7 +1201,7 @@ impl<T: Config> Pallet<T> {
11961201
delay: BlockNumberFor<T>,
11971202
) -> ReferendumIndex {
11981203
<Pallet<T>>::inject_referendum(
1199-
<frame_system::Pallet<T>>::block_number().saturating_add(T::VotingPeriod::get()),
1204+
T::BlockNumberProvider::current_block_number().saturating_add(T::VotingPeriod::get()),
12001205
proposal,
12011206
threshold,
12021207
delay,
@@ -1291,7 +1296,7 @@ impl<T: Config> Pallet<T> {
12911296
if let Some((lock_periods, balance)) = votes[i].1.locked_if(approved) {
12921297
let unlock_at =
12931298
end.saturating_add(T::VoteLockingPeriod::get().saturating_mul(lock_periods.into()));
1294-
let now = frame_system::Pallet::<T>::block_number();
1299+
let now = T::BlockNumberProvider::current_block_number();
12951300
if now < unlock_at {
12961301
ensure!(matches!(scope, UnvoteScope::Any), Error::<T>::NoPermission);
12971302
prior.accumulate(unlock_at, balance)
@@ -1380,7 +1385,7 @@ impl<T: Config> Pallet<T> {
13801385
Voting::Delegating { balance, target, conviction, delegations, mut prior, .. } => {
13811386
// remove any delegation votes to our current target.
13821387
Self::reduce_upstream_delegation(&target, conviction.votes(balance));
1383-
let now = frame_system::Pallet::<T>::block_number();
1388+
let now = T::BlockNumberProvider::current_block_number();
13841389
let lock_periods = conviction.lock_periods().into();
13851390
let unlock_block = now.saturating_add(T::VoteLockingPeriod::get().saturating_mul(lock_periods));
13861391
prior.accumulate(unlock_block, balance);
@@ -1413,7 +1418,7 @@ impl<T: Config> Pallet<T> {
14131418
Voting::Delegating { balance, target, conviction, delegations, mut prior } => {
14141419
// remove any delegation votes to our current target.
14151420
let votes = Self::reduce_upstream_delegation(&target, conviction.votes(balance));
1416-
let now = frame_system::Pallet::<T>::block_number();
1421+
let now = T::BlockNumberProvider::current_block_number();
14171422
let lock_periods = conviction.lock_periods().into();
14181423
let unlock_block = now.saturating_add(T::VoteLockingPeriod::get().saturating_mul(lock_periods));
14191424
prior.accumulate(unlock_block, balance);
@@ -1432,7 +1437,7 @@ impl<T: Config> Pallet<T> {
14321437
/// a security hole) but may be reduced from what they are currently.
14331438
fn update_lock(who: &T::AccountId) -> DispatchResult {
14341439
let lock_needed = VotingOf::<T>::mutate(who, |voting| {
1435-
voting.rejig(frame_system::Pallet::<T>::block_number());
1440+
voting.rejig(T::BlockNumberProvider::current_block_number());
14361441
voting.locked_balance()
14371442
});
14381443
if lock_needed.is_zero() {

pallets/democracy/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ impl GetElectorate<BalanceOf<Test>> for Electorate {
149149

150150
impl Config for Test {
151151
type BlacklistOrigin = EnsureRoot<u64>;
152+
type BlockNumberProvider = System;
152153
type CancelProposalOrigin = EnsureRoot<u64>;
153154
type CancellationOrigin = EnsureSignedBy<Four, u64>;
154155
type CooloffPeriod = ConstU64<2>;

pallets/dispenser/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub mod pallet {
5555
pallet_prelude::{ValueQuery, *},
5656
PalletId,
5757
};
58-
use frame_system::pallet_prelude::*;
58+
use frame_system::pallet_prelude::{BlockNumberFor, *};
5959
use sp_runtime::{
6060
traits::{AccountIdConversion, CheckedDiv},
6161
Saturating,
@@ -115,6 +115,9 @@ pub mod pallet {
115115
/// The Whitelisted policy for the dispenser. Users' credentials should have the same
116116
/// policy to be eligible for token dispensing.
117117
type WhitelistedPolicy: Get<Cid>;
118+
119+
// /// Block number provider.
120+
// type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;
118121
}
119122

120123
#[pallet::pallet]

pallets/funding/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ hex.workspace = true
5050
# Used in the instantiator.
5151
itertools.workspace = true
5252
sp-io.workspace = true
53+
cumulus-pallet-parachain-system.workspace = true
54+
cumulus-primitives-core.workspace = true
5355

5456
[dev-dependencies]
5557
pallet-timestamp.workspace = true

pallets/funding/src/benchmarking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn string_account<AccountId: Decode>(
9797

9898
#[benchmarks(
9999
where
100-
T: Config + frame_system::Config<RuntimeEvent = <T as Config>::RuntimeEvent> + pallet_balances::Config<Balance = Balance> + core::fmt::Debug,
100+
T: Config + frame_system::Config<RuntimeEvent = <T as Config>::RuntimeEvent> + pallet_balances::Config<Balance = Balance> + cumulus_pallet_parachain_system::Config + sp_std::fmt::Debug,
101101
<T as Config>::RuntimeEvent: TryInto<Event<T>> + Parameter + Member,
102102
<T as Config>::Price: From<u128>,
103103
T::Hash: From<H256>,

pallets/funding/src/functions/2_evaluation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<T: Config> Pallet<T> {
8484
// * Get variables *
8585
let project_metadata = ProjectsMetadata::<T>::get(project_id).ok_or(Error::<T>::ProjectMetadataNotFound)?;
8686
let mut project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
87-
let now = <frame_system::Pallet<T>>::block_number();
87+
let now = <T as Config>::BlockNumberProvider::current_block_number();
8888
let evaluation_id = NextEvaluationId::<T>::get();
8989
let plmc_usd_price =
9090
<PriceProviderOf<T>>::get_decimals_aware_price(Location::here(), USD_DECIMALS, PLMC_DECIMALS)

pallets/funding/src/functions/3_auction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<T: Config> Pallet<T> {
2222

2323
// Fetch current bucket details and other required info
2424
let mut current_bucket = Buckets::<T>::get(project_id).ok_or(Error::<T>::BucketNotFound)?;
25-
let now = <frame_system::Pallet<T>>::block_number();
25+
let now = <T as Config>::BlockNumberProvider::current_block_number();
2626
let mut amount_to_bid = ct_amount;
2727
let project_policy = project_metadata.policy_ipfs_cid.ok_or(Error::<T>::ImpossibleState)?;
2828

0 commit comments

Comments
 (0)