Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce softblock #61

Merged
merged 7 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions crates/consensus/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,10 @@ pub enum ConsensusError {
/// Error when the first transaction in the block is not an anchor transaction.
#[display("missing anchor transaction")]
AnchorTxMissing,

/// Error when fetching L1 origin.
#[display("failed to load L1 origin")]
LoadL1Origin,
}

impl ConsensusError {
Expand Down
3 changes: 3 additions & 0 deletions crates/node/core/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ pub use benchmark_args::BenchmarkArgs;

mod error;
pub mod types;

mod taiko;
pub use taiko::TaikoArgs;
7 changes: 7 additions & 0 deletions crates/node/core/src/args/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use crate::args::{
GasPriceOracleArgs, RpcStateCacheArgs,
};

use super::TaikoArgs;

/// Default max number of subscriptions per connection.
pub(crate) const RPC_DEFAULT_MAX_SUBS_PER_CONN: u32 = 1024;

Expand Down Expand Up @@ -197,6 +199,10 @@ pub struct RpcServerArgs {
/// Gas price oracle configuration.
#[command(flatten)]
pub gas_price_oracle: GasPriceOracleArgs,

/// Taiko additional configuration.
#[command(flatten)]
pub taiko: TaikoArgs,
}

impl RpcServerArgs {
Expand Down Expand Up @@ -332,6 +338,7 @@ impl Default for RpcServerArgs {
rpc_state_cache: RpcStateCacheArgs::default(),
rpc_proof_permits: constants::DEFAULT_PROOF_PERMITS,
builder_disallow: Default::default(),
taiko: TaikoArgs::default(),
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions crates/node/core/src/args/taiko.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! Taiko arguments

use clap::Args;
/// Parameters for debugging purposes
#[derive(Debug, Default, Clone, Args, PartialEq, Eq)]
#[command(next_help_heading = "Taiko")]
pub struct TaikoArgs {
/// The URL of the preconf forwarding server
#[arg(long = "taiko.preconf-forwarding-server", default_value = None)]
pub preconf_forwarding_server: Option<String>,
}
1 change: 1 addition & 0 deletions crates/rpc/rpc-builder/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl RethRpcServerConfig for RpcServerArgs {
.state_cache(self.state_cache_config())
.gpo_config(self.gas_price_oracle_config())
.proof_permits(self.rpc_proof_permits)
.preconf_forwarding_server(self.taiko.preconf_forwarding_server.clone())
}

fn flashbots_config(&self) -> ValidationApiConfig {
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,7 @@ pub struct RpcModuleConfigBuilder {

impl RpcModuleConfigBuilder {
/// Configures a custom eth namespace config
pub const fn eth(mut self, eth: EthConfig) -> Self {
pub fn eth(mut self, eth: EthConfig) -> Self {
self.eth = Some(eth);
self
}
Expand Down Expand Up @@ -1371,7 +1371,7 @@ where
pool.clone(),
network.clone(),
evm_config,
config.eth,
config.eth.clone(),
executor.clone(),
events.clone(),
eth_api_builder,
Expand Down
11 changes: 10 additions & 1 deletion crates/rpc/rpc-eth-types/src/builder/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};
pub const DEFAULT_STALE_FILTER_TTL: Duration = Duration::from_secs(5 * 60);

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

impl EthConfig {
Expand All @@ -68,6 +70,7 @@ impl Default for EthConfig {
stale_filter_ttl: DEFAULT_STALE_FILTER_TTL,
fee_history_cache: FeeHistoryCacheConfig::default(),
proof_permits: DEFAULT_PROOF_PERMITS,
preconf_forwarding_server: None,
}
}
}
Expand Down Expand Up @@ -126,6 +129,12 @@ impl EthConfig {
self.proof_permits = permits;
self
}

/// Configures the preconf forwarding server
pub fn preconf_forwarding_server(mut self, server: Option<String>) -> Self {
self.preconf_forwarding_server = server;
self
}
}

/// Config for the filter
Expand Down
5 changes: 5 additions & 0 deletions crates/rpc/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ alloy-rpc-types-txpool.workspace = true
alloy-rpc-types-admin.workspace = true
alloy-rpc-types-engine.workspace = true
alloy-serde.workspace = true
alloy-provider.workspace = true
revm = { workspace = true, features = [
"optional_block_gas_limit",
"optional_eip3607",
Expand Down Expand Up @@ -92,6 +93,10 @@ rand.workspace = true
serde.workspace = true
thiserror.workspace = true
derive_more.workspace = true
# reqwest
reqwest = { workspace = true, default-features = false, features = [
"rustls-tls-native-roots",
] }

[dev-dependencies]
reth-evm-ethereum.workspace = true
Expand Down
18 changes: 18 additions & 0 deletions crates/rpc/rpc/src/eth/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use alloy_consensus::BlockHeader;
use alloy_eips::BlockNumberOrTag;
use alloy_network::Ethereum;
use alloy_primitives::U256;
use alloy_provider::{ProviderBuilder, ReqwestProvider};
use derive_more::Deref;
use reqwest::Url;
use reth_primitives::NodePrimitives;
use reth_provider::{
BlockReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider, L1OriginReader,
Expand Down Expand Up @@ -76,6 +78,7 @@ where
fee_history_cache: FeeHistoryCache,
evm_config: EvmConfig,
proof_permits: usize,
preconf_forwarding_server: Option<String>,
) -> Self {
let inner = EthApiInner::new(
provider,
Expand All @@ -91,6 +94,7 @@ where
evm_config,
TokioTaskExecutor::default(),
proof_permits,
preconf_forwarding_server,
);

Self { inner: Arc::new(inner), tx_resp_builder: EthTxBuilder }
Expand Down Expand Up @@ -134,6 +138,7 @@ where
ctx.evm_config.clone(),
ctx.executor.clone(),
ctx.config.proof_permits,
ctx.config.preconf_forwarding_server.clone(),
);

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

/// Guard for getproof calls
blocking_task_guard: BlockingTaskGuard,

/// The preconfigured forwarding server
preconf_forwarding_server: Option<ReqwestProvider>,
}

impl<Provider, Pool, Network, EvmConfig> EthApiInner<Provider, Pool, Network, EvmConfig>
Expand All @@ -292,6 +300,7 @@ where
evm_config: EvmConfig,
task_spawner: impl TaskSpawner + 'static,
proof_permits: usize,
preconf_forwarding_server: Option<String>,
) -> Self {
let signers = parking_lot::RwLock::new(Default::default());
// get the block number of the latest block
Expand Down Expand Up @@ -321,6 +330,8 @@ where
fee_history_cache,
evm_config,
blocking_task_guard: BlockingTaskGuard::new(proof_permits),
preconf_forwarding_server: preconf_forwarding_server
.map(|url| ProviderBuilder::default().on_http(Url::parse(&url).unwrap())),
}
}
}
Expand Down Expand Up @@ -428,6 +439,12 @@ where
pub const fn blocking_task_guard(&self) -> &BlockingTaskGuard {
&self.blocking_task_guard
}

/// Returns reference to [`BlockingTaskGuard`].
#[inline]
pub const fn preconf_forwarding_server(&self) -> Option<&ReqwestProvider> {
self.preconf_forwarding_server.as_ref()
}
}

#[cfg(test)]
Expand Down Expand Up @@ -491,6 +508,7 @@ mod tests {
fee_history_cache,
evm_config,
DEFAULT_PROOF_PERMITS,
None,
)
}

