Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to initialize "pending" blocks in a specific way (add runtime api pending_initialize_block) #1253

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading