Skip to content

Commit 87f4632

Browse files
committed
wip: syncing and execution pipeline
1 parent 844576f commit 87f4632

File tree

4 files changed

+357
-53
lines changed

4 files changed

+357
-53
lines changed

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

Lines changed: 96 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,70 +4,121 @@ use crate::{
44
flashblocks::{FlashblocksConfig, payload::FlashblocksExtraCtx},
55
},
66
gas_limiter::AddressGasLimiter,
7+
metrics::OpRBuilderMetrics,
78
traits::ClientBounds,
89
};
910
use eyre::WrapErr as _;
10-
use reth_evm::ConfigureEvm as _;
11-
use reth_optimism_chainspec::OpHardforks as _;
11+
use op_revm::OpSpecId;
12+
use reth_basic_payload_builder::PayloadConfig;
13+
use reth_evm::{ConfigureEvm as _, EvmEnv};
14+
use reth_optimism_chainspec::{OpChainSpec, OpHardforks as _};
1215
use reth_optimism_evm::{OpEvmConfig, OpNextBlockEnvAttributes};
13-
use reth_optimism_payload_builder::OpPayloadBuilderAttributes;
16+
use reth_optimism_payload_builder::{OpPayloadBuilderAttributes, config::OpDAConfig};
17+
use reth_optimism_primitives::OpTransactionSigned;
1418
use reth_payload_primitives::PayloadBuilderAttributes as _;
19+
use std::sync::Arc;
1520
use tokio_util::sync::CancellationToken;
1621

17-
fn get_op_payload_builder_ctx<Client>(
22+
#[derive(Debug)]
23+
pub(super) struct OpPayloadSyncerCtx {
24+
/// The type that knows how to perform system calls and configure the evm.
25+
pub evm_config: OpEvmConfig,
26+
/// The DA config for the payload builder
27+
pub da_config: OpDAConfig,
28+
/// The chainspec
29+
pub chain_spec: Arc<OpChainSpec>,
30+
// /// How to build the payload.
31+
// pub config: PayloadConfig<OpPayloadBuilderAttributes<OpTransactionSigned>>,
32+
/// Block env attributes for the current block.
33+
//pub block_env_attributes: OpNextBlockEnvAttributes,
34+
/// Marker to check whether the job has been cancelled.
35+
//pub cancel: CancellationToken,
36+
/// Extra context for the payload builder
37+
pub extra_ctx: FlashblocksExtraCtx,
38+
/// Max gas that can be used by a transaction.
39+
pub max_gas_per_txn: Option<u64>,
40+
}
41+
42+
impl OpPayloadSyncerCtx {
43+
pub(super) fn into_op_payload_builder_ctx(
44+
self,
45+
payload_config: PayloadConfig<OpPayloadBuilderAttributes<OpTransactionSigned>>,
46+
evm_env: EvmEnv<OpSpecId>,
47+
block_env_attributes: OpNextBlockEnvAttributes,
48+
cancel: CancellationToken,
49+
metrics: Arc<OpRBuilderMetrics>,
50+
address_gas_limiter: AddressGasLimiter,
51+
) -> OpPayloadBuilderCtx {
52+
OpPayloadBuilderCtx {
53+
evm_config: self.evm_config,
54+
da_config: self.da_config,
55+
chain_spec: self.chain_spec,
56+
config: payload_config,
57+
evm_env,
58+
block_env_attributes,
59+
cancel,
60+
builder_signer: None,
61+
metrics,
62+
extra_ctx: (),
63+
max_gas_per_txn: self.max_gas_per_txn,
64+
address_gas_limiter,
65+
}
66+
}
67+
}
68+
69+
pub(super) fn get_op_payload_syncer_ctx<Client>(
1870
client: Client,
1971
evm_config: OpEvmConfig,
2072
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,
73+
// address_gas_limiter: AddressGasLimiter,
74+
// config: reth_basic_payload_builder::PayloadConfig<
75+
// OpPayloadBuilderAttributes<op_alloy_consensus::OpTxEnvelope>,
76+
// >,
2677
extra_ctx: FlashblocksExtraCtx,
27-
) -> eyre::Result<OpPayloadBuilderCtx<FlashblocksExtraCtx>>
78+
) -> OpPayloadSyncerCtx
2879
where
2980
Client: ClientBounds,
3081
{
3182
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-
};
83+
// let timestamp = config.attributes.timestamp();
84+
// let block_env_attributes = OpNextBlockEnvAttributes {
85+
// timestamp,
86+
// suggested_fee_recipient: config.attributes.suggested_fee_recipient(),
87+
// prev_randao: config.attributes.prev_randao(),
88+
// gas_limit: config
89+
// .attributes
90+
// .gas_limit
91+
// .unwrap_or(config.parent_header.gas_limit),
92+
// parent_beacon_block_root: config
93+
// .attributes
94+
// .payload_attributes
95+
// .parent_beacon_block_root,
96+
// extra_data: if chain_spec.is_holocene_active_at_timestamp(timestamp) {
97+
// config
98+
// .attributes
99+
// .get_holocene_extra_data(chain_spec.base_fee_params_at_timestamp(timestamp))
100+
// .wrap_err("failed to get holocene extra data for flashblocks payload builder")?
101+
// } else {
102+
// Default::default()
103+
// },
104+
// };
54105

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")?;
106+
// let evm_env = evm_config
107+
// .next_evm_env(&config.parent_header, &block_env_attributes)
108+
// .wrap_err("failed to create next evm env")?;
58109

