Skip to content

Commit

Permalink
add rpc api initialize_pending_block
Browse files Browse the repository at this point in the history
  • Loading branch information
librelois committed Nov 24, 2023
1 parent 6ba7e7c commit 3388642
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
9 changes: 8 additions & 1 deletion client/rpc/src/eth/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -60,6 +61,7 @@ where
B: BlockT,
C: ProvideRuntimeApi<B>,
C::Api: BlockBuilderApi<B>,
C::Api: EthereumRuntimeRPCApi<B>,
C: HeaderBackend<B> + StorageProvider<B, BE> + 'static,
BE: Backend<B>,
A: ChainApi<Block = B>,
Expand Down Expand Up @@ -100,7 +102,12 @@ where
);

// Initialize the pending block header
api.initialize_block(best_hash, &pending_header)?;
match api.api_version::<dyn EthereumRuntimeRPCApi<B>>(best_hash)? {
Some(version) if version >= 6 => {
api.initialize_pending_block(best_hash, &pending_header)?
}
_ => api.initialize_block(best_hash, &pending_header)?,
}

// Apply inherents to the pending block.
let inherents = api.execute_in_transaction(move |api| {
Expand Down
4 changes: 3 additions & 1 deletion primitives/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<B: BlockT, C> RuntimeStorageOverride<B, C> for () {

sp_api::decl_runtime_apis! {
/// API necessary for Ethereum-compatibility layer.
#[api_version(5)]
#[api_version(6)]
pub trait EthereumRuntimeRPCApi {
/// Returns runtime defined pallet_evm::ChainId.
fn chain_id() -> u64;
Expand Down Expand Up @@ -245,6 +245,8 @@ sp_api::decl_runtime_apis! {
fn pending_block(
xts: Vec<<Block as BlockT>::Extrinsic>,
) -> (Option<ethereum::BlockV2>, Option<Vec<TransactionStatus>>);
/// initialize the pending block
fn initialize_pending_block(header: &<Block as BlockT>::Header);
}

#[api_version(2)]
Expand Down
4 changes: 4 additions & 0 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,10 @@ impl_runtime_apis! {
pallet_ethereum::CurrentTransactionStatuses::<Runtime>::get()
)
}

fn initialize_pending_block(header: &<Block as BlockT>::Header) {
Executive::initialize_block(header)
}
}

impl fp_rpc::ConvertTransactionRuntimeApi<Block> for Runtime {
Expand Down

0 comments on commit 3388642

Please sign in to comment.