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
+1 -5
View File
@@ -30,7 +30,7 @@ use sc_executor::{RuntimeVersion, NativeVersion};
use sp_externalities::Extensions;
use sp_core::NativeOrEncoded;
use sp_api::{ProofRecorder, InitializeBlock, StorageTransactionCache};
use sp_api::{ProofRecorder, StorageTransactionCache};
use crate::execution_extensions::ExecutionExtensions;
/// Executor Provider
@@ -71,8 +71,6 @@ pub trait CallExecutor<B: BlockT> {
/// Before executing the method, passed header is installed as the current header
/// of the execution context.
fn contextual_call<
'a,
IB: Fn() -> sp_blockchain::Result<()>,
EM: Fn(
Result<NativeOrEncoded<R>, Self::Error>,
Result<NativeOrEncoded<R>, Self::Error>
@@ -81,7 +79,6 @@ pub trait CallExecutor<B: BlockT> {
NC: FnOnce() -> result::Result<R, sp_api::ApiError> + UnwindSafe,
>(
&self,
initialize_block_fn: IB,
at: &BlockId<B>,
method: &str,
call_data: &[u8],
@@ -89,7 +86,6 @@ pub trait CallExecutor<B: BlockT> {
storage_transaction_cache: Option<&RefCell<
StorageTransactionCache<B, <Self::Backend as crate::backend::Backend<B>>::State>,
>>,
initialize_block: InitializeBlock<'a, B>,
execution_manager: ExecutionManager<EM>,
native_call: Option<NC>,
proof_recorder: &Option<ProofRecorder<B>>,