Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Nov 3, 2024
1 parent 00de90f commit 9e1e4b9
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 81 deletions.
6 changes: 1 addition & 5 deletions crates/consensus/debug-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> = 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(),
Expand Down
8 changes: 1 addition & 7 deletions crates/optimism/chainspec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions crates/primitives-traits/src/header/sealed.rs
Original file line number Diff line number Diff line change
@@ -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"))]
Expand Down Expand Up @@ -132,6 +133,12 @@ impl SealedHeader {
}
}

impl<H> From<SealedHeader<H>> for Sealed<H> {
fn from(value: SealedHeader<H>) -> 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<Self> {
Expand Down
14 changes: 1 addition & 13 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
5 changes: 0 additions & 5 deletions crates/primitives/src/transaction/pooled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
11 changes: 6 additions & 5 deletions crates/rpc/rpc-api/src/otterscan.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<T: RpcObject, H: RpcObject> {
pub trait Otterscan<T: RpcObject> {
/// Get the block header by block number, required by otterscan.
/// Otterscan currently requires this endpoint, used as:
///
Expand All @@ -19,7 +20,7 @@ pub trait Otterscan<T: RpcObject, H: RpcObject> {
///
/// Ref: <https://github.com/otterscan/otterscan/blob/071d8c55202badf01804f6f8d53ef9311d4a9e47/src/useProvider.ts#L71>
#[method(name = "getHeaderByNumber", aliases = ["erigon_getHeaderByNumber"])]
async fn get_header_by_number(&self, block_number: u64) -> RpcResult<Option<H>>;
async fn get_header_by_number(&self, block_number: u64) -> RpcResult<Option<Header>>;

/// Check if a certain address contains a deployed code.
#[method(name = "hasCode")]
Expand Down Expand Up @@ -47,11 +48,11 @@ pub trait Otterscan<T: RpcObject, H: RpcObject> {
/// 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<BlockDetails<H>>;
async fn get_block_details(&self, block_number: u64) -> RpcResult<BlockDetails>;

/// 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<BlockDetails<H>>;
async fn get_block_details_by_hash(&self, block_hash: B256) -> RpcResult<BlockDetails>;

/// Get paginated transactions for a certain block. Also remove some verbose fields like logs.
#[method(name = "getBlockTransactions")]
Expand All @@ -60,7 +61,7 @@ pub trait Otterscan<T: RpcObject, H: RpcObject> {
block_number: u64,
page_number: usize,
page_size: usize,
) -> RpcResult<OtsBlockTransactions<T, H>>;
) -> RpcResult<OtsBlockTransactions<T>>;

/// Gets paginated inbound/outbound transaction calls for a certain address.
#[method(name = "searchTransactionsBefore")]
Expand Down
34 changes: 15 additions & 19 deletions crates/rpc/rpc-builder/tests/it/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -399,32 +399,28 @@ where
let nonce = 1;
let block_hash = B256::default();

OtterscanClient::<Transaction, Header>::get_header_by_number(client, block_number)
.await
.unwrap();
OtterscanClient::<Transaction>::get_header_by_number(client, block_number).await.unwrap();

OtterscanClient::<Transaction, Header>::has_code(client, address, None).await.unwrap();
OtterscanClient::<Transaction, Header>::has_code(client, address, Some(block_number.into()))
OtterscanClient::<Transaction>::has_code(client, address, None).await.unwrap();
OtterscanClient::<Transaction>::has_code(client, address, Some(block_number.into()))
.await
.unwrap();

OtterscanClient::<Transaction, Header>::get_api_level(client).await.unwrap();
OtterscanClient::<Transaction>::get_api_level(client).await.unwrap();

OtterscanClient::<Transaction, Header>::get_internal_operations(client, tx_hash).await.unwrap();
OtterscanClient::<Transaction>::get_internal_operations(client, tx_hash).await.unwrap();

OtterscanClient::<Transaction, Header>::get_transaction_error(client, tx_hash).await.unwrap();
OtterscanClient::<Transaction>::get_transaction_error(client, tx_hash).await.unwrap();

OtterscanClient::<Transaction, Header>::trace_transaction(client, tx_hash).await.unwrap();
OtterscanClient::<Transaction>::trace_transaction(client, tx_hash).await.unwrap();

OtterscanClient::<Transaction, Header>::get_block_details(client, block_number)
.await
.unwrap_err();
OtterscanClient::<Transaction>::get_block_details(client, block_number).await.unwrap_err();

OtterscanClient::<Transaction, Header>::get_block_details_by_hash(client, block_hash)
OtterscanClient::<Transaction>::get_block_details_by_hash(client, block_hash)
.await
.unwrap_err();

OtterscanClient::<Transaction, Header>::get_block_transactions(
OtterscanClient::<Transaction>::get_block_transactions(
client,
block_number,
page_number,
Expand All @@ -435,7 +431,7 @@ where
.unwrap();

assert!(is_unimplemented(
OtterscanClient::<Transaction, Header>::search_transactions_before(
OtterscanClient::<Transaction>::search_transactions_before(
client,
address,
block_number,
Expand All @@ -446,7 +442,7 @@ where
.unwrap()
));
assert!(is_unimplemented(
OtterscanClient::<Transaction, Header>::search_transactions_after(
OtterscanClient::<Transaction>::search_transactions_after(
client,
address,
block_number,
Expand All @@ -456,13 +452,13 @@ where
.err()
.unwrap()
));
assert!(OtterscanClient::<Transaction, Header>::get_transaction_by_sender_and_nonce(
assert!(OtterscanClient::<Transaction>::get_transaction_by_sender_and_nonce(
client, sender, nonce
)
.await
.err()
.is_none());
assert!(OtterscanClient::<Transaction, Header>::get_contract_creator(client, address)
assert!(OtterscanClient::<Transaction>::get_contract_creator(client, address)
.await
.unwrap()
.is_none());
Expand Down
15 changes: 1 addition & 14 deletions crates/rpc/rpc-eth-api/src/helpers/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down
11 changes: 0 additions & 11 deletions crates/rpc/rpc-types-compat/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,6 @@ pub fn from_block_full<T: TransactionCompat>(
))
}

/// 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<T>(
block_length: usize,
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc/src/eth/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ where
self.chain_events.canonical_state_stream().flat_map(|new_chain| {
let headers = new_chain.committed().headers().collect::<Vec<_>>();
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)),
)
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc/src/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ where
}

#[async_trait]
impl<Eth> OtterscanServer<RpcTransaction<Eth::NetworkTypes>, Header> for OtterscanApi<Eth>
impl<Eth> OtterscanServer<RpcTransaction<Eth::NetworkTypes>> for OtterscanApi<Eth>
where
Eth: EthApiServer<
RpcTransaction<Eth::NetworkTypes>,
Expand Down

0 comments on commit 9e1e4b9

Please sign in to comment.