From cad73819b2a1f1839b064afda3aeab20696c5776 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Thu, 3 Aug 2023 16:37:01 +0200 Subject: [PATCH] tmp: dummy RLP impls --- crates/net/discv4/src/proto.rs | 12 +++++-- crates/net/eth-wire/src/types/blocks.rs | 4 ++- crates/net/eth-wire/src/types/broadcast.rs | 13 +++++--- crates/net/eth-wire/src/types/receipts.rs | 3 +- crates/net/eth-wire/src/types/state.rs | 3 +- crates/net/eth-wire/src/types/status.rs | 4 ++- crates/net/eth-wire/src/types/transactions.rs | 8 +++-- crates/primitives/src/lib.rs | 33 +++++++++++++++++++ crates/primitives/src/log.rs | 4 ++- .../primitives/src/transaction/access_list.rs | 4 ++- crates/primitives/src/transaction/mod.rs | 8 +++-- crates/primitives/src/withdrawal.rs | 4 ++- crates/trie/src/account.rs | 4 ++- 13 files changed, 84 insertions(+), 20 deletions(-) diff --git a/crates/net/discv4/src/proto.rs b/crates/net/discv4/src/proto.rs index bd0ad5f1cf58..cdbdd6c54132 100644 --- a/crates/net/discv4/src/proto.rs +++ b/crates/net/discv4/src/proto.rs @@ -289,12 +289,14 @@ pub struct EnrRequest { } /// A [ENRResponse packet](https://github.com/ethereum/devp2p/blob/master/discv4.md#enrresponse-packet-0x06). -#[derive(Clone, Debug, Eq, PartialEq, RlpEncodable, RlpDecodable)] +#[derive(Clone, Debug, Eq, PartialEq)] pub struct EnrResponse { pub request_hash: H256, pub enr: EnrWrapper, } +reth_primitives::dummy_rlp!(EnrResponse); + // === impl EnrResponse === impl EnrResponse { @@ -308,7 +310,7 @@ impl EnrResponse { } /// A [Ping packet](https://github.com/ethereum/devp2p/blob/master/discv4.md#ping-packet-0x01). -#[derive(Debug, Clone, Eq, PartialEq, RlpEncodable, RlpDecodable)] +#[derive(Debug, Clone, Eq, PartialEq)] // #[rlp(trailing)] pub struct Ping { pub version: u32, @@ -319,8 +321,10 @@ pub struct Ping { pub enr_sq: Option, } +reth_primitives::dummy_rlp!(Ping); + /// A [Pong packet](https://github.com/ethereum/devp2p/blob/master/discv4.md#pong-packet-0x02). -#[derive(Clone, Debug, Eq, PartialEq, RlpEncodable, RlpDecodable)] +#[derive(Clone, Debug, Eq, PartialEq)] // #[rlp(trailing)] pub struct Pong { pub to: NodeEndpoint, @@ -330,6 +334,8 @@ pub struct Pong { pub enr_sq: Option, } +reth_primitives::dummy_rlp!(Pong); + #[cfg(test)] mod tests { use super::*; diff --git a/crates/net/eth-wire/src/types/blocks.rs b/crates/net/eth-wire/src/types/blocks.rs index b12bbf889a64..b5583584df01 100644 --- a/crates/net/eth-wire/src/types/blocks.rs +++ b/crates/net/eth-wire/src/types/blocks.rs @@ -53,13 +53,15 @@ impl From> for BlockHeaders { /// A request for a peer to return block bodies for the given block hashes. #[derive_arbitrary(rlp)] -#[derive(Clone, Debug, Default, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper)] +#[derive(Clone, Debug, PartialEq, Eq, Default)] // RlpEncodableWrapper, RlpDecodableWrapper #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct GetBlockBodies( /// The block hashes to request bodies for. pub Vec, ); +reth_primitives::dummy_rlp!(GetBlockBodies); + impl From> for GetBlockBodies { fn from(hashes: Vec) -> Self { GetBlockBodies(hashes) diff --git a/crates/net/eth-wire/src/types/broadcast.rs b/crates/net/eth-wire/src/types/broadcast.rs index 32c5baff16be..9c841f2db773 100644 --- a/crates/net/eth-wire/src/types/broadcast.rs +++ b/crates/net/eth-wire/src/types/broadcast.rs @@ -37,7 +37,7 @@ impl NewBlockHashes { /// A block hash _and_ a block number. #[derive_arbitrary(rlp)] -#[derive(Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)] +#[derive(Clone, Debug, PartialEq, Eq, Default)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct BlockHashNumber { /// The block hash @@ -46,6 +46,8 @@ pub struct BlockHashNumber { pub number: u64, } +reth_primitives::dummy_rlp!(BlockHashNumber); + impl From> for NewBlockHashes { fn from(v: Vec) -> Self { NewBlockHashes(v) @@ -207,7 +209,7 @@ impl From for NewPooledTransactionHashes { /// This informs peers of transaction hashes for transactions that have appeared on the network, /// but have not been included in a block. #[derive_arbitrary(rlp)] -#[derive(Clone, Debug, Default, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper)] +#[derive(Clone, Debug, Default, PartialEq, Eq)] // RlpEncodableWrapper, RlpDecodableWrapper #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct NewPooledTransactionHashes66( /// Transaction hashes for new transactions that have appeared on the network. @@ -216,6 +218,8 @@ pub struct NewPooledTransactionHashes66( pub Vec, ); +reth_primitives::dummy_rlp!(NewPooledTransactionHashes66); + impl From> for NewPooledTransactionHashes66 { fn from(v: Vec) -> Self { NewPooledTransactionHashes66(v) @@ -258,13 +262,14 @@ pub struct NewPooledTransactionHashes68 { pub hashes: Vec, } -#[derive(RlpEncodable)] +// #[derive(RlpEncodable)] #[allow(unused)] struct EncodableNewPooledTransactionHashes68<'a> { types: &'a [u8], sizes: &'a Vec, hashes: &'a Vec, } +reth_primitives::dummy_rlp!(EncodableNewPooledTransactionHashes68<'_>, Encodable); impl Encodable for NewPooledTransactionHashes68 { fn encode(&self, out: &mut dyn bytes::BufMut) { @@ -287,12 +292,12 @@ impl Encodable for NewPooledTransactionHashes68 { impl Decodable for NewPooledTransactionHashes68 { fn decode(buf: &mut &[u8]) -> alloy_rlp::Result { - #[derive(RlpDecodable)] struct EncodableNewPooledTransactionHashes68 { types: Bytes, sizes: Vec, hashes: Vec, } + reth_primitives::dummy_rlp!(EncodableNewPooledTransactionHashes68, Decodable); let encodable = EncodableNewPooledTransactionHashes68::decode(buf)?; Ok(Self { types: encodable.types.into(), sizes: encodable.sizes, hashes: encodable.hashes }) diff --git a/crates/net/eth-wire/src/types/receipts.rs b/crates/net/eth-wire/src/types/receipts.rs index 7c278b7be38b..75ae2a3818ca 100644 --- a/crates/net/eth-wire/src/types/receipts.rs +++ b/crates/net/eth-wire/src/types/receipts.rs @@ -8,12 +8,13 @@ use serde::{Deserialize, Serialize}; /// A request for transaction receipts from the given block hashes. #[derive_arbitrary(rlp)] -#[derive(Clone, Debug, Default, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper)] +#[derive(Clone, Debug, Default, PartialEq, Eq)] // RlpEncodableWrapper, RlpDecodableWrapper #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct GetReceipts( /// The block hashes to request receipts for. pub Vec, ); +reth_primitives::dummy_rlp!(GetReceipts); /// The response to [`GetReceipts`], containing receipt lists that correspond to each block /// requested. diff --git a/crates/net/eth-wire/src/types/state.rs b/crates/net/eth-wire/src/types/state.rs index bcd4ea529d2a..6ae111bc0481 100644 --- a/crates/net/eth-wire/src/types/state.rs +++ b/crates/net/eth-wire/src/types/state.rs @@ -10,9 +10,10 @@ use serde::{Deserialize, Serialize}; /// This message was removed in `eth/67`, only clients running `eth/66` or earlier will respond to /// this message. #[derive_arbitrary(rlp)] -#[derive(Clone, Debug, Default, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper)] +#[derive(Clone, Debug, Default, PartialEq, Eq)] // RlpEncodableWrapper, RlpDecodableWrapper #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct GetNodeData(pub Vec); +reth_primitives::dummy_rlp!(GetNodeData); /// The response to [`GetNodeData`], containing the state tree nodes or contract bytecode /// corresponding to the requested hashes. diff --git a/crates/net/eth-wire/src/types/status.rs b/crates/net/eth-wire/src/types/status.rs index 05331fcc86ff..7b146e45d932 100644 --- a/crates/net/eth-wire/src/types/status.rs +++ b/crates/net/eth-wire/src/types/status.rs @@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize}; /// When performing a handshake, the total difficulty is not guaranteed to correspond to the block /// hash. This information should be treated as untrusted. #[derive_arbitrary(rlp)] -#[derive(Copy, Clone, PartialEq, Eq, RlpEncodable, RlpDecodable)] +#[derive(Copy, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Status { /// The current protocol version. For example, peers running `eth/66` would have a version of @@ -43,6 +43,8 @@ pub struct Status { pub forkid: ForkId, } +reth_primitives::dummy_rlp!(Status); + impl From for Status { fn from(genesis: Genesis) -> Status { let chain = genesis.config.chain_id; diff --git a/crates/net/eth-wire/src/types/transactions.rs b/crates/net/eth-wire/src/types/transactions.rs index 8f707d69a962..6c8b4f620c11 100644 --- a/crates/net/eth-wire/src/types/transactions.rs +++ b/crates/net/eth-wire/src/types/transactions.rs @@ -24,13 +24,15 @@ use reth_primitives::{ /// A list of transaction hashes that the peer would like transaction bodies for. #[derive_arbitrary(rlp)] -#[derive(Clone, Debug, Default, PartialEq, Eq, RlpEncodableWrapper, RlpDecodableWrapper)] +#[derive(Clone, Debug, Default, PartialEq, Eq)] // RlpEncodableWrapper, RlpDecodableWrapper #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct GetPooledTransactions( /// The transaction hashes to request transaction bodies for. pub Vec, ); +reth_primitives::dummy_rlp!(GetPooledTransactions); + impl From> for GetPooledTransactions where T: Into, @@ -73,7 +75,7 @@ impl From for Vec { /// This is defined in [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844#networking) as an element /// of a [PooledTransactions] response. #[add_arbitrary_tests(rlp, 20)] -#[derive(Clone, Debug, PartialEq, Eq, RlpEncodable, RlpDecodable, Default)] +#[derive(Clone, Debug, PartialEq, Eq, Default)] pub struct BlobTransaction { /// The transaction payload. pub transaction: TransactionSigned, @@ -85,6 +87,8 @@ pub struct BlobTransaction { pub proofs: Vec, } +reth_primitives::dummy_rlp!(BlobTransaction); + impl BlobTransaction { /// Verifies that the transaction's blob data, commitments, and proofs are all valid. /// diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index ff90d9b0c2c5..04c861264e3a 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -20,6 +20,39 @@ //! - `arbitrary`: Adds `proptest` and `arbitrary` support for primitive types. //! - `test-utils`: Export utilities for testing +#[macro_use] +mod macros { + /// TODO: temporarily used to make the build pass. + /// replace with derive macros + #[macro_export] + macro_rules! dummy_rlp { + ($t:ty) => { + $crate::dummy_rlp!($t, Encodable); + $crate::dummy_rlp!($t, Decodable); + }; + + ($t:ty, Encodable) => { + impl alloy_rlp::Encodable for $t { + fn encode(&self, _out: &mut dyn alloy_rlp::BufMut) { + unimplemented!(concat!(stringify!($t), "::encode")) + } + + fn length(&self) -> usize { + unimplemented!(concat!(stringify!($t), "::length")) + } + } + }; + + ($t:ty, Decodable) => { + impl alloy_rlp::Decodable for $t { + fn decode(_buf: &mut &[u8]) -> alloy_rlp::Result { + unimplemented!(concat!(stringify!($t), "::decode")) + } + } + }; + } +} + pub mod abi; mod account; pub mod basefee; diff --git a/crates/primitives/src/log.rs b/crates/primitives/src/log.rs index 41e71cd06a1e..e6a805472771 100644 --- a/crates/primitives/src/log.rs +++ b/crates/primitives/src/log.rs @@ -4,7 +4,7 @@ use reth_codecs::{main_codec, Compact}; /// Ethereum Log #[main_codec(rlp)] -#[derive(Clone, Debug, Default, PartialEq, Eq, RlpEncodable, RlpDecodable)] +#[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct Log { /// Contract that emitted this log. pub address: Address, @@ -19,3 +19,5 @@ pub struct Log { /// Arbitrary length data. pub data: Bytes, } + +dummy_rlp!(Log); diff --git a/crates/primitives/src/transaction/access_list.rs b/crates/primitives/src/transaction/access_list.rs index 8897c7e450b1..5241be538ef7 100644 --- a/crates/primitives/src/transaction/access_list.rs +++ b/crates/primitives/src/transaction/access_list.rs @@ -8,7 +8,7 @@ use std::mem; /// A list of addresses and storage keys that the transaction plans to access. /// Accesses outside the list are possible, but become more expensive. #[main_codec(rlp)] -#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, RlpEncodable, RlpDecodable)] +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] #[serde(rename_all = "camelCase")] pub struct AccessListItem { /// Account addresses that would be loaded at the start of execution @@ -23,6 +23,8 @@ pub struct AccessListItem { pub storage_keys: Vec, } +dummy_rlp!(AccessListItem); + impl AccessListItem { /// Calculates a heuristic for the in-memory size of the [AccessListItem]. #[inline] diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index 2b615dd2b563..7ce9e8db0e80 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -409,7 +409,8 @@ impl Transaction { len += to.length(); len += value.length(); len += access_list.length(); - len += blob_versioned_hashes.length(); + // TODO(rlp) + // len += blob_versioned_hashes.length(); len += max_fee_per_blob_gas.length(); len += input.0.length(); len @@ -499,7 +500,8 @@ impl Transaction { input.0.encode(out); access_list.encode(out); max_fee_per_blob_gas.encode(out); - blob_versioned_hashes.encode(out); + // TODO(rlp) + // blob_versioned_hashes.encode(out); } } } @@ -1101,7 +1103,7 @@ impl TransactionSigned { input: Bytes(Decodable::decode(data)?), access_list: Decodable::decode(data)?, max_fee_per_blob_gas: Decodable::decode(data)?, - blob_versioned_hashes: Decodable::decode(data)?, + blob_versioned_hashes: todo!("TODO(rlp)"), }), _ => return Err(RlpError::Custom("unsupported typed transaction type")), }; diff --git a/crates/primitives/src/withdrawal.rs b/crates/primitives/src/withdrawal.rs index 161b4b881918..adcf51a90b8b 100644 --- a/crates/primitives/src/withdrawal.rs +++ b/crates/primitives/src/withdrawal.rs @@ -5,7 +5,7 @@ use std::mem; /// Withdrawal represents a validator withdrawal from the consensus layer. #[main_codec] -#[derive(Debug, Clone, PartialEq, Eq, Default, Hash, RlpEncodable, RlpDecodable)] +#[derive(Debug, Clone, PartialEq, Eq, Default, Hash)] pub struct Withdrawal { /// Monotonically increasing identifier issued by consensus layer. #[serde(with = "u64_hex")] @@ -20,6 +20,8 @@ pub struct Withdrawal { pub amount: u64, } +dummy_rlp!(Withdrawal); + impl Withdrawal { /// Return the withdrawal amount in wei. pub fn amount_wei(&self) -> U256 { diff --git a/crates/trie/src/account.rs b/crates/trie/src/account.rs index 29ce5d47ccb5..b44acc41c881 100644 --- a/crates/trie/src/account.rs +++ b/crates/trie/src/account.rs @@ -2,7 +2,7 @@ use alloy_rlp::{RlpDecodable, RlpEncodable}; use reth_primitives::{proofs::EMPTY_ROOT, Account, H256, KECCAK_EMPTY, U256}; /// An Ethereum account as represented in the trie. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] pub struct EthAccount { /// Account nonce. nonce: u64, @@ -14,6 +14,8 @@ pub struct EthAccount { code_hash: H256, } +reth_primitives::dummy_rlp!(EthAccount); + impl From for EthAccount { fn from(acc: Account) -> Self { EthAccount {