Skip to content

Commit

Permalink
Add RPC api pending_initialize_block (#1253)
Browse files Browse the repository at this point in the history
  • Loading branch information
librelois authored Aug 1, 2024
1 parent 0488006 commit cacdfd7
Show file tree
Hide file tree
Showing 3 changed files with 18 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;
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 @@ -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| {
Expand Down
6 changes: 6 additions & 0 deletions primitives/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ sp_api::decl_runtime_apis! {
fn pending_block(
xts: Vec<<Block as BlockT>::Extrinsic>,
) -> (Option<ethereum::BlockV2>, Option<Vec<TransactionStatus>>);
/// 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: &<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 @@ -994,6 +994,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 cacdfd7

Please sign in to comment.