reth_optimism_rpc/
miner.rs1use alloy_primitives::U64;
4use jsonrpsee_core::{async_trait, RpcResult};
5pub use op_alloy_rpc_jsonrpsee::traits::MinerApiExtServer;
6use reth_metrics::{metrics::Gauge, Metrics};
7use reth_optimism_payload_builder::config::OpDAConfig;
8use tracing::debug;
9
10#[derive(Debug, Clone)]
13pub struct OpMinerExtApi {
14 da_config: OpDAConfig,
15 metrics: OpMinerMetrics,
16}
17
18impl OpMinerExtApi {
19 pub fn new(da_config: OpDAConfig) -> Self {
22 Self { da_config, metrics: OpMinerMetrics::default() }
23 }
24}
25
26#[async_trait]
27impl MinerApiExtServer for OpMinerExtApi {
28 async fn set_max_da_size(&self, max_tx_size: U64, max_block_size: U64) -> RpcResult<bool> {
30 debug!(target: "rpc", "Setting max DA size: tx={}, block={}", max_tx_size, max_block_size);
31 self.da_config.set_max_da_size(max_tx_size.to(), max_block_size.to());
32
33 self.metrics.set_max_da_tx_size(max_tx_size.to());
34 self.metrics.set_max_da_block_size(max_block_size.to());
35
36 Ok(true)
37 }
38}
39
40#[derive(Metrics, Clone)]
42#[metrics(scope = "optimism_rpc.miner")]
43pub struct OpMinerMetrics {
44 max_da_tx_size: Gauge,
46 max_da_block_size: Gauge,
48}
49
50impl OpMinerMetrics {
51 #[inline]
53 pub fn set_max_da_tx_size(&self, size: u64) {
54 self.max_da_tx_size.set(size as f64);
55 }
56
57 #[inline]
59 pub fn set_max_da_block_size(&self, size: u64) {
60 self.max_da_block_size.set(size as f64);
61 }
62}