diff --git a/client/rpc/src/eth/pending.rs b/client/rpc/src/eth/pending.rs index ea208ecf12..f03522c9a3 100644 --- a/client/rpc/src/eth/pending.rs +++ b/client/rpc/src/eth/pending.rs @@ -37,6 +37,7 @@ use sp_runtime::{ use sp_timestamp::TimestampInherentData; use crate::eth::Eth; +use fp_rpc::EthereumRuntimeRPCApi; const LOG_TARGET: &str = "eth-pending"; @@ -60,6 +61,7 @@ where B: BlockT, C: ProvideRuntimeApi, C::Api: BlockBuilderApi, + C::Api: EthereumRuntimeRPCApi, C: HeaderBackend + StorageProvider + 'static, BE: Backend, A: ChainApi, @@ -99,7 +101,12 @@ where ); // Initialize the pending block header - api.initialize_block(best_hash, &pending_header)?; + if api + .initialize_pending_block(best_hash, &pending_header) + .is_err() + { + api.initialize_block(best_hash, &pending_header)?; + } // Apply inherents to the pending block. let inherents = api.execute_in_transaction(move |api| { diff --git a/primitives/rpc/src/lib.rs b/primitives/rpc/src/lib.rs index 51c9c50a15..9c3d623c94 100644 --- a/primitives/rpc/src/lib.rs +++ b/primitives/rpc/src/lib.rs @@ -256,6 +256,12 @@ sp_api::decl_runtime_apis! { fn pending_block( xts: Vec<::Extrinsic>, ) -> (Option, Option>); + /// Initialize the pending block. + /// The behavior should be the same as the runtime api Core_initialize_block but + /// for a "pending" block. + /// If your project don't need to have a different behavior to initialize "pending" blocks, + /// you can copy your Core_initialize_block implementation. + fn initialize_pending_block(header: &::Header); } #[api_version(2)] diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index 4ed97e9c8f..4d81817b3a 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -994,6 +994,10 @@ impl_runtime_apis! { pallet_ethereum::CurrentTransactionStatuses::::get() ) } + + fn initialize_pending_block(header: &::Header) { + Executive::initialize_block(header); + } } impl fp_rpc::ConvertTransactionRuntimeApi for Runtime {