Skip to content

Commit 00c87f0

Browse files
authored
Merge pull request #22 from flashbots/tx-proxy
Proxy eth_sendRawTransaction to builder
2 parents bbdab15 + 392cae0 commit 00c87f0

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/proxy.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use std::{future::Future, pin::Pin};
99
use tower::{Layer, Service};
1010
use tracing::debug;
1111

12+
const MULTIPLEX_METHODS: [&str; 2] = ["engine_", "eth_sendRawTransaction"];
13+
1214
#[derive(Debug, Clone)]
1315
pub struct ProxyLayer {
1416
target_url: Uri,
@@ -84,7 +86,7 @@ where
8486
message = "received json rpc request for",
8587
method = method.method
8688
);
87-
if method.method.starts_with("engine_") {
89+
if PROXY_METHODS.iter().any(|&m| method.method.starts_with(m)) {
8890
// let rpc server handle engine rpc requests
8991
let res = inner.call(req).await.map_err(|e| e.into())?;
9092
Ok(res)

src/server.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloy::primitives::B256;
2+
use alloy_primitives::Bytes;
23
use alloy_rpc_types_engine::{
34
ExecutionPayload, ExecutionPayloadV3, ForkchoiceState, ForkchoiceUpdated, PayloadId,
45
PayloadStatus,
@@ -14,7 +15,7 @@ use op_alloy_rpc_types_engine::{
1415
};
1516
use reth_rpc_layer::AuthClientService;
1617
use std::sync::Arc;
17-
use tracing::{error, info};
18+
use tracing::{debug, error, info};
1819

1920
#[rpc(server, client, namespace = "engine")]
2021
pub trait EngineApi {
@@ -40,6 +41,12 @@ pub trait EngineApi {
4041
) -> RpcResult<PayloadStatus>;
4142
}
4243

44+
#[rpc(server, client, namespace = "eth")]
45+
pub trait EthApi {
46+
#[method(name = "sendRawTransaction")]
47+
async fn send_raw_transaction(&self, bytes: Bytes) -> RpcResult<B256>;
48+
}
49+
4350
pub struct EthEngineApi<S = AuthClientService<HttpBackend>> {
4451
l2_client: Arc<HttpClient<S>>,
4552
builder_client: Arc<HttpClient<S>>,
@@ -60,6 +67,36 @@ impl<S> EthEngineApi<S> {
6067
}
6168
}
6269

70+
#[async_trait]
71+
impl EthApiServer for EthEngineApi {
72+
async fn send_raw_transaction(&self, bytes: Bytes) -> RpcResult<B256> {
73+
debug!(
74+
message = "received send_raw_transaction",
75+
"bytes_len" = bytes.len()
76+
);
77+
let builder = self.builder_client.clone();
78+
let tx_bytes = bytes.clone();
79+
tokio::spawn(async move {
80+
builder.send_raw_transaction(tx_bytes).await.map_err(|e| {
81+
error!(message = "error calling send_raw_transaction for builder", "error" = %e);
82+
})
83+
});
84+
self.l2_client
85+
.send_raw_transaction(bytes)
86+
.await
87+
.map_err(|e| match e {
88+
ClientError::Call(err) => err, // Already an ErrorObjectOwned, so just return it
89+
other_error => {
90+
error!(
91+
message = "error calling send_raw_transaction for l2 client",
92+
"error" = %other_error,
93+
);
94+
ErrorCode::InternalError.into()
95+
}
96+
})
97+
}
98+
}
99+
63100
#[async_trait]
64101
impl EngineApiServer for EthEngineApi {
65102
async fn fork_choice_updated_v3(

0 commit comments

Comments
 (0)