mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 11:41:04 +00:00
Make ExecuteBlock::execute_block return the final block header (#8244)
This pr changes the `ExecuteBlock` trait to return the final header that results from executing the given block.
This commit is contained in:
@@ -119,26 +119,20 @@
|
||||
use sp_std::{prelude::*, marker::PhantomData};
|
||||
use frame_support::{
|
||||
weights::{GetDispatchInfo, DispatchInfo, DispatchClass},
|
||||
traits::{OnInitialize, OnFinalize, OnRuntimeUpgrade, OffchainWorker},
|
||||
traits::{OnInitialize, OnFinalize, OnRuntimeUpgrade, OffchainWorker, ExecuteBlock},
|
||||
dispatch::PostDispatchInfo,
|
||||
};
|
||||
use sp_runtime::{
|
||||
generic::Digest, ApplyExtrinsicResult,
|
||||
traits::{
|
||||
self, Header, Zero, One, Checkable, Applyable, CheckEqual, ValidateUnsigned, NumberFor,
|
||||
Block as BlockT, Dispatchable, Saturating,
|
||||
Dispatchable, Saturating,
|
||||
},
|
||||
transaction_validity::{TransactionValidity, TransactionSource},
|
||||
};
|
||||
use codec::{Codec, Encode};
|
||||
use frame_system::DigestOf;
|
||||
|
||||
/// Trait that can be used to execute a block.
|
||||
pub trait ExecuteBlock<Block: BlockT> {
|
||||
/// Actually execute all transitions for `block`.
|
||||
fn execute_block(block: Block);
|
||||
}
|
||||
|
||||
pub type CheckedOf<E, C> = <E as Checkable<C>>::Checked;
|
||||
pub type CallOf<E, C> = <CheckedOf<E, C> as Applyable>::Call;
|
||||
pub type OriginOf<E, C> = <CallOf<E, C> as Dispatchable>::Origin;
|
||||
@@ -180,8 +174,8 @@ where
|
||||
OriginOf<Block::Extrinsic, Context>: From<Option<System::AccountId>>,
|
||||
UnsignedValidator: ValidateUnsigned<Call=CallOf<Block::Extrinsic, Context>>,
|
||||
{
|
||||
fn execute_block(block: Block) {
|
||||
Executive::<System, Block, Context, UnsignedValidator, AllModules>::execute_block(block);
|
||||
fn execute_block(block: Block) -> Block::Header {
|
||||
Executive::<System, Block, Context, UnsignedValidator, AllModules>::execute_block(block)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,11 +312,11 @@ where
|
||||
}
|
||||
|
||||
/// Actually execute all transitions for `block`.
|
||||
pub fn execute_block(block: Block) {
|
||||
pub fn execute_block(block: Block) -> Block::Header {
|
||||
sp_io::init_tracing();
|
||||
sp_tracing::within_span! {
|
||||
sp_tracing::info_span!( "execute_block", ?block);
|
||||
{
|
||||
sp_tracing::info_span!("execute_block", ?block);
|
||||
|
||||
Self::initialize_block(block.header());
|
||||
|
||||
// any initial checks
|
||||
@@ -339,8 +333,8 @@ where
|
||||
}
|
||||
|
||||
// any final checks
|
||||
Self::final_checks(&header);
|
||||
} };
|
||||
Self::final_checks(&header)
|
||||
}
|
||||
}
|
||||
|
||||
/// Execute given extrinsics and take care of post-extrinsics book-keeping.
|
||||
@@ -412,7 +406,7 @@ where
|
||||
Ok(r.map(|_| ()).map_err(|e| e.error))
|
||||
}
|
||||
|
||||
fn final_checks(header: &System::Header) {
|
||||
fn final_checks(header: &System::Header) -> System::Header {
|
||||
sp_tracing::enter_span!(sp_tracing::Level::TRACE, "final_checks");
|
||||
// remove temporaries
|
||||
let new_header = <frame_system::Module<System>>::finalize();
|
||||
@@ -438,6 +432,8 @@ where
|
||||
header.extrinsics_root() == new_header.extrinsics_root(),
|
||||
"Transaction trie root must be valid.",
|
||||
);
|
||||
|
||||
new_header
|
||||
}
|
||||
|
||||
/// Check a given signed transaction for validity. This doesn't execute any
|
||||
@@ -502,7 +498,7 @@ mod tests {
|
||||
use sp_core::H256;
|
||||
use sp_runtime::{
|
||||
generic::{Era, DigestItem}, DispatchError, testing::{Digest, Header, Block},
|
||||
traits::{Header as HeaderT, BlakeTwo256, IdentityLookup},
|
||||
traits::{Header as HeaderT, BlakeTwo256, IdentityLookup, Block as BlockT},
|
||||
transaction_validity::{
|
||||
InvalidTransaction, ValidTransaction, TransactionValidityError, UnknownTransaction
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user