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

chore(op): type safety in computation of op tx metadata #10619

Merged
merged 31 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
233d99b
Fix clone impl for OpEthApi
emhane Aug 29, 2024
f0c4120
Add helper trait reth_node_api::NodeCore for simplified type def
emhane Aug 29, 2024
a64bfa7
Add auto trait bounds to reth_node_api::NodeCore
emhane Aug 29, 2024
5c3f060
Relax trait bounds for reth_node_api::BuilderProvider
emhane Aug 29, 2024
0d228c9
Relax trait bounds for OpEthApi
emhane Aug 29, 2024
f40fc8d
Merge branch 'emhane/fix-clone-op-ethapi' into emhane/test-op-eth-api
emhane Aug 29, 2024
8a97ca6
Fix docs
emhane Aug 29, 2024
9c80ed2
Relax trait bounds on core node components for testing OpEthApi::buil…
emhane Aug 29, 2024
1d9cc76
Decompose impl of LoadReceipt::build_transaction_receipt for reth_opt…
emhane Aug 29, 2024
937a711
Merge branch 'main' into emhane/test-op-ethapi
emhane Aug 29, 2024
c94389d
Remove optimism feature from reth-optimism-rpc for devx
emhane Aug 29, 2024
175e5db
Fix semantics for reth_optimism_rpc::OpTxMeta -> reth_optimism_rpc::O…
emhane Aug 29, 2024
c1a54f1
Rename reth_optimism_rpc::OpReceiptMetaBuilder -> OpReceiptFieldsBuilder
emhane Aug 29, 2024
bd50c79
Fix OP bug, l1 fee scalar depreceated since ecotone
emhane Aug 29, 2024
e173a3e
Revert c94389d
emhane Aug 29, 2024
8f9a6fe
Merge branch 'main' into emhane/op-receipt-fields-builder
emhane Sep 2, 2024
a40b15a
Fix offset bug extracting ecotone l1 block info in reth-evm-optimism
emhane Sep 2, 2024
99cddad
Extract method reth_evm_optimism::parse_l1_info that can be tested wi…
emhane Sep 2, 2024
1f6cd8e
Add test for reth_evm_optimism::parse_l1_info
emhane Sep 2, 2024
3146b99
Update test comment
emhane Sep 4, 2024
4a9220f
Rewrite reth_evm_optimism::l1::tests::sanity_l1_block_ecotone to use …
emhane Sep 4, 2024
4915d54
Merge branch 'emhane/op-l1-block-info' into emhane/op-receipt-fields-…
emhane Sep 4, 2024
12e2471
Merge branch 'main' into emhane/op-receipt-fields-builder
emhane Sep 4, 2024
5323ee0
Revert redundant changes
emhane Sep 4, 2024
257112d
test(op): add test for assembling of op tx receipt RPC response (#10620)
emhane Sep 5, 2024
b4d2e75
Merge branch 'main' into emhane/op-receipt-fields-builder
emhane Sep 5, 2024
578201c
Merge branch 'emhane/op-receipt-fields-builder' of github.com:paradig…
emhane Sep 5, 2024
0b65d46
Merge branch 'main' into emhane/op-receipt-fields-builder
emhane Sep 5, 2024
b8478e1
Update deps
emhane Sep 5, 2024
69fe418
Merge branch 'main' into emhane/op-receipt-fields-builder
emhane Sep 5, 2024
753ba52
Fix merge conflicts
emhane Sep 5, 2024
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

8 changes: 6 additions & 2 deletions crates/ethereum-forks/src/hardforks/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ pub trait OptimismHardforks: EthereumHardforks {
self.fork(OptimismHardfork::Bedrock).active_at_block(block_number)
}

/// Convenience method to check if [`Ecotone`](OptimismHardfork::Ecotone) is active at a given
/// timestamp.
/// Returns `true` if [`Ecotone`](OptimismHardfork::Ecotone) is active at given block timestamp.
fn is_ecotone_active_at_timestamp(&self, timestamp: u64) -> bool {
self.fork(OptimismHardfork::Ecotone).active_at_timestamp(timestamp)
}

/// Returns `true` if [`Ecotone`](OptimismHardfork::Ecotone) is active at given block timestamp.
fn is_fjord_active_at_timestamp(&self, timestamp: u64) -> bool {
self.fork(OptimismHardfork::Ecotone).active_at_timestamp(timestamp)
}
}

impl OptimismHardforks for ChainHardforks {}
4 changes: 4 additions & 0 deletions crates/optimism/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ reth-chainspec.workspace = true
alloy-primitives.workspace = true
op-alloy-network.workspace = true
revm.workspace = true
op-alloy-rpc-types.workspace = true

# async
parking_lot.workspace = true
Expand All @@ -47,6 +48,9 @@ serde_json.workspace = true
thiserror.workspace = true
tracing.workspace = true

[dev-dependencies]
reth-optimism-chainspec.workspace = true

