Skip to content

Commit 5acc32a

Browse files
committed
feat: Added preconf forwarding and TaikoArgs; updated dependencies
1 parent 5833f22 commit 5acc32a

File tree

11 files changed

+108
-5
lines changed

11 files changed

+108
-5
lines changed

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/node/core/src/args/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ pub use benchmark_args::BenchmarkArgs;
5858

5959
mod error;
6060
pub mod types;
61+
62+
mod taiko;
63+
pub use taiko::TaikoArgs;

crates/node/core/src/args/rpc_server.rs

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ use crate::args::{
2121
GasPriceOracleArgs, RpcStateCacheArgs,
2222
};
2323

24+
use super::TaikoArgs;
25+
2426
/// Default max number of subscriptions per connection.
2527
pub(crate) const RPC_DEFAULT_MAX_SUBS_PER_CONN: u32 = 1024;
2628

@@ -197,6 +199,10 @@ pub struct RpcServerArgs {
197199
/// Gas price oracle configuration.
198200
#[command(flatten)]
199201
pub gas_price_oracle: GasPriceOracleArgs,
202+
203+
/// Taiko additional configuration.
204+
#[command(flatten)]
205+
pub taiko: TaikoArgs,
200206
}
201207

202208
impl RpcServerArgs {
@@ -332,6 +338,7 @@ impl Default for RpcServerArgs {
332338
rpc_state_cache: RpcStateCacheArgs::default(),
333339
rpc_proof_permits: constants::DEFAULT_PROOF_PERMITS,
334340
builder_disallow: Default::default(),
341+
taiko: TaikoArgs::default(),
335342
}
336343
}
337344
}

crates/node/core/src/args/taiko.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! Taiko arguments
2+
3+
use clap::Args;
4+
/// Parameters for debugging purposes
5+
#[derive(Debug, Default, Clone, Args, PartialEq, Eq)]
6+
#[command(next_help_heading = "Taiko")]
7+
pub struct TaikoArgs {
8+
/// The URL of the preconf forwarding server
9+
#[arg(long = "taiko.preconf-forwarding-server", default_value = None)]
10+
pub preconf_forwarding_server: Option<String>,
11+
}

crates/rpc/rpc-builder/src/config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ impl RethRpcServerConfig for RpcServerArgs {
103103
.state_cache(self.state_cache_config())
104104
.gpo_config(self.gas_price_oracle_config())
105105
.proof_permits(self.rpc_proof_permits)
106+
.preconf_forwarding_server(self.taiko.preconf_forwarding_server.clone())
106107
}
107108

