From 8d1d13ef89cf19459adc37ba0c45e7aac6270dc1 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 4 Apr 2024 16:11:34 +0200 Subject: [PATCH] chore: bump revm+alloy (#7431) --- Cargo.lock | 139 ++++++++++-------- Cargo.toml | 22 +-- crates/primitives/src/log.rs | 6 + crates/rpc/rpc-api/src/eth.rs | 12 +- crates/rpc/rpc-api/src/otterscan.rs | 7 +- crates/rpc/rpc-types-compat/src/log.rs | 7 +- .../rpc-types-compat/src/transaction/mod.rs | 6 +- crates/rpc/rpc-types/Cargo.toml | 6 +- crates/rpc/rpc-types/src/admin.rs | 1 - crates/rpc/rpc-types/src/eth/mod.rs | 2 +- crates/rpc/rpc-types/src/lib.rs | 9 +- crates/rpc/rpc-types/src/otterscan.rs | 124 ---------------- crates/rpc/rpc/src/eth/api/block.rs | 4 +- crates/rpc/rpc/src/eth/api/server.rs | 11 +- crates/rpc/rpc/src/eth/api/transactions.rs | 94 ++++++------ crates/rpc/rpc/src/eth/logs_utils.rs | 32 ++-- crates/rpc/rpc/src/otterscan.rs | 49 +++++- 17 files changed, 242 insertions(+), 289 deletions(-) delete mode 100644 crates/rpc/rpc-types/src/otterscan.rs diff --git a/Cargo.lock b/Cargo.lock index a9c3c04ed..bde4ecbd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -146,19 +146,21 @@ dependencies = [ [[package]] name = "alloy-consensus" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7e39c85#7e39c85f9f51e6449a8b661f54df0ac213f18639" +source = "git+https://github.com/alloy-rs/alloy?rev=8c9dd0a#8c9dd0ae0a0f12eb81b5afe75a9b55ea4ad3abf4" dependencies = [ "alloy-eips", "alloy-primitives", "alloy-rlp", + "alloy-serde", + "serde", "sha2 0.10.8", ] [[package]] name = "alloy-dyn-abi" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2919acdad13336bc5dc26b636cdd6892c2f27fb0d4a58320a00c2713cf6a4e9a" +checksum = "872f239c15befa27cc4f0d3d82a70b3365c2d0202562bf906eb93b299fa31882" dependencies = [ "alloy-json-abi", "alloy-primitives", @@ -175,7 +177,7 @@ dependencies = [ [[package]] name = "alloy-eips" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7e39c85#7e39c85f9f51e6449a8b661f54df0ac213f18639" +source = "git+https://github.com/alloy-rs/alloy?rev=8c9dd0a#8c9dd0ae0a0f12eb81b5afe75a9b55ea4ad3abf4" dependencies = [ "alloy-primitives", "alloy-rlp", @@ -190,7 +192,7 @@ dependencies = [ [[package]] name = "alloy-genesis" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7e39c85#7e39c85f9f51e6449a8b661f54df0ac213f18639" +source = "git+https://github.com/alloy-rs/alloy?rev=8c9dd0a#8c9dd0ae0a0f12eb81b5afe75a9b55ea4ad3abf4" dependencies = [ "alloy-primitives", "alloy-serde", @@ -199,9 +201,9 @@ dependencies = [ [[package]] name = "alloy-json-abi" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24ed0f2a6c3a1c947b4508522a53a190dba8f94dcd4e3e1a5af945a498e78f2f" +checksum = "83a35ddfd27576474322a5869e4c123e5f3e7b2177297c18e4e82ea501cb125b" dependencies = [ "alloy-primitives", "alloy-sol-type-parser", @@ -212,7 +214,7 @@ dependencies = [ [[package]] name = "alloy-node-bindings" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7e39c85#7e39c85f9f51e6449a8b661f54df0ac213f18639" +source = "git+https://github.com/alloy-rs/alloy?rev=8c9dd0a#8c9dd0ae0a0f12eb81b5afe75a9b55ea4ad3abf4" dependencies = [ "alloy-genesis", "alloy-primitives", @@ -226,9 +228,9 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "600d34d8de81e23b6d909c094e23b3d357e01ca36b78a8c5424c501eedbe86f0" +checksum = "99bbad0a6b588ef4aec1b5ddbbfdacd9ef04e00b979617765b03174318ee1f3a" dependencies = [ "alloy-rlp", "arbitrary", @@ -274,10 +276,34 @@ dependencies = [ ] [[package]] -name = "alloy-rpc-engine-types" +name = "alloy-rpc-types" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7e39c85#7e39c85f9f51e6449a8b661f54df0ac213f18639" +source = "git+https://github.com/alloy-rs/alloy?rev=8c9dd0a#8c9dd0ae0a0f12eb81b5afe75a9b55ea4ad3abf4" dependencies = [ + "alloy-consensus", + "alloy-eips", + "alloy-genesis", + "alloy-primitives", + "alloy-rlp", + "alloy-serde", + "alloy-sol-types", + "arbitrary", + "itertools 0.12.1", + "jsonrpsee-types", + "proptest", + "proptest-derive", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "alloy-rpc-types-engine" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy?rev=8c9dd0a#8c9dd0ae0a0f12eb81b5afe75a9b55ea4ad3abf4" +dependencies = [ + "alloy-consensus", + "alloy-eips", "alloy-primitives", "alloy-rlp", "alloy-rpc-types", @@ -290,9 +316,9 @@ dependencies = [ ] [[package]] -name = "alloy-rpc-trace-types" +name = "alloy-rpc-types-trace" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7e39c85#7e39c85f9f51e6449a8b661f54df0ac213f18639" +source = "git+https://github.com/alloy-rs/alloy?rev=8c9dd0a#8c9dd0ae0a0f12eb81b5afe75a9b55ea4ad3abf4" dependencies = [ "alloy-primitives", "alloy-rpc-types", @@ -301,30 +327,10 @@ dependencies = [ "serde_json", ] -[[package]] -name = "alloy-rpc-types" -version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7e39c85#7e39c85f9f51e6449a8b661f54df0ac213f18639" -dependencies = [ - "alloy-consensus", - "alloy-eips", - "alloy-primitives", - "alloy-rlp", - "alloy-serde", - "arbitrary", - "itertools 0.12.1", - "jsonrpsee-types", - "proptest", - "proptest-derive", - "serde", - "serde_json", - "thiserror", -] - [[package]] name = "alloy-serde" version = "0.1.0" -source = "git+https://github.com/alloy-rs/alloy?rev=7e39c85#7e39c85f9f51e6449a8b661f54df0ac213f18639" +source = "git+https://github.com/alloy-rs/alloy?rev=8c9dd0a#8c9dd0ae0a0f12eb81b5afe75a9b55ea4ad3abf4" dependencies = [ "alloy-primitives", "serde", @@ -333,12 +339,12 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86ec0a47740b20bc5613b8712d0d321d031c4efc58e9645af96085d5cccfc27" +checksum = "452d929748ac948a10481fff4123affead32c553cf362841c5103dd508bdfc16" dependencies = [ + "alloy-sol-macro-input", "const-hex", - "dunce", "heck 0.4.1", "indexmap 2.2.6", "proc-macro-error", @@ -350,19 +356,34 @@ dependencies = [ ] [[package]] -name = "alloy-sol-type-parser" -version = "0.6.4" +name = "alloy-sol-macro-input" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0045cc89524e1451ccf33e8581355b6027ac7c6e494bb02959d4213ad0d8e91d" +checksum = "df64e094f6d2099339f9e82b5b38440b159757b6920878f28316243f8166c8d1" +dependencies = [ + "const-hex", + "dunce", + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.57", + "syn-solidity", +] + +[[package]] +name = "alloy-sol-type-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "715f4d09a330cc181fc7c361b5c5c2766408fa59a0bac60349dcb7baabd404cc" dependencies = [ "winnow 0.6.5", ] [[package]] name = "alloy-sol-types" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad09ec5853fa700d12d778ad224dcdec636af424d29fad84fb9a2f16a5b0ef09" +checksum = "43bc2d6dfc2a19fd56644494479510f98b1ee929e04cf0d4aa45e98baa3e545b" dependencies = [ "alloy-primitives", "alloy-sol-macro", @@ -372,9 +393,9 @@ dependencies = [ [[package]] name = "alloy-trie" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b9e1498416f7e7f09af8061970e14936846b6271e153aa5ba539a22a7eb414d" +checksum = "beb28aa4ecd32fdfa1b1bdd111ff7357dd562c6b2372694cf9e613434fcba659" dependencies = [ "alloy-primitives", "alloy-rlp", @@ -6949,9 +6970,9 @@ dependencies = [ "alloy-genesis", "alloy-primitives", "alloy-rlp", - "alloy-rpc-engine-types", - "alloy-rpc-trace-types", "alloy-rpc-types", + "alloy-rpc-types-engine", + "alloy-rpc-types-trace", "arbitrary", "bytes", "enr", @@ -7172,9 +7193,9 @@ dependencies = [ [[package]] name = "revm" -version = "7.2.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24fd3ed4b62dc61c647552d8b781811ae25ec74d23309055077e4dfb392444d2" +checksum = "72a454c1c650b2b2e23f0c461af09e6c31e1d15e1cbebe905a701c46b8a50afc" dependencies = [ "auto_impl", "cfg-if", @@ -7188,11 +7209,11 @@ dependencies = [ [[package]] name = "revm-inspectors" version = "0.1.0" -source = "git+https://github.com/paradigmxyz/evm-inspectors?rev=0ad0338#0ad033820ff216f854ba08515f6f37ac71aa15d8" +source = "git+https://github.com/paradigmxyz/evm-inspectors?rev=0ef5814#0ef5814ed4df2a1fab17921afb69eccb05f6ef16" dependencies = [ "alloy-primitives", - "alloy-rpc-trace-types", "alloy-rpc-types", + "alloy-rpc-types-trace", "alloy-sol-types", "anstyle", "boa_engine", @@ -7205,9 +7226,9 @@ dependencies = [ [[package]] name = "revm-interpreter" -version = "3.4.0" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f0a1818f8c876b0d71a0714217c34da7df8a42c0462750768779d55680e4554" +checksum = "d322f2730cd300e99d271a1704a2dfb8973d832428f5aa282aaa40e2473b5eec" dependencies = [ "revm-primitives", "serde", @@ -7215,9 +7236,9 @@ dependencies = [ [[package]] name = "revm-precompile" -version = "5.1.0" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a9645a70f1df1e5bd7fa8718b9ba486fac9c3f0467aa6b58e7f590d5f6fd0f7" +checksum = "931f692f3f4fc72ec39d5d270f8e9d208c4a6008de7590ee96cf948e3b6d3f8d" dependencies = [ "aurora-engine-modexp", "c-kzg", @@ -7232,9 +7253,9 @@ dependencies = [ [[package]] name = "revm-primitives" -version = "3.1.0" +version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "323ad597cf75ac9cb1d161be29fcc3562426f0278a1d04741697fca556e1ceea" +checksum = "cbbc9640790cebcb731289afb7a7d96d16ad94afeb64b5d0b66443bd151e79d6" dependencies = [ "alloy-primitives", "auto_impl", @@ -8286,9 +8307,9 @@ dependencies = [ [[package]] name = "syn-solidity" -version = "0.6.4" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb3d0961cd53c23ea94eeec56ba940f636f6394788976e9f16ca5ee0aca7464a" +checksum = "4497156948bd342b52038035a6fa514a89626e37af9d2c52a5e8d8ebcc7ee479" dependencies = [ "paste", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 5393b2a5f..ded02e93d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -250,23 +250,23 @@ reth-trie = { path = "crates/trie" } reth-trie-parallel = { path = "crates/trie-parallel" } # revm -revm = { version = "7.2.0", features = ["std", "secp256k1"], default-features = false } +revm = { version = "8.0.0", features = ["std", "secp256k1"], default-features = false } revm-primitives = { version = "3.1.0", features = ["std"], default-features = false } -revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "0ad0338" } +revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "0ef5814" } # eth alloy-chains = { version = "0.1", feature = ["serde", "rlp", "arbitrary"] } -alloy-primitives = "0.6.4" -alloy-dyn-abi = "0.6.4" -alloy-sol-types = "0.6.4" +alloy-primitives = "0.7.0" +alloy-dyn-abi = "0.7.0" +alloy-sol-types = "0.7.0" alloy-rlp = "0.3.4" alloy-trie = "0.3" -alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "7e39c85" } -alloy-rpc-trace-types = { git = "https://github.com/alloy-rs/alloy", rev = "7e39c85" } -alloy-rpc-engine-types = { git = "https://github.com/alloy-rs/alloy", rev = "7e39c85" } -alloy-genesis = { git = "https://github.com/alloy-rs/alloy", rev = "7e39c85" } -alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy", rev = "7e39c85" } -alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "7e39c85" } +alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "8c9dd0a" } +alloy-rpc-types-trace = { git = "https://github.com/alloy-rs/alloy", rev = "8c9dd0a" } +alloy-rpc-types-engine = { git = "https://github.com/alloy-rs/alloy", rev = "8c9dd0a" } +alloy-genesis = { git = "https://github.com/alloy-rs/alloy", rev = "8c9dd0a" } +alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy", rev = "8c9dd0a" } +alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "8c9dd0a" } # TODO: Remove ethers-core = { version = "2.0.14", default-features = false } diff --git a/crates/primitives/src/log.rs b/crates/primitives/src/log.rs index 4771b32dc..295f4e70c 100644 --- a/crates/primitives/src/log.rs +++ b/crates/primitives/src/log.rs @@ -31,6 +31,12 @@ impl From for Log { } } +impl From for AlloyLog { + fn from(log: Log) -> AlloyLog { + AlloyLog::new_unchecked(log.address, log.topics, log.data) + } +} + /// Calculate receipt logs bloom. pub fn logs_bloom<'a, It>(logs: It) -> Bloom where diff --git a/crates/rpc/rpc-api/src/eth.rs b/crates/rpc/rpc-api/src/eth.rs index 79e2251d6..c878a7e1c 100644 --- a/crates/rpc/rpc-api/src/eth.rs +++ b/crates/rpc/rpc-api/src/eth.rs @@ -4,9 +4,9 @@ use reth_primitives::{ Address, BlockId, BlockNumberOrTag, Bytes, B256, B64, U256, U64, }; use reth_rpc_types::{ - state::StateOverride, AccessListWithGasUsed, BlockOverrides, Bundle, + state::StateOverride, AccessListWithGasUsed, AnyTransactionReceipt, BlockOverrides, Bundle, EIP1186AccountProofResponse, EthCallResponse, FeeHistory, Header, Index, RichBlock, - StateContext, SyncStatus, Transaction, TransactionReceipt, TransactionRequest, Work, + StateContext, SyncStatus, Transaction, TransactionRequest, Work, }; /// Eth rpc interface: @@ -73,8 +73,10 @@ pub trait EthApi { /// Returns all transaction receipts for a given block. #[method(name = "getBlockReceipts")] - async fn block_receipts(&self, block_id: BlockId) - -> RpcResult>>; + async fn block_receipts( + &self, + block_id: BlockId, + ) -> RpcResult>>; /// Returns an uncle block of the given block and index. #[method(name = "getUncleByBlockHashAndIndex")] @@ -137,7 +139,7 @@ pub trait EthApi { /// Returns the receipt of a transaction by transaction hash. #[method(name = "getTransactionReceipt")] - async fn transaction_receipt(&self, hash: B256) -> RpcResult>; + async fn transaction_receipt(&self, hash: B256) -> RpcResult>; /// Returns the balance of the account of given address. #[method(name = "getBalance")] diff --git a/crates/rpc/rpc-api/src/otterscan.rs b/crates/rpc/rpc-api/src/otterscan.rs index 2593a1142..2156765bb 100644 --- a/crates/rpc/rpc-api/src/otterscan.rs +++ b/crates/rpc/rpc-api/src/otterscan.rs @@ -1,8 +1,11 @@ use jsonrpsee::{core::RpcResult, proc_macros::rpc}; use reth_primitives::{Address, BlockId, BlockNumberOrTag, Bytes, TxHash, B256}; use reth_rpc_types::{ - BlockDetails, ContractCreator, InternalOperation, OtsBlockTransactions, TraceEntry, - Transaction, TransactionsWithReceipts, + trace::otterscan::{ + BlockDetails, ContractCreator, InternalOperation, OtsBlockTransactions, TraceEntry, + TransactionsWithReceipts, + }, + Transaction, }; /// Otterscan rpc interface. diff --git a/crates/rpc/rpc-types-compat/src/log.rs b/crates/rpc/rpc-types-compat/src/log.rs index 16d59692c..15261cbf9 100644 --- a/crates/rpc/rpc-types-compat/src/log.rs +++ b/crates/rpc/rpc-types-compat/src/log.rs @@ -4,11 +4,10 @@ #[inline] pub fn from_primitive_log(log: reth_primitives::Log) -> reth_rpc_types::Log { reth_rpc_types::Log { - address: log.address, - topics: log.topics, - data: log.data, + inner: log.into(), block_hash: None, block_number: None, + block_timestamp: None, transaction_hash: None, transaction_index: None, log_index: None, @@ -19,5 +18,5 @@ pub fn from_primitive_log(log: reth_primitives::Log) -> reth_rpc_types::Log { /// Converts from a [reth_rpc_types::Log] to a [reth_primitives::Log] #[inline] pub fn to_primitive_log(log: reth_rpc_types::Log) -> reth_primitives::Log { - reth_primitives::Log { address: log.address, topics: log.topics, data: log.data } + log.inner.into() } diff --git a/crates/rpc/rpc-types-compat/src/transaction/mod.rs b/crates/rpc/rpc-types-compat/src/transaction/mod.rs index d969247fd..518c83bf6 100644 --- a/crates/rpc/rpc-types-compat/src/transaction/mod.rs +++ b/crates/rpc/rpc-types-compat/src/transaction/mod.rs @@ -1,10 +1,7 @@ //! Compatibility functions for rpc `Transaction` type. mod signature; mod typed; -use alloy_rpc_types::{ - other::OtherFields, - request::{TransactionInput, TransactionRequest}, -}; +use alloy_rpc_types::request::{TransactionInput, TransactionRequest}; use reth_primitives::{ BlockNumber, Transaction as PrimitiveTransaction, TransactionKind as PrimitiveTransactionKind, TransactionSignedEcRecovered, TxType, B256, U128, U256, U8, @@ -216,6 +213,5 @@ pub fn transaction_to_call_request(tx: TransactionSignedEcRecovered) -> Transact blob_versioned_hashes, transaction_type: Some(tx_type.into()), sidecar: None, - other: OtherFields::default(), } } diff --git a/crates/rpc/rpc-types/Cargo.toml b/crates/rpc/rpc-types/Cargo.toml index 424600e50..dfb27e9a7 100644 --- a/crates/rpc/rpc-types/Cargo.toml +++ b/crates/rpc/rpc-types/Cargo.toml @@ -16,8 +16,8 @@ workspace = true alloy-rlp = { workspace = true, features = ["arrayvec", "derive"] } alloy-primitives = { workspace = true, features = ["rand", "rlp", "serde"] } alloy-rpc-types = { workspace = true, features = ["jsonrpsee-types"] } -alloy-rpc-trace-types.workspace = true -alloy-rpc-engine-types = { workspace = true, features = ["jsonrpsee-types"] } +alloy-rpc-types-trace.workspace = true +alloy-rpc-types-engine = { workspace = true, features = ["jsonrpsee-types"] } ethereum_ssz_derive = { version = "0.5", optional = true } ethereum_ssz = { version = "0.5", optional = true } alloy-genesis.workspace = true @@ -42,7 +42,7 @@ proptest-derive = { workspace = true, optional = true } [features] default = ["jsonrpsee-types"] arbitrary = ["dep:arbitrary", "dep:proptest-derive", "dep:proptest", "alloy-primitives/arbitrary", "alloy-rpc-types/arbitrary"] -ssz = ["dep:ethereum_ssz" ,"dep:ethereum_ssz_derive", "alloy-primitives/ssz", "alloy-rpc-types/ssz", "alloy-rpc-engine-types/ssz"] +ssz = ["dep:ethereum_ssz" ,"dep:ethereum_ssz_derive", "alloy-primitives/ssz", "alloy-rpc-types/ssz", "alloy-rpc-types-engine/ssz"] [dev-dependencies] diff --git a/crates/rpc/rpc-types/src/admin.rs b/crates/rpc/rpc-types/src/admin.rs index 30ab4185d..aeb44fab6 100644 --- a/crates/rpc/rpc-types/src/admin.rs +++ b/crates/rpc/rpc-types/src/admin.rs @@ -83,7 +83,6 @@ pub struct NetworkStatus { #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct EthProtocolInfo { /// The current difficulty at the head of the chain. - #[serde(deserialize_with = "crate::serde_helpers::json_u256::deserialize_json_u256")] pub difficulty: U256, /// The block hash of the head of the chain. pub head: B256, diff --git a/crates/rpc/rpc-types/src/eth/mod.rs b/crates/rpc/rpc-types/src/eth/mod.rs index bebf0a923..dd36e7fd5 100644 --- a/crates/rpc/rpc-types/src/eth/mod.rs +++ b/crates/rpc/rpc-types/src/eth/mod.rs @@ -3,4 +3,4 @@ pub mod transaction; // re-export -pub use alloy_rpc_engine_types as engine; +pub use alloy_rpc_types_engine as engine; diff --git a/crates/rpc/rpc-types/src/lib.rs b/crates/rpc/rpc-types/src/lib.rs index 414d0b85b..59cf5be09 100644 --- a/crates/rpc/rpc-types/src/lib.rs +++ b/crates/rpc/rpc-types/src/lib.rs @@ -8,13 +8,13 @@ issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/" )] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +#![allow(hidden_glob_reexports)] // TODO rm in followup PR mod admin; pub mod beacon; mod eth; mod mev; mod net; -mod otterscan; mod peer; pub mod relay; mod rpc; @@ -24,9 +24,13 @@ pub use alloy_rpc_types::serde_helpers; // Ethereum specific rpc types coming from alloy. pub use alloy_rpc_types::*; + +/// Type alias for a transaction receipt with a RPC logs. +pub type AnyTransactionReceipt = WithOtherFields>>; + pub mod trace { //! RPC types for trace endpoints and inspectors. - pub use alloy_rpc_trace_types::*; + pub use alloy_rpc_types_trace::*; } // Ethereum specific rpc types related to typed transaction requests and the engine API. pub use eth::{ @@ -40,6 +44,5 @@ pub use eth::{ pub use admin::*; pub use mev::*; pub use net::*; -pub use otterscan::*; pub use peer::*; pub use rpc::*; diff --git a/crates/rpc/rpc-types/src/otterscan.rs b/crates/rpc/rpc-types/src/otterscan.rs deleted file mode 100644 index 3f49d56e8..000000000 --- a/crates/rpc/rpc-types/src/otterscan.rs +++ /dev/null @@ -1,124 +0,0 @@ -#![allow(missing_docs)] - -use crate::{ - serde_helpers::u64_hex, Block, BlockTransactions, Rich, Transaction, TransactionReceipt, -}; -use alloy_primitives::{Address, Bytes, U256}; -use serde::{Deserialize, Serialize}; - -/// Operation type enum for `InternalOperation` struct -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] -pub enum OperationType { - /// Operation Transfer - OpTransfer = 0, - /// Operation Contract self destruct - OpSelfDestruct = 1, - /// Operation Create - OpCreate = 2, - /// Operation Create2 - OpCreate2 = 3, -} - -/// Custom struct for otterscan `getInternalOperations` RPC response -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] -pub struct InternalOperation { - pub r#type: OperationType, - pub from: Address, - pub to: Address, - pub value: U256, -} - -/// Custom struct for otterscan `traceTransaction` RPC response -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] -pub struct TraceEntry { - pub r#type: String, - pub depth: u32, - pub from: Address, - pub to: Address, - pub value: U256, - pub input: Bytes, -} - -/// Internal issuance struct for `BlockDetails` struct -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Default)] -#[serde(rename_all = "camelCase")] -pub struct InternalIssuance { - pub block_reward: U256, - pub uncle_reward: U256, - pub issuance: U256, -} - -/// Custom `Block` struct that includes transaction count for Otterscan responses -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct OtsBlock { - #[serde(flatten)] - pub block: Block, - pub transaction_count: usize, -} - -/// Custom struct for otterscan `getBlockDetails` RPC response -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct BlockDetails { - pub block: OtsBlock, - pub issuance: InternalIssuance, - pub total_fees: U256, -} - -/// Custom transaction receipt struct for otterscan `OtsBlockTransactions` struct -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct OtsTransactionReceipt { - #[serde(flatten)] - pub receipt: TransactionReceipt, - #[serde(with = "u64_hex")] - pub timestamp: u64, -} - -/// Custom struct for otterscan `getBlockTransactions` RPC response -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] -pub struct OtsBlockTransactions { - pub fullblock: OtsBlock, - pub receipts: Vec, -} - -/// Custom struct for otterscan `searchTransactionsAfter`and `searchTransactionsBefore` RPC -/// responses -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct TransactionsWithReceipts { - pub txs: Vec, - pub receipts: Vec, - pub first_page: bool, - pub last_page: bool, -} - -/// Custom struct for otterscan `getContractCreator` RPC responses -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] -pub struct ContractCreator { - pub tx: Transaction, - pub creator: Address, -} - -impl From for OtsBlock { - fn from(block: Block) -> Self { - let transaction_count = match &block.transactions { - BlockTransactions::Full(t) => t.len(), - BlockTransactions::Hashes(t) => t.len(), - BlockTransactions::Uncle => 0, - }; - - Self { block, transaction_count } - } -} - -impl From> for BlockDetails { - fn from(rich_block: Rich) -> Self { - Self { - block: rich_block.inner.into(), - issuance: Default::default(), - total_fees: U256::default(), - } - } -} diff --git a/crates/rpc/rpc/src/eth/api/block.rs b/crates/rpc/rpc/src/eth/api/block.rs index da9afa7c3..308a7f699 100644 --- a/crates/rpc/rpc/src/eth/api/block.rs +++ b/crates/rpc/rpc/src/eth/api/block.rs @@ -11,7 +11,7 @@ use reth_network_api::NetworkInfo; use reth_node_api::ConfigureEvmEnv; use reth_primitives::{BlockId, TransactionMeta}; use reth_provider::{BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, StateProviderFactory}; -use reth_rpc_types::{Header, Index, RichBlock, TransactionReceipt}; +use reth_rpc_types::{AnyTransactionReceipt, Header, Index, RichBlock}; use reth_rpc_types_compat::block::{from_block, uncle_block_from_header}; use reth_transaction_pool::TransactionPool; use std::sync::Arc; @@ -62,7 +62,7 @@ where pub(crate) async fn block_receipts( &self, block_id: BlockId, - ) -> EthResult>> { + ) -> EthResult>> { let mut block_and_receipts = None; if block_id.is_pending() { diff --git a/crates/rpc/rpc/src/eth/api/server.rs b/crates/rpc/rpc/src/eth/api/server.rs index 4e6c854b8..beb61478f 100644 --- a/crates/rpc/rpc/src/eth/api/server.rs +++ b/crates/rpc/rpc/src/eth/api/server.rs @@ -23,9 +23,9 @@ use reth_provider::{ }; use reth_rpc_api::EthApiServer; use reth_rpc_types::{ - state::StateOverride, AccessListWithGasUsed, BlockOverrides, Bundle, + state::StateOverride, AccessListWithGasUsed, AnyTransactionReceipt, BlockOverrides, Bundle, EIP1186AccountProofResponse, EthCallResponse, FeeHistory, Header, Index, RichBlock, - StateContext, SyncStatus, TransactionReceipt, TransactionRequest, Work, + StateContext, SyncStatus, TransactionRequest, Work, }; use reth_transaction_pool::TransactionPool; use serde_json::Value; @@ -128,7 +128,10 @@ where } /// Handler for: `eth_getBlockReceipts` - async fn block_receipts(&self, block_id: BlockId) -> Result>> { + async fn block_receipts( + &self, + block_id: BlockId, + ) -> Result>> { trace!(target: "rpc::eth", ?block_id, "Serving eth_getBlockReceipts"); Ok(EthApi::block_receipts(self, block_id).await?) } @@ -206,7 +209,7 @@ where } /// Handler for: `eth_getTransactionReceipt` - async fn transaction_receipt(&self, hash: B256) -> Result> { + async fn transaction_receipt(&self, hash: B256) -> Result> { trace!(target: "rpc::eth", ?hash, "Serving eth_getTransactionReceipt"); Ok(EthTransactions::transaction_receipt(self, hash).await?) } diff --git a/crates/rpc/rpc/src/eth/api/transactions.rs b/crates/rpc/rpc/src/eth/api/transactions.rs index a6e501a5e..37977411b 100644 --- a/crates/rpc/rpc/src/eth/api/transactions.rs +++ b/crates/rpc/rpc/src/eth/api/transactions.rs @@ -17,7 +17,7 @@ use reth_primitives::{ Address, BlockId, BlockNumberOrTag, Bytes, FromRecoveredPooledTransaction, Header, IntoRecoveredTransaction, Receipt, SealedBlock, SealedBlockWithSenders, TransactionKind::{Call, Create}, - TransactionMeta, TransactionSigned, TransactionSignedEcRecovered, B256, U128, U256, U64, + TransactionMeta, TransactionSigned, TransactionSignedEcRecovered, B256, U256, U64, }; use reth_provider::{ BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, StateProviderBox, StateProviderFactory, @@ -31,8 +31,9 @@ use reth_rpc_types::{ EIP1559TransactionRequest, EIP2930TransactionRequest, EIP4844TransactionRequest, LegacyTransactionRequest, }, - Index, Log, Transaction, TransactionInfo, TransactionKind as RpcTransactionKind, - TransactionReceipt, TransactionRequest, TypedTransactionRequest, + AnyReceiptEnvelope, AnyTransactionReceipt, Index, Log, ReceiptWithBloom, Transaction, + TransactionInfo, TransactionKind as RpcTransactionKind, TransactionReceipt, TransactionRequest, + TypedTransactionRequest, WithOtherFields, }; use reth_rpc_types_compat::transaction::from_recovered_with_block_context; use reth_transaction_pool::{TransactionOrigin, TransactionPool}; @@ -261,7 +262,7 @@ pub trait EthTransactions: Send + Sync { /// /// Returns None if the transaction does not exist or is pending /// Note: The tx receipt is not available for pending transactions. - async fn transaction_receipt(&self, hash: B256) -> EthResult>; + async fn transaction_receipt(&self, hash: B256) -> EthResult>; /// Decodes and recovers the transaction and submits it to the pool. /// @@ -835,7 +836,7 @@ where } } - async fn transaction_receipt(&self, hash: B256) -> EthResult> { + async fn transaction_receipt(&self, hash: B256) -> EthResult> { let result = self .on_blocking_task(|this| async move { let (tx, meta) = match this.provider().transaction_by_hash_with_meta(hash)? { @@ -1436,7 +1437,7 @@ where tx: TransactionSigned, meta: TransactionMeta, receipt: Receipt, - ) -> EthResult { + ) -> EthResult { // get all receipts for the block let all_receipts = match self.cache().get_receipts(meta.block_hash).await? { Some(recpts) => recpts, @@ -1454,7 +1455,7 @@ where tx: TransactionSigned, meta: TransactionMeta, receipt: Receipt, - ) -> EthResult { + ) -> EthResult { let (block, receipts) = self .cache() .get_block_and_receipts(meta.block_hash) @@ -1706,7 +1707,7 @@ pub(crate) fn build_transaction_receipt_with_block_receipts( receipt: Receipt, all_receipts: &[Receipt], #[cfg(feature = "optimism")] optimism_tx_meta: OptimismTxMeta, -) -> EthResult { +) -> EthResult { // Note: we assume this transaction is valid, because it's mined (or part of pending block) and // we don't need to check for pre EIP-2 let from = @@ -1723,34 +1724,60 @@ pub(crate) fn build_transaction_receipt_with_block_receipts( .unwrap_or_default() }; - let blob_gas_used = transaction.transaction.blob_gas_used().map(U128::from); + let blob_gas_used = transaction.transaction.blob_gas_used(); // Blob gas price should only be present if the transaction is a blob transaction - let blob_gas_price = - blob_gas_used.and_then(|_| meta.excess_blob_gas.map(calc_blob_gasprice).map(U128::from)); + let blob_gas_price = blob_gas_used.and_then(|_| meta.excess_blob_gas.map(calc_blob_gasprice)); + let logs_bloom = receipt.bloom_slow(); + + // get number of logs in the block + let mut num_logs = 0; + for prev_receipt in all_receipts.iter().take(meta.index as usize) { + num_logs += prev_receipt.logs.len(); + } + + let mut logs = Vec::with_capacity(receipt.logs.len()); + for (tx_log_idx, log) in receipt.logs.into_iter().enumerate() { + let rpclog = Log { + inner: log.into(), + block_hash: Some(meta.block_hash), + block_number: Some(meta.block_number), + block_timestamp: None, + transaction_hash: Some(meta.tx_hash), + transaction_index: Some(meta.index), + log_index: Some((num_logs + tx_log_idx) as u64), + removed: false, + }; + logs.push(rpclog); + } + + let rpc_receipt = reth_rpc_types::Receipt { + status: receipt.success, + cumulative_gas_used: receipt.cumulative_gas_used, + logs, + }; #[allow(clippy::needless_update)] - let mut res_receipt = TransactionReceipt { + let res_receipt = TransactionReceipt { + inner: AnyReceiptEnvelope { + inner: ReceiptWithBloom { receipt: rpc_receipt, logs_bloom }, + r#type: transaction.transaction.tx_type().into(), + }, transaction_hash: meta.tx_hash, - transaction_index: U64::from(meta.index), + transaction_index: meta.index, block_hash: Some(meta.block_hash), - block_number: Some(U256::from(meta.block_number)), + block_number: Some(meta.block_number), from, to: None, - cumulative_gas_used: U256::from(receipt.cumulative_gas_used), - gas_used: Some(U256::from(gas_used)), + gas_used: Some(gas_used), contract_address: None, - logs: Vec::with_capacity(receipt.logs.len()), - effective_gas_price: U128::from(transaction.effective_gas_price(meta.base_fee)), - transaction_type: transaction.transaction.tx_type().into(), + effective_gas_price: transaction.effective_gas_price(meta.base_fee) as u64, // TODO pre-byzantium receipts have a post-transaction state root state_root: None, - logs_bloom: receipt.bloom_slow(), - status_code: if receipt.success { Some(U64::from(1)) } else { Some(U64::from(0)) }, // EIP-4844 fields - blob_gas_price, + blob_gas_price: blob_gas_price.map(|gas| gas as u64), blob_gas_used, - ..Default::default() }; + let mut res_receipt = WithOtherFields::new(res_receipt); #[cfg(feature = "optimism")] { @@ -1781,27 +1808,6 @@ pub(crate) fn build_transaction_receipt_with_block_receipts( } } - // get number of logs in the block - let mut num_logs = 0; - for prev_receipt in all_receipts.iter().take(meta.index as usize) { - num_logs += prev_receipt.logs.len(); - } - - for (tx_log_idx, log) in receipt.logs.into_iter().enumerate() { - let rpclog = Log { - address: log.address, - topics: log.topics, - data: log.data, - block_hash: Some(meta.block_hash), - block_number: Some(U256::from(meta.block_number)), - transaction_hash: Some(meta.tx_hash), - transaction_index: Some(U256::from(meta.index)), - log_index: Some(U256::from(num_logs + tx_log_idx)), - removed: false, - }; - res_receipt.logs.push(rpclog); - } - Ok(res_receipt) } diff --git a/crates/rpc/rpc/src/eth/logs_utils.rs b/crates/rpc/rpc/src/eth/logs_utils.rs index c3f37202a..6e58040f0 100644 --- a/crates/rpc/rpc/src/eth/logs_utils.rs +++ b/crates/rpc/rpc/src/eth/logs_utils.rs @@ -1,6 +1,6 @@ use super::filter::FilterError; use alloy_primitives::TxHash; -use reth_primitives::{BlockNumHash, ChainInfo, Receipt, U256}; +use reth_primitives::{BlockNumHash, ChainInfo, Receipt}; use reth_provider::{BlockReader, ProviderError}; use reth_rpc_types::{FilteredParams, Log}; @@ -16,22 +16,21 @@ where { let mut all_logs = Vec::new(); // Tracks the index of a log in the entire block. - let mut log_index: u32 = 0; + let mut log_index: u64 = 0; // Iterate over transaction hashes and receipts and append matching logs. for (receipt_idx, (tx_hash, receipt)) in tx_hashes_and_receipts.into_iter().enumerate() { for log in receipt.logs.iter() { if log_matches_filter(block_num_hash, log, filter) { let log = Log { - address: log.address, - topics: log.topics.clone(), - data: log.data.clone(), + inner: log.clone().into(), block_hash: Some(block_num_hash.hash), - block_number: Some(U256::from(block_num_hash.number)), + block_number: Some(block_num_hash.number), transaction_hash: Some(tx_hash), // The transaction and receipt index is always the same. - transaction_index: Some(U256::from(receipt_idx)), - log_index: Some(U256::from(log_index)), + transaction_index: Some(receipt_idx as u64), + log_index: Some(log_index), removed, + block_timestamp: None, }; all_logs.push(log); } @@ -52,7 +51,7 @@ pub(crate) fn append_matching_block_logs( removed: bool, ) -> Result<(), FilterError> { // Tracks the index of a log in the entire block. - let mut log_index: u32 = 0; + let mut log_index: u64 = 0; // Lazy loaded number of the first transaction in the block. // This is useful for blocks with multiple matching logs because it prevents @@ -90,16 +89,15 @@ pub(crate) fn append_matching_block_logs( } let log = Log { - address: log.address, - topics: log.topics.clone(), - data: log.data.clone(), + inner: log.clone().into(), block_hash: Some(block_num_hash.hash), - block_number: Some(U256::from(block_num_hash.number)), + block_number: Some(block_num_hash.number), transaction_hash, // The transaction and receipt index is always the same. - transaction_index: Some(U256::from(receipt_idx)), - log_index: Some(U256::from(log_index)), + transaction_index: Some(receipt_idx as u64), + log_index: Some(log_index), removed, + block_timestamp: None, }; all_logs.push(log); } @@ -154,10 +152,10 @@ pub(crate) fn get_filter_block_range( #[cfg(test)] mod tests { - use super::*; - use reth_rpc_types::Filter; + use super::*; + #[test] fn test_log_range_from_and_to() { let from = 14000000u64; diff --git a/crates/rpc/rpc/src/otterscan.rs b/crates/rpc/rpc/src/otterscan.rs index 206c1b6f6..28f5f02c2 100644 --- a/crates/rpc/rpc/src/otterscan.rs +++ b/crates/rpc/rpc/src/otterscan.rs @@ -8,8 +8,11 @@ use revm_primitives::ExecutionResult; use reth_primitives::{Address, BlockId, BlockNumberOrTag, TxHash, B256}; use reth_rpc_api::{EthApiServer, OtterscanServer}; use reth_rpc_types::{ - BlockDetails, BlockTransactions, ContractCreator, InternalOperation, OperationType, - OtsBlockTransactions, OtsTransactionReceipt, TraceEntry, Transaction, TransactionsWithReceipts, + trace::otterscan::{ + BlockDetails, ContractCreator, InternalOperation, OperationType, OtsBlockTransactions, + OtsReceipt, OtsTransactionReceipt, TraceEntry, TransactionsWithReceipts, + }, + BlockTransactions, Transaction, TransactionReceipt, }; use crate::{eth::EthTransactions, result::internal_rpc_err}; @@ -155,10 +158,48 @@ where } // Crop receipts and transform them into OtsTransactionReceipt - let timestamp = u64::try_from(block.header.timestamp).unwrap_or(u64::MAX); + let timestamp = Some(u64::try_from(block.header.timestamp).unwrap_or(u64::MAX)); let receipts = receipts .drain(page_start..page_end) - .map(|receipt| OtsTransactionReceipt { receipt, timestamp }) + .map(|receipt| { + let TransactionReceipt { + inner, + transaction_hash, + transaction_index, + block_hash, + block_number, + gas_used, + effective_gas_price, + blob_gas_used, + blob_gas_price, + from, + to, + contract_address, + state_root, + } = receipt.inner; + let receipt = TransactionReceipt { + inner: OtsReceipt { + status: inner.inner.receipt.status, + cumulative_gas_used: inner.inner.receipt.cumulative_gas_used, + logs: None, + logs_bloom: None, + r#type: inner.r#type, + }, + transaction_hash, + transaction_index, + block_hash, + block_number, + gas_used, + effective_gas_price, + blob_gas_used, + blob_gas_price, + from, + to, + contract_address, + state_root, + }; + OtsTransactionReceipt { receipt, timestamp } + }) .collect(); Ok(OtsBlockTransactions { fullblock: block.inner.into(), receipts }) }