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

* Initial setup

* Adds node block

* Uses UncheckedExtrinsic and removes Where section

* Updates frame_system to use Block

* Adds deprecation warning

* Fixes pallet-timestamp

* Removes Header and BlockNumber

* Addresses review comments

* Addresses review comments

* Adds comment about compiler bug

* Removes where clause

* Refactors code

* Fixes errors in cargo check

* Fixes errors in cargo check

* Fixes warnings in cargo check

* Formatting

* Fixes construct_runtime tests

* Uses import instead of full path for BlockNumber

* Uses import instead of full path for Header

* Formatting

* Fixes construct_runtime tests

* Fixes imports in benchmarks

* Formatting

* Fixes construct_runtime tests

* Formatting

* Minor updates

* Fixes construct_runtime ui tests

* Fixes construct_runtime ui tests with 1.70

* Fixes docs

* Fixes docs

* Adds u128 mock block type

* Fixes split example

* fixes for cumulus

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

* Updates new tests

* Fixes fully-qualified path in few places

* Formatting

* Update frame/examples/default-config/src/lib.rs

Co-authored-by: Juan <juangirini@gmail.com>

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Juan <juangirini@gmail.com>

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

* Addresses some review comments

* Fixes build

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

* Update frame/democracy/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/democracy/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Addresses review comments

* Updates trait bounds

* Minor fix

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

* Removes unnecessary bound

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

* Updates test

* Fixes build

* Adds a bound for header

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

* Removes where block

* Minor fix

* Minor fix

* Fixes tests

* ".git/.scripts/commands/update-ui/update-ui.sh" 1.70

* Updates test

* Update primitives/runtime/src/traits.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update primitives/runtime/src/traits.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Updates doc

* Updates doc

---------

