mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: simplify PayloadBuilder trait (#14246)
This commit is contained in:
@ -4,7 +4,6 @@ use reth::{
|
||||
api::Block,
|
||||
providers::{BlockReaderIdExt, BlockSource, StateProviderFactory},
|
||||
tasks::TaskSpawner,
|
||||
transaction_pool::TransactionPool,
|
||||
};
|
||||
use reth_basic_payload_builder::{BasicPayloadJobGeneratorConfig, PayloadBuilder, PayloadConfig};
|
||||
use reth_node_api::PayloadBuilderAttributes;
|
||||
@ -14,11 +13,9 @@ use std::sync::Arc;
|
||||
|
||||
/// The generator type that creates new jobs that builds empty blocks.
|
||||
#[derive(Debug)]
|
||||
pub struct EmptyBlockPayloadJobGenerator<Client, Pool, Tasks, Builder> {
|
||||
pub struct EmptyBlockPayloadJobGenerator<Client, Tasks, Builder> {
|
||||
/// 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.
|
||||
@ -31,41 +28,39 @@ pub struct EmptyBlockPayloadJobGenerator<Client, Pool, Tasks, Builder> {
|
||||
|
||||
// === impl EmptyBlockPayloadJobGenerator ===
|
||||
|
||||
impl<Client, Pool, Tasks, Builder> EmptyBlockPayloadJobGenerator<Client, Pool, Tasks, Builder> {
|
||||
impl<Client, Tasks, Builder> EmptyBlockPayloadJobGenerator<Client, Tasks, Builder> {
|
||||
/// 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,
|
||||
) -> Self {
|
||||
Self { client, pool, executor, _config: config, builder }
|
||||
Self { client, executor, _config: config, builder }
|
||||
}
|
||||
}
|
||||
|
||||
impl<Client, Pool, Tasks, Builder> PayloadJobGenerator
|
||||
for EmptyBlockPayloadJobGenerator<Client, Pool, Tasks, Builder>
|
||||
impl<Client, Tasks, Builder> PayloadJobGenerator
|
||||
for EmptyBlockPayloadJobGenerator<Client, Tasks, Builder>
|
||||
where
|
||||
Client: StateProviderFactory
|
||||
+ BlockReaderIdExt<Block = reth_primitives::Block>
|
||||
+ Clone
|
||||
+ Unpin
|
||||
+ 'static,
|
||||
Pool: TransactionPool + Unpin + 'static,
|
||||
Tasks: TaskSpawner + Clone + Unpin + 'static,
|
||||
Builder: PayloadBuilder<Pool, Client> + Unpin + 'static,
|
||||
<Builder as PayloadBuilder<Pool, Client>>::Attributes: Unpin + Clone,
|
||||
<Builder as PayloadBuilder<Pool, Client>>::BuiltPayload: Unpin + Clone,
|
||||
Builder: PayloadBuilder + Unpin + 'static,
|
||||
Builder::Attributes: Unpin + Clone,
|
||||
Builder::BuiltPayload: Unpin + Clone,
|
||||
{
|
||||
type Job = EmptyBlockPayloadJob<Client, Pool, Tasks, Builder>;
|
||||
type Job = EmptyBlockPayloadJob<Tasks, Builder>;
|
||||
|
||||
/// This is invoked when the node receives payload attributes from the beacon node via
|
||||
/// `engine_forkchoiceUpdatedV1`
|
||||
fn new_payload_job(
|
||||
&self,
|
||||
attributes: <Builder as PayloadBuilder<Pool, Client>>::Attributes,
|
||||
attributes: Builder::Attributes,
|
||||
) -> Result<Self::Job, PayloadBuilderError> {
|
||||
let parent_block = if attributes.parent().is_zero() {
|
||||
// use latest block if parent is zero: genesis block
|
||||
@ -87,8 +82,6 @@ where
|
||||
|
||||
let config = PayloadConfig::new(Arc::new(header), attributes);
|
||||
Ok(EmptyBlockPayloadJob {
|
||||
client: self.client.clone(),
|
||||
_pool: self.pool.clone(),
|
||||
_executor: self.executor.clone(),
|
||||
builder: self.builder.clone(),
|
||||
config,
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
use futures_util::Future;
|
||||
use reth::{
|
||||
providers::StateProviderFactory, tasks::TaskSpawner, transaction_pool::TransactionPool,
|
||||
};
|
||||
use reth::tasks::TaskSpawner;
|
||||
use reth_basic_payload_builder::{PayloadBuilder, PayloadConfig};
|
||||
use reth_node_api::PayloadKind;
|
||||
use reth_payload_builder::{KeepPayloadJobAlive, PayloadBuilderError, PayloadJob};
|
||||
@ -12,16 +10,12 @@ use std::{
|
||||
};
|
||||
|
||||
/// A [PayloadJob] that builds empty blocks.
|
||||
pub struct EmptyBlockPayloadJob<Client, Pool, Tasks, Builder>
|
||||
pub struct EmptyBlockPayloadJob<Tasks, Builder>
|
||||
where
|
||||
Builder: PayloadBuilder<Pool, Client>,
|
||||
Builder: PayloadBuilder,
|
||||
{
|
||||
/// The configuration for how the payload will be created.
|
||||
pub(crate) config: PayloadConfig<Builder::Attributes>,
|
||||
/// The client that can interact with the chain.
|
||||
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.
|
||||
@ -30,14 +24,12 @@ where
|
||||
pub(crate) builder: Builder,
|
||||
}
|
||||
|
||||
impl<Client, Pool, Tasks, Builder> PayloadJob for EmptyBlockPayloadJob<Client, Pool, Tasks, Builder>
|
||||
impl<Tasks, Builder> PayloadJob for EmptyBlockPayloadJob<Tasks, Builder>
|
||||
where
|
||||
Client: StateProviderFactory + Clone + Unpin + 'static,
|
||||
Pool: TransactionPool + Unpin + 'static,
|
||||
Tasks: TaskSpawner + Clone + 'static,
|
||||
Builder: PayloadBuilder<Pool, Client> + Unpin + 'static,
|
||||
<Builder as PayloadBuilder<Pool, Client>>::Attributes: Unpin + Clone,
|
||||
<Builder as PayloadBuilder<Pool, Client>>::BuiltPayload: Unpin + Clone,
|
||||
Builder: PayloadBuilder + Unpin + 'static,
|
||||
Builder::Attributes: Unpin + Clone,
|
||||
Builder::BuiltPayload: Unpin + Clone,
|
||||
{
|
||||
type PayloadAttributes = Builder::Attributes;
|
||||
type ResolvePayloadFuture =
|
||||
@ -45,7 +37,7 @@ where
|
||||
type BuiltPayload = Builder::BuiltPayload;
|
||||
|
||||
fn best_payload(&self) -> Result<Self::BuiltPayload, PayloadBuilderError> {
|
||||
let payload = self.builder.build_empty_payload(&self.client, self.config.clone())?;
|
||||
let payload = self.builder.build_empty_payload(self.config.clone())?;
|
||||
Ok(payload)
|
||||
}
|
||||
|
||||
@ -63,14 +55,12 @@ where
|
||||
}
|
||||
|
||||
/// A [PayloadJob] is a a future that's being polled by the `PayloadBuilderService`
|
||||
impl<Client, Pool, Tasks, Builder> Future for EmptyBlockPayloadJob<Client, Pool, Tasks, Builder>
|
||||
impl<Tasks, Builder> Future for EmptyBlockPayloadJob<Tasks, Builder>
|
||||
where
|
||||
Client: StateProviderFactory + Clone + Unpin + 'static,
|
||||
Pool: TransactionPool + Unpin + 'static,
|
||||
Tasks: TaskSpawner + Clone + 'static,
|
||||
Builder: PayloadBuilder<Pool, Client> + Unpin + 'static,
|
||||
<Builder as PayloadBuilder<Pool, Client>>::Attributes: Unpin + Clone,
|
||||
<Builder as PayloadBuilder<Pool, Client>>::BuiltPayload: Unpin + Clone,
|
||||
Builder: PayloadBuilder + Unpin + 'static,
|
||||
Builder::Attributes: Unpin + Clone,
|
||||
Builder::BuiltPayload: Unpin + Clone,
|
||||
{
|
||||
type Output = Result<(), PayloadBuilderError>;
|
||||
|
||||
|
||||
@ -62,10 +62,11 @@ where
|
||||
|
||||
let payload_generator = EmptyBlockPayloadJobGenerator::with_builder(
|
||||
ctx.provider().clone(),
|
||||
pool,
|
||||
ctx.task_executor().clone(),
|
||||
payload_job_config,
|
||||
reth_ethereum_payload_builder::EthereumPayloadBuilder::new(
|
||||
ctx.provider().clone(),
|
||||
pool,
|
||||
EthEvmConfig::new(ctx.chain_spec()),
|
||||
EthereumBuilderConfig::new(conf.extra_data_bytes()),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user