Skip to content

Commit

Permalink
feat(rpc): Start to implement flashbots_validateBuilderSubmissionV3
Browse files Browse the repository at this point in the history
* Currently just parses params and accepts all inputs.
* Mainly so we can unblock kurtosis testing for pectra
  • Loading branch information
ryanschneider committed Oct 24, 2024
1 parent 777417a commit 92e67d0
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion crates/rpc/rpc-api/src/validation.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<()>;
}
10 changes: 9 additions & 1 deletion crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,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::{
Expand Down Expand Up @@ -1063,6 +1063,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>
Expand Down Expand Up @@ -1219,6 +1224,9 @@ where
.into_rpc()
.into()
}
RethRpcModule::Flashbots => {
ValidationApi::new(self.provider.clone()).into_rpc().into()
}
})
.clone()
})
Expand Down
3 changes: 3 additions & 0 deletions crates/rpc/rpc-server-types/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ pub enum RethRpcModule {
Reth,
/// `ots_` module
Ots,
/// `flashbots_` module
Flashbots,
}

// === impl RethRpcModule ===
Expand Down Expand Up @@ -306,6 +308,7 @@ impl FromStr for RethRpcModule {
"rpc" => Self::Rpc,
"reth" => Self::Reth,
"ots" => Self::Ots,
"flashbots" => Self::Flashbots,
_ => return Err(ParseError::VariantNotFound),
})
}
Expand Down
1 change: 1 addition & 0 deletions crates/rpc/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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
Expand Down
3 changes: 3 additions & 0 deletions crates/rpc/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
91 changes: 91 additions & 0 deletions crates/rpc/rpc/src/validation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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 std::sync::Arc;

/// 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<()> {
todo!()
}

async fn validate_builder_submission_v2(
&self,
_request: BuilderBlockValidationRequestV2,
) -> RpcResult<()> {
todo!()
}

/// Validates a block submitted to the relay
async fn validate_builder_submission_v3(
&self,
request: BuilderBlockValidationRequestV3,
) -> RpcResult<()> {
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,
}

0 comments on commit 92e67d0

Please sign in to comment.