mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 15:11:03 +00:00
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:
@@ -126,6 +126,7 @@ use frame_support::{
|
||||
},
|
||||
weights::Weight,
|
||||
};
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use sp_runtime::{
|
||||
generic::Digest,
|
||||
traits::{
|
||||
@@ -178,14 +179,17 @@ pub struct Executive<
|
||||
|
||||
impl<
|
||||
System: frame_system::Config + EnsureInherentsAreFirst<Block>,
|
||||
Block: traits::Block<Header = System::Header, Hash = System::Hash>,
|
||||
Block: traits::Block<
|
||||
Header = frame_system::pallet_prelude::HeaderFor<System>,
|
||||
Hash = System::Hash,
|
||||
>,
|
||||
Context: Default,
|
||||
UnsignedValidator,
|
||||
AllPalletsWithSystem: OnRuntimeUpgrade
|
||||
+ OnInitialize<System::BlockNumber>
|
||||
+ OnIdle<System::BlockNumber>
|
||||
+ OnFinalize<System::BlockNumber>
|
||||
+ OffchainWorker<System::BlockNumber>,
|
||||
+ OnInitialize<BlockNumberFor<System>>
|
||||
+ OnIdle<BlockNumberFor<System>>
|
||||
+ OnFinalize<BlockNumberFor<System>>
|
||||
+ OffchainWorker<BlockNumberFor<System>>,
|
||||
COnRuntimeUpgrade: OnRuntimeUpgrade,
|
||||
> ExecuteBlock<Block>
|
||||
for Executive<System, Block, Context, UnsignedValidator, AllPalletsWithSystem, COnRuntimeUpgrade>
|
||||
@@ -212,15 +216,18 @@ where
|
||||
#[cfg(feature = "try-runtime")]
|
||||
impl<
|
||||
System: frame_system::Config + EnsureInherentsAreFirst<Block>,
|
||||
Block: traits::Block<Header = System::Header, Hash = System::Hash>,
|
||||
Block: traits::Block<
|
||||
Header = frame_system::pallet_prelude::HeaderFor<System>,
|
||||
Hash = System::Hash,
|
||||
>,
|
||||
Context: Default,
|
||||
UnsignedValidator,
|
||||
AllPalletsWithSystem: OnRuntimeUpgrade
|
||||
+ OnInitialize<System::BlockNumber>
|
||||
+ OnIdle<System::BlockNumber>
|
||||
+ OnFinalize<System::BlockNumber>
|
||||
+ OffchainWorker<System::BlockNumber>
|
||||
+ frame_support::traits::TryState<System::BlockNumber>,
|
||||
+ OnInitialize<BlockNumberFor<System>>
|
||||
+ OnIdle<BlockNumberFor<System>>
|
||||
+ OnFinalize<BlockNumberFor<System>>
|
||||
+ OffchainWorker<BlockNumberFor<System>>
|
||||
+ frame_support::traits::TryState<BlockNumberFor<System>>,
|
||||
COnRuntimeUpgrade: OnRuntimeUpgrade,
|
||||
> Executive<System, Block, Context, UnsignedValidator, AllPalletsWithSystem, COnRuntimeUpgrade>
|
||||
where
|
||||
@@ -297,10 +304,9 @@ where
|
||||
|
||||
// run the try-state checks of all pallets, ensuring they don't alter any state.
|
||||
let _guard = frame_support::StorageNoopGuard::default();
|
||||
<AllPalletsWithSystem as frame_support::traits::TryState<System::BlockNumber>>::try_state(
|
||||
*header.number(),
|
||||
select,
|
||||
)
|
||||
<AllPalletsWithSystem as frame_support::traits::TryState<
|
||||
BlockNumberFor<System>,
|
||||
>>::try_state(*header.number(), select)
|
||||
.map_err(|e| {
|
||||
frame_support::log::error!(target: LOG_TARGET, "failure: {:?}", e);
|
||||
e
|
||||
@@ -350,7 +356,9 @@ where
|
||||
) -> Result<Weight, TryRuntimeError> {
|
||||
if checks.try_state() {
|
||||
let _guard = frame_support::StorageNoopGuard::default();
|
||||
<AllPalletsWithSystem as frame_support::traits::TryState<System::BlockNumber>>::try_state(
|
||||
<AllPalletsWithSystem as frame_support::traits::TryState<
|
||||
BlockNumberFor<System>,
|
||||
>>::try_state(
|
||||
frame_system::Pallet::<System>::block_number(),
|
||||
frame_try_runtime::TryStateSelect::All,
|
||||
)?;
|
||||
@@ -363,7 +371,9 @@ where
|
||||
|
||||
if checks.try_state() {
|
||||
let _guard = frame_support::StorageNoopGuard::default();
|
||||
<AllPalletsWithSystem as frame_support::traits::TryState<System::BlockNumber>>::try_state(
|
||||
<AllPalletsWithSystem as frame_support::traits::TryState<
|
||||
BlockNumberFor<System>,
|
||||
>>::try_state(
|
||||
frame_system::Pallet::<System>::block_number(),
|
||||
frame_try_runtime::TryStateSelect::All,
|
||||
)?;
|
||||
@@ -375,14 +385,17 @@ where
|
||||
|
||||
impl<
|
||||
System: frame_system::Config + EnsureInherentsAreFirst<Block>,
|
||||
Block: traits::Block<Header = System::Header, Hash = System::Hash>,
|
||||
Block: traits::Block<
|
||||
Header = frame_system::pallet_prelude::HeaderFor<System>,
|
||||
Hash = System::Hash,
|
||||
>,
|
||||
Context: Default,
|
||||
UnsignedValidator,
|
||||
AllPalletsWithSystem: OnRuntimeUpgrade
|
||||
+ OnInitialize<System::BlockNumber>
|
||||
+ OnIdle<System::BlockNumber>
|
||||
+ OnFinalize<System::BlockNumber>
|
||||
+ OffchainWorker<System::BlockNumber>,
|
||||
+ OnInitialize<BlockNumberFor<System>>
|
||||
+ OnIdle<BlockNumberFor<System>>
|
||||
+ OnFinalize<BlockNumberFor<System>>
|
||||
+ OffchainWorker<BlockNumberFor<System>>,
|
||||
COnRuntimeUpgrade: OnRuntimeUpgrade,
|
||||
> Executive<System, Block, Context, UnsignedValidator, AllPalletsWithSystem, COnRuntimeUpgrade>
|
||||
where
|
||||
@@ -399,14 +412,14 @@ where
|
||||
}
|
||||
|
||||
/// Start the execution of a particular block.
|
||||
pub fn initialize_block(header: &System::Header) {
|
||||
pub fn initialize_block(header: &frame_system::pallet_prelude::HeaderFor<System>) {
|
||||
sp_io::init_tracing();
|
||||
sp_tracing::enter_span!(sp_tracing::Level::TRACE, "init_block");
|
||||
let digests = Self::extract_pre_digest(header);
|
||||
Self::initialize_block_impl(header.number(), header.parent_hash(), &digests);
|
||||
}
|
||||
|
||||
fn extract_pre_digest(header: &System::Header) -> Digest {
|
||||
fn extract_pre_digest(header: &frame_system::pallet_prelude::HeaderFor<System>) -> Digest {
|
||||
let mut digest = <Digest>::default();
|
||||
header.digest().logs().iter().for_each(|d| {
|
||||
if d.as_pre_runtime().is_some() {
|
||||
@@ -417,7 +430,7 @@ where
|
||||
}
|
||||
|
||||
fn initialize_block_impl(
|
||||
block_number: &System::BlockNumber,
|
||||
block_number: &BlockNumberFor<System>,
|
||||
parent_hash: &System::Hash,
|
||||
digest: &Digest,
|
||||
) {
|
||||
@@ -432,7 +445,7 @@ where
|
||||
}
|
||||
<frame_system::Pallet<System>>::initialize(block_number, parent_hash, digest);
|
||||
weight = weight.saturating_add(<AllPalletsWithSystem as OnInitialize<
|
||||
System::BlockNumber,
|
||||
BlockNumberFor<System>,
|
||||
>>::on_initialize(*block_number));
|
||||
weight = weight.saturating_add(
|
||||
<System::BlockWeights as frame_support::traits::Get<_>>::get().base_block,
|
||||
@@ -467,8 +480,8 @@ where
|
||||
// Check that `parent_hash` is correct.
|
||||
let n = *header.number();
|
||||
assert!(
|
||||
n > System::BlockNumber::zero() &&
|
||||
<frame_system::Pallet<System>>::block_hash(n - System::BlockNumber::one()) ==
|
||||
n > BlockNumberFor::<System>::zero() &&
|
||||
<frame_system::Pallet<System>>::block_hash(n - BlockNumberFor::<System>::one()) ==
|
||||
*header.parent_hash(),
|
||||
"Parent hash should be valid.",
|
||||
);
|
||||
@@ -518,7 +531,7 @@ where
|
||||
|
||||
/// Finalize the block - it is up the caller to ensure that all header fields are valid
|
||||
/// except state-root.
|
||||
pub fn finalize_block() -> System::Header {
|
||||
pub fn finalize_block() -> frame_system::pallet_prelude::HeaderFor<System> {
|
||||
sp_io::init_tracing();
|
||||
sp_tracing::enter_span!(sp_tracing::Level::TRACE, "finalize_block");
|
||||
<frame_system::Pallet<System>>::note_finished_extrinsics();
|
||||
@@ -535,7 +548,7 @@ where
|
||||
let remaining_weight = max_weight.saturating_sub(weight.total());
|
||||
|
||||
if remaining_weight.all_gt(Weight::zero()) {
|
||||
let used_weight = <AllPalletsWithSystem as OnIdle<System::BlockNumber>>::on_idle(
|
||||
let used_weight = <AllPalletsWithSystem as OnIdle<BlockNumberFor<System>>>::on_idle(
|
||||
block_number,
|
||||
remaining_weight,
|
||||
);
|
||||
@@ -545,7 +558,7 @@ where
|
||||
);
|
||||
}
|
||||
|
||||
<AllPalletsWithSystem as OnFinalize<System::BlockNumber>>::on_finalize(block_number);
|
||||
<AllPalletsWithSystem as OnFinalize<BlockNumberFor<System>>>::on_finalize(block_number);
|
||||
}
|
||||
|
||||
/// Apply extrinsic outside of the block execution function.
|
||||
@@ -585,7 +598,7 @@ where
|
||||
Ok(r.map(|_| ()).map_err(|e| e.error))
|
||||
}
|
||||
|
||||
fn final_checks(header: &System::Header) {
|
||||
fn final_checks(header: &frame_system::pallet_prelude::HeaderFor<System>) {
|
||||
sp_tracing::enter_span!(sp_tracing::Level::TRACE, "final_checks");
|
||||
// remove temporaries
|
||||
let new_header = <frame_system::Pallet<System>>::finalize();
|
||||
@@ -657,7 +670,7 @@ where
|
||||
}
|
||||
|
||||
/// Start an offchain worker and generate extrinsics.
|
||||
pub fn offchain_worker(header: &System::Header) {
|
||||
pub fn offchain_worker(header: &frame_system::pallet_prelude::HeaderFor<System>) {
|
||||
sp_io::init_tracing();
|
||||
// We need to keep events available for offchain workers,
|
||||
// hence we initialize the block manually.
|
||||
@@ -671,7 +684,7 @@ where
|
||||
// as well.
|
||||
frame_system::BlockHash::<System>::insert(header.number(), header.hash());
|
||||
|
||||
<AllPalletsWithSystem as OffchainWorker<System::BlockNumber>>::offchain_worker(
|
||||
<AllPalletsWithSystem as OffchainWorker<BlockNumberFor<System>>>::offchain_worker(
|
||||
*header.number(),
|
||||
)
|
||||
}
|
||||
@@ -718,17 +731,17 @@ mod tests {
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
// module hooks.
|
||||
// one with block number arg and one without
|
||||
fn on_initialize(n: T::BlockNumber) -> Weight {
|
||||
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
|
||||
println!("on_initialize({})", n);
|
||||
Weight::from_parts(175, 0)
|
||||
}
|
||||
|
||||
fn on_idle(n: T::BlockNumber, remaining_weight: Weight) -> Weight {
|
||||
fn on_idle(n: BlockNumberFor<T>, remaining_weight: Weight) -> Weight {
|
||||
println!("on_idle{}, {})", n, remaining_weight);
|
||||
Weight::from_parts(175, 0)
|
||||
}
|
||||
|
||||
fn on_finalize(n: T::BlockNumber) {
|
||||
fn on_finalize(n: BlockNumberFor<T>) {
|
||||
println!("on_finalize({})", n);
|
||||
}
|
||||
|
||||
@@ -737,8 +750,8 @@ mod tests {
|
||||
Weight::from_parts(200, 0)
|
||||
}
|
||||
|
||||
fn offchain_worker(n: T::BlockNumber) {
|
||||
assert_eq!(T::BlockNumber::from(1u32), n);
|
||||
fn offchain_worker(n: BlockNumberFor<T>) {
|
||||
assert_eq!(BlockNumberFor::<T>::from(1u32), n);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -828,10 +841,7 @@ mod tests {
|
||||
}
|
||||
|
||||
frame_support::construct_runtime!(
|
||||
pub struct Runtime where
|
||||
Block = TestBlock,
|
||||
NodeBlock = TestBlock,
|
||||
UncheckedExtrinsic = TestUncheckedExtrinsic
|
||||
pub struct Runtime
|
||||
{
|
||||
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
@@ -860,12 +870,11 @@ mod tests {
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type Index = u64;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type BlockNumber = u64;
|
||||
type Hash = sp_core::H256;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
type Lookup = IdentityLookup<u64>;
|
||||
type Header = Header;
|
||||
type Block = TestBlock;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type BlockHashCount = ConstU64<250>;
|
||||
type Version = RuntimeVersion;
|
||||
@@ -929,7 +938,6 @@ mod tests {
|
||||
);
|
||||
type TestXt = sp_runtime::testing::TestXt<RuntimeCall, SignedExtra>;
|
||||
type TestBlock = Block<TestXt>;
|
||||
type TestUncheckedExtrinsic = TestXt;
|
||||
|
||||
// Will contain `true` when the custom runtime logic was called.
|
||||
const CUSTOM_ON_RUNTIME_KEY: &[u8] = b":custom:on_runtime";
|
||||
|
||||
Reference in New Issue
Block a user