feat(rpc): Start to implement flashbots_validateBuilderSubmissionV3 (#12061)

This commit is contained in:
Ryan Schneider
2024-10-26 09:15:08 -07:00
committed by GitHub
parent 09ebecffc7
commit f616de6d94
8 changed files with 121 additions and 4 deletions

1
Cargo.lock generated
View File

@ -8598,6 +8598,7 @@ dependencies = [
"alloy-rlp",
"alloy-rpc-types",
"alloy-rpc-types-admin",
"alloy-rpc-types-beacon",
"alloy-rpc-types-debug",
"alloy-rpc-types-eth",
"alloy-rpc-types-mev",

View File

@ -245,7 +245,7 @@ RPC:
--http.api <HTTP_API>
Rpc Modules to be configured for the HTTP server
[possible values: admin, debug, eth, net, trace, txpool, web3, rpc, reth, ots]
[possible values: admin, debug, eth, net, trace, txpool, web3, rpc, reth, ots, flashbots]
--http.corsdomain <HTTP_CORSDOMAIN>
Http Corsdomain to allow request from
@ -269,7 +269,7 @@ RPC:
--ws.api <WS_API>
Rpc Modules to be configured for the WS server
[possible values: admin, debug, eth, net, trace, txpool, web3, rpc, reth, ots]
[possible values: admin, debug, eth, net, trace, txpool, web3, rpc, reth, ots, flashbots]
--ipcdisable
Disable the IPC-RPC server

View File

@ -1,7 +1,7 @@
//! API for block submission validation.
use alloy_rpc_types_beacon::relay::{
BuilderBlockValidationRequest, BuilderBlockValidationRequestV2,
BuilderBlockValidationRequest, BuilderBlockValidationRequestV2, BuilderBlockValidationRequestV3,
};
use jsonrpsee::proc_macros::rpc;
@ -22,4 +22,11 @@ pub trait BlockSubmissionValidationApi {
&self,
request: BuilderBlockValidationRequestV2,
) -> jsonrpsee::core::RpcResult<()>;
/// A Request to validate a block submission.
#[method(name = "validateBuilderSubmissionV3")]
async fn validate_builder_submission_v3(
&self,
request: BuilderBlockValidationRequestV3,
) -> jsonrpsee::core::RpcResult<()>;
}

View File

@ -180,7 +180,7 @@ use reth_provider::{
};
use reth_rpc::{
AdminApi, DebugApi, EngineEthApi, EthBundle, NetApi, OtterscanApi, RPCApi, RethApi, TraceApi,
TxPoolApi, Web3Api,
TxPoolApi, ValidationApi, Web3Api,
};
use reth_rpc_api::servers::*;
use reth_rpc_eth_api::{
@ -1067,6 +1067,11 @@ where
pub fn reth_api(&self) -> RethApi<Provider> {
RethApi::new(self.provider.clone(), Box::new(self.executor.clone()))
}
/// Instantiates `ValidationApi`
pub fn validation_api(&self) -> ValidationApi<Provider> {
ValidationApi::new(self.provider.clone())
}
}
impl<Provider, Pool, Network, Tasks, Events, EthApi, BlockExecutor>
@ -1223,6 +1228,9 @@ where
.into_rpc()
.into()
}
RethRpcModule::Flashbots => {
ValidationApi::new(self.provider.clone()).into_rpc().into()
}
})
.clone()
})

View File

@ -258,6 +258,8 @@ pub enum RethRpcModule {
Reth,
/// `ots_` module
Ots,
/// `flashbots_` module
Flashbots,
}
// === impl RethRpcModule ===
@ -306,6 +308,7 @@ impl FromStr for RethRpcModule {
"rpc" => Self::Rpc,
"reth" => Self::Reth,
"ots" => Self::Ots,
"flashbots" => Self::Flashbots,
_ => return Err(ParseError::VariantNotFound),
})
}

View File

@ -45,6 +45,7 @@ alloy-network.workspace = true
alloy-primitives.workspace = true
alloy-rlp.workspace = true
alloy-rpc-types.workspace = true
alloy-rpc-types-beacon.workspace = true
alloy-rpc-types-eth = { workspace = true, features = ["jsonrpsee-types"] }
alloy-rpc-types-debug.workspace = true
alloy-rpc-types-trace.workspace = true

View File

@ -42,7 +42,9 @@ mod reth;
mod rpc;
mod trace;
mod txpool;
mod validation;
mod web3;
pub use admin::AdminApi;
pub use debug::DebugApi;
pub use engine::{EngineApi, EngineEthApi};
@ -53,4 +55,5 @@ pub use reth::RethApi;
pub use rpc::RPCApi;
pub use trace::TraceApi;
pub use txpool::TxPoolApi;
pub use validation::ValidationApi;
pub use web3::Web3Api;

View File

@ -0,0 +1,94 @@
use alloy_rpc_types_beacon::relay::{
BuilderBlockValidationRequest, BuilderBlockValidationRequestV2, BuilderBlockValidationRequestV3,
};
use async_trait::async_trait;
use jsonrpsee::core::RpcResult;
use reth_chainspec::ChainSpecProvider;
use reth_provider::{
AccountReader, BlockReaderIdExt, HeaderProvider, StateProviderFactory, WithdrawalsProvider,
};
use reth_rpc_api::BlockSubmissionValidationApiServer;
use reth_rpc_server_types::result::internal_rpc_err;
use std::sync::Arc;
use tracing::warn;
/// The type that implements the `validation` rpc namespace trait
pub struct ValidationApi<Provider> {
inner: Arc<ValidationApiInner<Provider>>,
}
impl<Provider> ValidationApi<Provider>
where
Provider: BlockReaderIdExt
+ ChainSpecProvider
+ StateProviderFactory
+ HeaderProvider
+ AccountReader
+ WithdrawalsProvider
+ Clone
+ 'static,
{
/// The provider that can interact with the chain.
pub fn provider(&self) -> Provider {
self.inner.provider.clone()
}
/// Create a new instance of the [`ValidationApi`]
pub fn new(provider: Provider) -> Self {
let inner = Arc::new(ValidationApiInner { provider });
Self { inner }
}
}
#[async_trait]
impl<Provider> BlockSubmissionValidationApiServer for ValidationApi<Provider>
where
Provider: BlockReaderIdExt
+ ChainSpecProvider
+ StateProviderFactory
+ HeaderProvider
+ AccountReader
+ WithdrawalsProvider
+ Clone
+ 'static,
{
async fn validate_builder_submission_v1(
&self,
_request: BuilderBlockValidationRequest,
) -> RpcResult<()> {
Err(internal_rpc_err("unimplemented"))
}
async fn validate_builder_submission_v2(
&self,
_request: BuilderBlockValidationRequestV2,
) -> RpcResult<()> {
Err(internal_rpc_err("unimplemented"))
}
/// Validates a block submitted to the relay
async fn validate_builder_submission_v3(
&self,
request: BuilderBlockValidationRequestV3,
) -> RpcResult<()> {
warn!("flashbots_validateBuilderSubmissionV3: blindly accepting request without validation {:?}", request);
Ok(())
}
}
impl<Provider> std::fmt::Debug for ValidationApi<Provider> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ValidationApi").finish_non_exhaustive()
}
}
impl<Provider> Clone for ValidationApi<Provider> {
fn clone(&self) -> Self {
Self { inner: Arc::clone(&self.inner) }
}
}
struct ValidationApiInner<Provider> {
/// The provider that can interact with the chain.
provider: Provider,
}