diff --git a/crates/consensus/debug-client/src/client.rs b/crates/consensus/debug-client/src/client.rs index 7ef79d515809a..a237ba084f14d 100644 --- a/crates/consensus/debug-client/src/client.rs +++ b/crates/consensus/debug-client/src/client.rs @@ -206,11 +206,7 @@ pub fn block_to_execution_payload_v3(block: Block) -> ExecutionNewPayload { block_hash: block.header.hash, transactions: transactions .into_iter() - .map(|tx| { - let mut buffer: Vec = vec![]; - tx.inner.encode_2718(&mut buffer); - buffer.into() - }) + .map(|tx| tx.inner.encoded_2718().into()) .collect(), }, withdrawals: block.withdrawals.clone().unwrap_or_default().to_vec(), diff --git a/crates/optimism/chainspec/src/lib.rs b/crates/optimism/chainspec/src/lib.rs index 4b116a8d7b9f1..a60a9a22abc22 100644 --- a/crates/optimism/chainspec/src/lib.rs +++ b/crates/optimism/chainspec/src/lib.rs @@ -20,7 +20,7 @@ mod op_sepolia; use alloc::{boxed::Box, vec, vec::Vec}; use alloy_chains::Chain; use alloy_genesis::Genesis; -use alloy_primitives::{Bytes, PrimitiveSignature as Signature, B256, U256}; +use alloy_primitives::{Bytes, B256, U256}; pub use base::BASE_MAINNET; pub use base_sepolia::BASE_SEPOLIA; use derive_more::{Constructor, Deref, Display, From, Into}; @@ -256,12 +256,6 @@ pub fn decode_holocene_1559_params(extra_data: Bytes) -> Result<(u32, u32), Deco Ok((u32::from_be_bytes(denominator), u32::from_be_bytes(elasticity))) } -/// Returns the signature for the optimism deposit transactions, which don't include a -/// signature. -pub fn optimism_deposit_tx_signature() -> Signature { - Signature::new(U256::ZERO, U256::ZERO, false) -} - impl EthChainSpec for OpChainSpec { fn chain(&self) -> alloy_chains::Chain { self.inner.chain() diff --git a/crates/primitives-traits/src/header/sealed.rs b/crates/primitives-traits/src/header/sealed.rs index 7119a37e742aa..7552ece31f103 100644 --- a/crates/primitives-traits/src/header/sealed.rs +++ b/crates/primitives-traits/src/header/sealed.rs @@ -1,4 +1,5 @@ use super::Header; +use alloy_consensus::Sealed; use alloy_eips::BlockNumHash; use alloy_primitives::{keccak256, BlockHash, Sealable}; #[cfg(any(test, feature = "test-utils"))] @@ -132,6 +133,12 @@ impl SealedHeader { } } +impl From> for Sealed { + fn from(value: SealedHeader) -> Self { + Self::new_unchecked(value.header, value.hash) + } +} + #[cfg(any(test, feature = "arbitrary"))] impl<'a> arbitrary::Arbitrary<'a> for SealedHeader { fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index 0525c050baddb..73ba4baf75459 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -1442,19 +1442,7 @@ impl Encodable2718 for TransactionSigned { } fn encode_2718(&self, out: &mut dyn alloy_rlp::BufMut) { - match &self.transaction { - Transaction::Legacy(legacy_tx) => legacy_tx.eip2718_encode(&self.signature, out), - Transaction::Eip2930(access_list_tx) => { - access_list_tx.eip2718_encode(&self.signature, out) - } - Transaction::Eip1559(dynamic_fee_tx) => { - dynamic_fee_tx.eip2718_encode(&self.signature, out) - } - Transaction::Eip4844(blob_tx) => blob_tx.eip2718_encode(&self.signature, out), - Transaction::Eip7702(set_code_tx) => set_code_tx.eip2718_encode(&self.signature, out), - #[cfg(feature = "optimism")] - Transaction::Deposit(deposit_tx) => deposit_tx.eip2718_encode(out), - } + self.transaction.eip2718_encode(&self.signature, out) } } diff --git a/crates/primitives/src/transaction/pooled.rs b/crates/primitives/src/transaction/pooled.rs index d41e703265c15..9bf40cd45157b 100644 --- a/crates/primitives/src/transaction/pooled.rs +++ b/crates/primitives/src/transaction/pooled.rs @@ -399,23 +399,18 @@ impl Encodable2718 for PooledTransactionsElement { fn encode_2718_len(&self) -> usize { match self { Self::Legacy { transaction, signature, .. } => { - // method computes the payload len with a RLP header transaction.eip2718_encoded_length(signature) } Self::Eip2930 { transaction, signature, .. } => { - // method computes the payload len without a RLP header transaction.eip2718_encoded_length(signature) } Self::Eip1559 { transaction, signature, .. } => { - // method computes the payload len without a RLP header transaction.eip2718_encoded_length(signature) } Self::Eip7702 { transaction, signature, .. } => { - // method computes the payload len without a RLP header transaction.eip2718_encoded_length(signature) } Self::BlobTransaction(BlobTransaction { transaction, signature, .. }) => { - // the encoding does not use a header, so we set `with_header` to false transaction.eip2718_encoded_length(signature) } } diff --git a/crates/rpc/rpc-api/src/otterscan.rs b/crates/rpc/rpc-api/src/otterscan.rs index 62e5676fe5086..ee805b482c34f 100644 --- a/crates/rpc/rpc-api/src/otterscan.rs +++ b/crates/rpc/rpc-api/src/otterscan.rs @@ -1,5 +1,6 @@ use alloy_json_rpc::RpcObject; use alloy_primitives::{Address, Bytes, TxHash, B256}; +use alloy_rpc_types::Header; use alloy_rpc_types_trace::otterscan::{ BlockDetails, ContractCreator, InternalOperation, OtsBlockTransactions, TraceEntry, TransactionsWithReceipts, @@ -10,7 +11,7 @@ use reth_primitives::BlockId; /// Otterscan rpc interface. #[cfg_attr(not(feature = "client"), rpc(server, namespace = "ots"))] #[cfg_attr(feature = "client", rpc(server, client, namespace = "ots"))] -pub trait Otterscan { +pub trait Otterscan { /// Get the block header by block number, required by otterscan. /// Otterscan currently requires this endpoint, used as: /// @@ -19,7 +20,7 @@ pub trait Otterscan { /// /// Ref: #[method(name = "getHeaderByNumber", aliases = ["erigon_getHeaderByNumber"])] - async fn get_header_by_number(&self, block_number: u64) -> RpcResult>; + async fn get_header_by_number(&self, block_number: u64) -> RpcResult>; /// Check if a certain address contains a deployed code. #[method(name = "hasCode")] @@ -47,11 +48,11 @@ pub trait Otterscan { /// Tailor-made and expanded version of eth_getBlockByNumber for block details page in /// Otterscan. #[method(name = "getBlockDetails")] - async fn get_block_details(&self, block_number: u64) -> RpcResult>; + async fn get_block_details(&self, block_number: u64) -> RpcResult; /// Tailor-made and expanded version of eth_getBlockByHash for block details page in Otterscan. #[method(name = "getBlockDetailsByHash")] - async fn get_block_details_by_hash(&self, block_hash: B256) -> RpcResult>; + async fn get_block_details_by_hash(&self, block_hash: B256) -> RpcResult; /// Get paginated transactions for a certain block. Also remove some verbose fields like logs. #[method(name = "getBlockTransactions")] @@ -60,7 +61,7 @@ pub trait Otterscan { block_number: u64, page_number: usize, page_size: usize, - ) -> RpcResult>; + ) -> RpcResult>; /// Gets paginated inbound/outbound transaction calls for a certain address. #[method(name = "searchTransactionsBefore")] diff --git a/crates/rpc/rpc-builder/tests/it/http.rs b/crates/rpc/rpc-builder/tests/it/http.rs index 89aafce9f36fb..ed9ef56d62bf6 100644 --- a/crates/rpc/rpc-builder/tests/it/http.rs +++ b/crates/rpc/rpc-builder/tests/it/http.rs @@ -4,7 +4,7 @@ use crate::utils::{launch_http, launch_http_ws, launch_ws}; use alloy_primitives::{hex_literal::hex, Address, Bytes, TxHash, B256, B64, U256, U64}; use alloy_rpc_types_eth::{ - transaction::TransactionRequest, Block, FeeHistory, Filter, Header, Index, Log, + transaction::TransactionRequest, Block, FeeHistory, Filter, Index, Log, PendingTransactionFilterKind, SyncStatus, Transaction, TransactionReceipt, }; use alloy_rpc_types_trace::filter::TraceFilter; @@ -399,32 +399,28 @@ where let nonce = 1; let block_hash = B256::default(); - OtterscanClient::::get_header_by_number(client, block_number) - .await - .unwrap(); + OtterscanClient::::get_header_by_number(client, block_number).await.unwrap(); - OtterscanClient::::has_code(client, address, None).await.unwrap(); - OtterscanClient::::has_code(client, address, Some(block_number.into())) + OtterscanClient::::has_code(client, address, None).await.unwrap(); + OtterscanClient::::has_code(client, address, Some(block_number.into())) .await .unwrap(); - OtterscanClient::::get_api_level(client).await.unwrap(); + OtterscanClient::::get_api_level(client).await.unwrap(); - OtterscanClient::::get_internal_operations(client, tx_hash).await.unwrap(); + OtterscanClient::::get_internal_operations(client, tx_hash).await.unwrap(); - OtterscanClient::::get_transaction_error(client, tx_hash).await.unwrap(); + OtterscanClient::::get_transaction_error(client, tx_hash).await.unwrap(); - OtterscanClient::::trace_transaction(client, tx_hash).await.unwrap(); + OtterscanClient::::trace_transaction(client, tx_hash).await.unwrap(); - OtterscanClient::::get_block_details(client, block_number) - .await - .unwrap_err(); + OtterscanClient::::get_block_details(client, block_number).await.unwrap_err(); - OtterscanClient::::get_block_details_by_hash(client, block_hash) + OtterscanClient::::get_block_details_by_hash(client, block_hash) .await .unwrap_err(); - OtterscanClient::::get_block_transactions( + OtterscanClient::::get_block_transactions( client, block_number, page_number, @@ -435,7 +431,7 @@ where .unwrap(); assert!(is_unimplemented( - OtterscanClient::::search_transactions_before( + OtterscanClient::::search_transactions_before( client, address, block_number, @@ -446,7 +442,7 @@ where .unwrap() )); assert!(is_unimplemented( - OtterscanClient::::search_transactions_after( + OtterscanClient::::search_transactions_after( client, address, block_number, @@ -456,13 +452,13 @@ where .err() .unwrap() )); - assert!(OtterscanClient::::get_transaction_by_sender_and_nonce( + assert!(OtterscanClient::::get_transaction_by_sender_and_nonce( client, sender, nonce ) .await .err() .is_none()); - assert!(OtterscanClient::::get_contract_creator(client, address) + assert!(OtterscanClient::::get_contract_creator(client, address) .await .unwrap() .is_none()); diff --git a/crates/rpc/rpc-eth-api/src/helpers/block.rs b/crates/rpc/rpc-eth-api/src/helpers/block.rs index 090f2ab0d562c..288f5dfc0f192 100644 --- a/crates/rpc/rpc-eth-api/src/helpers/block.rs +++ b/crates/rpc/rpc-eth-api/src/helpers/block.rs @@ -188,20 +188,7 @@ pub trait EthBlocks: LoadBlock { } .unwrap_or_default(); - Ok(uncles.into_iter().nth(index.into()).map(|uncle| { - let block = Block::uncle_from_header(uncle); - Block { - header: Header { - inner: block.header.inner, - size: block.header.size, - total_difficulty: block.header.total_difficulty, - hash: block.header.hash, - }, - uncles: block.uncles, - transactions: block.transactions, - withdrawals: block.withdrawals, - } - })) + Ok(uncles.into_iter().nth(index.into()).map(Block::uncle_from_header)) } } } diff --git a/crates/rpc/rpc-types-compat/src/block.rs b/crates/rpc/rpc-types-compat/src/block.rs index c56c51f5ad2c1..3b297ba0bc36c 100644 --- a/crates/rpc/rpc-types-compat/src/block.rs +++ b/crates/rpc/rpc-types-compat/src/block.rs @@ -99,17 +99,6 @@ pub fn from_block_full( )) } -/// Converts from a [`reth_primitives::SealedHeader`] to a [`alloy-rpc-types::Header`] -/// -/// # Note -/// -/// This does not set the `totalDifficulty` field. -pub fn from_primitive_with_hash(primitive_header: reth_primitives::SealedHeader) -> Header { - let (inner, hash) = primitive_header.split(); - - Header { hash, inner, total_difficulty: None, size: None } -} - #[inline] fn from_block_with_transactions( block_length: usize, diff --git a/crates/rpc/rpc/src/eth/pubsub.rs b/crates/rpc/rpc/src/eth/pubsub.rs index 663ec0b99d6da..922694cdba63e 100644 --- a/crates/rpc/rpc/src/eth/pubsub.rs +++ b/crates/rpc/rpc/src/eth/pubsub.rs @@ -329,7 +329,7 @@ where self.chain_events.canonical_state_stream().flat_map(|new_chain| { let headers = new_chain.committed().headers().collect::>(); futures::stream::iter( - headers.into_iter().map(reth_rpc_types_compat::block::from_primitive_with_hash), + headers.into_iter().map(|h| Header::from_consensus(h.into(), None, None)), ) }) } diff --git a/crates/rpc/rpc/src/otterscan.rs b/crates/rpc/rpc/src/otterscan.rs index 7a7ac8923bdb9..133240516ac74 100644 --- a/crates/rpc/rpc/src/otterscan.rs +++ b/crates/rpc/rpc/src/otterscan.rs @@ -61,7 +61,7 @@ where } #[async_trait] -impl OtterscanServer, Header> for OtterscanApi +impl OtterscanServer> for OtterscanApi where Eth: EthApiServer< RpcTransaction,