Skip to content

Commit

Permalink
add rpc api pending_initialize_block
Browse files Browse the repository at this point in the history
  • Loading branch information
librelois committed Nov 27, 2023
1 parent 092da72 commit fcb06a0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
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)?;
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| {
Expand Down
2 changes: 2 additions & 0 deletions primitives/rpc/src/lib.rs
Original file line number Diff line number Diff line change
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 fcb06a0

Please sign in to comment.