Skip to content
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
19 changes: 14 additions & 5 deletions crates/op-rbuilder/src/builders/flashblocks/payload_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use alloy_primitives::B64;
use eyre::{WrapErr as _, bail};
use op_alloy_rpc_types_engine::OpFlashblockPayload;
use op_revm::L1BlockInfo;
use reth::revm::{State, database::StateProviderDatabase};
use reth::{
revm::{State, database::StateProviderDatabase},
tasks::TaskSpawner,
};
use reth_basic_payload_builder::PayloadConfig;
use reth_node_builder::Events;
use reth_optimism_chainspec::OpChainSpec;
Expand All @@ -30,7 +33,7 @@ use tracing::warn;
///
/// In the case of a payload built by this node, it is broadcast to peers and an event is sent to the payload builder.
/// In the case of a payload received from a peer, it is executed and if successful, an event is sent to the payload builder.
pub(crate) struct PayloadHandler<Client> {
pub(crate) struct PayloadHandler<Client, Tasks> {
// receives new payloads built by this builder.
built_rx: mpsc::Receiver<OpBuiltPayload>,
// receives incoming p2p messages from peers.
Expand All @@ -43,12 +46,15 @@ pub(crate) struct PayloadHandler<Client> {
ctx: OpPayloadSyncerCtx,
// chain client
client: Client,
// task executor
task_executor: Tasks,
cancel: tokio_util::sync::CancellationToken,
}

impl<Client> PayloadHandler<Client>
impl<Client, Tasks> PayloadHandler<Client, Tasks>
where
Client: ClientBounds + 'static,
Tasks: TaskSpawner + Clone + Unpin + 'static,
{
#[allow(clippy::too_many_arguments)]
pub(crate) fn new(
Expand All @@ -58,6 +64,7 @@ where
payload_events_handle: tokio::sync::broadcast::Sender<Events<OpEngineTypes>>,
ctx: OpPayloadSyncerCtx,
client: Client,
task_executor: Tasks,
cancel: tokio_util::sync::CancellationToken,
) -> Self {
Self {
Expand All @@ -67,6 +74,7 @@ where
payload_events_handle,
ctx,
client,
task_executor,
cancel,
}
}
Expand All @@ -79,6 +87,7 @@ where
payload_events_handle,
ctx,
client,
task_executor,
cancel,
} = self;

Expand All @@ -104,7 +113,7 @@ where

// execute the flashblock on a thread where blocking is acceptable,
// as it's potentially a heavy operation
tokio::task::spawn_blocking(move || {
task_executor.spawn_blocking(Box::pin(async move {
let res = execute_flashblock(
payload,
ctx,
Expand All @@ -122,7 +131,7 @@ where
tracing::error!(target: "payload_builder", error = ?e, "failed to execute external received flashblock");
}
}
});
}));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/op-rbuilder/src/builders/flashblocks/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ impl FlashblocksServiceBuilder {
payload_service.payload_events_handle(),
syncer_ctx,
ctx.provider().clone(),
ctx.task_executor().clone(),
cancel,
);

Expand Down
Loading