108109
fn flashbots_config(&self) -> ValidationApiConfig {

crates/rpc/rpc-builder/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ pub struct RpcModuleConfigBuilder {
12411241

12421242
impl RpcModuleConfigBuilder {
12431243
/// Configures a custom eth namespace config
1244-
pub const fn eth(mut self, eth: EthConfig) -> Self {
1244+
pub fn eth(mut self, eth: EthConfig) -> Self {
12451245
self.eth = Some(eth);
12461246
self
12471247
}
@@ -1371,7 +1371,7 @@ where
13711371
pool.clone(),
13721372
network.clone(),
13731373
evm_config,
1374-
config.eth,
1374+
config.eth.clone(),
13751375
executor.clone(),
13761376
events.clone(),
13771377
eth_api_builder,

crates/rpc/rpc-eth-types/src/builder/config.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};
1515
pub const DEFAULT_STALE_FILTER_TTL: Duration = Duration::from_secs(5 * 60);
1616

1717
/// Additional config values for the eth namespace.
18-
#[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)]
18+
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
1919
pub struct EthConfig {
2020
/// Settings for the caching layer
2121
pub cache: EthStateCacheConfig,
@@ -42,6 +42,8 @@ pub struct EthConfig {
4242
pub fee_history_cache: FeeHistoryCacheConfig,
4343
/// The maximum number of getproof calls that can be executed concurrently.
4444
pub proof_permits: usize,
45+
/// The preconf server url for forwarding
46+
pub preconf_forwarding_server: Option<String>,
4547
}
4648

4749
impl EthConfig {
@@ -68,6 +70,7 @@ impl Default for EthConfig {
6870
stale_filter_ttl: DEFAULT_STALE_FILTER_TTL,
6971
fee_history_cache: FeeHistoryCacheConfig::default(),
7072
proof_permits: DEFAULT_PROOF_PERMITS,
73+
preconf_forwarding_server: None,
7174
}
7275
}
7376
}
@@ -126,6 +129,12 @@ impl EthConfig {
126129
self.proof_permits = permits;
127130
self
128131
}
132+
133+
/// Configures the preconf forwarding server
134+
pub fn preconf_forwarding_server(mut self, server: Option<String>) -> Self {
135+
self.preconf_forwarding_server = server;
136+
self
137+
}
129138
}
130139

131140
/// Config for the filter

crates/rpc/rpc/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ alloy-rpc-types-txpool.workspace = true
6161
alloy-rpc-types-admin.workspace = true
6262
alloy-rpc-types-engine.workspace = true
6363
alloy-serde.workspace = true
64+
alloy-provider.workspace = true
6465
revm = { workspace = true, features = [
6566
"optional_block_gas_limit",
6667
"optional_eip3607",
@@ -92,6 +93,10 @@ rand.workspace = true
9293
serde.workspace = true
9394
thiserror.workspace = true
9495
derive_more.workspace = true
96+
# reqwest
97+
reqwest = { workspace = true, default-features = false, features = [
98+
"rustls-tls-native-roots",
99+
] }
95100

96101
[dev-dependencies]
97102
reth-evm-ethereum.workspace = true

crates/rpc/rpc/src/eth/core.rs

+18
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use alloy_consensus::BlockHeader;
77
use alloy_eips::BlockNumberOrTag;
88
use alloy_network::Ethereum;
99
use alloy_primitives::U256;
10+
use alloy_provider::{ProviderBuilder, ReqwestProvider};
1011
use derive_more::Deref;
12+
use reqwest::Url;
1113
use reth_primitives::NodePrimitives;
1214
use reth_provider::{
1315
BlockReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider, L1OriginReader,
@@ -76,6 +78,7 @@ where
7678
fee_history_cache: FeeHistoryCache,
7779
evm_config: EvmConfig,
7880
proof_permits: usize,
81+
preconf_forwarding_server: Option<String>,
7982
) -> Self {
8083
let inner = EthApiInner::new(
8184
provider,
@@ -91,6 +94,7 @@ where
9194
evm_config,
9295
TokioTaskExecutor::default(),
9396
proof_permits,
97+
preconf_forwarding_server,
9498
);
9599

96100
Self { inner: Arc::new(inner), tx_resp_builder: EthTxBuilder }
@@ -134,6 +138,7 @@ where
134138
ctx.evm_config.clone(),
135139
ctx.executor.clone(),
136140
ctx.config.proof_permits,
141+
ctx.config.preconf_forwarding_server.clone(),
137142
);
138143

139144
Self { inner: Arc::new(inner), tx_resp_builder: EthTxBuilder }
@@ -270,6 +275,9 @@ pub struct EthApiInner<Provider: BlockReader, Pool, Network, EvmConfig> {
270275

271276
/// Guard for getproof calls
272277
blocking_task_guard: BlockingTaskGuard,
278+
279+
/// The preconfigured forwarding server
280+
preconf_forwarding_server: Option<ReqwestProvider>,
273281
}
274282

275283
impl<Provider, Pool, Network, EvmConfig> EthApiInner<Provider, Pool, Network, EvmConfig>
@@ -292,6 +300,7 @@ where
292300
evm_config: EvmConfig,
293301
task_spawner: impl TaskSpawner + 'static,
294302
proof_permits: usize,
303+
preconf_forwarding_server: Option<String>,
295304
) -> Self {
296305
let signers = parking_lot::RwLock::new(Default::default());
297306
// get the block number of the latest block
@@ -321,6 +330,8 @@ where
321330
fee_history_cache,
322331
evm_config,
323332
blocking_task_guard: BlockingTaskGuard::new(proof_permits),
333+
preconf_forwarding_server: preconf_forwarding_server
334+
.map(|url| ProviderBuilder::default().on_http(Url::parse(&url).unwrap())),
324335
}
325336
}
326337
}
@@ -428,6 +439,12 @@ where
428439
pub const fn blocking_task_guard(&self) -> &BlockingTaskGuard {
429440
&self.blocking_task_guard
430441
}
442+
443+
/// Returns reference to [`BlockingTaskGuard`].
444+
#[inline]
445+
pub const fn preconf_forwarding_server(&self) -> Option<&ReqwestProvider> {
446+
self.preconf_forwarding_server.as_ref()
447+
}
431448
}
432449

