mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 12:17:58 +00:00
Do not call initialize_block before any runtime api (#8953)
* Do not call `initialize_block` before any runtime api Before this change we always called `initialize_block` before calling into the runtime. There was already support with `skip_initialize` to skip the initialization. Almost no runtime_api requires that `initialize_block` is called before. Actually this only leads to higher execution times most of the time, because all runtime modules are initialized and this is especially expensive when the block contained a runtime upgrade. TLDR: Do not call `initialize_block` before calling a runtime api. * Change `validate_transaction` interface * Fix rpc test * Fixes and comments * Some docs
This commit is contained in:
@@ -474,10 +474,18 @@ where
|
||||
pub fn validate_transaction(
|
||||
source: TransactionSource,
|
||||
uxt: Block::Extrinsic,
|
||||
block_hash: Block::Hash,
|
||||
) -> TransactionValidity {
|
||||
sp_io::init_tracing();
|
||||
use sp_tracing::{enter_span, within_span};
|
||||
|
||||
<frame_system::Pallet<System>>::initialize(
|
||||
&(frame_system::Pallet::<System>::block_number() + One::one()),
|
||||
&block_hash,
|
||||
&Default::default(),
|
||||
frame_system::InitKind::Inspection,
|
||||
);
|
||||
|
||||
enter_span!{ sp_tracing::Level::TRACE, "validate_transaction" };
|
||||
|
||||
let encoded_len = within_span!{ sp_tracing::Level::TRACE, "using_encoded";
|
||||
@@ -1006,11 +1014,19 @@ mod tests {
|
||||
default_with_prio_3.priority = 3;
|
||||
t.execute_with(|| {
|
||||
assert_eq!(
|
||||
Executive::validate_transaction(TransactionSource::InBlock, valid.clone()),
|
||||
Executive::validate_transaction(
|
||||
TransactionSource::InBlock,
|
||||
valid.clone(),
|
||||
Default::default(),
|
||||
),
|
||||
Ok(default_with_prio_3),
|
||||
);
|
||||
assert_eq!(
|
||||
Executive::validate_transaction(TransactionSource::InBlock, invalid.clone()),
|
||||
Executive::validate_transaction(
|
||||
TransactionSource::InBlock,
|
||||
invalid.clone(),
|
||||
Default::default(),
|
||||
),
|
||||
Err(TransactionValidityError::Unknown(UnknownTransaction::NoUnsignedValidator)),
|
||||
);
|
||||
assert_eq!(Executive::apply_extrinsic(valid), Ok(Err(DispatchError::BadOrigin)));
|
||||
|
||||
Reference in New Issue
Block a user