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
@@ -36,7 +36,10 @@ const MAX_KEYS: u32 = 1000;
pub fn create_heartbeat<T: Config>(
k: u32,
) -> Result<
(crate::Heartbeat<T::BlockNumber>, <T::AuthorityId as RuntimeAppPublic>::Signature),
(
crate::Heartbeat<frame_system::pallet_prelude::BlockNumberFor<T>>,
<T::AuthorityId as RuntimeAppPublic>::Signature,
),
&'static str,
> {
let mut keys = Vec::new();
@@ -48,7 +51,7 @@ pub fn create_heartbeat<T: Config>(
Keys::<T>::put(bounded_keys);
let input_heartbeat = Heartbeat {
block_number: T::BlockNumber::zero(),
block_number: frame_system::pallet_prelude::BlockNumberFor::<T>::zero(),
session_index: 0,
authority_index: k - 1,
validators_len: keys.len() as u32,
+9 -9
View File
@@ -245,7 +245,7 @@ pub type IdentificationTuple<T> = (
>>::Identification,
);
type OffchainResult<T, A> = Result<A, OffchainErr<<T as frame_system::Config>::BlockNumber>>;
type OffchainResult<T, A> = Result<A, OffchainErr<BlockNumberFor<T>>>;
#[frame_support::pallet]
pub mod pallet {
@@ -287,7 +287,7 @@ pub mod pallet {
/// rough time when we should start considering sending heartbeats, since the workers
/// avoids sending them at the very beginning of the session, assuming there is a
/// chance the authority will produce a block and they won't be necessary.
type NextSessionRotation: EstimateNextSessionRotation<Self::BlockNumber>;
type NextSessionRotation: EstimateNextSessionRotation<BlockNumberFor<Self>>;
/// A type that gives us the ability to submit unresponsiveness offence reports.
type ReportUnresponsiveness: ReportOffence<
@@ -339,7 +339,7 @@ pub mod pallet {
/// more accurate then the value we calculate for `HeartbeatAfter`.
#[pallet::storage]
#[pallet::getter(fn heartbeat_after)]
pub(super) type HeartbeatAfter<T: Config> = StorageValue<_, T::BlockNumber, ValueQuery>;
pub(super) type HeartbeatAfter<T: Config> = StorageValue<_, BlockNumberFor<T>, ValueQuery>;
/// The current set of keys that may issue a heartbeat.
#[pallet::storage]
@@ -393,7 +393,7 @@ pub mod pallet {
))]
pub fn heartbeat(
origin: OriginFor<T>,
heartbeat: Heartbeat<T::BlockNumber>,
heartbeat: Heartbeat<BlockNumberFor<T>>,
// since signature verification is done in `validate_unsigned`
// we can skip doing it here again.
_signature: <T::AuthorityId as RuntimeAppPublic>::Signature,
@@ -505,7 +505,7 @@ pub mod pallet {
/// Keep track of number of authored blocks per authority, uncles are counted as
/// well since they're a valid proof of being online.
impl<T: Config + pallet_authorship::Config>
pallet_authorship::EventHandler<ValidatorId<T>, T::BlockNumber> for Pallet<T>
pallet_authorship::EventHandler<ValidatorId<T>, BlockNumberFor<T>> for Pallet<T>
{
fn note_author(author: ValidatorId<T>) {
Self::note_authorship(author);
@@ -551,7 +551,7 @@ impl<T: Config> Pallet<T> {
}
pub(crate) fn send_heartbeats(
block_number: T::BlockNumber,
block_number: BlockNumberFor<T>,
) -> OffchainResult<T, impl Iterator<Item = OffchainResult<T, ()>>> {
const START_HEARTBEAT_RANDOM_PERIOD: Permill = Permill::from_percent(10);
const START_HEARTBEAT_FINAL_PERIOD: Permill = Permill::from_percent(80);
@@ -614,7 +614,7 @@ impl<T: Config> Pallet<T> {
authority_index: u32,
key: T::AuthorityId,
session_index: SessionIndex,
block_number: T::BlockNumber,
block_number: BlockNumberFor<T>,
validators_len: u32,
) -> OffchainResult<T, ()> {
// A helper function to prepare heartbeat call.
@@ -677,7 +677,7 @@ impl<T: Config> Pallet<T> {
fn with_heartbeat_lock<R>(
authority_index: u32,
session_index: SessionIndex,
now: T::BlockNumber,
now: BlockNumberFor<T>,
f: impl FnOnce() -> OffchainResult<T, R>,
) -> OffchainResult<T, R> {
let key = {
@@ -687,7 +687,7 @@ impl<T: Config> Pallet<T> {
};
let storage = StorageValueRef::persistent(&key);
let res = storage.mutate(
|status: Result<Option<HeartbeatStatus<T::BlockNumber>>, StorageRetrievalError>| {
|status: Result<Option<HeartbeatStatus<BlockNumberFor<T>>>, StorageRetrievalError>| {
// Check if there is already a lock for that particular block.
// This means that the heartbeat has already been sent, and we are just waiting
// for it to be included. However if it doesn't get included for INCLUDE_THRESHOLD
+3 -8
View File
@@ -27,7 +27,7 @@ use frame_support::{
use pallet_session::historical as pallet_session_historical;
use sp_core::H256;
use sp_runtime::{
testing::{Header, TestXt, UintAuthorityId},
testing::{TestXt, UintAuthorityId},
traits::{BlakeTwo256, ConvertInto, IdentityLookup},
BuildStorage, Permill,
};
@@ -39,14 +39,10 @@ use sp_staking::{
use crate as imonline;
use crate::Config;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Runtime>;
type Block = frame_system::mocking::MockBlock<Runtime>;
frame_support::construct_runtime!(
pub struct Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
pub struct Runtime
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
@@ -124,13 +120,12 @@ impl frame_system::Config for Runtime {
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Index = u64;
type BlockNumber = u64;
type RuntimeCall = RuntimeCall;
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 = ConstU64<250>;
type Version = ();