Skip to content

Commit

Permalink
tmp: dummy RLP impls
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Aug 3, 2023
1 parent a80fa6f commit 1805c21
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 16 deletions.
12 changes: 9 additions & 3 deletions crates/net/discv4/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SecretKey>,
}

reth_primitives::dummy_rlp!(EnrResponse);

// === impl EnrResponse ===

impl EnrResponse {
Expand All @@ -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,
Expand All @@ -319,8 +321,10 @@ pub struct Ping {
pub enr_sq: Option<u64>,
}

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,
Expand All @@ -330,6 +334,8 @@ pub struct Pong {
pub enr_sq: Option<u64>,
}

reth_primitives::dummy_rlp!(Pong);

#[cfg(test)]
mod tests {
use super::*;
Expand Down
4 changes: 3 additions & 1 deletion crates/net/eth-wire/src/types/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ impl From<Vec<Header>> 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<H256>,
);

reth_primitives::dummy_rlp!(GetBlockBodies);

impl From<Vec<H256>> for GetBlockBodies {
fn from(hashes: Vec<H256>) -> Self {
GetBlockBodies(hashes)
Expand Down
13 changes: 9 additions & 4 deletions crates/net/eth-wire/src/types/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,6 +46,8 @@ pub struct BlockHashNumber {
pub number: u64,
}

reth_primitives::dummy_rlp!(BlockHashNumber);

impl From<Vec<BlockHashNumber>> for NewBlockHashes {
fn from(v: Vec<BlockHashNumber>) -> Self {
NewBlockHashes(v)
Expand Down Expand Up @@ -207,7 +209,7 @@ impl From<NewPooledTransactionHashes68> 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.
Expand All @@ -216,6 +218,8 @@ pub struct NewPooledTransactionHashes66(
pub Vec<H256>,
);

reth_primitives::dummy_rlp!(NewPooledTransactionHashes66);

impl From<Vec<H256>> for NewPooledTransactionHashes66 {
fn from(v: Vec<H256>) -> Self {
NewPooledTransactionHashes66(v)
Expand Down Expand Up @@ -258,13 +262,14 @@ pub struct NewPooledTransactionHashes68 {
pub hashes: Vec<H256>,
}

#[derive(RlpEncodable)]
// #[derive(RlpEncodable)]
#[allow(unused)]
struct EncodableNewPooledTransactionHashes68<'a> {
types: &'a [u8],
sizes: &'a Vec<usize>,
hashes: &'a Vec<H256>,
}
reth_primitives::dummy_rlp!(EncodableNewPooledTransactionHashes68<'_>, Encodable);

impl Encodable for NewPooledTransactionHashes68 {
fn encode(&self, out: &mut dyn bytes::BufMut) {
Expand All @@ -287,12 +292,12 @@ impl Encodable for NewPooledTransactionHashes68 {

impl Decodable for NewPooledTransactionHashes68 {
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
#[derive(RlpDecodable)]
struct EncodableNewPooledTransactionHashes68 {
types: Bytes,
sizes: Vec<usize>,
hashes: Vec<H256>,
}
reth_primitives::dummy_rlp!(EncodableNewPooledTransactionHashes68, Decodable);

let encodable = EncodableNewPooledTransactionHashes68::decode(buf)?;
Ok(Self { types: encodable.types.into(), sizes: encodable.sizes, hashes: encodable.hashes })
Expand Down
3 changes: 2 additions & 1 deletion crates/net/eth-wire/src/types/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<H256>,
);
reth_primitives::dummy_rlp!(GetReceipts);

/// The response to [`GetReceipts`], containing receipt lists that correspond to each block
/// requested.
Expand Down
3 changes: 2 additions & 1 deletion crates/net/eth-wire/src/types/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<H256>);
reth_primitives::dummy_rlp!(GetNodeData);

/// The response to [`GetNodeData`], containing the state tree nodes or contract bytecode
/// corresponding to the requested hashes.
Expand Down
4 changes: 3 additions & 1 deletion crates/net/eth-wire/src/types/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,6 +43,8 @@ pub struct Status {
pub forkid: ForkId,
}

reth_primitives::dummy_rlp!(Status);

impl From<Genesis> for Status {
fn from(genesis: Genesis) -> Status {
let chain = genesis.config.chain_id;
Expand Down
4 changes: 3 additions & 1 deletion crates/net/eth-wire/src/types/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ use serde::{Deserialize, Serialize};

/// 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<H256>,
);

reth_primitives::dummy_rlp!(GetPooledTransactions);

impl<T> From<Vec<T>> for GetPooledTransactions
where
T: Into<H256>,
Expand Down
33 changes: 33 additions & 0 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
unimplemented!(concat!(stringify!($t), "::decode"))
}
}
};
}
}

pub mod abi;
mod account;
pub mod basefee;
Expand Down
4 changes: 3 additions & 1 deletion crates/primitives/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -19,3 +19,5 @@ pub struct Log {
/// Arbitrary length data.
pub data: Bytes,
}

dummy_rlp!(Log);
4 changes: 3 additions & 1 deletion crates/primitives/src/transaction/access_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,6 +23,8 @@ pub struct AccessListItem {
pub storage_keys: Vec<H256>,
}

dummy_rlp!(AccessListItem);

impl AccessListItem {
/// Calculates a heuristic for the in-memory size of the [AccessListItem].
#[inline]
Expand Down
4 changes: 3 additions & 1 deletion crates/primitives/src/withdrawal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion crates/trie/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -14,6 +14,8 @@ pub struct EthAccount {
code_hash: H256,
}

reth_primitives::dummy_rlp!(EthAccount);

impl From<Account> for EthAccount {
fn from(acc: Account) -> Self {
EthAccount {
Expand Down

0 comments on commit 1805c21

Please sign in to comment.