|
| 1 | +use crate::{ |
| 2 | + builders::{BuilderConfig, OpPayloadBuilderCtx, flashblocks::FlashblocksConfig}, |
| 3 | + gas_limiter::{AddressGasLimiter, args::GasLimiterArgs}, |
| 4 | + metrics::OpRBuilderMetrics, |
| 5 | + traits::ClientBounds, |
| 6 | +}; |
| 7 | +use op_revm::OpSpecId; |
| 8 | +use reth_basic_payload_builder::PayloadConfig; |
| 9 | +use reth_evm::EvmEnv; |
| 10 | +use reth_optimism_chainspec::OpChainSpec; |
| 11 | +use reth_optimism_evm::{OpEvmConfig, OpNextBlockEnvAttributes}; |
| 12 | +use reth_optimism_payload_builder::{OpPayloadBuilderAttributes, config::OpDAConfig}; |
| 13 | +use reth_optimism_primitives::OpTransactionSigned; |
| 14 | +use std::sync::Arc; |
| 15 | +use tokio_util::sync::CancellationToken; |
| 16 | + |
| 17 | +#[derive(Debug, Clone)] |
| 18 | +pub(super) struct OpPayloadSyncerCtx { |
| 19 | + /// The type that knows how to perform system calls and configure the evm. |
| 20 | + evm_config: OpEvmConfig, |
| 21 | + /// The DA config for the payload builder |
| 22 | + da_config: OpDAConfig, |
| 23 | + /// The chainspec |
| 24 | + chain_spec: Arc<OpChainSpec>, |
| 25 | + /// Max gas that can be used by a transaction. |
| 26 | + max_gas_per_txn: Option<u64>, |
| 27 | + /// The metrics for the builder |
| 28 | + metrics: Arc<OpRBuilderMetrics>, |
| 29 | +} |
| 30 | + |
| 31 | +impl OpPayloadSyncerCtx { |
| 32 | + pub(super) fn new<Client>( |
| 33 | + client: &Client, |
| 34 | + builder_config: BuilderConfig<FlashblocksConfig>, |
| 35 | + evm_config: OpEvmConfig, |
| 36 | + metrics: Arc<OpRBuilderMetrics>, |
| 37 | + ) -> eyre::Result<Self> |
| 38 | + where |
| 39 | + Client: ClientBounds, |
| 40 | + { |
| 41 | + let chain_spec = client.chain_spec(); |
| 42 | + Ok(Self { |
| 43 | + evm_config, |
| 44 | + da_config: builder_config.da_config.clone(), |
| 45 | + chain_spec, |
| 46 | + max_gas_per_txn: builder_config.max_gas_per_txn, |
| 47 | + metrics, |
| 48 | + }) |
| 49 | + } |
| 50 | + |
| 51 | + pub(super) fn evm_config(&self) -> &OpEvmConfig { |
| 52 | + &self.evm_config |
| 53 | + } |
| 54 | + |
| 55 | + pub(super) fn max_gas_per_txn(&self) -> Option<u64> { |
| 56 | + self.max_gas_per_txn |
| 57 | + } |
| 58 | + |
| 59 | + pub(super) fn into_op_payload_builder_ctx( |
| 60 | + self, |
| 61 | + payload_config: PayloadConfig<OpPayloadBuilderAttributes<OpTransactionSigned>>, |
| 62 | + evm_env: EvmEnv<OpSpecId>, |
| 63 | + block_env_attributes: OpNextBlockEnvAttributes, |
| 64 | + cancel: CancellationToken, |
| 65 | + ) -> OpPayloadBuilderCtx { |
| 66 | + OpPayloadBuilderCtx { |
| 67 | + evm_config: self.evm_config, |
| 68 | + da_config: self.da_config, |
| 69 | + chain_spec: self.chain_spec, |
| 70 | + config: payload_config, |
| 71 | + evm_env, |
| 72 | + block_env_attributes, |
| 73 | + cancel, |
| 74 | + builder_signer: None, |
| 75 | + metrics: self.metrics, |
| 76 | + extra_ctx: (), |
| 77 | + max_gas_per_txn: self.max_gas_per_txn, |
| 78 | + address_gas_limiter: AddressGasLimiter::new(GasLimiterArgs::default()), |
| 79 | + } |
| 80 | + } |
| 81 | +} |
0 commit comments