59-
Ok(OpPayloadBuilderCtx::<FlashblocksExtraCtx> {
110+
OpPayloadSyncerCtx {
60111
evm_config: evm_config.clone(),
61-
chain_spec,
62-
config,
63-
evm_env,
64-
block_env_attributes,
65-
cancel,
66112
da_config: builder_config.da_config.clone(),
67-
builder_signer: builder_config.builder_signer,
68-
metrics: Default::default(),
113+
chain_spec,
114+
//config,
115+
// evm_env,
116+
// block_env_attributes,
117+
// cancel,
118+
// builder_signer: builder_config.builder_signer,
119+
// metrics: Default::default(),
69120
extra_ctx,
70121
max_gas_per_txn: builder_config.max_gas_per_txn,
71-
address_gas_limiter,
72-
})
122+
//address_gas_limiter,
123+
}
73124
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type NextBestFlashblocksTxs<Pool> = BestFlashblocksTxs<
6868
>;
6969

7070
#[derive(Debug, Default)]
71-
struct ExtraExecutionInfo {
71+
pub(super) struct ExtraExecutionInfo {
7272
/// Index of the last consumed flashblock
7373
last_flashblock_index: usize,
7474
}
@@ -152,8 +152,8 @@ impl<Pool, Client, BuilderTx> OpPayloadBuilder<Pool, Client, BuilderTx> {
152152
config: BuilderConfig<FlashblocksConfig>,
153153
builder_tx: BuilderTx,
154154
payload_tx: mpsc::Sender<OpBuiltPayload>,
155+
metrics: Arc<OpRBuilderMetrics>,
155156
) -> eyre::Result<Self> {
156-
let metrics = Arc::new(OpRBuilderMetrics::default());
157157
let ws_pub = WebSocketPublisher::new(config.specific.ws_addr, Arc::clone(&metrics))?.into();
158158
let address_gas_limiter = AddressGasLimiter::new(config.gas_limiter_config.clone());
159159
Ok(Self {
@@ -404,7 +404,6 @@ where
404404
// We adjust our flashblocks timings based on time_drift if dynamic adjustment enable
405405
let (flashblocks_per_block, first_flashblock_offset) =
406406
self.calculate_flashblocks(timestamp);
407-
//ctx.set_target_flashblock_count(flashblocks_per_block);
408407
info!(
409408
target: "payload_builder",
410409
message = "Performed flashblocks timing derivation",
@@ -925,13 +924,13 @@ where
925924
.map_err(PayloadBuilderError::other)?
926925
.apply_pre_execution_changes()?;
927926

928-
// 3. execute sequencer transactions
927+
// 2. execute sequencer transactions
929928
let info = ctx.execute_sequencer_transactions(state)?;
930929

931930
Ok(info)
932931
}
933932

934-
fn build_block<DB, P, ExtraCtx>(
933+
pub(super) fn build_block<DB, P, ExtraCtx>(
935934
state: &mut State<DB>,
936935
ctx: &OpPayloadBuilderCtx<ExtraCtx>,
937936
info: &mut ExecutionInfo<ExtraExecutionInfo>,
@@ -978,7 +977,7 @@ where
978977
.expect("Number is in range");
979978

980979
// TODO: maybe recreate state with bundle in here
981-
// // calculate the state root
980+
// calculate the state root
982981
let state_root_start_time = Instant::now();
983982
let mut state_root = B256::ZERO;
984983
let mut trie_output = TrieUpdates::default();

0 commit comments

Comments
 (0)