433450
#[cfg(test)]
@@ -491,6 +508,7 @@ mod tests {
491508
fee_history_cache,
492509
evm_config,
493510
DEFAULT_PROOF_PERMITS,
511+
None,
494512
)
495513
}
496514

crates/rpc/rpc/src/eth/helpers/state.rs

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ mod tests {
7171
FeeHistoryCache::new(FeeHistoryCacheConfig::default()),
7272
evm_config,
7373
DEFAULT_PROOF_PERMITS,
74+
None,
7475
)
7576
}
7677

@@ -97,6 +98,7 @@ mod tests {
9798
FeeHistoryCache::new(FeeHistoryCacheConfig::default()),
9899
evm_config,
99100
DEFAULT_PROOF_PERMITS,
101+
None,
100102
)
101103
}
102104

crates/rpc/rpc/src/eth/helpers/transaction.rs

+47-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
//! Contains RPC handler implementations specific to transactions
22
3+
use std::future::Future;
4+
5+
use alloy_primitives::Bytes;
6+
use alloy_provider::Provider;
37
use reth_provider::{BlockReader, BlockReaderIdExt, ProviderTx, TransactionsProvider};
48
use reth_rpc_eth_api::{
59
helpers::{EthSigner, EthTransactions, LoadTransaction, SpawnBlocking},
6-
FullEthApiTypes, RpcNodeCoreExt,
10+
EthApiTypes, FromEthApiError, FullEthApiTypes, RpcNodeCore, RpcNodeCoreExt,
711
};
8-
use reth_transaction_pool::TransactionPool;
12+
use reth_rpc_eth_types::{utils::recover_raw_transaction, EthApiError};
13+
use reth_rpc_server_types::result::internal_rpc_err;
14+
use reth_transaction_pool::{PoolTransaction, TransactionOrigin, TransactionPool};
15+
use revm_primitives::B256;
916

1017
use crate::EthApi;
1118

@@ -14,11 +21,48 @@ impl<Provider, Pool, Network, EvmConfig> EthTransactions
1421
where
1522
Self: LoadTransaction<Provider: BlockReaderIdExt>,
1623
Provider: BlockReader<Transaction = ProviderTx<Self::Provider>>,
24+
<Self as RpcNodeCore>::Pool: TransactionPool,
1725
{
1826
#[inline]
1927
fn signers(&self) -> &parking_lot::RwLock<Vec<Box<dyn EthSigner<ProviderTx<Self::Provider>>>>> {
2028
self.inner.signers()
2129
}
30+
31+
#[inline]
32+
#[allow(clippy::manual_async_fn)]
33+
fn send_raw_transaction(
34+
&self,
35+
tx: Bytes,
36+
) -> impl Future<Output = Result<B256, Self::Error>> + Send {
37+
async move {
38+
// TODO: forwarding tx
39+
if let Some(client) = self.preconf_forwarding_server() {
40+
return client
41+
.send_raw_transaction(&tx)
42+
.await
43+
.map_err(|err| internal_rpc_err(err.to_string()))
44+
.map_err(EthApiError::other)
45+
.map_err(Into::into)?
46+
.watch()
47+
.await
48+
.map_err(|err| internal_rpc_err(err.to_string()))
49+
.map_err(EthApiError::other)
50+
.map_err(Into::into);
51+
}
52+
let recovered = recover_raw_transaction(&tx)?;
53+
let pool_transaction =
54+
<Self::Pool as TransactionPool>::Transaction::from_pooled(recovered);
55+
56+
// submit the transaction to the pool with a `Local` origin
57+
let hash = self
58+
.pool()
59+
.add_transaction(TransactionOrigin::Local, pool_transaction)
60+
.await
61+
.map_err(<Self as EthApiTypes>::Error::from_eth_err)?;
62+
63+
Ok(hash)
64+
}
65+
}
2266
}
2367

2468
impl<Provider, Pool, Network, EvmConfig> LoadTransaction
@@ -74,6 +118,7 @@ mod tests {
74118
fee_history_cache,
75119
evm_config,
76120
DEFAULT_PROOF_PERMITS,
121+
None,
77122
);
78123

79124
// https://etherscan.io/tx/0xa694b71e6c128a2ed8e2e0f6770bddbe52e3bb8f10e8472f9a79ab81497a8b5d

0 commit comments

Comments
 (0)