[features]
optimism = [
"reth-evm-optimism/optimism",
Expand Down
13 changes: 8 additions & 5 deletions crates/optimism/rpc/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! RPC errors specific to OP.

use reth_evm_optimism::OptimismBlockExecutionError;
use reth_primitives::revm_primitives::{InvalidTransaction, OptimismInvalidTransaction};
use reth_rpc_eth_api::AsEthApiError;
use reth_rpc_eth_types::EthApiError;
Expand All @@ -12,6 +13,9 @@ pub enum OpEthApiError {
/// L1 ethereum error.
#[error(transparent)]
Eth(#[from] EthApiError),
/// EVM error originating from invalid optimism data.
#[error(transparent)]
Evm(#[from] OptimismBlockExecutionError),
/// Thrown when calculating L1 gas fee.
#[error("failed to calculate l1 gas fee")]
L1BlockFeeError,
Expand All @@ -35,11 +39,10 @@ impl AsEthApiError for OpEthApiError {
impl From<OpEthApiError> for jsonrpsee_types::error::ErrorObject<'static> {
fn from(err: OpEthApiError) -> Self {
match err {
OpEthApiError::Eth(err) => err.into(),
OpEthApiError::L1BlockFeeError | OpEthApiError::L1BlockGasError => {
internal_rpc_err(err.to_string())
}
OpEthApiError::InvalidTransaction(err) => err.into(),
OpEthApiError::Eth(_) | OpEthApiError::InvalidTransaction(_) => err.into(),
OpEthApiError::Evm(_) |
OpEthApiError::L1BlockFeeError |
OpEthApiError::L1BlockGasError => internal_rpc_err(err.to_string()),
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions crates/optimism/rpc/src/eth/block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Loads and formats OP block RPC response.
//! Loads and formats OP block RPC response.

use reth_node_api::FullNodeComponents;
use reth_chainspec::ChainSpec;
use reth_node_api::{FullNodeComponents, NodeTypes};
use reth_primitives::TransactionMeta;
use reth_provider::{BlockReaderIdExt, HeaderProvider};
use reth_rpc_eth_api::{
Expand All @@ -13,13 +14,12 @@ use reth_rpc_eth_api::{
use reth_rpc_eth_types::{EthStateCache, ReceiptBuilder};
use reth_rpc_types::{AnyTransactionReceipt, BlockId};

use crate::{op_receipt_fields, OpEthApi, OpEthApiError};
use crate::{OpEthApi, OpEthApiError};

impl<N> EthBlocks for OpEthApi<N>
where
Self: LoadBlock + EthApiSpec + LoadTransaction,
Self::Error: From<OpEthApiError>,
N: FullNodeComponents,
Self: EthApiSpec + LoadBlock<Error = OpEthApiError> + LoadTransaction,
N: FullNodeComponents<Types: NodeTypes<ChainSpec = ChainSpec>>,
{
#[inline]
fn provider(&self) -> impl HeaderProvider {
Expand All @@ -41,14 +41,15 @@ where
let timestamp = block.timestamp;
let block = block.unseal();

let l1_block_info = reth_evm_optimism::extract_l1_info(&block).ok();
let l1_block_info =
reth_evm_optimism::extract_l1_info(&block).map_err(OpEthApiError::from)?;

let receipts = block
.body
.into_iter()
.zip(receipts.iter())
.enumerate()
.map(|(idx, (ref tx, receipt))| {
.map(|(idx, (ref tx, receipt))| -> Result<_, _> {
let meta = TransactionMeta {
tx_hash: tx.hash,
index: idx as u64,
Expand All @@ -59,14 +60,13 @@ where
timestamp,
};

let optimism_tx_meta =
self.build_op_tx_meta(tx, l1_block_info.clone(), timestamp)?;
let op_tx_meta =
self.build_op_receipt_meta(tx, l1_block_info.clone(), receipt)?;

ReceiptBuilder::new(tx, meta, receipt, &receipts)
.map(|builder| {
op_receipt_fields(builder, tx, receipt, optimism_tx_meta).build()
})
.map_err(Self::Error::from_eth_err)
Ok(ReceiptBuilder::new(tx, meta, receipt, &receipts)
.map_err(Self::Error::from_eth_err)?
.add_other_fields(op_tx_meta.into())
.build())
})
.collect::<Result<Vec<_>, Self::Error>>();
return receipts.map(Some)
Expand Down
14 changes: 9 additions & 5 deletions crates/optimism/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub mod rpc;

use std::{fmt, sync::Arc};

use crate::eth::rpc::SequencerClient;
use alloy_primitives::U256;
use op_alloy_network::AnyNetwork;
use reth_chainspec::ChainSpec;
Expand All @@ -19,8 +18,8 @@ use reth_network_api::NetworkInfo;
use reth_node_api::{BuilderProvider, FullNodeComponents, FullNodeTypes, NodeTypes};
use reth_node_builder::EthApiBuilderCtx;
use reth_provider::{
BlockIdReader, BlockNumReader, BlockReaderIdExt, ChainSpecProvider, HeaderProvider,
StageCheckpointReader, StateProviderFactory,
BlockIdReader, BlockNumReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider,
HeaderProvider, StageCheckpointReader, StateProviderFactory,
};
use reth_rpc::eth::{core::EthApiInner, DevSigner};
use reth_rpc_eth_api::{
Expand All @@ -37,7 +36,7 @@ use reth_tasks::{
};
use reth_transaction_pool::TransactionPool;

use crate::OpEthApiError;
use crate::{eth::rpc::SequencerClient, OpEthApiError};

/// Adapter for [`EthApiInner`], which holds all the data required to serve core `eth_` API.
pub type EthApiNodeBackend<N> = EthApiInner<
Expand All @@ -63,7 +62,12 @@ pub struct OpEthApi<N: FullNodeComponents> {
sequencer_client: Arc<parking_lot::RwLock<Option<SequencerClient>>>,
}

impl<N: FullNodeComponents> OpEthApi<N> {
impl<N> OpEthApi<N>
where
N: FullNodeComponents<
Provider: BlockReaderIdExt + ChainSpecProvider + CanonStateSubscriptions + Clone + 'static,
>,
{
/// Creates a new instance for given context.
#[allow(clippy::type_complexity)]
pub fn with_spawner(ctx: &EthApiBuilderCtx<N>) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/rpc/src/eth/pending_block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Loads OP pending block for a RPC response.
//! Loads OP pending block for a RPC response.

use reth_chainspec::ChainSpec;
use reth_evm::ConfigureEvm;
Expand Down
Loading
Loading