refactor: integrate BuiltPayload::Primitives (#13484)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Arsenii Kulikov
2024-12-24 03:06:47 +04:00
committed by GitHub
parent 4c1208e9d9
commit af1c9b7614
24 changed files with 136 additions and 78 deletions

View File

@ -7,7 +7,7 @@ use alloy_eips::eip4895::Withdrawals;
use alloy_primitives::{Address, B256, U256};
use reth_payload_builder::PayloadId;
use reth_payload_primitives::BuiltPayload;
use reth_primitives::SealedBlock;
use reth_primitives::{NodePrimitives, SealedBlockFor};
use alloy_eips::eip7685::Requests;
use std::{error::Error, fmt};
@ -151,9 +151,11 @@ where
impl<L, R> BuiltPayload for Either<L, R>
where
L: BuiltPayload,
R: BuiltPayload,
R: BuiltPayload<Primitives = L::Primitives>,
{
fn block(&self) -> &SealedBlock {
type Primitives = L::Primitives;
fn block(&self) -> &SealedBlockFor<<L::Primitives as NodePrimitives>::Block> {
match self {
Self::Left(l) => l.block(),
Self::Right(r) => r.block(),
@ -184,7 +186,8 @@ where
L::Attributes: Unpin + Clone,
R::Attributes: Unpin + Clone,
L::BuiltPayload: Unpin + Clone,
R::BuiltPayload: Unpin + Clone,
R::BuiltPayload:
BuiltPayload<Primitives = <L::BuiltPayload as BuiltPayload>::Primitives> + Unpin + Clone,
<<L as PayloadBuilder<Pool, Client>>::Attributes as PayloadBuilderAttributes>::Error: 'static,
<<R as PayloadBuilder<Pool, Client>>::Attributes as PayloadBuilderAttributes>::Error: 'static,
{

View File

@ -21,6 +21,7 @@ reth-payload-primitives.workspace = true
reth-ethereum-engine-primitives.workspace = true
# alloy
alloy-consensus.workspace = true
alloy-primitives = { workspace = true, optional = true }
alloy-rpc-types = { workspace = true, features = ["engine"] }

View File

@ -7,6 +7,7 @@ use crate::{
metrics::PayloadBuilderServiceMetrics, traits::PayloadJobGenerator, KeepPayloadJobAlive,
PayloadJob,
};
use alloy_consensus::BlockHeader;
use alloy_rpc_types::engine::PayloadId;
use futures_util::{future::FutureExt, Stream, StreamExt};
use reth_chain_state::CanonStateNotification;
@ -284,7 +285,7 @@ where
.find(|(_, job_id)| *job_id == id)
.map(|(j, _)| j.best_payload().map(|p| p.into()));
if let Some(Ok(ref best)) = res {
self.metrics.set_best_revenue(best.block().number, f64::from(best.fees()));
self.metrics.set_best_revenue(best.block().number(), f64::from(best.fees()));
}
res
@ -318,7 +319,7 @@ where
payload_events.send(Events::BuiltPayload(payload.clone().into())).ok();
resolved_metrics
.set_resolved_revenue(payload.block().number, f64::from(payload.fees()));
.set_resolved_revenue(payload.block().number(), f64::from(payload.fees()));
}
res.map(|p| p.into())
};

View File

@ -5,19 +5,22 @@ use alloy_eips::{
use alloy_primitives::{Address, B256, U256};
use alloy_rpc_types_engine::{PayloadAttributes as EthPayloadAttributes, PayloadId};
use reth_chain_state::ExecutedBlock;
use reth_primitives::{EthPrimitives, NodePrimitives, SealedBlock};
use reth_primitives::{NodePrimitives, SealedBlockFor};
/// Represents a built payload type that contains a built [`SealedBlock`] and can be converted into
/// Represents a built payload type that contains a built `SealedBlock` and can be converted into
/// engine API execution payloads.
pub trait BuiltPayload<N: NodePrimitives = EthPrimitives>: Send + Sync + std::fmt::Debug {
pub trait BuiltPayload: Send + Sync + std::fmt::Debug {
/// The node's primitive types
type Primitives: NodePrimitives;
/// Returns the built block (sealed)
fn block(&self) -> &SealedBlock<N::BlockHeader, N::BlockBody>;
fn block(&self) -> &SealedBlockFor<<Self::Primitives as NodePrimitives>::Block>;
/// Returns the fees collected for the built block
fn fees(&self) -> U256;
/// Returns the entire execution data for the built block, if available.
fn executed_block(&self) -> Option<ExecutedBlock<N>> {
fn executed_block(&self) -> Option<ExecutedBlock<Self::Primitives>> {
None
}