From 05ed9d9bc20587ca5a6e7ff1e397932208e481d9 Mon Sep 17 00:00:00 2001 From: librelois Date: Mon, 27 Nov 2023 16:27:20 +0100 Subject: [PATCH] add rpc api pending_initialize_block --- client/rpc/src/eth/pending.rs | 9 ++++++++- primitives/rpc/src/lib.rs | 6 ++++++ template/runtime/src/lib.rs | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/client/rpc/src/eth/pending.rs b/client/rpc/src/eth/pending.rs index 822562ded0..24a7886e5e 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, EthConfig}; +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, @@ -100,7 +102,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 5512a5c379..851aa4dece 100644 --- a/primitives/rpc/src/lib.rs +++ b/primitives/rpc/src/lib.rs @@ -239,6 +239,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 5995ec780a..54339e2764 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -823,6 +823,10 @@ impl_runtime_apis! { pallet_ethereum::CurrentTransactionStatuses::::get() ) } + + fn initialize_pending_block(header: &::Header) { + Executive::initialize_block(header) + } } impl fp_rpc::ConvertTransactionRuntimeApi for Runtime {