Companion for #8372 (Replace 'Module' with 'Pallet' in construct_runtime macro) (#2629)

* Replace 'Module' with 'Pallet'.

* "Update Substrate"

* fix babe usage

* fix benchmark

Co-authored-by: parity-processbot <>
Co-authored-by: thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Shaun Wang
2021-03-18 23:10:17 +13:00
committed by GitHub
parent 503e2b74f9
commit 9047bbb392
36 changed files with 491 additions and 493 deletions
+15 -15
View File
@@ -231,7 +231,7 @@ decl_module! {
let n = AuctionCounter::mutate(|n| { *n += 1; *n });
// Set the information.
let ending = frame_system::Module::<T>::block_number().saturating_add(duration);
let ending = frame_system::Pallet::<T>::block_number().saturating_add(duration);
AuctionInfo::<T>::put((lease_period_index, ending));
Self::deposit_event(RawEvent::AuctionStarted(n, lease_period_index, ending))
@@ -313,7 +313,7 @@ impl<T: Config> Module<T> {
let late_end = early_end.saturating_add(T::EndingPeriod::get());
// We need to check that the auction isn't in the period where it has definitely ended, but yeah we keep the
// info around because we haven't yet decided *exactly* when in the `EndingPeriod` that it ended.
let now = frame_system::Module::<T>::block_number();
let now = frame_system::Pallet::<T>::block_number();
now < late_end
})
}
@@ -334,7 +334,7 @@ impl<T: Config> Module<T> {
let n = AuctionCounter::mutate(|n| { *n += 1; *n });
// Set the information.
let ending = frame_system::Module::<T>::block_number().saturating_add(duration);
let ending = frame_system::Pallet::<T>::block_number().saturating_add(duration);
AuctionInfo::<T>::put((lease_period_index, ending));
Self::deposit_event(RawEvent::AuctionStarted(n, lease_period_index, ending));
@@ -365,7 +365,7 @@ impl<T: Config> Module<T> {
// We need to check that the auction isn't in the period where it has definitely ended, but yeah we keep the
// info around because we haven't yet decided *exactly* when in the `EndingPeriod` that it ended.
let now = frame_system::Module::<T>::block_number();
let now = frame_system::Pallet::<T>::block_number();
ensure!(now < late_end, Error::<T>::AuctionEnded);
// Our range.
@@ -373,7 +373,7 @@ impl<T: Config> Module<T> {
// Range as an array index.
let range_index = range as u8 as usize;
// The offset into the auction ending set.
let offset = Self::is_ending(frame_system::Module::<T>::block_number()).unwrap_or_default();
let offset = Self::is_ending(frame_system::Pallet::<T>::block_number()).unwrap_or_default();
// The current winning ranges.
let mut current_winning = Winning::<T>::get(offset)
.or_else(|| offset.checked_sub(&One::one()).and_then(Winning::<T>::get))
@@ -601,9 +601,9 @@ mod tests {
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Auctions: auctions::{Module, Call, Storage, Event<T>},
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Auctions: auctions::{Pallet, Call, Storage, Event<T>},
}
);
@@ -737,7 +737,7 @@ mod tests {
if let Some((output, known_since)) = &*p.borrow() {
(*output, *known_since)
} else {
(H256::zero(), frame_system::Module::<Test>::block_number())
(H256::zero(), frame_system::Pallet::<Test>::block_number())
}
})
}
@@ -1323,7 +1323,7 @@ mod benchmarking {
use frame_benchmarking::{benchmarks, whitelisted_caller, account, impl_benchmark_test_suite};
fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
let events = frame_system::Module::<T>::events();
let events = frame_system::Pallet::<T>::events();
let system_event: <T as frame_system::Config>::Event = generic_event.into();
// compare to the last event record
let frame_system::EventRecord { event, .. } = &events[events.len() - 1];
@@ -1386,7 +1386,7 @@ mod benchmarking {
// Create a new auction
let duration: T::BlockNumber = 99u32.into();
let lease_period_index = LeasePeriodOf::<T>::zero();
let now = frame_system::Module::<T>::block_number();
let now = frame_system::Pallet::<T>::block_number();
Auctions::<T>::new_auction(RawOrigin::Root.into(), duration, lease_period_index)?;
let auction_index = AuctionCounter::get();
@@ -1425,14 +1425,14 @@ mod benchmarking {
}
// Move ahead to the block we want to initialize
frame_system::Module::<T>::set_block_number(duration + now + T::EndingPeriod::get());
frame_system::Pallet::<T>::set_block_number(duration + now + T::EndingPeriod::get());
// Trigger epoch change for new random number value:
{
pallet_babe::Module::<T>::on_initialize(duration + now + T::EndingPeriod::get());
let authorities = pallet_babe::Module::<T>::authorities();
pallet_babe::Pallet::<T>::on_initialize(duration + now + T::EndingPeriod::get());
let authorities = pallet_babe::Pallet::<T>::authorities();
let next_authorities = authorities.clone();
pallet_babe::Module::<T>::enact_epoch_change(authorities, next_authorities);
pallet_babe::Pallet::<T>::enact_epoch_change(authorities, next_authorities);
}
}: {
+4 -4
View File
@@ -624,10 +624,10 @@ mod tests {
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Vesting: pallet_vesting::{Module, Call, Storage, Config<T>, Event<T>},
Claims: claims::{Module, Call, Storage, Config<T>, Event<T>, ValidateUnsigned},
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Vesting: pallet_vesting::{Pallet, Call, Storage, Config<T>, Event<T>},
Claims: claims::{Pallet, Call, Storage, Config<T>, Event<T>, ValidateUnsigned},
}
);
+11 -11
View File
@@ -312,7 +312,7 @@ decl_module! {
ensure!(first_slot <= last_slot, Error::<T>::LastSlotBeforeFirstSlot);
let last_slot_limit = first_slot.checked_add(&3u32.into()).ok_or(Error::<T>::FirstSlotTooFarInFuture)?;
ensure!(last_slot <= last_slot_limit, Error::<T>::LastSlotTooFarInFuture);
ensure!(end > <frame_system::Module<T>>::block_number(), Error::<T>::CannotEndInPast);
ensure!(end > <frame_system::Pallet<T>>::block_number(), Error::<T>::CannotEndInPast);
// There should not be an existing fund.
ensure!(!Funds::<T>::contains_key(index), Error::<T>::FundNotEnded);
@@ -363,7 +363,7 @@ decl_module! {
ensure!(fund.raised <= fund.cap, Error::<T>::CapExceeded);
// Make sure crowdloan has not ended
let now = <frame_system::Module<T>>::block_number();
let now = <frame_system::Pallet<T>>::block_number();
ensure!(now < fund.end, Error::<T>::ContributionPeriodOver);
let old_balance = Self::contribution_get(fund.trie_index, &who);
@@ -437,7 +437,7 @@ decl_module! {
let mut fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
// `fund.end` can represent the end of a failed crowdsale or the beginning of retirement
let now = frame_system::Module::<T>::block_number();
let now = frame_system::Pallet::<T>::block_number();
let current_lease_period = T::Auctioneer::lease_period_index();
ensure!(now >= fund.end || current_lease_period > fund.last_slot, Error::<T>::FundNotEnded);
@@ -471,7 +471,7 @@ decl_module! {
ensure_signed(origin)?;
let fund = Self::funds(index).ok_or(Error::<T>::InvalidParaId)?;
let now = frame_system::Module::<T>::block_number();
let now = frame_system::Pallet::<T>::block_number();
let dissolution = fund.end.saturating_add(T::RetirementPeriod::get());
ensure!((fund.retiring && now >= dissolution) || fund.raised.is_zero(), Error::<T>::NotReadyToDissolve);
@@ -626,9 +626,9 @@ mod tests {
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Crowdloan: crowdloan::{Module, Call, Storage, Event<T>},
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Crowdloan: crowdloan::{Pallet, Call, Storage, Event<T>},
}
);
@@ -1256,7 +1256,7 @@ mod benchmarking {
use frame_benchmarking::{benchmarks, whitelisted_caller, account, impl_benchmark_test_suite};
fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
let events = frame_system::Module::<T>::events();
let events = frame_system::Pallet::<T>::events();
let system_event: <T as frame_system::Config>::Event = generic_event.into();
// compare to the last event record
let frame_system::EventRecord { event, .. } = &events[events.len() - 1];
@@ -1350,7 +1350,7 @@ mod benchmarking {
let caller: T::AccountId = whitelisted_caller();
let contributor = account("contributor", 0, 0);
contribute_fund::<T>(&contributor, fund_index);
frame_system::Module::<T>::set_block_number(200u32.into());
frame_system::Pallet::<T>::set_block_number(200u32.into());
}: _(RawOrigin::Signed(caller), contributor.clone(), fund_index)
verify {
assert_last_event::<T>(RawEvent::Withdrew(contributor, fund_index, T::MinContribution::get()).into());
@@ -1370,7 +1370,7 @@ mod benchmarking {
contribute_fund::<T>(&account("last_contributor", 0, 0), fund_index);
let caller: T::AccountId = whitelisted_caller();
frame_system::Module::<T>::set_block_number(T::BlockNumber::max_value());
frame_system::Pallet::<T>::set_block_number(T::BlockNumber::max_value());
Crowdloan::<T>::withdraw(
RawOrigin::Signed(caller.clone()).into(),
account("last_contributor", 0, 0),
@@ -1404,7 +1404,7 @@ mod benchmarking {
let lease_period_index = T::Auctioneer::lease_period_index();
let duration = end_block
.checked_sub(&frame_system::Module::<T>::block_number())
.checked_sub(&frame_system::Pallet::<T>::block_number())
.ok_or("duration of auction less than zero")?;
T::Auctioneer::new_auction(duration, lease_period_index)?;
+6 -6
View File
@@ -31,8 +31,8 @@ where
fn on_nonzero_unbalanced(amount: NegativeImbalance<R>) {
let numeric_amount = amount.peek();
let author = <pallet_authorship::Module<R>>::author();
<pallet_balances::Module<R>>::resolve_creating(&<pallet_authorship::Module<R>>::author(), amount);
<frame_system::Module<R>>::deposit_event(pallet_balances::Event::Deposit(author, numeric_amount));
<pallet_balances::Pallet<R>>::resolve_creating(&<pallet_authorship::Module<R>>::author(), amount);
<frame_system::Pallet<R>>::deposit_event(pallet_balances::Event::Deposit(author, numeric_amount));
}
}
@@ -84,9 +84,9 @@ mod tests {
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>},
}
);
@@ -144,7 +144,7 @@ mod tests {
}
impl pallet_treasury::Config for Test {
type Currency = pallet_balances::Module<Test>;
type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<AccountId>;
type RejectOrigin = frame_system::EnsureRoot<AccountId>;
type Event = Event;
@@ -59,19 +59,19 @@ frame_support::construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic,
{
// System Stuff
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Babe: pallet_babe::{Module, Call, Storage, Config, ValidateUnsigned},
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Babe: pallet_babe::{Pallet, Call, Storage, Config, ValidateUnsigned},
// Parachains Runtime
Configuration: configuration::{Module, Call, Storage, Config<T>},
Paras: paras::{Module, Origin, Call, Storage, Config<T>},
Configuration: configuration::{Pallet, Call, Storage, Config<T>},
Paras: paras::{Pallet, Origin, Call, Storage, Config<T>},
// Para Onboarding Pallets
Registrar: paras_registrar::{Module, Call, Storage, Event<T>},
Auctions: auctions::{Module, Call, Storage, Event<T>},
Crowdloan: crowdloan::{Module, Call, Storage, Event<T>},
Slots: slots::{Module, Call, Storage, Event<T>},
Registrar: paras_registrar::{Pallet, Call, Storage, Event<T>},
Auctions: auctions::{Pallet, Call, Storage, Event<T>},
Crowdloan: crowdloan::{Pallet, Call, Storage, Event<T>},
Slots: slots::{Pallet, Call, Storage, Event<T>},
}
);
@@ -271,12 +271,12 @@ fn run_to_block(n: u32) {
assert!(System::block_number() < n);
while System::block_number() < n {
let block_number = System::block_number();
AllModules::on_finalize(block_number);
AllPallets::on_finalize(block_number);
System::on_finalize(block_number);
System::set_block_number(block_number + 1);
System::on_initialize(block_number + 1);
maybe_new_session(block_number + 1);
AllModules::on_initialize(block_number + 1);
AllPallets::on_initialize(block_number + 1);
}
}
+2 -2
View File
@@ -55,7 +55,7 @@ pub use pallet_balances::Call as BalancesCall;
/// Implementations of some helper traits passed into runtime modules as associated types.
pub use impls::ToAuthor;
pub type NegativeImbalance<T> = <pallet_balances::Module<T> as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
pub type NegativeImbalance<T> = <pallet_balances::Pallet<T> as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
/// The sequence of bytes a valid wasm module binary always starts with. Apart from that it's also a
/// valid wasm module.
@@ -212,7 +212,7 @@ mod multiplier_tests {
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>}
System: frame_system::{Pallet, Call, Config, Storage, Event<T>}
}
);
+2 -2
View File
@@ -99,7 +99,7 @@ impl<T: frame_system::Config> Registrar for TestRegistrar<T> {
}
fn make_parachain(id: ParaId) -> DispatchResult {
OPERATIONS.with(|x| x.borrow_mut().push((id, frame_system::Module::<T>::block_number().saturated_into(), true)));
OPERATIONS.with(|x| x.borrow_mut().push((id, frame_system::Pallet::<T>::block_number().saturated_into(), true)));
PARATHREADS.with(|x| {
let mut parathreads = x.borrow_mut();
match parathreads.binary_search(&id) {
@@ -119,7 +119,7 @@ impl<T: frame_system::Config> Registrar for TestRegistrar<T> {
Ok(())
}
fn make_parathread(id: ParaId) -> DispatchResult {
OPERATIONS.with(|x| x.borrow_mut().push((id, frame_system::Module::<T>::block_number().saturated_into(), false)));
OPERATIONS.with(|x| x.borrow_mut().push((id, frame_system::Pallet::<T>::block_number().saturated_into(), false)));
PARACHAINS.with(|x| {
let mut parachains = x.borrow_mut();
match parachains.binary_search(&id) {
@@ -427,10 +427,10 @@ mod tests {
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Parachains: paras::{Module, Origin, Call, Storage, Config<T>},
Registrar: paras_registrar::{Module, Call, Storage, Event<T>},
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Parachains: paras::{Pallet, Origin, Call, Storage, Config<T>},
Registrar: paras_registrar::{Pallet, Call, Storage, Event<T>},
}
);
@@ -853,7 +853,7 @@ mod benchmarking {
use frame_benchmarking::{benchmarks, whitelisted_caller};
fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
let events = frame_system::Module::<T>::events();
let events = frame_system::Pallet::<T>::events();
let system_event: <T as frame_system::Config>::Event = generic_event.into();
// compare to the last event record
let frame_system::EventRecord { event, .. } = &events[events.len() - 1];
+5 -5
View File
@@ -332,7 +332,7 @@ decl_module! {
#[weight = T::DbWeight::get().writes(1)]
fn set_unlock_block(origin, unlock_block: T::BlockNumber) {
T::ConfigurationOrigin::ensure_origin(origin)?;
ensure!(unlock_block > frame_system::Module::<T>::block_number(), Error::<T>::InvalidUnlockBlock);
ensure!(unlock_block > frame_system::Pallet::<T>::block_number(), Error::<T>::InvalidUnlockBlock);
// Possibly this is worse than having the caller account be the payment account?
UnlockBlock::<T>::set(unlock_block);
Self::deposit_event(RawEvent::UnlockBlockUpdated(unlock_block));
@@ -414,10 +414,10 @@ mod tests {
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Vesting: pallet_vesting::{Module, Call, Storage, Config<T>, Event<T>},
Purchase: purchase::{Module, Call, Storage, Event<T>},
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Vesting: pallet_vesting::{Pallet, Call, Storage, Config<T>, Event<T>},
Purchase: purchase::{Pallet, Call, Storage, Event<T>},
}
);
+6 -6
View File
@@ -354,7 +354,7 @@ impl<T: Config> Leaser for Module<T> {
}
fn lease_period_index() -> Self::LeasePeriod {
<frame_system::Module<T>>::block_number() / T::LeasePeriod::get()
<frame_system::Pallet<T>>::block_number() / T::LeasePeriod::get()
}
}
@@ -383,10 +383,10 @@ mod tests {
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
Slots: slots::{Module, Call, Storage, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Module, Call, Storage},
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Slots: slots::{Pallet, Call, Storage, Event<T>},
RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Call, Storage},
}
);
@@ -667,7 +667,7 @@ mod benchmarking {
use crate::slots::Module as Slots;
fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) {
let events = frame_system::Module::<T>::events();
let events = frame_system::Pallet::<T>::events();
let system_event: <T as frame_system::Config>::Event = generic_event.into();
// compare to the last event record
let frame_system::EventRecord { event, .. } = &events[events.len() - 1];