Skip to content

Commit 844576f

Browse files
committed
refactor payload builder ctx so that sync process can create
1 parent 380a5c1 commit 844576f

File tree

4 files changed

+204
-89
lines changed

4 files changed

+204
-89
lines changed

crates/op-rbuilder/src/builders/context.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ pub struct OpPayloadBuilderCtx<ExtraCtx: Debug + Default = ()> {
7474
}
7575

7676
impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx> {
77+
pub(super) fn with_cancel(self, cancel: CancellationToken) -> Self {
78+
Self { cancel, ..self }
79+
}
80+
81+
pub(super) fn with_extra_ctx(self, extra_ctx: ExtraCtx) -> Self {
82+
Self { extra_ctx, ..self }
83+
}
84+
7785
/// Returns the parent block the payload will be build on.
7886
pub(super) fn parent(&self) -> &SealedHeader {
7987
&self.config.parent_header
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use crate::{
2+
builders::{
3+
BuilderConfig, OpPayloadBuilderCtx,
4+
flashblocks::{FlashblocksConfig, payload::FlashblocksExtraCtx},
5+
},
6+
gas_limiter::AddressGasLimiter,
7+
traits::ClientBounds,
8+
};
9+
use eyre::WrapErr as _;
10+
use reth_evm::ConfigureEvm as _;
11+
use reth_optimism_chainspec::OpHardforks as _;
12+
use reth_optimism_evm::{OpEvmConfig, OpNextBlockEnvAttributes};
13+
use reth_optimism_payload_builder::OpPayloadBuilderAttributes;
14+
use reth_payload_primitives::PayloadBuilderAttributes as _;
15+
use tokio_util::sync::CancellationToken;
16+
17+
fn get_op_payload_builder_ctx<Client>(
18+
client: Client,
19+
evm_config: OpEvmConfig,
20+
builder_config: BuilderConfig<FlashblocksConfig>,
21+
address_gas_limiter: AddressGasLimiter,
22+
config: reth_basic_payload_builder::PayloadConfig<
23+
OpPayloadBuilderAttributes<op_alloy_consensus::OpTxEnvelope>,
24+
>,
25+
cancel: CancellationToken,
26+
extra_ctx: FlashblocksExtraCtx,
27+
) -> eyre::Result<OpPayloadBuilderCtx<FlashblocksExtraCtx>>
28+
where
29+
Client: ClientBounds,
30+
{
31+
let chain_spec = client.chain_spec();
32+
let timestamp = config.attributes.timestamp();
33+
let block_env_attributes = OpNextBlockEnvAttributes {
34+
timestamp,
35+
suggested_fee_recipient: config.attributes.suggested_fee_recipient(),
36+
prev_randao: config.attributes.prev_randao(),
37+
gas_limit: config
38+
.attributes
39+
.gas_limit
40+
.unwrap_or(config.parent_header.gas_limit),
41+
parent_beacon_block_root: config
42+
.attributes
43+
.payload_attributes
44+
.parent_beacon_block_root,
45+
extra_data: if chain_spec.is_holocene_active_at_timestamp(timestamp) {
46+
config
47+
.attributes
48+
.get_holocene_extra_data(chain_spec.base_fee_params_at_timestamp(timestamp))
49+
.wrap_err("failed to get holocene extra data for flashblocks payload builder")?
50+
} else {
51+
Default::default()
52+
},
53+
};
54+
55+
let evm_env = evm_config
56+
.next_evm_env(&config.parent_header, &block_env_attributes)
57+
.wrap_err("failed to create next evm env")?;
58+
59+
Ok(OpPayloadBuilderCtx::<FlashblocksExtraCtx> {
60+
evm_config: evm_config.clone(),
61+
chain_spec,
62+
config,
63+
evm_env,
64+
block_env_attributes,
65+
cancel,
66+
da_config: builder_config.da_config.clone(),
67+
builder_signer: builder_config.builder_signer,
68+
metrics: Default::default(),
69+
extra_ctx,
70+
max_gas_per_txn: builder_config.max_gas_per_txn,
71+
address_gas_limiter,
72+
})
73+
}

crates/op-rbuilder/src/builders/flashblocks/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use service::FlashblocksServiceBuilder;
66
mod best_txs;
77
mod builder_tx;
88
mod config;
9+
mod ctx;
910
mod p2p;
1011
mod payload;
1112
mod payload_handler;

0 commit comments

Comments
 (0)