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

Prepare pallets for async backing #471

Open
wants to merge 1 commit into
base: 03-14-upgrade_to_stable2412-2
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
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pallet-elections-phragmen.workspace = true
pallet-message-queue.workspace = true
cumulus-primitives-core.workspace = true
cumulus-pallet-xcm.workspace = true
cumulus-pallet-parachain-system.workspace = true

parachain-info.workspace = true
parachains-common.workspace = true
Expand Down Expand Up @@ -151,6 +152,7 @@ std = [
"xcm-executor/std",
"xcm-runtime-apis/std",
"xcm/std",
"cumulus-pallet-parachain-system/std"
]
development-settings = [ "polimec-runtime/development-settings" ]
runtime-benchmarks = [
Expand Down Expand Up @@ -193,5 +195,6 @@ runtime-benchmarks = [
"xcm-executor/runtime-benchmarks",
"xcm-runtime-apis/runtime-benchmarks",
"assets-common/runtime-benchmarks",
"pallet-transaction-payment/runtime-benchmarks"
"pallet-transaction-payment/runtime-benchmarks",
"cumulus-pallet-parachain-system/runtime-benchmarks"
]
2 changes: 1 addition & 1 deletion integration-tests/src/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ fn e2e_test() {
assert_close_enough!(sub_account_held_plmc, plmc_balance, Perquintill::from_float(0.999));

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

let treasury_account = <PolimecRuntime as pallet_proxy_bonding::Config>::Treasury::get();
Expand Down
29 changes: 17 additions & 12 deletions pallets/democracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ use frame_support::{
},
weights::Weight,
};
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
use frame_system::pallet_prelude::OriginFor;
use parity_scale_codec::{Decode, Encode};
use sp_runtime::{
traits::{Bounded as ArithBounded, One, Saturating, StaticLookup, Zero},
traits::{BlockNumberProvider, Bounded as ArithBounded, One, Saturating, StaticLookup, Zero},
ArithmeticError, DispatchError, DispatchResult,
};

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

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

#[frame_support::pallet]
pub mod pallet {
use super::{DispatchResult, *};
use super::{BlockNumberFor, DispatchResult, *};
use frame_support::{
pallet_prelude::*,
traits::{
Expand All @@ -212,6 +213,7 @@ pub mod pallet {
},
};
use frame_system::pallet_prelude::*;
use sp_runtime::traits::BlockNumberProvider;
/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);

Expand Down Expand Up @@ -350,6 +352,9 @@ pub mod pallet {

/// Type returning the total electorate.
type Electorate: GetElectorate<BalanceOf<Self>>;

/// Block number provider.
type BlockNumberProvider: BlockNumberProvider<BlockNumber = frame_system::pallet_prelude::BlockNumberFor<Self>>;
}

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

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

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

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

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

Self::deposit_event(Event::<T>::Vetoed { who, proposal_hash, until });
Expand Down Expand Up @@ -1196,7 +1201,7 @@ impl<T: Config> Pallet<T> {
delay: BlockNumberFor<T>,
) -> ReferendumIndex {
<Pallet<T>>::inject_referendum(
<frame_system::Pallet<T>>::block_number().saturating_add(T::VotingPeriod::get()),
T::BlockNumberProvider::current_block_number().saturating_add(T::VotingPeriod::get()),
proposal,
threshold,
delay,
Expand Down Expand Up @@ -1291,7 +1296,7 @@ impl<T: Config> Pallet<T> {
if let Some((lock_periods, balance)) = votes[i].1.locked_if(approved) {
let unlock_at =
end.saturating_add(T::VoteLockingPeriod::get().saturating_mul(lock_periods.into()));
let now = frame_system::Pallet::<T>::block_number();
let now = T::BlockNumberProvider::current_block_number();
if now < unlock_at {
ensure!(matches!(scope, UnvoteScope::Any), Error::<T>::NoPermission);
prior.accumulate(unlock_at, balance)
Expand Down Expand Up @@ -1380,7 +1385,7 @@ impl<T: Config> Pallet<T> {
Voting::Delegating { balance, target, conviction, delegations, mut prior, .. } => {
// remove any delegation votes to our current target.
Self::reduce_upstream_delegation(&target, conviction.votes(balance));
let now = frame_system::Pallet::<T>::block_number();
let now = T::BlockNumberProvider::current_block_number();
let lock_periods = conviction.lock_periods().into();
let unlock_block = now.saturating_add(T::VoteLockingPeriod::get().saturating_mul(lock_periods));
prior.accumulate(unlock_block, balance);
Expand Down Expand Up @@ -1413,7 +1418,7 @@ impl<T: Config> Pallet<T> {
Voting::Delegating { balance, target, conviction, delegations, mut prior } => {
// remove any delegation votes to our current target.
let votes = Self::reduce_upstream_delegation(&target, conviction.votes(balance));
let now = frame_system::Pallet::<T>::block_number();
let now = T::BlockNumberProvider::current_block_number();
let lock_periods = conviction.lock_periods().into();
let unlock_block = now.saturating_add(T::VoteLockingPeriod::get().saturating_mul(lock_periods));
prior.accumulate(unlock_block, balance);
Expand All @@ -1432,7 +1437,7 @@ impl<T: Config> Pallet<T> {
/// a security hole) but may be reduced from what they are currently.
fn update_lock(who: &T::AccountId) -> DispatchResult {
let lock_needed = VotingOf::<T>::mutate(who, |voting| {
voting.rejig(frame_system::Pallet::<T>::block_number());
voting.rejig(T::BlockNumberProvider::current_block_number());
voting.locked_balance()
});
if lock_needed.is_zero() {
Expand Down
1 change: 1 addition & 0 deletions pallets/democracy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl GetElectorate<BalanceOf<Test>> for Electorate {

impl Config for Test {
type BlacklistOrigin = EnsureRoot<u64>;
type BlockNumberProvider = System;
type CancelProposalOrigin = EnsureRoot<u64>;
type CancellationOrigin = EnsureSignedBy<Four, u64>;
type CooloffPeriod = ConstU64<2>;
Expand Down
5 changes: 4 additions & 1 deletion pallets/dispenser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub mod pallet {
pallet_prelude::{ValueQuery, *},
PalletId,
};
use frame_system::pallet_prelude::*;
use frame_system::pallet_prelude::{BlockNumberFor, *};
use sp_runtime::{
traits::{AccountIdConversion, CheckedDiv},
Saturating,
Expand Down Expand Up @@ -115,6 +115,9 @@ pub mod pallet {
/// The Whitelisted policy for the dispenser. Users' credentials should have the same
/// policy to be eligible for token dispensing.
type WhitelistedPolicy: Get<Cid>;

// /// Block number provider.
// type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;
}

#[pallet::pallet]
Expand Down
7 changes: 7 additions & 0 deletions pallets/funding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ hex.workspace = true
# Used in the instantiator.
itertools.workspace = true
sp-io.workspace = true
cumulus-pallet-parachain-system.workspace = true
cumulus-primitives-core.workspace = true

[dev-dependencies]
pallet-timestamp.workspace = true
Expand Down Expand Up @@ -92,6 +94,8 @@ std = [
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
"cumulus-pallet-parachain-system/std",
"cumulus-primitives-core/std"
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
Expand All @@ -112,6 +116,8 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"cumulus-pallet-parachain-system/runtime-benchmarks",
"cumulus-primitives-core/runtime-benchmarks"
]
try-runtime = [
"frame-support/try-runtime",
Expand All @@ -124,5 +130,6 @@ try-runtime = [
"polimec-common-test-utils?/try-runtime",
"polimec-common/try-runtime",
"sp-runtime/try-runtime",
"cumulus-pallet-parachain-system/try-runtime"
]
on-chain-release-build = []
2 changes: 1 addition & 1 deletion pallets/funding/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn string_account<AccountId: Decode>(

#[benchmarks(
where
T: Config + frame_system::Config<RuntimeEvent = <T as Config>::RuntimeEvent> + pallet_balances::Config<Balance = Balance> + core::fmt::Debug,
T: Config + frame_system::Config<RuntimeEvent = <T as Config>::RuntimeEvent> + pallet_balances::Config<Balance = Balance> + cumulus_pallet_parachain_system::Config + sp_std::fmt::Debug,
<T as Config>::RuntimeEvent: TryInto<Event<T>> + Parameter + Member,
<T as Config>::Price: From<u128>,
T::Hash: From<H256>,
Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/functions/2_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<T: Config> Pallet<T> {
// * Get variables *
let project_metadata = ProjectsMetadata::<T>::get(project_id).ok_or(Error::<T>::ProjectMetadataNotFound)?;
let mut project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
let now = <frame_system::Pallet<T>>::block_number();
let now = <T as Config>::BlockNumberProvider::current_block_number();
let evaluation_id = NextEvaluationId::<T>::get();
let plmc_usd_price =
<PriceProviderOf<T>>::get_decimals_aware_price(Location::here(), USD_DECIMALS, PLMC_DECIMALS)
Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/functions/3_auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<T: Config> Pallet<T> {

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

Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/functions/4_funding_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl<T: Config> Pallet<T> {
let project_metadata = ProjectsMetadata::<T>::get(project_id).ok_or(Error::<T>::ProjectMetadataNotFound)?;
let mut project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
let bucket = Buckets::<T>::get(project_id).ok_or(Error::<T>::BucketNotFound)?;
let now = <frame_system::Pallet<T>>::block_number();
let now = <T as Config>::BlockNumberProvider::current_block_number();
let issuer_did = project_details.issuer_did.clone();
let ct_amount_oversubscribed = CTAmountOversubscribed::<T>::get(project_id);

Expand Down
4 changes: 2 additions & 2 deletions pallets/funding/src/functions/5_settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<T: Config> Pallet<T> {
let mut project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
let token_information =
ProjectsMetadata::<T>::get(project_id).ok_or(Error::<T>::ProjectMetadataNotFound)?.token_information;
let now = <frame_system::Pallet<T>>::block_number();
let now = <T as Config>::BlockNumberProvider::current_block_number();

project_details.funding_end_block = Some(now);

Expand All @@ -38,7 +38,7 @@ impl<T: Config> Pallet<T> {
let multiplier: MultiplierOf<T> =
ParticipationMode::OTM.multiplier().try_into().map_err(|_| Error::<T>::ImpossibleState)?;
let duration = multiplier.calculate_vesting_duration::<T>();
let now = <frame_system::Pallet<T>>::block_number();
let now = <T as Config>::BlockNumberProvider::current_block_number();
ReleaseType::Locked(duration.saturating_add(now))
};
<pallet_proxy_bonding::Pallet<T>>::set_release_type(
Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/functions/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl<T: Config> Pallet<T> {
skip_end_check: bool,
) -> DispatchResult {
/* Verify */
let now = <frame_system::Pallet<T>>::block_number();
let now = <T as Config>::BlockNumberProvider::current_block_number();
ensure!(project_details.status == current_round, Error::<T>::IncorrectRound);
ensure!(project_details.round_duration.ended(now) || skip_end_check, Error::<T>::TooEarlyForRound);

Expand Down
1 change: 0 additions & 1 deletion pallets/funding/src/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use frame_support::{
},
transactional,
};
use frame_system::pallet_prelude::BlockNumberFor;
use polimec_common::{
credentials::{Did, InvestorType},
USD_DECIMALS,
Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/functions/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl<T: Config> Pallet<T> {
.enumerate()
// Filter out schedules with future starting blocks before collecting them into a vector.
.filter_map(|(i, schedule)| {
if schedule.starting_block > <frame_system::Pallet<T>>::block_number() {
if schedule.starting_block > <T as Config>::BlockNumberProvider::current_block_number() {
None
} else {
Some((i, schedule.ending_block_as_balance::<BlockNumberToBalanceOf<T>>()))
Expand Down
2 changes: 1 addition & 1 deletion pallets/funding/src/instantiator/calculations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use sp_runtime::traits::TrailingZeroInput;
use InvestorType::{self, *};

impl<
T: Config,
T: Config + cumulus_pallet_parachain_system::Config,
AllPalletsWithoutSystem: OnFinalize<BlockNumberFor<T>> + OnIdle<BlockNumberFor<T>> + OnInitialize<BlockNumberFor<T>>,
RuntimeEvent: From<Event<T>> + TryInto<Event<T>> + Parameter + Member + IsType<<T as frame_system::Config>::RuntimeEvent>,
> Instantiator<T, AllPalletsWithoutSystem, RuntimeEvent>
Expand Down
Loading