Skip to content

Commit 8b99690

Browse files
committed
Use custom payload builder in payload service builder
1 parent 262b4c1 commit 8b99690

File tree

1 file changed

+137
-8
lines changed

1 file changed

+137
-8
lines changed

crates/node/src/node.rs

Lines changed: 137 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
//! Optimism Node types config.
22
33
use fraxtal_evm::FraxtalEvmConfig;
4-
use reth_evm::execute::BasicBlockExecutorProvider;
5-
use reth_node_api::FullNodeComponents;
4+
use reth_evm::{execute::BasicBlockExecutorProvider, ConfigureEvm};
5+
use reth_node_api::{FullNodeComponents, PrimitivesTy, TxTy};
66
use reth_node_builder::{
7-
components::{BasicPayloadServiceBuilder, ComponentsBuilder, ExecutorBuilder},
7+
components::{
8+
BasicPayloadServiceBuilder, ComponentsBuilder, ExecutorBuilder, PayloadBuilderBuilder,
9+
},
810
node::{FullNodeTypes, NodeTypes, NodeTypesWithEngine},
911
BuilderContext, DebugNode, Node, NodeAdapter, NodeComponentsBuilder,
1012
};
1113
use reth_optimism_chainspec::OpChainSpec;
1214
use reth_optimism_node::{
1315
args::RollupArgs,
14-
node::{OpAddOns, OpConsensusBuilder, OpNetworkBuilder, OpPayloadBuilder, OpPoolBuilder},
16+
node::{OpAddOns, OpConsensusBuilder, OpNetworkBuilder, OpPoolBuilder},
17+
txpool::OpPooledTx,
1518
OpEngineTypes,
1619
};
17-
use reth_optimism_payload_builder::config::OpDAConfig;
20+
use reth_optimism_payload_builder::{
21+
builder::OpPayloadTransactions,
22+
config::{OpBuilderConfig, OpDAConfig},
23+
};
1824
use reth_optimism_primitives::{OpPrimitives, OpTransactionSigned};
1925
use reth_provider::{providers::ProviderFactoryBuilder, EthStorage};
26+
use reth_transaction_pool::{PoolTransaction, TransactionPool};
2027
use reth_trie_db::MerklePatriciaTrie;
2128

