Moves Block to frame_system instead of construct_runtime and removes Header and BlockNumber (#7431)

* Companion for substrate

* Minor update

* Formatting

* Fixes for cumulus

* Fixes tests in polkadot-runtime-parachains

* Minor update

* Removes unused import

* Fixes tests in polkadot-runtime-common

* Minor fix

* Update roadmap/implementers-guide/src/runtime/configuration.md

Co-authored-by: ordian <write@reusable.software>

* ".git/.scripts/commands/fmt/fmt.sh"

* update lockfile for {"substrate"}

---------

Co-authored-by: ordian <write@reusable.software>
Co-authored-by: command-bot <>
This commit is contained in:
gupnik
2023-07-13 18:07:50 +05:30
committed by GitHub
parent bfaec080cc
commit 2802414473
47 changed files with 562 additions and 643 deletions
+18 -25
View File
@@ -66,6 +66,7 @@ use frame_support::{
},
Identity, PalletId,
};
use frame_system::pallet_prelude::BlockNumberFor;
pub use pallet::*;
use parity_scale_codec::{Decode, Encode};
use primitives::Id as ParaId;
@@ -78,11 +79,8 @@ use sp_runtime::{
};
use sp_std::vec::Vec;
type CurrencyOf<T> =
<<T as Config>::Auctioneer as Auctioneer<<T as frame_system::Config>::BlockNumber>>::Currency;
type LeasePeriodOf<T> = <<T as Config>::Auctioneer as Auctioneer<
<T as frame_system::Config>::BlockNumber,
>>::LeasePeriod;
type CurrencyOf<T> = <<T as Config>::Auctioneer as Auctioneer<BlockNumberFor<T>>>::Currency;
type LeasePeriodOf<T> = <<T as Config>::Auctioneer as Auctioneer<BlockNumberFor<T>>>::LeasePeriod;
type BalanceOf<T> = <CurrencyOf<T> as Currency<<T as frame_system::Config>::AccountId>>::Balance;
#[allow(dead_code)]
@@ -216,9 +214,9 @@ pub mod pallet {
/// The type representing the auctioning system.
type Auctioneer: Auctioneer<
Self::BlockNumber,
BlockNumberFor<Self>,
AccountId = Self::AccountId,
LeasePeriod = Self::BlockNumber,
LeasePeriod = BlockNumberFor<Self>,
>;
/// The maximum length for the memo attached to a crowdloan contribution.
@@ -235,7 +233,7 @@ pub mod pallet {
_,
Twox64Concat,
ParaId,
FundInfo<T::AccountId, BalanceOf<T>, T::BlockNumber, LeasePeriodOf<T>>,
FundInfo<T::AccountId, BalanceOf<T>, BlockNumberFor<T>, LeasePeriodOf<T>>,
>;
/// The funds that have had additional contributions during the last block. This is used
@@ -332,7 +330,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(num: T::BlockNumber) -> frame_support::weights::Weight {
fn on_initialize(num: BlockNumberFor<T>) -> frame_support::weights::Weight {
if let Some((sample, sub_sample)) = T::Auctioneer::auction_status(num).is_ending() {
// This is the very first block in the ending period
if sample.is_zero() && sub_sample.is_zero() {
@@ -377,7 +375,7 @@ pub mod pallet {
#[pallet::compact] cap: BalanceOf<T>,
#[pallet::compact] first_period: LeasePeriodOf<T>,
#[pallet::compact] last_period: LeasePeriodOf<T>,
#[pallet::compact] end: T::BlockNumber,
#[pallet::compact] end: BlockNumberFor<T>,
verifier: Option<MultiSigner>,
) -> DispatchResult {
let depositor = ensure_signed(origin)?;
@@ -594,7 +592,7 @@ pub mod pallet {
#[pallet::compact] cap: BalanceOf<T>,
#[pallet::compact] first_period: LeasePeriodOf<T>,
#[pallet::compact] last_period: LeasePeriodOf<T>,
#[pallet::compact] end: T::BlockNumber,
#[pallet::compact] end: BlockNumberFor<T>,
verifier: Option<MultiSigner>,
) -> DispatchResult {
ensure_root(origin)?;
@@ -725,9 +723,9 @@ impl<T: Config> Pallet<T> {
/// trying to bid for has started already.
/// * And, if the fund has enough free funds to refund full raised amount.
fn ensure_crowdloan_ended(
now: T::BlockNumber,
now: BlockNumberFor<T>,
fund_account: &T::AccountId,
fund: &FundInfo<T::AccountId, BalanceOf<T>, T::BlockNumber, LeasePeriodOf<T>>,
fund: &FundInfo<T::AccountId, BalanceOf<T>, BlockNumberFor<T>, LeasePeriodOf<T>>,
) -> sp_runtime::DispatchResult {
// `fund.end` can represent the end of a failed crowdloan or the beginning of retirement
// If the current lease period is past the first period they are trying to bid for, then
@@ -878,19 +876,14 @@ mod tests {
use ::test_helpers::{dummy_head_data, dummy_validation_code};
use sp_keystore::{testing::MemoryKeystore, KeystoreExt};
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup, TrailingZeroInput},
BuildStorage, DispatchResult,
};
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub enum Test
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
@@ -912,12 +905,12 @@ mod tests {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = BlockNumber;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
@@ -1968,7 +1961,7 @@ mod benchmarking {
assert_eq!(event, &system_event);
}
fn create_fund<T: Config + paras::Config>(id: u32, end: T::BlockNumber) -> ParaId {
fn create_fund<T: Config + paras::Config>(id: u32, end: BlockNumberFor<T>) -> ParaId {
let cap = BalanceOf::<T>::max_value();
let (_, offset) = T::Auctioneer::lease_period_length();
// Set to the very beginning of lease period index 0.
@@ -2088,7 +2081,7 @@ mod benchmarking {
let caller: T::AccountId = whitelisted_caller();
let contributor = account("contributor", 0, 0);
contribute_fund::<T>(&contributor, fund_index);
frame_system::Pallet::<T>::set_block_number(T::BlockNumber::max_value());
frame_system::Pallet::<T>::set_block_number(BlockNumberFor::<T>::max_value());
}: _(RawOrigin::Signed(caller), contributor.clone(), fund_index)
verify {
assert_last_event::<T>(Event::<T>::Withdrew { who: contributor, fund_index, amount: T::MinContribution::get() }.into());
@@ -2108,7 +2101,7 @@ mod benchmarking {
}
let caller: T::AccountId = whitelisted_caller();
frame_system::Pallet::<T>::set_block_number(T::BlockNumber::max_value());
frame_system::Pallet::<T>::set_block_number(BlockNumberFor::<T>::max_value());
}: _(RawOrigin::Signed(caller), fund_index)
verify {
assert_last_event::<T>(Event::<T>::AllRefunded { para_id: fund_index }.into());
@@ -2119,7 +2112,7 @@ mod benchmarking {
let end = lpl + offset;
let fund_index = create_fund::<T>(1337, end);
let caller: T::AccountId = whitelisted_caller();
frame_system::Pallet::<T>::set_block_number(T::BlockNumber::max_value());
frame_system::Pallet::<T>::set_block_number(BlockNumberFor::<T>::max_value());
}: _(RawOrigin::Signed(caller.clone()), fund_index)
verify {
assert_last_event::<T>(Event::<T>::Dissolved { para_id: fund_index }.into());