Skip to content

Commit

Permalink
feat: relax eth_callBundle bounds (#13485)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Dec 22, 2024
1 parent 05382ec commit a163a5c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 44 deletions.
13 changes: 3 additions & 10 deletions crates/node/builder/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ use reth_node_core::{
version::{CARGO_PKG_VERSION, CLIENT_CODE, NAME_CLIENT, VERGEN_GIT_SHA},
};
use reth_payload_builder::PayloadStore;
use reth_primitives::{EthPrimitives, PooledTransaction};
use reth_provider::providers::NodeTypesForProvider;
use reth_primitives::EthPrimitives;
use reth_rpc::{
eth::{EthApiTypes, FullEthApiServer},
EthApi,
Expand All @@ -33,7 +32,6 @@ use reth_rpc_builder::{
use reth_rpc_engine_api::{capabilities::EngineCapabilities, EngineApi};
use reth_tasks::TaskExecutor;
use reth_tracing::tracing::{debug, info};
use reth_transaction_pool::{PoolTransaction, TransactionPool};
use std::sync::Arc;

use crate::EthApiBuilderCtx;
Expand Down Expand Up @@ -404,9 +402,7 @@ where

impl<N, EthApi, EV> RpcAddOns<N, EthApi, EV>
where
N: FullNodeComponents<
Pool: TransactionPool<Transaction: PoolTransaction<Pooled = PooledTransaction>>,
>,
N: FullNodeComponents,
EthApi: EthApiTypes
+ FullEthApiServer<Provider = N::Provider, Pool = N::Pool, Network = N::Network>
+ AddDevSigners
Expand Down Expand Up @@ -534,10 +530,7 @@ where

impl<N, EthApi, EV> NodeAddOns<N> for RpcAddOns<N, EthApi, EV>
where
N: FullNodeComponents<
Types: NodeTypesForProvider<Primitives = EthPrimitives>,
Pool: TransactionPool<Transaction: PoolTransaction<Pooled = PooledTransaction>>,
>,
N: FullNodeComponents,
EthApi: EthApiTypes
+ FullEthApiServer<Provider = N::Provider, Pool = N::Pool, Network = N::Network>
+ AddDevSigners
Expand Down
2 changes: 0 additions & 2 deletions crates/optimism/node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ where
Storage = OpStorage,
Engine = OpEngineTypes,
>,
Pool: TransactionPool<Transaction: PoolTransaction<Pooled = PooledTransaction>>,
>,
OpEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
{
Expand Down Expand Up @@ -303,7 +302,6 @@ where
Storage = OpStorage,
Engine = OpEngineTypes,
>,
Pool: TransactionPool<Transaction: PoolTransaction<Pooled = PooledTransaction>>,
>,
OpEngineValidator: EngineValidator<<N::Types as NodeTypesWithEngine>::Engine>,
{
Expand Down
8 changes: 2 additions & 6 deletions crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ use reth_consensus::FullConsensus;
use reth_engine_primitives::{EngineTypes, PayloadValidator};
use reth_evm::{execute::BlockExecutorProvider, ConfigureEvm};
use reth_network_api::{noop::NoopNetwork, NetworkInfo, Peers};
use reth_primitives::{NodePrimitives, PooledTransaction};
use reth_primitives::NodePrimitives;
use reth_provider::{
AccountReader, BlockReader, CanonStateSubscriptions, ChainSpecProvider, ChangeSetReader,
EvmEnvProvider, FullRpcProvider, ProviderBlock, ProviderHeader, ProviderReceipt,
Expand All @@ -248,7 +248,7 @@ use reth_rpc_eth_api::{
use reth_rpc_eth_types::{EthConfig, EthStateCache, EthSubscriptionIdProvider};
use reth_rpc_layer::{AuthLayer, Claims, CompressionLayer, JwtAuthValidator, JwtSecret};
use reth_tasks::{pool::BlockingTaskGuard, TaskSpawner, TokioTaskExecutor};
use reth_transaction_pool::{noop::NoopTransactionPool, PoolTransaction, TransactionPool};
use reth_transaction_pool::{noop::NoopTransactionPool, TransactionPool};
use serde::{Deserialize, Serialize};
use tower::Layer;
use tower_http::cors::CorsLayer;
Expand Down Expand Up @@ -323,7 +323,6 @@ where
Receipt = <BlockExecutor::Primitives as NodePrimitives>::Receipt,
Header = <BlockExecutor::Primitives as NodePrimitives>::BlockHeader,
>,
Pool: TransactionPool<Transaction: PoolTransaction<Pooled = PooledTransaction>>,
>,
BlockExecutor: BlockExecutorProvider,
{
Expand Down Expand Up @@ -715,7 +714,6 @@ where
Receipt = <Events::Primitives as NodePrimitives>::Receipt,
Header = <Events::Primitives as NodePrimitives>::BlockHeader,
>,
Pool: TransactionPool<Transaction: PoolTransaction<Pooled = PooledTransaction>>,
>,
{
let Self {
Expand Down Expand Up @@ -841,7 +839,6 @@ where
Block = <Events::Primitives as NodePrimitives>::Block,
Header = <Events::Primitives as NodePrimitives>::BlockHeader,
>,
Pool: TransactionPool<Transaction: PoolTransaction<Pooled = PooledTransaction>>,
>,
Pool: TransactionPool<Transaction = <EthApi::Pool as TransactionPool>::Transaction>,
{
Expand Down Expand Up @@ -1382,7 +1379,6 @@ where
Receipt = <BlockExecutor::Primitives as NodePrimitives>::Receipt,
Header = <BlockExecutor::Primitives as NodePrimitives>::BlockHeader,
>,
Pool: TransactionPool<Transaction: PoolTransaction<Pooled = PooledTransaction>>,
>,
BlockExecutor: BlockExecutorProvider,
Consensus: reth_consensus::FullConsensus<BlockExecutor::Primitives> + Clone + 'static,
Expand Down
49 changes: 23 additions & 26 deletions crates/rpc/rpc/src/eth/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use alloy_rpc_types_mev::{EthCallBundle, EthCallBundleResponse, EthCallBundleTra
use jsonrpsee::core::RpcResult;
use reth_chainspec::EthChainSpec;
use reth_evm::{env::EvmEnv, ConfigureEvm, ConfigureEvmEnv};
use reth_primitives::PooledTransaction;
use reth_primitives_traits::SignedTransaction;
use reth_provider::{ChainSpecProvider, HeaderProvider};
use reth_revm::database::StateProviderDatabase;
Expand All @@ -16,7 +15,9 @@ use reth_rpc_eth_api::{
};
use reth_rpc_eth_types::{utils::recover_raw_transaction, EthApiError, RpcInvalidTransactionError};
use reth_tasks::pool::BlockingTaskGuard;
use reth_transaction_pool::{PoolPooledTx, PoolTransaction, PoolTx, TransactionPool};
use reth_transaction_pool::{
EthBlobTransactionSidecar, EthPoolTransaction, PoolPooledTx, PoolTransaction, TransactionPool,
};
use revm::{
db::{CacheDB, DatabaseCommit, DatabaseRef},
primitives::{ResultAndState, TxEnv},
Expand Down Expand Up @@ -44,11 +45,7 @@ impl<Eth> EthBundle<Eth> {

impl<Eth> EthBundle<Eth>
where
Eth: EthTransactions<
Pool: TransactionPool<Transaction: PoolTransaction<Pooled = PooledTransaction>>,
> + LoadPendingBlock
+ Call
+ 'static,
Eth: EthTransactions + LoadPendingBlock + Call + 'static,
{
/// Simulates a bundle of transactions at the top of a given block number with the state of
/// another (or the same) block. This can be used to simulate future blocks with the current
Expand Down Expand Up @@ -88,12 +85,11 @@ where
.map(|tx| recover_raw_transaction::<PoolPooledTx<Eth::Pool>>(&tx))
.collect::<Result<Vec<_>, _>>()?
.into_iter()
.map(|tx| tx.to_components())
.collect::<Vec<_>>();

// Validate that the bundle does not contain more than MAX_BLOB_NUMBER_PER_BLOCK blob
// transactions.
if transactions.iter().filter_map(|(tx, _)| tx.blob_gas_used()).sum::<u64>() >
if transactions.iter().filter_map(|tx| tx.blob_gas_used()).sum::<u64>() >
MAX_BLOB_GAS_PER_BLOCK
{
return Err(EthApiError::InvalidParams(
Expand Down Expand Up @@ -185,18 +181,23 @@ where
let mut results = Vec::with_capacity(transactions.len());
let mut transactions = transactions.into_iter().peekable();

while let Some((tx, signer)) = transactions.next() {
// Verify that the given blob data, commitments, and proofs are all valid for
// this transaction.
if let PooledTransaction::Eip4844(ref tx) = tx {
tx.tx().validate_blob(EnvKzgSettings::Default.get()).map_err(|e| {
Eth::Error::from_eth_err(EthApiError::InvalidParams(e.to_string()))
})?;
}

let tx: PoolPooledTx<Eth::Pool> = tx;
let tx = PoolTx::<Eth::Pool>::pooled_into_consensus(tx);
// let tx = PoolConsensusTx::<Eth::Pool>::Trafrom(tx);
while let Some(tx) = transactions.next() {
let signer = tx.signer();
let tx = {
let mut tx: <Eth::Pool as TransactionPool>::Transaction = tx.into();

if let EthBlobTransactionSidecar::Present(sidecar) = tx.take_blob() {
tx.validate_blob(&sidecar, EnvKzgSettings::Default.get()).map_err(
|e| {
Eth::Error::from_eth_err(EthApiError::InvalidParams(
e.to_string(),
))
},
)?;
}

tx.into_consensus()
};

hasher.update(*tx.tx_hash());
let gas_price = tx.effective_gas_price(basefee);
Expand Down Expand Up @@ -278,11 +279,7 @@ where
#[async_trait::async_trait]
impl<Eth> EthCallBundleApiServer for EthBundle<Eth>
where
Eth: EthTransactions<
Pool: TransactionPool<Transaction: PoolTransaction<Pooled = PooledTransaction>>,
> + LoadPendingBlock
+ Call
+ 'static,
Eth: EthTransactions + LoadPendingBlock + Call + 'static,
{
async fn call_bundle(&self, request: EthCallBundle) -> RpcResult<EthCallBundleResponse> {
Self::call_bundle(self, request).await.map_err(Into::into)
Expand Down

0 comments on commit a163a5c

Please sign in to comment.