Expand Down
2 changes: 2 additions & 0 deletions crates/rpc/rpc/src/eth/helpers/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ mod tests {
FeeHistoryCache::new(FeeHistoryCacheConfig::default()),
evm_config,
DEFAULT_PROOF_PERMITS,
None,
)
}

Expand All @@ -97,6 +98,7 @@ mod tests {
FeeHistoryCache::new(FeeHistoryCacheConfig::default()),
evm_config,
DEFAULT_PROOF_PERMITS,
None,
)
}

Expand Down
48 changes: 46 additions & 2 deletions crates/rpc/rpc/src/eth/helpers/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
//! Contains RPC handler implementations specific to transactions

use std::future::Future;

use alloy_primitives::Bytes;
use alloy_provider::Provider;
use reth_provider::{BlockReader, BlockReaderIdExt, ProviderTx, TransactionsProvider};
use reth_rpc_eth_api::{
helpers::{EthSigner, EthTransactions, LoadTransaction, SpawnBlocking},
FullEthApiTypes, RpcNodeCoreExt,
EthApiTypes, FromEthApiError, FullEthApiTypes, RpcNodeCore, RpcNodeCoreExt,
};
use reth_transaction_pool::TransactionPool;
use reth_rpc_eth_types::{utils::recover_raw_transaction, EthApiError};
use reth_rpc_server_types::result::internal_rpc_err;
use reth_transaction_pool::{PoolTransaction, TransactionOrigin, TransactionPool};
use revm_primitives::B256;

