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:
Bastian Köcher
2021-07-01 17:50:42 +02:00
committed by GitHub
parent 73a6e3effc
commit d489bd70b5
23 changed files with 192 additions and 301 deletions
@@ -22,22 +22,32 @@ use sp_runtime::traits::Block as BlockT;
sp_api::decl_runtime_apis! {
/// The `TaggedTransactionQueue` api trait for interfering with the transaction queue.
#[api_version(2)]
#[api_version(3)]
pub trait TaggedTransactionQueue {
/// Validate the transaction.
#[changed_in(2)]
fn validate_transaction(tx: <Block as BlockT>::Extrinsic) -> TransactionValidity;
/// Validate the transaction.
#[changed_in(3)]
fn validate_transaction(
source: TransactionSource,
tx: <Block as BlockT>::Extrinsic,
) -> TransactionValidity;
/// Validate the transaction.
///
/// This method is invoked by the transaction pool to learn details about given transaction.
/// The implementation should make sure to verify the correctness of the transaction
/// against current state.
/// against current state. The given `block_hash` corresponds to the hash of the block
/// that is used as current state.
///
/// Note that this call may be performed by the pool multiple times and transactions
/// might be verified in any possible order.
fn validate_transaction(
source: TransactionSource,
tx: <Block as BlockT>::Extrinsic,
block_hash: Block::Hash,
) -> TransactionValidity;
}
}