diff --git a/crates/op-rbuilder/src/generator.rs b/crates/op-rbuilder/src/generator.rs index 7f3e19ff..36b4b310 100644 --- a/crates/op-rbuilder/src/generator.rs +++ b/crates/op-rbuilder/src/generator.rs @@ -1,13 +1,13 @@ use futures_util::Future; use futures_util::FutureExt; use reth::providers::BlockReaderIdExt; +use reth::providers::StateProviderFactory; use reth::{ builder::{components::PayloadServiceBuilder, node::FullNodeTypes, BuilderContext}, payload::PayloadBuilderHandle, providers::CanonStateSubscriptions, transaction_pool::TransactionPool, }; -use reth::{providers::StateProviderFactory, tasks::TaskSpawner}; use reth_basic_payload_builder::{BasicPayloadJobGeneratorConfig, PayloadConfig}; use reth_node_api::NodeTypesWithEngine; use reth_node_api::PayloadBuilderAttributes; @@ -78,7 +78,6 @@ where let payload_generator = BlockPayloadJobGenerator::with_builder( ctx.provider().clone(), pool, - ctx.task_executor().clone(), payload_job_config, self.builder, false, @@ -131,13 +130,11 @@ pub trait PayloadBuilder: Send + Sync + Clone { /// The generator type that creates new jobs that builds empty blocks. #[derive(Debug)] -pub struct BlockPayloadJobGenerator { +pub struct BlockPayloadJobGenerator { /// The client that can interact with the chain. client: Client, /// txpool pool: Pool, - /// How to spawn building tasks - executor: Tasks, /// The configuration for the job generator. _config: BasicPayloadJobGeneratorConfig, /// The type responsible for building payloads. @@ -152,13 +149,12 @@ pub struct BlockPayloadJobGenerator { // === impl EmptyBlockPayloadJobGenerator === -impl BlockPayloadJobGenerator { +impl BlockPayloadJobGenerator { /// Creates a new [EmptyBlockPayloadJobGenerator] with the given config and custom /// [PayloadBuilder] pub fn with_builder( client: Client, pool: Pool, - executor: Tasks, config: BasicPayloadJobGeneratorConfig, builder: Builder, ensure_only_one_payload: bool, @@ -166,7 +162,6 @@ impl BlockPayloadJobGenerator BlockPayloadJobGenerator PayloadJobGenerator - for BlockPayloadJobGenerator +impl PayloadJobGenerator for BlockPayloadJobGenerator where Client: StateProviderFactory + BlockReaderIdExt
@@ -184,12 +178,11 @@ where + Unpin + 'static, Pool: TransactionPool + Unpin + 'static, - Tasks: TaskSpawner + Clone + Unpin + 'static, Builder: PayloadBuilder + Unpin + 'static, >::Attributes: Unpin + Clone, >::BuiltPayload: Unpin + Clone, { - type Job = BlockPayloadJob; + type Job = BlockPayloadJob; /// This is invoked when the node receives payload attributes from the beacon node via /// `engine_forkchoiceUpdatedV1` @@ -243,7 +236,6 @@ where let mut job = BlockPayloadJob { client: self.client.clone(), pool: self.pool.clone(), - executor: self.executor.clone(), builder: self.builder.clone(), config, cell: BlockCell::new(), @@ -264,7 +256,7 @@ use std::{ }; /// A [PayloadJob] that builds empty blocks. -pub struct BlockPayloadJob +pub struct BlockPayloadJob where Builder: PayloadBuilder, { @@ -274,8 +266,6 @@ where pub(crate) client: Client, /// The transaction pool. pub(crate) pool: Pool, - /// How to spawn building tasks - pub(crate) executor: Tasks, /// The type responsible for building payloads. /// /// See [PayloadBuilder] @@ -288,11 +278,10 @@ where pub(crate) build_complete: Option>>, } -impl PayloadJob for BlockPayloadJob +impl PayloadJob for BlockPayloadJob where Client: StateProviderFactory + Clone + Unpin + 'static, Pool: TransactionPool + Unpin + 'static, - Tasks: TaskSpawner + Clone + 'static, Builder: PayloadBuilder + Unpin + 'static, >::Attributes: Unpin + Clone, >::BuiltPayload: Unpin + Clone, @@ -339,11 +328,10 @@ pub struct BuildArguments { } /// A [PayloadJob] is a future that's being polled by the `PayloadBuilderService` -impl BlockPayloadJob +impl BlockPayloadJob where Client: StateProviderFactory + Clone + Unpin + 'static, Pool: TransactionPool + Unpin + 'static, - Tasks: TaskSpawner + Clone + 'static, Builder: PayloadBuilder + Unpin + 'static, >::Attributes: Unpin + Clone, >::BuiltPayload: Unpin + Clone, @@ -359,27 +347,28 @@ where let (tx, rx) = oneshot::channel(); self.build_complete = Some(rx); - self.executor.spawn_blocking(Box::pin(async move { - let args = BuildArguments { - client, - pool, - cached_reads: Default::default(), - config: payload_config, - cancel, - }; - - let result = builder.try_build(args, cell); - let _ = tx.send(result); - })); + tokio::task::spawn_blocking(move || { + tokio::runtime::Handle::current().block_on(async move { + let args = BuildArguments { + client, + pool, + cached_reads: Default::default(), + config: payload_config, + cancel, + }; + + let result = builder.try_build(args, cell); + let _ = tx.send(result); + }) + }); } } /// A [PayloadJob] is a a future that's being polled by the `PayloadBuilderService` -impl Future for BlockPayloadJob +impl Future for BlockPayloadJob where Client: StateProviderFactory + Clone + Unpin + 'static, Pool: TransactionPool + Unpin + 'static, - Tasks: TaskSpawner + Clone + 'static, Builder: PayloadBuilder + Unpin + 'static, >::Attributes: Unpin + Clone, >::BuiltPayload: Unpin + Clone, @@ -718,7 +707,6 @@ mod tests { let generator = BlockPayloadJobGenerator::with_builder( client.clone(), pool, - executor, config, builder.clone(), false,