feat: relax bounds for eth_simulateV1 (#13232)

This commit is contained in:
Arsenii Kulikov
2024-12-09 23:08:49 +04:00
committed by GitHub
parent 3af2afe995
commit c7c84f2d3f
16 changed files with 172 additions and 200 deletions

View File

@ -5,15 +5,15 @@ use alloy_rpc_types_eth::transaction::TransactionRequest;
use reth_evm::ConfigureEvm;
use reth_provider::ProviderHeader;
use reth_rpc_eth_api::{
helpers::{estimate::EstimateCall, Call, EthCall, LoadPendingBlock, LoadState, SpawnBlocking},
FromEthApiError, IntoEthApiError,
helpers::{estimate::EstimateCall, Call, EthCall, LoadBlock, LoadState, SpawnBlocking},
FromEthApiError, FullEthApiTypes, IntoEthApiError,
};
use reth_rpc_eth_types::{revm_utils::CallFees, RpcInvalidTransactionError};
use revm::primitives::{BlockEnv, OptimismFields, TxEnv};
impl<N> EthCall for OpEthApi<N>
where
Self: EstimateCall + LoadPendingBlock,
Self: EstimateCall + LoadBlock + FullEthApiTypes,
N: OpNodeCore,
{
}

View File

@ -21,7 +21,7 @@ use reth_rpc_eth_api::{
};
use reth_rpc_eth_types::{EthApiError, PendingBlock};
use reth_transaction_pool::{PoolTransaction, TransactionPool};
use revm::primitives::{BlockEnv, CfgEnvWithHandlerCfg, ExecutionResult, SpecId};
use revm::primitives::{BlockEnv, ExecutionResult};
impl<N> LoadPendingBlock for OpEthApi<N>
where
@ -82,23 +82,26 @@ where
fn assemble_block(
&self,
cfg: CfgEnvWithHandlerCfg,
block_env: BlockEnv,
block_env: &BlockEnv,
parent_hash: B256,
state_root: B256,
transactions: Vec<ProviderTx<Self::Provider>>,
receipts: &[ProviderReceipt<Self::Provider>],
) -> reth_provider::ProviderBlock<Self::Provider> {
let chain_spec = self.provider().chain_spec();
let timestamp = block_env.timestamp.to::<u64>();
let transactions_root = calculate_transaction_root(&transactions);
let receipts_root = calculate_receipt_root_no_memo_optimism(
&receipts.iter().collect::<Vec<_>>(),
&chain_spec,
block_env.timestamp.to::<u64>(),
timestamp,
);
let logs_bloom = logs_bloom(receipts.iter().flat_map(|r| &r.logs));
let is_cancun = chain_spec.is_cancun_active_at_timestamp(timestamp);
let is_prague = chain_spec.is_prague_active_at_timestamp(timestamp);
let is_shanghai = chain_spec.is_shanghai_active_at_timestamp(timestamp);
let header = Header {
parent_hash,
@ -107,10 +110,9 @@ where
state_root,
transactions_root,
receipts_root,
withdrawals_root: (cfg.handler_cfg.spec_id >= SpecId::SHANGHAI)
.then_some(EMPTY_WITHDRAWALS),
withdrawals_root: (is_shanghai).then_some(EMPTY_WITHDRAWALS),
logs_bloom,
timestamp: block_env.timestamp.to::<u64>(),
timestamp,
mix_hash: block_env.prevrandao.unwrap_or_default(),
nonce: BEACON_NONCE.into(),
base_fee_per_gas: Some(block_env.basefee.to::<u64>()),
@ -118,15 +120,13 @@ where
gas_limit: block_env.gas_limit.to::<u64>(),
difficulty: U256::ZERO,
gas_used: receipts.last().map(|r| r.cumulative_gas_used).unwrap_or_default(),
blob_gas_used: (cfg.handler_cfg.spec_id >= SpecId::CANCUN).then(|| {
blob_gas_used: is_cancun.then(|| {
transactions.iter().map(|tx| tx.blob_gas_used().unwrap_or_default()).sum::<u64>()
}),
excess_blob_gas: block_env.get_blob_excess_gas().map(Into::into),
extra_data: Default::default(),
parent_beacon_block_root: (cfg.handler_cfg.spec_id >= SpecId::CANCUN)
.then_some(B256::ZERO),
requests_hash: (cfg.handler_cfg.spec_id >= SpecId::PRAGUE)
.then_some(EMPTY_REQUESTS_HASH),
parent_beacon_block_root: is_cancun.then_some(B256::ZERO),
requests_hash: is_prague.then_some(EMPTY_REQUESTS_HASH),
target_blobs_per_block: None,
};
@ -139,7 +139,7 @@ where
fn assemble_receipt(
&self,
tx: &reth_primitives::RecoveredTx<ProviderTx<Self::Provider>>,
tx: &ProviderTx<Self::Provider>,
result: ExecutionResult,
cumulative_gas_used: u64,
) -> reth_provider::ProviderReceipt<Self::Provider> {

View File

@ -1,7 +1,7 @@
//! Loads and formats OP transaction RPC response.
use alloy_consensus::{Signed, Transaction as _};
use alloy_primitives::{Bytes, Sealable, Sealed, B256};
use alloy_primitives::{Bytes, PrimitiveSignature as Signature, Sealable, Sealed, B256};
use alloy_rpc_types_eth::TransactionInfo;
use op_alloy_consensus::OpTxEnvelope;
use op_alloy_rpc_types::Transaction;
@ -14,7 +14,7 @@ use reth_rpc_eth_api::{
helpers::{EthSigner, EthTransactions, LoadTransaction, SpawnBlocking},
FromEthApiError, FullEthApiTypes, RpcNodeCore, RpcNodeCoreExt, TransactionCompat,
};
use reth_rpc_eth_types::utils::recover_raw_transaction;
use reth_rpc_eth_types::{utils::recover_raw_transaction, EthApiError};
use reth_transaction_pool::{PoolTransaction, TransactionOrigin, TransactionPool};
use crate::{eth::OpNodeCore, OpEthApi, OpEthApiError, SequencerClient};
@ -151,6 +151,19 @@ where
})
}
fn build_simulate_v1_transaction(
&self,
request: alloy_rpc_types_eth::TransactionRequest,
) -> Result<TransactionSigned, Self::Error> {
let Ok(tx) = request.build_typed_tx() else {
return Err(OpEthApiError::Eth(EthApiError::TransactionConversionError))
};
// Create an empty signature for the transaction.
let signature = Signature::new(Default::default(), Default::default(), false);
Ok(TransactionSigned::new_unhashed(tx.into(), signature))
}
fn otterscan_api_truncate_input(tx: &mut Self::Transaction) {
let input = match &mut tx.inner.inner {
OpTxEnvelope::Eip1559(tx) => &mut tx.tx_mut().input,