use crate::EthApi;

Expand All @@ -14,11 +21,47 @@ impl<Provider, Pool, Network, EvmConfig> EthTransactions
where
Self: LoadTransaction<Provider: BlockReaderIdExt>,
Provider: BlockReader<Transaction = ProviderTx<Self::Provider>>,
<Self as RpcNodeCore>::Pool: TransactionPool,
{
#[inline]
fn signers(&self) -> &parking_lot::RwLock<Vec<Box<dyn EthSigner<ProviderTx<Self::Provider>>>>> {
self.inner.signers()
}

#[inline]
#[allow(clippy::manual_async_fn)]
fn send_raw_transaction(
&self,
tx: Bytes,
) -> impl Future<Output = Result<B256, Self::Error>> + Send {
async move {
if let Some(client) = self.preconf_forwarding_server() {
return client
.send_raw_transaction(&tx)
.await
.map_err(|err| internal_rpc_err(err.to_string()))
.map_err(EthApiError::other)
.map_err(Into::into)?
.watch()
.await
.map_err(|err| internal_rpc_err(err.to_string()))
.map_err(EthApiError::other)
.map_err(Into::into);
}
let recovered = recover_raw_transaction(&tx)?;
let pool_transaction =
<Self::Pool as TransactionPool>::Transaction::from_pooled(recovered);

// submit the transaction to the pool with a `Local` origin
let hash = self
.pool()
.add_transaction(TransactionOrigin::Local, pool_transaction)
.await
.map_err(<Self as EthApiTypes>::Error::from_eth_err)?;

Ok(hash)
}
}
}

impl<Provider, Pool, Network, EvmConfig> LoadTransaction
Expand Down Expand Up @@ -74,6 +117,7 @@ mod tests {
fee_history_cache,
evm_config,
DEFAULT_PROOF_PERMITS,
None,
);

// https://etherscan.io/tx/0xa694b71e6c128a2ed8e2e0f6770bddbe52e3bb8f10e8472f9a79ab81497a8b5d
Expand Down
7 changes: 7 additions & 0 deletions crates/storage/provider/src/providers/blockchain_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,13 @@ impl<N: ProviderNodeTypes> L1OriginWriter for BlockchainProvider2<N> {
provider_rw.commit()?;
Ok(())
}

fn delete_l1_origin(&self, block_number: BlockNumber) -> ProviderResult<()> {
let provider_rw = self.database_provider_rw()?;
provider_rw.delete_l1_origin(block_number)?;
provider_rw.commit()?;
Ok(())
}
}

#[cfg(test)]
Expand Down
5 changes: 5 additions & 0 deletions crates/storage/provider/src/providers/database/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3224,4 +3224,9 @@ impl<TX: DbTxMut + DbTx + 'static, N: NodeTypes> L1OriginWriter for DatabaseProv
self.tx_ref().put::<tables::HeadL1Origin>(HeadL1OriginKey, block_number)?;
Ok(())
}

fn delete_l1_origin(&self, block_number: BlockNumber) -> ProviderResult<()> {
self.tx_ref().delete::<tables::L1Origins>(block_number, None)?;
Ok(())
}
}
7 changes: 7 additions & 0 deletions crates/storage/provider/src/providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,4 +1002,11 @@ impl<N: ProviderNodeTypes> L1OriginWriter for BlockchainProvider<N> {
provider_rw.commit()?;
Ok(())
}

fn delete_l1_origin(&self, block_number: BlockNumber) -> ProviderResult<()> {
let provider_rw = self.database_provider_rw()?;
provider_rw.delete_l1_origin(block_number)?;
provider_rw.commit()?;
Ok(())
}
}
4 changes: 4 additions & 0 deletions crates/storage/provider/src/test_utils/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,4 +856,8 @@ impl L1OriginWriter for MockEthProvider {
) -> ProviderResult<()> {
todo!()
}

fn delete_l1_origin(&self, _block_number: BlockNumber) -> ProviderResult<()> {
todo!()
}
}
Loading
Loading