Skip to content

Commit 4317213

Browse files
committedMar 19, 2025
Prepare pallets for async backing
1 parent 891799a commit 4317213

File tree

35 files changed

+171
-60
lines changed

35 files changed

+171
-60
lines changed
 

‎Cargo.lock

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎integration-tests/Cargo.toml

+4-1
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
@@ -151,6 +152,7 @@ std = [
151152
"xcm-executor/std",
152153
"xcm-runtime-apis/std",
153154
"xcm/std",
155+
"cumulus-pallet-parachain-system/std"
154156
]
155157
development-settings = [ "polimec-runtime/development-settings" ]
156158
runtime-benchmarks = [
@@ -193,5 +195,6 @@ runtime-benchmarks = [
193195
"xcm-executor/runtime-benchmarks",
194196
"xcm-runtime-apis/runtime-benchmarks",
195197
"assets-common/runtime-benchmarks",
196-
"pallet-transaction-payment/runtime-benchmarks"
198+
"pallet-transaction-payment/runtime-benchmarks",
199+
"cumulus-pallet-parachain-system/runtime-benchmarks"
197200
]

‎integration-tests/src/tests/e2e.rs

+1-1
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

+17-12
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

+1
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

+4-1
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

+7
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
@@ -92,6 +94,8 @@ std = [
9294
"xcm-builder/std",
9395
"xcm-executor/std",
9496
"xcm/std",
97+
"cumulus-pallet-parachain-system/std",
98+
"cumulus-primitives-core/std"
9599
]
96100
runtime-benchmarks = [
97101
"frame-benchmarking/runtime-benchmarks",
@@ -112,6 +116,8 @@ runtime-benchmarks = [
112116
"sp-runtime/runtime-benchmarks",
113117
"xcm-builder/runtime-benchmarks",
114118
"xcm-executor/runtime-benchmarks",
119+
"cumulus-pallet-parachain-system/runtime-benchmarks",
120+
"cumulus-primitives-core/runtime-benchmarks"
115121
]
116122
try-runtime = [
117123
"frame-support/try-runtime",
@@ -124,5 +130,6 @@ try-runtime = [
124130
"polimec-common-test-utils?/try-runtime",
125131
"polimec-common/try-runtime",
126132
"sp-runtime/try-runtime",
133+
"cumulus-pallet-parachain-system/try-runtime"
127134
]
128135
on-chain-release-build = []

‎pallets/funding/src/benchmarking.rs

+1-1
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

+1-1
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

+1-1
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

‎pallets/funding/src/functions/4_funding_end.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ impl<T: Config> Pallet<T> {
99
let project_metadata = ProjectsMetadata::<T>::get(project_id).ok_or(Error::<T>::ProjectMetadataNotFound)?;
1010
let mut project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
1111
let bucket = Buckets::<T>::get(project_id).ok_or(Error::<T>::BucketNotFound)?;
12-
let now = <frame_system::Pallet<T>>::block_number();
12+
let now = <T as Config>::BlockNumberProvider::current_block_number();
1313
let issuer_did = project_details.issuer_did.clone();
1414
let ct_amount_oversubscribed = CTAmountOversubscribed::<T>::get(project_id);
1515

‎pallets/funding/src/functions/5_settlement.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<T: Config> Pallet<T> {
2828
let mut project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
2929
let token_information =
3030
ProjectsMetadata::<T>::get(project_id).ok_or(Error::<T>::ProjectMetadataNotFound)?.token_information;
31-
let now = <frame_system::Pallet<T>>::block_number();
31+
let now = <T as Config>::BlockNumberProvider::current_block_number();
3232

3333
project_details.funding_end_block = Some(now);
3434

@@ -38,7 +38,7 @@ impl<T: Config> Pallet<T> {
3838
let multiplier: MultiplierOf<T> =
3939
ParticipationMode::OTM.multiplier().try_into().map_err(|_| Error::<T>::ImpossibleState)?;
4040
let duration = multiplier.calculate_vesting_duration::<T>();
41-
let now = <frame_system::Pallet<T>>::block_number();
41+
let now = <T as Config>::BlockNumberProvider::current_block_number();
4242
ReleaseType::Locked(duration.saturating_add(now))
4343
};
4444
<pallet_proxy_bonding::Pallet<T>>::set_release_type(

‎pallets/funding/src/functions/misc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<T: Config> Pallet<T> {
263263
skip_end_check: bool,
264264
) -> DispatchResult {
265265
/* Verify */
266-
let now = <frame_system::Pallet<T>>::block_number();
266+
let now = <T as Config>::BlockNumberProvider::current_block_number();
267267
ensure!(project_details.status == current_round, Error::<T>::IncorrectRound);
268268
ensure!(project_details.round_duration.ended(now) || skip_end_check, Error::<T>::TooEarlyForRound);
269269

‎pallets/funding/src/functions/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use frame_support::{
1717
},
1818
transactional,
1919
};
20-
use frame_system::pallet_prelude::BlockNumberFor;
2120
use polimec_common::{
2221
credentials::{Did, InvestorType},
2322
USD_DECIMALS,

‎pallets/funding/src/functions/runtime_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<T: Config> Pallet<T> {
237237
.enumerate()
238238
// Filter out schedules with future starting blocks before collecting them into a vector.
239239
.filter_map(|(i, schedule)| {
240-
if schedule.starting_block > <frame_system::Pallet<T>>::block_number() {
240+
if schedule.starting_block > <T as Config>::BlockNumberProvider::current_block_number() {
241241
None
242242
} else {
243243
Some((i, schedule.ending_block_as_balance::<BlockNumberToBalanceOf<T>>()))

‎pallets/funding/src/instantiator/calculations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use sp_runtime::traits::TrailingZeroInput;
1313
use InvestorType::{self, *};
1414

1515
impl<
16-
T: Config,
16+
T: Config + cumulus_pallet_parachain_system::Config,
1717
AllPalletsWithoutSystem: OnFinalize<BlockNumberFor<T>> + OnIdle<BlockNumberFor<T>> + OnInitialize<BlockNumberFor<T>>,
1818
RuntimeEvent: From<Event<T>> + TryInto<Event<T>> + Parameter + Member + IsType<<T as frame_system::Config>::RuntimeEvent>,
1919
> Instantiator<T, AllPalletsWithoutSystem, RuntimeEvent>

0 commit comments

Comments
 (0)