From c1a305ca5cad287d7312d3542939d558544b790b Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Thu, 6 Feb 2025 04:59:14 +0400 Subject: [PATCH] feat: relax `BasicPayloadJobGenerator` bounds (#14254) --- crates/payload/basic/src/lib.rs | 27 ++++++++++--------- crates/payload/basic/src/stack.rs | 6 ++--- .../custom-payload-builder/src/generator.rs | 6 +++-- examples/custom-payload-builder/src/job.rs | 4 +-- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/crates/payload/basic/src/lib.rs b/crates/payload/basic/src/lib.rs index 70f65e24f..84995d3e7 100644 --- a/crates/payload/basic/src/lib.rs +++ b/crates/payload/basic/src/lib.rs @@ -20,7 +20,7 @@ use reth_payload_builder::{KeepPayloadJobAlive, PayloadId, PayloadJob, PayloadJo use reth_payload_builder_primitives::PayloadBuilderError; use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes, PayloadKind}; use reth_primitives::{NodePrimitives, SealedHeader}; -use reth_primitives_traits::proofs; +use reth_primitives_traits::{proofs, HeaderTy}; use reth_provider::{BlockReaderIdExt, CanonStateNotification, StateProviderFactory}; use reth_revm::{cached::CachedReads, cancelled::CancelOnDrop}; use reth_tasks::TaskSpawner; @@ -45,6 +45,9 @@ mod stack; pub use stack::PayloadBuilderStack; +/// Helper to access [`NodePrimitives::BlockHeader`] from [`PayloadBuilder::BuiltPayload`]. +pub type HeaderForPayload

= <

::Primitives as NodePrimitives>::BlockHeader; + /// The [`PayloadJobGenerator`] that creates [`BasicPayloadJob`]s. #[derive(Debug)] pub struct BasicPayloadJobGenerator { @@ -128,7 +131,7 @@ impl PayloadJobGenerator for BasicPayloadJobGenerator where Client: StateProviderFactory - + BlockReaderIdExt

+ + BlockReaderIdExt
> + Clone + Unpin + 'static, @@ -303,7 +306,7 @@ where Builder: PayloadBuilder, { /// The configuration for how the payload will be created. - config: PayloadConfig, + config: PayloadConfig>, /// How to spawn building tasks executor: Tasks, /// The deadline when this job should resolve. @@ -654,19 +657,19 @@ impl

Future for PendingPayload

{ /// Static config for how to build a payload. #[derive(Clone, Debug)] -pub struct PayloadConfig { +pub struct PayloadConfig { /// The parent header. - pub parent_header: Arc, + pub parent_header: Arc>, /// Requested attributes for the payload. pub attributes: Attributes, } -impl PayloadConfig +impl PayloadConfig where Attributes: PayloadBuilderAttributes, { /// Create new payload config. - pub const fn new(parent_header: Arc, attributes: Attributes) -> Self { + pub const fn new(parent_header: Arc>, attributes: Attributes) -> Self { Self { parent_header, attributes } } @@ -777,22 +780,22 @@ impl BuildOutcomeKind { /// building process. It holds references to the Ethereum client, transaction pool, cached reads, /// payload configuration, cancellation status, and the best payload achieved so far. #[derive(Debug)] -pub struct BuildArguments { +pub struct BuildArguments { /// Previously cached disk reads pub cached_reads: CachedReads, /// How to configure the payload. - pub config: PayloadConfig, + pub config: PayloadConfig>, /// A marker that can be used to cancel the job. pub cancel: CancelOnDrop, /// The best payload achieved so far. pub best_payload: Option, } -impl BuildArguments { +impl BuildArguments { /// Create new build arguments. pub const fn new( cached_reads: CachedReads, - config: PayloadConfig, + config: PayloadConfig>, cancel: CancelOnDrop, best_payload: Option, ) -> Self { @@ -844,7 +847,7 @@ pub trait PayloadBuilder: Send + Sync + Clone { /// Builds an empty payload without any transaction. fn build_empty_payload( &self, - config: PayloadConfig, + config: PayloadConfig>, ) -> Result; } diff --git a/crates/payload/basic/src/stack.rs b/crates/payload/basic/src/stack.rs index 6616e7e09..d7a581752 100644 --- a/crates/payload/basic/src/stack.rs +++ b/crates/payload/basic/src/stack.rs @@ -1,6 +1,6 @@ use crate::{ - BuildArguments, BuildOutcome, PayloadBuilder, PayloadBuilderAttributes, PayloadBuilderError, - PayloadConfig, + BuildArguments, BuildOutcome, HeaderForPayload, PayloadBuilder, PayloadBuilderAttributes, + PayloadBuilderError, PayloadConfig, }; use alloy_eips::eip4895::Withdrawals; @@ -238,7 +238,7 @@ where fn build_empty_payload( &self, - config: PayloadConfig, + config: PayloadConfig>, ) -> Result { match config.attributes { Either::Left(left_attr) => { diff --git a/examples/custom-payload-builder/src/generator.rs b/examples/custom-payload-builder/src/generator.rs index 8de625040..f1a5deb48 100644 --- a/examples/custom-payload-builder/src/generator.rs +++ b/examples/custom-payload-builder/src/generator.rs @@ -5,7 +5,9 @@ use reth::{ providers::{BlockReaderIdExt, BlockSource, StateProviderFactory}, tasks::TaskSpawner, }; -use reth_basic_payload_builder::{BasicPayloadJobGeneratorConfig, PayloadBuilder, PayloadConfig}; +use reth_basic_payload_builder::{ + BasicPayloadJobGeneratorConfig, HeaderForPayload, PayloadBuilder, PayloadConfig, +}; use reth_node_api::PayloadBuilderAttributes; use reth_payload_builder::{PayloadBuilderError, PayloadJobGenerator}; use reth_primitives::SealedHeader; @@ -45,7 +47,7 @@ impl PayloadJobGenerator for EmptyBlockPayloadJobGenerator where Client: StateProviderFactory - + BlockReaderIdExt + + BlockReaderIdExt

> + Clone + Unpin + 'static, diff --git a/examples/custom-payload-builder/src/job.rs b/examples/custom-payload-builder/src/job.rs index 73bb21238..49eedc011 100644 --- a/examples/custom-payload-builder/src/job.rs +++ b/examples/custom-payload-builder/src/job.rs @@ -1,6 +1,6 @@ use futures_util::Future; use reth::tasks::TaskSpawner; -use reth_basic_payload_builder::{PayloadBuilder, PayloadConfig}; +use reth_basic_payload_builder::{HeaderForPayload, PayloadBuilder, PayloadConfig}; use reth_node_api::PayloadKind; use reth_payload_builder::{KeepPayloadJobAlive, PayloadBuilderError, PayloadJob}; @@ -15,7 +15,7 @@ where Builder: PayloadBuilder, { /// The configuration for how the payload will be created. - pub(crate) config: PayloadConfig, + pub(crate) config: PayloadConfig>, /// How to spawn building tasks pub(crate) _executor: Tasks, /// The type responsible for building payloads.