2229
/// Storage implementation for Optimism.
@@ -58,7 +65,7 @@ impl FraxtalNode {
5865
) -> ComponentsBuilder<
5966
Node,
6067
OpPoolBuilder,
61-
BasicPayloadServiceBuilder<OpPayloadBuilder>,
68+
BasicPayloadServiceBuilder<FraxtalPayloadBuilder>,
6269
OpNetworkBuilder,
6370
FraxtalExecutorBuilder,
6471
OpConsensusBuilder,
@@ -85,7 +92,8 @@ impl FraxtalNode {
8592
.with_enable_tx_conditional(self.args.enable_tx_conditional),
8693
)
8794
.payload(BasicPayloadServiceBuilder::new(
88-
OpPayloadBuilder::new(compute_pending_block).with_da_config(self.da_config.clone()),
95+
FraxtalPayloadBuilder::new(compute_pending_block)
96+
.with_da_config(self.da_config.clone()),
8997
))
9098
.network(OpNetworkBuilder {
9199
disable_txpool_gossip,
@@ -144,7 +152,7 @@ where
144152
type ComponentsBuilder = ComponentsBuilder<
145153
N,
146154
OpPoolBuilder,
147-
BasicPayloadServiceBuilder<OpPayloadBuilder>,
155+
BasicPayloadServiceBuilder<FraxtalPayloadBuilder>,
148156
OpNetworkBuilder,
149157
FraxtalExecutorBuilder,
150158
OpConsensusBuilder,
@@ -221,3 +229,124 @@ where
221229
Ok((evm_config, executor))
222230
}
223231
}
232+
233+
/// A basic optimism payload service builder
234+
#[derive(Debug, Default, Clone)]
235+
pub struct FraxtalPayloadBuilder<Txs = ()> {
236+
/// By default the pending block equals the latest block
237+
/// to save resources and not leak txs from the tx-pool,
238+
/// this flag enables computing of the pending block
239+
/// from the tx-pool instead.
240+
///
241+
/// If `compute_pending_block` is not enabled, the payload builder
242+
/// will use the payload attributes from the latest block. Note
243+
/// that this flag is not yet functional.
244+
pub compute_pending_block: bool,
245+
/// The type responsible for yielding the best transactions for the payload if mempool
246+
/// transactions are allowed.
247+
pub best_transactions: Txs,
248+
/// This data availability configuration specifies constraints for the payload builder
249+
/// when assembling payloads
250+
pub da_config: OpDAConfig,
251+
}
252+
253+
impl FraxtalPayloadBuilder {
254+
/// Create a new instance with the given `compute_pending_block` flag and data availability
255+
/// config.
256+
pub fn new(compute_pending_block: bool) -> Self {
257+
Self {
258+
compute_pending_block,
259+
best_transactions: (),
260+
da_config: OpDAConfig::default(),
261+
}
262+
}
263+
264+
/// Configure the data availability configuration for the OP payload builder.
265+
pub fn with_da_config(mut self, da_config: OpDAConfig) -> Self {
266+
self.da_config = da_config;
267+
self
268+
}
269+
}
270+
271+
impl<Txs> FraxtalPayloadBuilder<Txs> {
272+
/// Configures the type responsible for yielding the transactions that should be included in the
273+
/// payload.
274+
pub fn with_transactions<T>(self, best_transactions: T) -> FraxtalPayloadBuilder<T> {
275+
let Self {
276+
compute_pending_block,
277+
da_config,
278+
..
279+
} = self;
280+
FraxtalPayloadBuilder {
281+
compute_pending_block,
282+
best_transactions,
283+
da_config,
284+
}
285+
}
286+
287+
/// A helper method to initialize [`reth_optimism_payload_builder::OpPayloadBuilder`] with the
288+
/// given EVM config.
289+
pub fn build<Node, Evm, Pool>(
290+
self,
291+
evm_config: Evm,
292+
ctx: &BuilderContext<Node>,
293+
pool: Pool,
294+
) -> eyre::Result<reth_optimism_payload_builder::OpPayloadBuilder<Pool, Node::Provider, Evm, Txs>>
295+
where
296+
Node: FullNodeTypes<
297+
Types: NodeTypesWithEngine<
298+
Engine = OpEngineTypes,
299+
ChainSpec = OpChainSpec,
300+
Primitives = OpPrimitives,
301+
>,
302+
>,
303+
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
304+
+ Unpin
305+
+ 'static,
306+
Evm: ConfigureEvm<Primitives = PrimitivesTy<Node::Types>>,
307+
Txs: OpPayloadTransactions<Pool::Transaction>,
308+
{
309+
let payload_builder = reth_optimism_payload_builder::OpPayloadBuilder::with_builder_config(
310+
pool,
311+
ctx.provider().clone(),
312+
evm_config,
313+
OpBuilderConfig {
314+
da_config: self.da_config.clone(),
315+
},
316+
)
317+
.with_transactions(self.best_transactions.clone())
318+
.set_compute_pending_block(self.compute_pending_block);
319+
Ok(payload_builder)
320+
}
321+
}
322+
323+
impl<Node, Pool, Txs> PayloadBuilderBuilder<Node, Pool> for FraxtalPayloadBuilder<Txs>
324+
where
325+
Node: FullNodeTypes<
326+
Types: NodeTypesWithEngine<
327+
Engine = OpEngineTypes,
328+
ChainSpec = OpChainSpec,
329+
Primitives = OpPrimitives,
330+
>,
331+
>,
332+
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = TxTy<Node::Types>>>
333+
+ Unpin
334+
+ 'static,
335+
Txs: OpPayloadTransactions<Pool::Transaction>,
336+
<Pool as TransactionPool>::Transaction: OpPooledTx,
337+
{
338+
type PayloadBuilder = reth_optimism_payload_builder::OpPayloadBuilder<
339+
Pool,
340+
Node::Provider,
341+
FraxtalEvmConfig,
342+
Txs,
343+
>;
344+
345+
async fn build_payload_builder(
346+
self,
347+
ctx: &BuilderContext<Node>,
348+
pool: Pool,
349+
) -> eyre::Result<Self::PayloadBuilder> {
350+
self.build(FraxtalEvmConfig::optimism(ctx.chain_spec()), ctx, pool)
351+
}
352+
}

0 commit comments

Comments
 (0)