mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: install op miner endpoint (#13147)
This commit is contained in:
@ -419,7 +419,7 @@ where
|
||||
ext: F,
|
||||
) -> eyre::Result<RpcHandle<N, EthApi>>
|
||||
where
|
||||
F: FnOnce(&mut TransportRpcModules) -> eyre::Result<()>,
|
||||
F: FnOnce(&mut TransportRpcModules, &mut AuthRpcModule) -> eyre::Result<()>,
|
||||
{
|
||||
let Self { eth_api_builder, engine_validator_builder, hooks, _pd: _ } = self;
|
||||
|
||||
@ -477,7 +477,7 @@ where
|
||||
|
||||
let RpcHooks { on_rpc_started, extend_rpc_modules } = hooks;
|
||||
|
||||
ext(ctx.modules)?;
|
||||
ext(ctx.modules, ctx.auth_module)?;
|
||||
extend_rpc_modules.extend_rpc_modules(ctx)?;
|
||||
|
||||
let server_config = config.rpc.rpc_server_config();
|
||||
@ -537,7 +537,7 @@ where
|
||||
type Handle = RpcHandle<N, EthApi>;
|
||||
|
||||
async fn launch_add_ons(self, ctx: AddOnsContext<'_, N>) -> eyre::Result<Self::Handle> {
|
||||
self.launch_add_ons_with(ctx, |_| Ok(())).await
|
||||
self.launch_add_ons_with(ctx, |_, _| Ok(())).await
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -27,9 +27,10 @@ use reth_node_builder::{
|
||||
use reth_optimism_chainspec::OpChainSpec;
|
||||
use reth_optimism_consensus::OpBeaconConsensus;
|
||||
use reth_optimism_evm::{OpEvmConfig, OpExecutionStrategyFactory};
|
||||
use reth_optimism_payload_builder::builder::OpPayloadTransactions;
|
||||
use reth_optimism_payload_builder::{builder::OpPayloadTransactions, config::OpDAConfig};
|
||||
use reth_optimism_primitives::OpPrimitives;
|
||||
use reth_optimism_rpc::{
|
||||
miner::{MinerApiExtServer, OpMinerExtApi},
|
||||
witness::{DebugExecutionWitnessApiServer, OpDebugWitnessApi},
|
||||
OpEthApi, SequencerClient,
|
||||
};
|
||||
@ -112,12 +113,25 @@ impl ChainStorage<OpPrimitives> for OpStorage {
|
||||
pub struct OpNode {
|
||||
/// Additional Optimism args
|
||||
pub args: RollupArgs,
|
||||
/// Data availability configuration for the OP builder.
|
||||
///
|
||||
/// Used to throttle the size of the data availability payloads (configured by the batcher via
|
||||
/// the `miner_` api).
|
||||
///
|
||||
/// By default no throttling is applied.
|
||||
pub da_config: OpDAConfig,
|
||||
}
|
||||
|
||||
impl OpNode {
|
||||
/// Creates a new instance of the Optimism node type.
|
||||
pub const fn new(args: RollupArgs) -> Self {
|
||||
Self { args }
|
||||
pub fn new(args: RollupArgs) -> Self {
|
||||
Self { args, da_config: OpDAConfig::default() }
|
||||
}
|
||||
|
||||
/// Configure the data availability configuration for the OP builder.
|
||||
pub fn with_da_config(mut self, da_config: OpDAConfig) -> Self {
|
||||
self.da_config = da_config;
|
||||
self
|
||||
}
|
||||
|
||||
/// Returns the components for the given [`RollupArgs`].
|
||||
@ -182,7 +196,10 @@ where
|
||||
}
|
||||
|
||||
fn add_ons(&self) -> Self::AddOns {
|
||||
Self::AddOns::builder().with_sequencer(self.args.sequencer_http.clone()).build()
|
||||
Self::AddOns::builder()
|
||||
.with_sequencer(self.args.sequencer_http.clone())
|
||||
.with_da_config(self.da_config.clone())
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
@ -199,7 +216,13 @@ impl NodeTypesWithEngine for OpNode {
|
||||
|
||||
/// Add-ons w.r.t. optimism.
|
||||
#[derive(Debug)]
|
||||
pub struct OpAddOns<N: FullNodeComponents>(pub RpcAddOns<N, OpEthApi<N>, OpEngineValidatorBuilder>);
|
||||
pub struct OpAddOns<N: FullNodeComponents> {
|
||||
/// Rpc add-ons responsible for launching the RPC servers and instantiating the RPC handlers
|
||||
/// and eth-api.
|
||||
pub rpc_add_ons: RpcAddOns<N, OpEthApi<N>, OpEngineValidatorBuilder>,
|
||||
/// Data availability configuration for the OP builder.
|
||||
pub da_config: OpDAConfig,
|
||||
}
|
||||
|
||||
impl<N: FullNodeComponents<Types: NodeTypes<Primitives = OpPrimitives>>> Default for OpAddOns<N> {
|
||||
fn default() -> Self {
|
||||
@ -228,14 +251,29 @@ where
|
||||
self,
|
||||
ctx: reth_node_api::AddOnsContext<'_, N>,
|
||||
) -> eyre::Result<Self::Handle> {
|
||||
let Self { rpc_add_ons, da_config } = self;
|
||||
// install additional OP specific rpc methods
|
||||
let debug_ext =
|
||||
OpDebugWitnessApi::new(ctx.node.provider().clone(), ctx.node.evm_config().clone());
|
||||
let miner_ext = OpMinerExtApi::new(da_config);
|
||||
|
||||
self.0
|
||||
.launch_add_ons_with(ctx, move |modules| {
|
||||
rpc_add_ons
|
||||
.launch_add_ons_with(ctx, move |modules, auth_modules| {
|
||||
debug!(target: "reth::cli", "Installing debug payload witness rpc endpoint");
|
||||
modules.merge_if_module_configured(RethRpcModule::Debug, debug_ext.into_rpc())?;
|
||||
|
||||
// extend the miner namespace if configured in the regular http server
|
||||
modules.merge_if_module_configured(
|
||||
RethRpcModule::Miner,
|
||||
miner_ext.clone().into_rpc(),
|
||||
)?;
|
||||
|
||||
// install the miner extension in the authenticated if configured
|
||||
if modules.module_config().contains_any(&RethRpcModule::Miner) {
|
||||
debug!(target: "reth::cli", "Installing miner DA rpc enddpoint");
|
||||
auth_modules.merge_auth_methods(miner_ext.into_rpc())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.await
|
||||
@ -253,7 +291,7 @@ where
|
||||
type EthApi = OpEthApi<N>;
|
||||
|
||||
fn hooks_mut(&mut self) -> &mut reth_node_builder::rpc::RpcHooks<N, Self::EthApi> {
|
||||
self.0.hooks_mut()
|
||||
self.rpc_add_ons.hooks_mut()
|
||||
}
|
||||
}
|
||||
|
||||
@ -276,6 +314,8 @@ pub struct OpAddOnsBuilder {
|
||||
/// Sequencer client, configured to forward submitted transactions to sequencer of given OP
|
||||
/// network.
|
||||
sequencer_client: Option<SequencerClient>,
|
||||
/// Data availability configuration for the OP builder.
|
||||
da_config: Option<OpDAConfig>,
|
||||
}
|
||||
|
||||
impl OpAddOnsBuilder {
|
||||
@ -284,6 +324,12 @@ impl OpAddOnsBuilder {
|
||||
self.sequencer_client = sequencer_client.map(SequencerClient::new);
|
||||
self
|
||||
}
|
||||
|
||||
/// Configure the data availability configuration for the OP builder.
|
||||
pub fn with_da_config(mut self, da_config: OpDAConfig) -> Self {
|
||||
self.da_config = Some(da_config);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl OpAddOnsBuilder {
|
||||
@ -292,12 +338,15 @@ impl OpAddOnsBuilder {
|
||||
where
|
||||
N: FullNodeComponents<Types: NodeTypes<Primitives = OpPrimitives>>,
|
||||
{
|
||||
let Self { sequencer_client, .. } = self;
|
||||
let Self { sequencer_client, da_config } = self;
|
||||
|
||||
OpAddOns(RpcAddOns::new(
|
||||
move |ctx| OpEthApi::<N>::builder().with_sequencer(sequencer_client).build(ctx),
|
||||
Default::default(),
|
||||
))
|
||||
OpAddOns {
|
||||
rpc_add_ons: RpcAddOns::new(
|
||||
move |ctx| OpEthApi::<N>::builder().with_sequencer(sequencer_client).build(ctx),
|
||||
Default::default(),
|
||||
),
|
||||
da_config: da_config.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -45,6 +45,7 @@ alloy-consensus.workspace = true
|
||||
op-alloy-network.workspace = true
|
||||
op-alloy-rpc-types.workspace = true
|
||||
op-alloy-rpc-types-engine.workspace = true
|
||||
op-alloy-rpc-jsonrpsee.workspace = true
|
||||
op-alloy-consensus.workspace = true
|
||||
revm.workspace = true
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
|
||||
pub mod error;
|
||||
pub mod eth;
|
||||
pub mod miner;
|
||||
pub mod sequencer;
|
||||
pub mod witness;
|
||||
|
||||
|
||||
32
crates/optimism/rpc/src/miner.rs
Normal file
32
crates/optimism/rpc/src/miner.rs
Normal file
@ -0,0 +1,32 @@
|
||||
//! Miner API extension for OP.
|
||||
|
||||
use alloy_primitives::U64;
|
||||
use jsonrpsee_core::{async_trait, RpcResult};
|
||||
pub use op_alloy_rpc_jsonrpsee::traits::MinerApiExtServer;
|
||||
use reth_optimism_payload_builder::config::OpDAConfig;
|
||||
use tracing::debug;
|
||||
|
||||
/// Miner API extension for OP, exposes settings for the data availability configuration via the
|
||||
/// `miner_` API.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct OpMinerExtApi {
|
||||
da_config: OpDAConfig,
|
||||
}
|
||||
|
||||
impl OpMinerExtApi {
|
||||
/// Instantiate the miner API extension with the given, sharable data availability
|
||||
/// configuration.
|
||||
pub const fn new(da_config: OpDAConfig) -> Self {
|
||||
Self { da_config }
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl MinerApiExtServer for OpMinerExtApi {
|
||||
/// Handler for `miner_setMaxDASize` RPC method.
|
||||
async fn set_max_da_size(&self, max_tx_size: U64, max_block_size: U64) -> RpcResult<()> {
|
||||
debug!(target: "rpc", "Setting max DA size: tx={}, block={}", max_tx_size, max_block_size);
|
||||
self.da_config.set_max_da_size(max_tx_size.to(), max_block_size.to());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user