Rename main codec to reth db codec (#9501)

This commit is contained in:
Pelle
2024-07-16 09:33:56 +00:00
committed by GitHub
parent 5ef3803dd3
commit 484dc916c1
31 changed files with 77 additions and 77 deletions

View File

@ -4,12 +4,12 @@ use alloy_primitives::{keccak256, Bytes, B256, U256};
use byteorder::{BigEndian, ReadBytesExt}; use byteorder::{BigEndian, ReadBytesExt};
use bytes::Buf; use bytes::Buf;
use derive_more::Deref; use derive_more::Deref;
use reth_codecs::{main_codec, Compact}; use reth_codecs::{reth_codec, Compact};
use revm_primitives::{AccountInfo, Bytecode as RevmBytecode, JumpTable}; use revm_primitives::{AccountInfo, Bytecode as RevmBytecode, JumpTable};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// An Ethereum account. /// An Ethereum account.
#[main_codec] #[reth_codec]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
pub struct Account { pub struct Account {
/// Account nonce. /// Account nonce.

View File

@ -16,11 +16,11 @@ use alloy_primitives::{keccak256, Address, BlockNumber, Bloom, Bytes, B256, B64,
use alloy_rlp::{length_of_length, Decodable, Encodable}; use alloy_rlp::{length_of_length, Decodable, Encodable};
use bytes::BufMut; use bytes::BufMut;
use core::mem; use core::mem;
use reth_codecs::{add_arbitrary_tests, main_codec, Compact}; use reth_codecs::{add_arbitrary_tests, reth_codec, Compact};
use revm_primitives::{calc_blob_gasprice, calc_excess_blob_gas}; use revm_primitives::{calc_blob_gasprice, calc_excess_blob_gas};
/// Block header /// Block header
#[main_codec(no_arbitrary)] #[reth_codec(no_arbitrary)]
#[add_arbitrary_tests(rlp, 25)] #[add_arbitrary_tests(rlp, 25)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Header { pub struct Header {

View File

@ -7,11 +7,11 @@ use alloy_rlp::{Decodable, Encodable};
use bytes::BufMut; use bytes::BufMut;
use core::mem; use core::mem;
use derive_more::{AsRef, Deref}; use derive_more::{AsRef, Deref};
use reth_codecs::{add_arbitrary_tests, main_codec, Compact}; use reth_codecs::{add_arbitrary_tests, reth_codec, Compact};
/// A [`Header`] that is sealed at a precalculated hash, use [`SealedHeader::unseal()`] if you want /// A [`Header`] that is sealed at a precalculated hash, use [`SealedHeader::unseal()`] if you want
/// to modify header. /// to modify header.
#[main_codec(no_arbitrary)] #[reth_codec(no_arbitrary)]
#[add_arbitrary_tests(rlp, compact)] #[add_arbitrary_tests(rlp, compact)]
#[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref)] #[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref)]
pub struct SealedHeader { pub struct SealedHeader {

View File

@ -19,11 +19,11 @@ mod tests {
use alloy_rlp::{RlpDecodable, RlpEncodable}; use alloy_rlp::{RlpDecodable, RlpEncodable};
use proptest::proptest; use proptest::proptest;
use proptest_arbitrary_interop::arb; use proptest_arbitrary_interop::arb;
use reth_codecs::{main_codec, Compact}; use reth_codecs::{reth_codec, Compact};
/// This type is kept for compatibility tests after the codec support was added to /// This type is kept for compatibility tests after the codec support was added to
/// alloy-primitives Log type natively /// alloy-primitives Log type natively
#[main_codec(rlp)] #[reth_codec(rlp)]
#[derive(Clone, Debug, PartialEq, Eq, RlpDecodable, RlpEncodable, Default)] #[derive(Clone, Debug, PartialEq, Eq, RlpDecodable, RlpEncodable, Default)]
struct Log { struct Log {
/// Contract that emitted this log. /// Contract that emitted this log.

View File

@ -4,14 +4,14 @@ pub use alloy_consensus::Request;
use alloy_eips::eip7685::{Decodable7685, Encodable7685}; use alloy_eips::eip7685::{Decodable7685, Encodable7685};
use alloy_rlp::{Decodable, Encodable}; use alloy_rlp::{Decodable, Encodable};
use derive_more::{Deref, DerefMut, From, IntoIterator}; use derive_more::{Deref, DerefMut, From, IntoIterator};
use reth_codecs::{main_codec, Compact}; use reth_codecs::{reth_codec, Compact};
use revm_primitives::Bytes; use revm_primitives::Bytes;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
use alloc::vec::Vec; use alloc::vec::Vec;
/// A list of EIP-7685 requests. /// A list of EIP-7685 requests.
#[main_codec] #[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash, Deref, DerefMut, From, IntoIterator)] #[derive(Debug, Clone, PartialEq, Eq, Default, Hash, Deref, DerefMut, From, IntoIterator)]
pub struct Requests(pub Vec<Request>); pub struct Requests(pub Vec<Request>);

View File

@ -27,7 +27,7 @@ impl From<(B256, U256)> for StorageEntry {
} }
} }
// NOTE: Removing main_codec and manually encode subkey // NOTE: Removing reth_codec and manually encode subkey
// and compress second part of the value. If we have compression // and compress second part of the value. If we have compression
// over whole value (Even SubKey) that would mess up fetching of values with seek_by_key_subkey // over whole value (Even SubKey) that would mess up fetching of values with seek_by_key_subkey
impl Compact for StorageEntry { impl Compact for StorageEntry {

View File

@ -2,7 +2,7 @@
use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper}; use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
use derive_more::{AsRef, Deref, DerefMut, From, IntoIterator}; use derive_more::{AsRef, Deref, DerefMut, From, IntoIterator};
use reth_codecs::{main_codec, Compact}; use reth_codecs::{reth_codec, Compact};
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
use alloc::vec::Vec; use alloc::vec::Vec;
@ -12,7 +12,7 @@ use alloc::vec::Vec;
pub use alloy_eips::eip4895::Withdrawal; pub use alloy_eips::eip4895::Withdrawal;
/// Represents a collection of Withdrawals. /// Represents a collection of Withdrawals.
#[main_codec] #[reth_codec]
#[derive( #[derive(
Debug, Debug,
Clone, Clone,
@ -92,7 +92,7 @@ mod tests {
/// This type is kept for compatibility tests after the codec support was added to alloy-eips /// This type is kept for compatibility tests after the codec support was added to alloy-eips
/// Withdrawal type natively /// Withdrawal type natively
#[main_codec] #[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash, RlpEncodable, RlpDecodable)] #[derive(Debug, Clone, PartialEq, Eq, Default, Hash, RlpEncodable, RlpDecodable)]
struct RethWithdrawal { struct RethWithdrawal {
/// Monotonically increasing identifier issued by consensus layer. /// Monotonically increasing identifier issued by consensus layer.

View File

@ -8,15 +8,15 @@ use core::{cmp::Ordering, ops::Deref};
use derive_more::{Deref, DerefMut, From, IntoIterator}; use derive_more::{Deref, DerefMut, From, IntoIterator};
#[cfg(feature = "zstd-codec")] #[cfg(feature = "zstd-codec")]
use reth_codecs::CompactZstd; use reth_codecs::CompactZstd;
use reth_codecs::{add_arbitrary_tests, main_codec, Compact}; use reth_codecs::{add_arbitrary_tests, reth_codec, Compact};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
use alloc::{vec, vec::Vec}; use alloc::{vec, vec::Vec};
/// Receipt containing result of transaction execution. /// Receipt containing result of transaction execution.
#[cfg_attr(feature = "zstd-codec", main_codec(no_arbitrary, zstd))] #[cfg_attr(feature = "zstd-codec", reth_codec(no_arbitrary, zstd))]
#[cfg_attr(not(feature = "zstd-codec"), main_codec(no_arbitrary))] #[cfg_attr(not(feature = "zstd-codec"), reth_codec(no_arbitrary))]
#[add_arbitrary_tests] #[add_arbitrary_tests]
#[derive(Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)] #[derive(Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)]
#[rlp(trailing)] #[rlp(trailing)]
@ -142,7 +142,7 @@ impl From<Receipt> for ReceiptWithBloom {
} }
/// [`Receipt`] with calculated bloom filter. /// [`Receipt`] with calculated bloom filter.
#[main_codec] #[reth_codec]
#[derive(Clone, Debug, PartialEq, Eq, Default)] #[derive(Clone, Debug, PartialEq, Eq, Default)]
pub struct ReceiptWithBloom { pub struct ReceiptWithBloom {
/// Bloom filter build from logs. /// Bloom filter build from logs.

View File

@ -11,11 +11,11 @@ mod tests {
use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper}; use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper};
use proptest::proptest; use proptest::proptest;
use proptest_arbitrary_interop::arb; use proptest_arbitrary_interop::arb;
use reth_codecs::{main_codec, Compact}; use reth_codecs::{reth_codec, Compact};
/// This type is kept for compatibility tests after the codec support was added to alloy-eips /// This type is kept for compatibility tests after the codec support was added to alloy-eips
/// AccessList type natively /// AccessList type natively
#[main_codec(rlp)] #[reth_codec(rlp)]
#[derive( #[derive(
Clone, Debug, PartialEq, Eq, Hash, Default, RlpDecodableWrapper, RlpEncodableWrapper, Clone, Debug, PartialEq, Eq, Hash, Default, RlpDecodableWrapper, RlpEncodableWrapper,
)] )]
@ -28,7 +28,7 @@ mod tests {
} }
// This // This
#[main_codec(rlp)] #[reth_codec(rlp)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default, RlpDecodable, RlpEncodable)] #[derive(Clone, Debug, PartialEq, Eq, Hash, Default, RlpDecodable, RlpEncodable)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
struct RethAccessListItem { struct RethAccessListItem {

View File

@ -2,13 +2,13 @@ use super::access_list::AccessList;
use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256}; use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256};
use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use alloy_rlp::{length_of_length, Decodable, Encodable, Header};
use core::mem; use core::mem;
use reth_codecs::{main_codec, Compact}; use reth_codecs::{reth_codec, Compact};
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
use alloc::vec::Vec; use alloc::vec::Vec;
/// A transaction with a priority fee ([EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)). /// A transaction with a priority fee ([EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)).
#[main_codec] #[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] #[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
pub struct TxEip1559 { pub struct TxEip1559 {
/// Added as EIP-155: Simple replay attack protection /// Added as EIP-155: Simple replay attack protection

View File

@ -2,13 +2,13 @@ use super::access_list::AccessList;
use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256}; use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256};
use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use alloy_rlp::{length_of_length, Decodable, Encodable, Header};
use core::mem; use core::mem;
use reth_codecs::{main_codec, Compact}; use reth_codecs::{reth_codec, Compact};
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
use alloc::vec::Vec; use alloc::vec::Vec;
/// Transaction with an [`AccessList`] ([EIP-2930](https://eips.ethereum.org/EIPS/eip-2930)). /// Transaction with an [`AccessList`] ([EIP-2930](https://eips.ethereum.org/EIPS/eip-2930)).
#[main_codec] #[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] #[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
pub struct TxEip2930 { pub struct TxEip2930 {
/// Added as EIP-155: Simple replay attack protection /// Added as EIP-155: Simple replay attack protection

View File

@ -5,7 +5,7 @@ use crate::{
}; };
use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use alloy_rlp::{length_of_length, Decodable, Encodable, Header};
use core::mem; use core::mem;
use reth_codecs::{main_codec, Compact, CompactPlaceholder}; use reth_codecs::{reth_codec, Compact, CompactPlaceholder};
#[cfg(feature = "c-kzg")] #[cfg(feature = "c-kzg")]
use crate::kzg::KzgSettings; use crate::kzg::KzgSettings;
@ -16,7 +16,7 @@ use alloc::vec::Vec;
/// [EIP-4844 Blob Transaction](https://eips.ethereum.org/EIPS/eip-4844#blob-transaction) /// [EIP-4844 Blob Transaction](https://eips.ethereum.org/EIPS/eip-4844#blob-transaction)
/// ///
/// A transaction with blob hashes and max blob fee /// A transaction with blob hashes and max blob fee
#[main_codec] #[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] #[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
pub struct TxEip4844 { pub struct TxEip4844 {
/// Added as EIP-155: Simple replay attack protection /// Added as EIP-155: Simple replay attack protection

View File

@ -4,7 +4,7 @@ use crate::{
}; };
use alloy_rlp::{length_of_length, Decodable, Encodable, Header}; use alloy_rlp::{length_of_length, Decodable, Encodable, Header};
use core::mem; use core::mem;
use reth_codecs::{main_codec, Compact}; use reth_codecs::{reth_codec, Compact};
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
use alloc::vec::Vec; use alloc::vec::Vec;
@ -12,7 +12,7 @@ use alloc::vec::Vec;
/// [EIP-7702 Set Code Transaction](https://eips.ethereum.org/EIPS/eip-7702) /// [EIP-7702 Set Code Transaction](https://eips.ethereum.org/EIPS/eip-7702)
/// ///
/// Set EOA account code for one transaction /// Set EOA account code for one transaction
#[main_codec(no_arbitrary, add_arbitrary_tests)] #[reth_codec(no_arbitrary, add_arbitrary_tests)]
#[derive(Debug, Clone, PartialEq, Eq, Default)] #[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct TxEip7702 { pub struct TxEip7702 {
/// Added as EIP-155: Simple replay attack protection /// Added as EIP-155: Simple replay attack protection

View File

@ -1,13 +1,13 @@
use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256}; use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256};
use alloy_rlp::{length_of_length, Encodable, Header}; use alloy_rlp::{length_of_length, Encodable, Header};
use core::mem; use core::mem;
use reth_codecs::{main_codec, Compact}; use reth_codecs::{reth_codec, Compact};
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
use alloc::vec::Vec; use alloc::vec::Vec;
/// Legacy transaction. /// Legacy transaction.
#[main_codec] #[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] #[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
pub struct TxLegacy { pub struct TxLegacy {
/// Added as EIP-155: Simple replay attack protection /// Added as EIP-155: Simple replay attack protection

View File

@ -3,11 +3,11 @@ use alloy_rlp::{
length_of_length, Decodable, Encodable, Error as DecodeError, Header, EMPTY_STRING_CODE, length_of_length, Decodable, Encodable, Error as DecodeError, Header, EMPTY_STRING_CODE,
}; };
use bytes::Buf; use bytes::Buf;
use reth_codecs::{main_codec, Compact}; use reth_codecs::{reth_codec, Compact};
use std::mem; use std::mem;
/// Deposit transactions, also known as deposits are initiated on L1, and executed on L2. /// Deposit transactions, also known as deposits are initiated on L1, and executed on L2.
#[main_codec] #[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] #[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
pub struct TxDeposit { pub struct TxDeposit {
/// Hash that uniquely identifies the source of the deposit. /// Hash that uniquely identifies the source of the deposit.

View File

@ -1,9 +1,9 @@
use crate::PruneMode; use crate::PruneMode;
use alloy_primitives::{BlockNumber, TxNumber}; use alloy_primitives::{BlockNumber, TxNumber};
use reth_codecs::{main_codec, Compact}; use reth_codecs::{reth_codec, Compact};
/// Saves the pruning progress of a stage. /// Saves the pruning progress of a stage.
#[main_codec] #[reth_codec]
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(test, derive(Default))] #[cfg_attr(test, derive(Default))]
pub struct PruneCheckpoint { pub struct PruneCheckpoint {

View File

@ -1,9 +1,9 @@
use crate::{segment::PrunePurpose, PruneSegment, PruneSegmentError}; use crate::{segment::PrunePurpose, PruneSegment, PruneSegmentError};
use alloy_primitives::BlockNumber; use alloy_primitives::BlockNumber;
use reth_codecs::{main_codec, Compact}; use reth_codecs::{reth_codec, Compact};
/// Prune mode. /// Prune mode.
#[main_codec] #[reth_codec]
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[serde(rename_all = "lowercase")] #[serde(rename_all = "lowercase")]
pub enum PruneMode { pub enum PruneMode {

View File

@ -1,10 +1,10 @@
use crate::MINIMUM_PRUNING_DISTANCE; use crate::MINIMUM_PRUNING_DISTANCE;
use derive_more::Display; use derive_more::Display;
use reth_codecs::{main_codec, Compact}; use reth_codecs::{reth_codec, Compact};
use thiserror::Error; use thiserror::Error;
/// Segment of the data that can be pruned. /// Segment of the data that can be pruned.
#[main_codec] #[reth_codec]
#[derive(Debug, Display, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] #[derive(Debug, Display, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum PruneSegment { pub enum PruneSegment {
/// Prune segment responsible for the `TransactionSenders` table. /// Prune segment responsible for the `TransactionSenders` table.

View File

@ -1,6 +1,6 @@
use alloy_primitives::{Address, BlockNumber, B256}; use alloy_primitives::{Address, BlockNumber, B256};
use bytes::Buf; use bytes::Buf;
use reth_codecs::{main_codec, Compact}; use reth_codecs::{reth_codec, Compact};
use reth_trie_common::{hash_builder::HashBuilderState, StoredSubNode}; use reth_trie_common::{hash_builder::HashBuilderState, StoredSubNode};
use std::ops::RangeInclusive; use std::ops::RangeInclusive;
@ -74,7 +74,7 @@ impl Compact for MerkleCheckpoint {
} }
/// Saves the progress of AccountHashing stage. /// Saves the progress of AccountHashing stage.
#[main_codec] #[reth_codec]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
pub struct AccountHashingCheckpoint { pub struct AccountHashingCheckpoint {
/// The next account to start hashing from. /// The next account to start hashing from.
@ -86,7 +86,7 @@ pub struct AccountHashingCheckpoint {
} }
/// Saves the progress of StorageHashing stage. /// Saves the progress of StorageHashing stage.
#[main_codec] #[reth_codec]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
pub struct StorageHashingCheckpoint { pub struct StorageHashingCheckpoint {
/// The next account to start hashing from. /// The next account to start hashing from.
@ -100,7 +100,7 @@ pub struct StorageHashingCheckpoint {
} }
/// Saves the progress of Execution stage. /// Saves the progress of Execution stage.
#[main_codec] #[reth_codec]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
pub struct ExecutionCheckpoint { pub struct ExecutionCheckpoint {
/// Block range which this checkpoint is valid for. /// Block range which this checkpoint is valid for.
@ -110,7 +110,7 @@ pub struct ExecutionCheckpoint {
} }
/// Saves the progress of Headers stage. /// Saves the progress of Headers stage.
#[main_codec] #[reth_codec]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
pub struct HeadersCheckpoint { pub struct HeadersCheckpoint {
/// Block range which this checkpoint is valid for. /// Block range which this checkpoint is valid for.
@ -120,7 +120,7 @@ pub struct HeadersCheckpoint {
} }
/// Saves the progress of Index History stages. /// Saves the progress of Index History stages.
#[main_codec] #[reth_codec]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
pub struct IndexHistoryCheckpoint { pub struct IndexHistoryCheckpoint {
/// Block range which this checkpoint is valid for. /// Block range which this checkpoint is valid for.
@ -130,7 +130,7 @@ pub struct IndexHistoryCheckpoint {
} }
/// Saves the progress of abstract stage iterating over or downloading entities. /// Saves the progress of abstract stage iterating over or downloading entities.
#[main_codec] #[reth_codec]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)] #[derive(Debug, Default, PartialEq, Eq, Clone, Copy)]
pub struct EntitiesCheckpoint { pub struct EntitiesCheckpoint {
/// Number of entities already processed. /// Number of entities already processed.
@ -158,7 +158,7 @@ impl EntitiesCheckpoint {
/// Saves the block range. Usually, it's used to check the validity of some stage checkpoint across /// Saves the block range. Usually, it's used to check the validity of some stage checkpoint across
/// multiple executions. /// multiple executions.
#[main_codec] #[reth_codec]
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)] #[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
pub struct CheckpointBlockRange { pub struct CheckpointBlockRange {
/// The first block of the range, inclusive. /// The first block of the range, inclusive.
@ -180,7 +180,7 @@ impl From<&RangeInclusive<BlockNumber>> for CheckpointBlockRange {
} }
/// Saves the progress of a stage. /// Saves the progress of a stage.
#[main_codec] #[reth_codec]
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)] #[derive(Debug, Default, PartialEq, Eq, Clone, Copy)]
pub struct StageCheckpoint { pub struct StageCheckpoint {
/// The maximum block processed by the stage. /// The maximum block processed by the stage.
@ -246,7 +246,7 @@ impl StageCheckpoint {
// TODO(alexey): add a merkle checkpoint. Currently it's hard because [`MerkleCheckpoint`] // TODO(alexey): add a merkle checkpoint. Currently it's hard because [`MerkleCheckpoint`]
// is not a Copy type. // is not a Copy type.
/// Stage-specific checkpoint metrics. /// Stage-specific checkpoint metrics.
#[main_codec] #[reth_codec]
#[derive(Debug, PartialEq, Eq, Clone, Copy)] #[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum StageUnitCheckpoint { pub enum StageUnitCheckpoint {
/// Saves the progress of AccountHashing stage. /// Saves the progress of AccountHashing stage.

View File

@ -2,18 +2,18 @@
This crate has helpers to implement the main codec used internally to save data in the different storage types. This crate has helpers to implement the main codec used internally to save data in the different storage types.
Currently `Compact` is used when adding the derive macro `main_codec`. Currently `Compact` is used when adding the derive macro `reth_codec`.
This crate implements the main codec (`Compact`) for: This crate implements the main codec (`Compact`) for:
* [primitive types](src/lib.rs) * [primitive types](src/lib.rs)
* [alloy types](src/alloy/mod.rs): uses bridge types alongside `main_codec` from [derive](derive/src/lib.rs) * [alloy types](src/alloy/mod.rs): uses bridge types alongside `reth_codec` from [derive](derive/src/lib.rs)
### reth-codecs-derive ### reth-codecs-derive
Provides derive macros that can be added and configured to stored data structs/enums Provides derive macros that can be added and configured to stored data structs/enums
* `#[main_codec]`: Implements `Compact` as well as `#[derive_arbitrary(compact)]` * `#[reth_codec]`: Implements `Compact` as well as `#[derive_arbitrary(compact)]`
* `#[main_codec(rlp)]`: Implements `Compact` as well as `#[derive_arbitrary(compact, rlp)]` * `#[reth_codec(rlp)]`: Implements `Compact` as well as `#[derive_arbitrary(compact, rlp)]`
* `#[main_codec(no_arbitrary)]`: Implements `Compact` without `derive_arbitrary`. * `#[reth_codec(no_arbitrary)]`: Implements `Compact` without `derive_arbitrary`.
* `#[derive_arbitrary]`: will derive arbitrary `Arbitrary` and `proptest::Arbitrary` with no generated tests. * `#[derive_arbitrary]`: will derive arbitrary `Arbitrary` and `proptest::Arbitrary` with no generated tests.
* `#[derive_arbitrary(rlp)]`: will derive arbitrary and generate rlp roundtrip proptests. * `#[derive_arbitrary(rlp)]`: will derive arbitrary and generate rlp roundtrip proptests.

View File

@ -33,12 +33,12 @@ pub fn derive_zstd(input: TokenStream) -> TokenStream {
/// If you prefer to manually implement the arbitrary traits, you can still use the [`add_arbitrary_tests()`] function to add arbitrary fuzz tests. /// If you prefer to manually implement the arbitrary traits, you can still use the [`add_arbitrary_tests()`] function to add arbitrary fuzz tests.
/// ///
/// Example usage: /// Example usage:
/// * `#[main_codec(rlp)]`: will implement `derive_arbitrary(rlp)` or `derive_arbitrary(compact, rlp)`, if `compact` is the `main_codec`. /// * `#[reth_codec(rlp)]`: will implement `derive_arbitrary(rlp)` or `derive_arbitrary(compact, rlp)`, if `compact` is the `reth_codec`.
/// * `#[main_codec(no_arbitrary)]`: will skip `derive_arbitrary` (both trait implementations and tests) /// * `#[reth_codec(no_arbitrary)]`: will skip `derive_arbitrary` (both trait implementations and tests)
#[proc_macro_attribute] #[proc_macro_attribute]
#[rustfmt::skip] #[rustfmt::skip]
#[allow(unreachable_code)] #[allow(unreachable_code)]
pub fn main_codec(args: TokenStream, input: TokenStream) -> TokenStream { pub fn reth_codec(args: TokenStream, input: TokenStream) -> TokenStream {
let ast = parse_macro_input!(input as DeriveInput); let ast = parse_macro_input!(input as DeriveInput);
let with_zstd = args.clone().into_iter().any(|tk| tk.to_string() == "zstd"); let with_zstd = args.clone().into_iter().any(|tk| tk.to_string() == "zstd");

View File

@ -2,12 +2,12 @@ use crate::Compact;
use alloy_eips::eip7702::{Authorization as AlloyAuthorization, SignedAuthorization}; use alloy_eips::eip7702::{Authorization as AlloyAuthorization, SignedAuthorization};
use alloy_primitives::{Address, ChainId, U256}; use alloy_primitives::{Address, ChainId, U256};
use bytes::Buf; use bytes::Buf;
use reth_codecs_derive::main_codec; use reth_codecs_derive::reth_codec;
/// Authorization acts as bridge which simplifies Compact implementation for AlloyAuthorization. /// Authorization acts as bridge which simplifies Compact implementation for AlloyAuthorization.
/// ///
/// Notice: Make sure this struct is 1:1 with `alloy_eips::eip7702::Authorization` /// Notice: Make sure this struct is 1:1 with `alloy_eips::eip7702::Authorization`
#[main_codec] #[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Default)] #[derive(Debug, Clone, PartialEq, Eq, Default)]
struct Authorization { struct Authorization {
chain_id: ChainId, chain_id: ChainId,

View File

@ -1,12 +1,12 @@
use crate::Compact; use crate::Compact;
use alloy_genesis::GenesisAccount as AlloyGenesisAccount; use alloy_genesis::GenesisAccount as AlloyGenesisAccount;
use alloy_primitives::{Bytes, B256, U256}; use alloy_primitives::{Bytes, B256, U256};
use reth_codecs_derive::main_codec; use reth_codecs_derive::reth_codec;
/// GenesisAccount acts as bridge which simplifies Compact implementation for AlloyGenesisAccount. /// GenesisAccount acts as bridge which simplifies Compact implementation for AlloyGenesisAccount.
/// ///
/// Notice: Make sure this struct is 1:1 with `alloy_genesis::GenesisAccount` /// Notice: Make sure this struct is 1:1 with `alloy_genesis::GenesisAccount`
#[main_codec] #[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Default)] #[derive(Debug, Clone, PartialEq, Eq, Default)]
struct GenesisAccount { struct GenesisAccount {
/// The nonce of the account at genesis. /// The nonce of the account at genesis.
@ -21,13 +21,13 @@ struct GenesisAccount {
private_key: Option<B256>, private_key: Option<B256>,
} }
#[main_codec] #[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Default)] #[derive(Debug, Clone, PartialEq, Eq, Default)]
struct StorageEntries { struct StorageEntries {
entries: Vec<StorageEntry>, entries: Vec<StorageEntry>,
} }
#[main_codec] #[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Default)] #[derive(Debug, Clone, PartialEq, Eq, Default)]
struct StorageEntry { struct StorageEntry {
key: B256, key: B256,

View File

@ -1,12 +1,12 @@
use crate::Compact; use crate::Compact;
use alloy_eips::eip4895::Withdrawal as AlloyWithdrawal; use alloy_eips::eip4895::Withdrawal as AlloyWithdrawal;
use alloy_primitives::Address; use alloy_primitives::Address;
use reth_codecs_derive::main_codec; use reth_codecs_derive::reth_codec;
/// Withdrawal acts as bridge which simplifies Compact implementation for AlloyWithdrawal. /// Withdrawal acts as bridge which simplifies Compact implementation for AlloyWithdrawal.
/// ///
/// Notice: Make sure this struct is 1:1 with `alloy_eips::eip4895::Withdrawal` /// Notice: Make sure this struct is 1:1 with `alloy_eips::eip4895::Withdrawal`
#[main_codec] #[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Default)] #[derive(Debug, Clone, PartialEq, Eq, Default)]
struct Withdrawal { struct Withdrawal {
/// Monotonically increasing identifier issued by consensus layer. /// Monotonically increasing identifier issued by consensus layer.

View File

@ -555,7 +555,7 @@ mod tests {
}); });
} }
#[main_codec] #[reth_codec]
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
struct TestStruct { struct TestStruct {
f_u64: u64, f_u64: u64,
@ -607,7 +607,7 @@ mod tests {
); );
} }
#[main_codec] #[reth_codec]
#[derive(Debug, PartialEq, Clone, Default)] #[derive(Debug, PartialEq, Clone, Default)]
enum TestEnum { enum TestEnum {
#[default] #[default]

View File

@ -23,7 +23,7 @@ pub struct AccountBeforeTx {
pub info: Option<Account>, pub info: Option<Account>,
} }
// NOTE: Removing main_codec and manually encode subkey // NOTE: Removing reth_codec and manually encode subkey
// and compress second part of the value. If we have compression // and compress second part of the value. If we have compression
// over whole value (Even SubKey) that would mess up fetching of values with seek_by_key_subkey // over whole value (Even SubKey) that would mess up fetching of values with seek_by_key_subkey
impl Compact for AccountBeforeTx { impl Compact for AccountBeforeTx {

View File

@ -1,6 +1,6 @@
//! Block related models and types. //! Block related models and types.
use reth_codecs::{main_codec, Compact}; use reth_codecs::{reth_codec, Compact};
use reth_primitives::{Header, TxNumber, Withdrawals, B256}; use reth_primitives::{Header, TxNumber, Withdrawals, B256};
use std::ops::Range; use std::ops::Range;
@ -12,7 +12,7 @@ pub type NumTransactions = u64;
/// It has the pointer to the transaction Number of the first /// It has the pointer to the transaction Number of the first
/// transaction in the block and the total number of transactions. /// transaction in the block and the total number of transactions.
#[derive(Debug, Default, Eq, PartialEq, Clone)] #[derive(Debug, Default, Eq, PartialEq, Clone)]
#[main_codec] #[reth_codec]
pub struct StoredBlockBodyIndices { pub struct StoredBlockBodyIndices {
/// The number of the first transaction in this block /// The number of the first transaction in this block
/// ///
@ -68,7 +68,7 @@ impl StoredBlockBodyIndices {
/// The storage representation of a block's ommers. /// The storage representation of a block's ommers.
/// ///
/// It is stored as the headers of the block's uncles. /// It is stored as the headers of the block's uncles.
#[main_codec] #[reth_codec]
#[derive(Debug, Default, Eq, PartialEq, Clone)] #[derive(Debug, Default, Eq, PartialEq, Clone)]
pub struct StoredBlockOmmers { pub struct StoredBlockOmmers {
/// The block headers of this block's uncles. /// The block headers of this block's uncles.
@ -76,7 +76,7 @@ pub struct StoredBlockOmmers {
} }
/// The storage representation of block withdrawals. /// The storage representation of block withdrawals.
#[main_codec] #[reth_codec]
#[derive(Debug, Default, Eq, PartialEq, Clone)] #[derive(Debug, Default, Eq, PartialEq, Clone)]
pub struct StoredBlockWithdrawals { pub struct StoredBlockWithdrawals {
/// The block withdrawals. /// The block withdrawals.

View File

@ -4,7 +4,7 @@ use crate::{
table::{Compress, Decode, Decompress, Encode}, table::{Compress, Decode, Decompress, Encode},
DatabaseError, DatabaseError,
}; };
use reth_codecs::{main_codec, Compact}; use reth_codecs::{reth_codec, Compact};
use reth_primitives::{Address, B256, *}; use reth_primitives::{Address, B256, *};
use reth_prune_types::{PruneCheckpoint, PruneSegment}; use reth_prune_types::{PruneCheckpoint, PruneSegment};
use reth_stages_types::StageCheckpoint; use reth_stages_types::StageCheckpoint;
@ -263,7 +263,7 @@ macro_rules! add_wrapper_struct {
($(($name:tt, $wrapper:tt)),+) => { ($(($name:tt, $wrapper:tt)),+) => {
$( $(
/// Wrapper struct so it can use StructFlags from Compact, when used as pure table values. /// Wrapper struct so it can use StructFlags from Compact, when used as pure table values.
#[main_codec] #[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Default)] #[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct $wrapper(pub $name); pub struct $wrapper(pub $name);

View File

@ -11,7 +11,7 @@ pub struct StorageTrieEntry {
pub node: BranchNodeCompact, pub node: BranchNodeCompact,
} }
// NOTE: Removing main_codec and manually encode subkey // NOTE: Removing reth_codec and manually encode subkey
// and compress second part of the value. If we have compression // and compress second part of the value. If we have compression
// over whole value (Even SubKey) that would mess up fetching of values with seek_by_key_subkey // over whole value (Even SubKey) that would mess up fetching of values with seek_by_key_subkey
impl Compact for StorageTrieEntry { impl Compact for StorageTrieEntry {

View File

@ -105,7 +105,7 @@ And the corresponding trait implementations are present in the primitives crate.
[File: crates/primitives/src/transaction/mod.rs](https://github.com/paradigmxyz/reth/blob/1563506aea09049a85e5cc72c2894f3f7a371581/crates/primitives/src/transaction/mod.rs) [File: crates/primitives/src/transaction/mod.rs](https://github.com/paradigmxyz/reth/blob/1563506aea09049a85e5cc72c2894f3f7a371581/crates/primitives/src/transaction/mod.rs)
```rust, ignore ```rust, ignore
#[main_codec] #[reth_codec]
#[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref, Default)] #[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref, Default)]
pub struct TransactionSigned { pub struct TransactionSigned {
pub hash: TxHash, pub hash: TxHash,

View File

@ -19,7 +19,7 @@
- [Scale Encoding](https://github.com/paritytech/parity-scale-codec) - [Scale Encoding](https://github.com/paritytech/parity-scale-codec)
- [Postcard Encoding](https://github.com/jamesmunns/postcard) - [Postcard Encoding](https://github.com/jamesmunns/postcard)
- Passthrough (called `no_codec` in the codebase) - Passthrough (called `no_codec` in the codebase)
- We made implementation of these traits easy via a derive macro called [`main_codec`](https://github.com/paradigmxyz/reth/blob/0d9b9a392d4196793736522f3fc2ac804991b45d/crates/codecs/derive/src/lib.rs#L15) that delegates to one of Compact (default), Scale, Postcard or Passthrough encoding. This is [derived on every struct we need](https://github.com/search?q=repo%3Aparadigmxyz%2Freth%20%22%23%5Bmain_codec%5D%22&type=code), and lets us experiment with different encoding formats without having to modify the entire codebase each time. - We made implementation of these traits easy via a derive macro called [`reth_codec`](https://github.com/paradigmxyz/reth/blob/0d9b9a392d4196793736522f3fc2ac804991b45d/crates/codecs/derive/src/lib.rs#L15) that delegates to one of Compact (default), Scale, Postcard or Passthrough encoding. This is [derived on every struct we need](https://github.com/search?q=repo%3Aparadigmxyz%2Freth%20%22%23%5Breth_codec%5D%22&type=code), and lets us experiment with different encoding formats without having to modify the entire codebase each time.
### Table layout ### Table layout