Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Moves Block to frame_system instead of construct_runtime and re…
Browse files Browse the repository at this point in the history
…moves `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 <[email protected]>

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

* update lockfile for {"substrate"}

---------

Co-authored-by: ordian <[email protected]>
Co-authored-by: command-bot <>
  • Loading branch information
gupnik and ordian authored Jul 13, 2023
1 parent 9361e82 commit 0b56bcd
Show file tree
Hide file tree
Showing 47 changed files with 562 additions and 643 deletions.
366 changes: 183 additions & 183 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion roadmap/implementers-guide/src/runtime/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn configuration() -> HostConfiguration {
///
/// If there is already a pending update for the current session index + 1, then it won't be touched. Otherwise,
/// that would violate the promise of this function that changes will be applied on the second session change (cur + 2).
fn schedule_config_update(updater: impl FnOnce(&mut HostConfiguration<T::BlockNumber>)) -> DispatchResult
fn schedule_config_update(updater: impl FnOnce(&mut HostConfiguration<BlockNumberFor<T>>)) -> DispatchResult
```

## Entry-points
Expand Down
5 changes: 3 additions & 2 deletions roadmap/implementers-guide/src/runtime/paras.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ During the transition period, the para object is still considered in its existin
### Storage Layout

```rust
use frame_system::pallet_prelude::BlockNumberFor;
/// All currently active PVF pre-checking votes.
///
/// Invariant:
Expand Down Expand Up @@ -197,12 +198,12 @@ UpgradeRestrictionSignal: map hasher(twox_64_concat) ParaId => Option<UpgradeRes
/// The list of parachains that are awaiting for their upgrade restriction to cooldown.
///
/// Ordered ascending by block number.
UpgradeCooldowns: Vec<(ParaId, T::BlockNumber)>;
UpgradeCooldowns: Vec<(ParaId, BlockNumberFor<T>)>;
/// The list of upcoming code upgrades. Each item is a pair of which para performs a code
/// upgrade and at which relay-chain block it is expected at.
///
/// Ordered ascending by block number.
UpcomingUpgrades: Vec<(ParaId, T::BlockNumber)>;
UpcomingUpgrades: Vec<(ParaId, BlockNumberFor<T>)>;
/// The actions to perform during the start of a specific session index.
ActionsQueue: map SessionIndex => Vec<ParaId>;
/// Upcoming paras instantiation arguments.
Expand Down
32 changes: 14 additions & 18 deletions runtime/common/src/assigned_slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ pub struct ParachainTemporarySlot<AccountId, LeasePeriod> {
pub lease_count: u32,
}

type BalanceOf<T> = <<<T as Config>::Leaser as Leaser<<T as frame_system::Config>::BlockNumber>>::Currency as Currency<
type BalanceOf<T> = <<<T as Config>::Leaser as Leaser<BlockNumberFor<T>>>::Currency as Currency<
<T as frame_system::Config>::AccountId,
>>::Balance;
type LeasePeriodOf<T> =
<<T as Config>::Leaser as Leaser<<T as frame_system::Config>::BlockNumber>>::LeasePeriod;
type LeasePeriodOf<T> = <<T as Config>::Leaser as Leaser<BlockNumberFor<T>>>::LeasePeriod;

#[frame_support::pallet]
pub mod pallet {
Expand All @@ -91,9 +90,9 @@ pub mod pallet {

/// The type representing the leasing system.
type Leaser: Leaser<
Self::BlockNumber,
BlockNumberFor<Self>,
AccountId = Self::AccountId,
LeasePeriod = Self::BlockNumber,
LeasePeriod = BlockNumberFor<Self>,
>;

/// The number of lease periods a permanent parachain slot lasts.
Expand Down Expand Up @@ -182,7 +181,7 @@ pub mod pallet {

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(n: T::BlockNumber) -> Weight {
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
if let Some((lease_period, first_block)) = Self::lease_period_index(n) {
// If we're beginning a new lease period then handle that.
if first_block {
Expand Down Expand Up @@ -213,14 +212,14 @@ pub mod pallet {
Error::<T>::SlotAlreadyAssigned
);

let current_lease_period: T::BlockNumber = Self::current_lease_period_index();
let current_lease_period: BlockNumberFor<T> = Self::current_lease_period_index();
ensure!(
!T::Leaser::already_leased(
id,
current_lease_period,
// Check current lease & next one
current_lease_period.saturating_add(
T::BlockNumber::from(2u32)
BlockNumberFor::<T>::from(2u32)
.saturating_mul(T::PermanentSlotLeasePeriodLength::get().into())
)
),
Expand Down Expand Up @@ -276,14 +275,14 @@ pub mod pallet {
Error::<T>::SlotAlreadyAssigned
);

let current_lease_period: T::BlockNumber = Self::current_lease_period_index();
let current_lease_period: BlockNumberFor<T> = Self::current_lease_period_index();
ensure!(
!T::Leaser::already_leased(
id,
current_lease_period,
// Check current lease & next one
current_lease_period.saturating_add(
T::BlockNumber::from(2u32)
BlockNumberFor::<T>::from(2u32)
.saturating_mul(T::TemporarySlotLeasePeriodLength::get().into())
)
),
Expand Down Expand Up @@ -548,7 +547,7 @@ mod tests {
use frame_support::{assert_noop, assert_ok, parameter_types};
use frame_system::EnsureRoot;
use pallet_balances;
use primitives::{BlockNumber, Header};
use primitives::BlockNumber;
use runtime_parachains::{
configuration as parachains_configuration, paras as parachains_paras,
shared as parachains_shared,
Expand All @@ -562,13 +561,10 @@ mod tests {
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
type Block = frame_system::mocking::MockBlockU32<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>},
Expand Down Expand Up @@ -598,12 +594,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 DbWeight = ();
Expand Down
Loading

0 comments on commit 0b56bcd

Please sign in to comment.