Co-authored-by: command-bot <>
Co-authored-by: Juan <juangirini@gmail.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
gupnik
2023-07-13 17:31:34 +05:30
committed by GitHub
parent e42a669c50
commit 5e7b27e98c
277 changed files with 2017 additions and 2450 deletions
@@ -313,7 +313,7 @@ frame_benchmarking::benchmarks! {
assert!(<DesiredTargets<T>>::get().is_none());
assert!(<Snapshot<T>>::get().is_none());
assert!(<SnapshotMetadata<T>>::get().is_none());
assert_eq!(<CurrentPhase<T>>::get(), <Phase<T::BlockNumber>>::Off);
assert_eq!(<CurrentPhase<T>>::get(), <Phase<frame_system::pallet_prelude::BlockNumberFor::<T>>>::Off);
}
submit {
@@ -241,7 +241,7 @@ use frame_support::{
weights::Weight,
DefaultNoBound, EqNoBound, PartialEqNoBound,
};
use frame_system::{ensure_none, offchain::SendTransactionTypes};
use frame_system::{ensure_none, offchain::SendTransactionTypes, pallet_prelude::BlockNumberFor};
use scale_info::TypeInfo;
use sp_arithmetic::{
traits::{CheckedAdd, Zero},
@@ -585,10 +585,10 @@ pub mod pallet {
/// Duration of the unsigned phase.
#[pallet::constant]
type UnsignedPhase: Get<Self::BlockNumber>;
type UnsignedPhase: Get<BlockNumberFor<Self>>;
/// Duration of the signed phase.
#[pallet::constant]
type SignedPhase: Get<Self::BlockNumber>;
type SignedPhase: Get<BlockNumberFor<Self>>;
/// The minimum amount of improvement to the solution score that defines a solution as
/// "better" in the Signed phase.
@@ -605,7 +605,7 @@ pub mod pallet {
/// For example, if it is 5, that means that at least 5 blocks will elapse between attempts
/// to submit the worker's solution.
#[pallet::constant]
type OffchainRepeat: Get<Self::BlockNumber>;
type OffchainRepeat: Get<BlockNumberFor<Self>>;
/// The priority of the unsigned transaction submitted in the unsigned-phase
#[pallet::constant]
@@ -685,13 +685,13 @@ pub mod pallet {
/// Something that will provide the election data.
type DataProvider: ElectionDataProvider<
AccountId = Self::AccountId,
BlockNumber = Self::BlockNumber,
BlockNumber = BlockNumberFor<Self>,
>;
/// Configuration for the fallback.
type Fallback: InstantElectionProvider<
AccountId = Self::AccountId,
BlockNumber = Self::BlockNumber,
BlockNumber = BlockNumberFor<Self>,
DataProvider = Self::DataProvider,
MaxWinners = Self::MaxWinners,
>;
@@ -702,7 +702,7 @@ pub mod pallet {
/// BoundedExecution<_>` if the test-net is not expected to have thousands of nominators.
type GovernanceFallback: InstantElectionProvider<
AccountId = Self::AccountId,
BlockNumber = Self::BlockNumber,
BlockNumber = BlockNumberFor<Self>,
DataProvider = Self::DataProvider,
MaxWinners = Self::MaxWinners,
>;
@@ -747,7 +747,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(now: T::BlockNumber) -> Weight {
fn on_initialize(now: BlockNumberFor<T>) -> Weight {
let next_election = T::DataProvider::next_election_prediction(now).max(now);
let signed_deadline = T::SignedPhase::get() + T::UnsignedPhase::get();
@@ -824,7 +824,7 @@ pub mod pallet {
}
}
fn offchain_worker(now: T::BlockNumber) {
fn offchain_worker(now: BlockNumberFor<T>) {
use sp_runtime::offchain::storage_lock::{BlockAndTime, StorageLock};
// Create a lock with the maximum deadline of number of blocks in the unsigned phase.
@@ -886,7 +886,7 @@ pub mod pallet {
}
#[cfg(feature = "try-runtime")]
fn try_state(_n: T::BlockNumber) -> Result<(), TryRuntimeError> {
fn try_state(_n: BlockNumberFor<T>) -> Result<(), TryRuntimeError> {
Self::do_try_state()
}
}
@@ -1155,7 +1155,11 @@ pub mod pallet {
/// An account has been slashed for submitting an invalid signed submission.
Slashed { account: <T as frame_system::Config>::AccountId, value: BalanceOf<T> },
/// There was a phase transition in a given round.
PhaseTransitioned { from: Phase<T::BlockNumber>, to: Phase<T::BlockNumber>, round: u32 },
PhaseTransitioned {
from: Phase<BlockNumberFor<T>>,
to: Phase<BlockNumberFor<T>>,
round: u32,
},
}
/// Error of the pallet that can be returned in response to dispatches.
@@ -1257,7 +1261,7 @@ pub mod pallet {
/// Current phase.
#[pallet::storage]
#[pallet::getter(fn current_phase)]
pub type CurrentPhase<T: Config> = StorageValue<_, Phase<T::BlockNumber>, ValueQuery>;
pub type CurrentPhase<T: Config> = StorageValue<_, Phase<BlockNumberFor<T>>, ValueQuery>;
/// Current best solution, signed or unsigned, queued to be returned upon `elect`.
///
@@ -1349,7 +1353,7 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
/// Internal logic of the offchain worker, to be executed only when the offchain lock is
/// acquired with success.
fn do_synchronized_offchain_worker(now: T::BlockNumber) {
fn do_synchronized_offchain_worker(now: BlockNumberFor<T>) {
let current_phase = Self::current_phase();
log!(trace, "lock for offchain worker acquired. Phase = {:?}", current_phase);
match current_phase {
@@ -1375,7 +1379,7 @@ impl<T: Config> Pallet<T> {
}
/// Phase transition helper.
pub(crate) fn phase_transition(to: Phase<T::BlockNumber>) {
pub(crate) fn phase_transition(to: Phase<BlockNumberFor<T>>) {
log!(info, "Starting phase {:?}, round {}.", to, Self::round());
Self::deposit_event(Event::PhaseTransitioned {
from: <CurrentPhase<T>>::get(),
@@ -1672,7 +1676,7 @@ impl<T: Config> Pallet<T> {
impl<T: Config> ElectionProviderBase for Pallet<T> {
type AccountId = T::AccountId;
type BlockNumber = T::BlockNumber;
type BlockNumber = BlockNumberFor<T>;
type Error = ElectionError<T>;
type MaxWinners = T::MaxWinners;
type DataProvider = T::DataProvider;
@@ -54,10 +54,7 @@ pub type UncheckedExtrinsic =
sp_runtime::generic::UncheckedExtrinsic<AccountId, RuntimeCall, (), ()>;
frame_support::construct_runtime!(
pub struct Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
pub struct Runtime
{
System: frame_system::{Pallet, Call, Event<T>, Config<T>},
Balances: pallet_balances::{Pallet, Call, Event<T>, Config<T>},
@@ -212,13 +209,12 @@ impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything;
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = BlockNumber;
type RuntimeCall = RuntimeCall;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = ();
type DbWeight = ();
@@ -322,8 +318,8 @@ impl onchain::Config for OnChainSeqPhragmen {
pub struct MockFallback;
impl ElectionProviderBase for MockFallback {
type BlockNumber = BlockNumber;
type AccountId = AccountId;
type BlockNumber = u64;
type Error = &'static str;
type DataProvider = StakingMock;
type MaxWinners = MaxWinners;
@@ -436,8 +432,8 @@ pub struct ExtBuilder {}
pub struct StakingMock;
impl ElectionDataProvider for StakingMock {
type BlockNumber = BlockNumber;
type AccountId = AccountId;
type BlockNumber = u64;
type MaxVotesPerVoter = MaxNominations;
fn electable_targets(maybe_max_len: Option<usize>) -> data_provider::Result<Vec<AccountId>> {
@@ -27,6 +27,7 @@ use frame_election_provider_support::NposSolution;
use frame_support::traits::{
defensive_prelude::*, Currency, Get, OnUnbalanced, ReservableCurrency,
};
use frame_system::pallet_prelude::BlockNumberFor;
use sp_arithmetic::traits::SaturatedConversion;
use sp_core::bounded::BoundedVec;
use sp_npos_elections::ElectionScore;
@@ -100,10 +101,8 @@ pub type SignedSubmissionOf<T> = SignedSubmission<
/// Always sorted vector of a score, submitted at the given block number, which can be found at the
/// given index (`u32`) of the `SignedSubmissionsMap`.
pub type SubmissionIndicesOf<T> = BoundedVec<
(ElectionScore, <T as frame_system::Config>::BlockNumber, u32),
<T as Config>::SignedMaxSubmissions,
>;
pub type SubmissionIndicesOf<T> =
BoundedVec<(ElectionScore, BlockNumberFor<T>, u32), <T as Config>::SignedMaxSubmissions>;
/// Outcome of [`SignedSubmissions::insert`].
pub enum InsertResult<T: Config> {
@@ -216,7 +215,7 @@ impl<T: Config> SignedSubmissions<T> {
fn swap_out_submission(
&mut self,
remove_pos: usize,
insert: Option<(ElectionScore, T::BlockNumber, u32)>,
insert: Option<(ElectionScore, BlockNumberFor<T>, u32)>,
) -> Option<SignedSubmissionOf<T>> {
if remove_pos >= self.indices.len() {
return None
@@ -29,7 +29,7 @@ use frame_support::{
traits::{DefensiveResult, Get},
BoundedVec,
};
use frame_system::offchain::SubmitTransaction;
use frame_system::{offchain::SubmitTransaction, pallet_prelude::BlockNumberFor};
use scale_info::TypeInfo;
use sp_npos_elections::{
assignment_ratio_to_staked_normalized, assignment_staked_to_ratio_normalized, ElectionResult,
@@ -298,12 +298,12 @@ impl<T: Config> Pallet<T> {
///
/// Returns `Ok(())` if offchain worker limit is respected, `Err(reason)` otherwise. If `Ok()`
/// is returned, `now` is written in storage and will be used in further calls as the baseline.
pub fn ensure_offchain_repeat_frequency(now: T::BlockNumber) -> Result<(), MinerError> {
pub fn ensure_offchain_repeat_frequency(now: BlockNumberFor<T>) -> Result<(), MinerError> {
let threshold = T::OffchainRepeat::get();
let last_block = StorageValueRef::persistent(OFFCHAIN_LAST_BLOCK);
let mutate_stat = last_block.mutate::<_, &'static str, _>(
|maybe_head: Result<Option<T::BlockNumber>, _>| {
|maybe_head: Result<Option<BlockNumberFor<T>>, _>| {
match maybe_head {
Ok(Some(head)) if now < head => Err("fork."),
Ok(Some(head)) if now >= head && now <= head + threshold =>