mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Rename main codec to reth db codec (#9501)
This commit is contained in:
@ -4,12 +4,12 @@ use alloy_primitives::{keccak256, Bytes, B256, U256};
|
||||
use byteorder::{BigEndian, ReadBytesExt};
|
||||
use bytes::Buf;
|
||||
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 serde::{Deserialize, Serialize};
|
||||
|
||||
/// An Ethereum account.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
|
||||
pub struct Account {
|
||||
/// Account nonce.
|
||||
|
||||
@ -16,11 +16,11 @@ use alloy_primitives::{keccak256, Address, BlockNumber, Bloom, Bytes, B256, B64,
|
||||
use alloy_rlp::{length_of_length, Decodable, Encodable};
|
||||
use bytes::BufMut;
|
||||
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};
|
||||
|
||||
/// Block header
|
||||
#[main_codec(no_arbitrary)]
|
||||
#[reth_codec(no_arbitrary)]
|
||||
#[add_arbitrary_tests(rlp, 25)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Header {
|
||||
|
||||
@ -7,11 +7,11 @@ use alloy_rlp::{Decodable, Encodable};
|
||||
use bytes::BufMut;
|
||||
use core::mem;
|
||||
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
|
||||
/// to modify header.
|
||||
#[main_codec(no_arbitrary)]
|
||||
#[reth_codec(no_arbitrary)]
|
||||
#[add_arbitrary_tests(rlp, compact)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref)]
|
||||
pub struct SealedHeader {
|
||||
|
||||
@ -19,11 +19,11 @@ mod tests {
|
||||
use alloy_rlp::{RlpDecodable, RlpEncodable};
|
||||
use proptest::proptest;
|
||||
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-primitives Log type natively
|
||||
#[main_codec(rlp)]
|
||||
#[reth_codec(rlp)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, RlpDecodable, RlpEncodable, Default)]
|
||||
struct Log {
|
||||
/// Contract that emitted this log.
|
||||
|
||||
@ -4,14 +4,14 @@ pub use alloy_consensus::Request;
|
||||
use alloy_eips::eip7685::{Decodable7685, Encodable7685};
|
||||
use alloy_rlp::{Decodable, Encodable};
|
||||
use derive_more::{Deref, DerefMut, From, IntoIterator};
|
||||
use reth_codecs::{main_codec, Compact};
|
||||
use reth_codecs::{reth_codec, Compact};
|
||||
use revm_primitives::Bytes;
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
|
||||
/// A list of EIP-7685 requests.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash, Deref, DerefMut, From, IntoIterator)]
|
||||
pub struct Requests(pub Vec<Request>);
|
||||
|
||||
|
||||
@ -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
|
||||
// over whole value (Even SubKey) that would mess up fetching of values with seek_by_key_subkey
|
||||
impl Compact for StorageEntry {
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper};
|
||||
use derive_more::{AsRef, Deref, DerefMut, From, IntoIterator};
|
||||
use reth_codecs::{main_codec, Compact};
|
||||
use reth_codecs::{reth_codec, Compact};
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
@ -12,7 +12,7 @@ use alloc::vec::Vec;
|
||||
pub use alloy_eips::eip4895::Withdrawal;
|
||||
|
||||
/// Represents a collection of Withdrawals.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(
|
||||
Debug,
|
||||
Clone,
|
||||
@ -92,7 +92,7 @@ mod tests {
|
||||
|
||||
/// This type is kept for compatibility tests after the codec support was added to alloy-eips
|
||||
/// Withdrawal type natively
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash, RlpEncodable, RlpDecodable)]
|
||||
struct RethWithdrawal {
|
||||
/// Monotonically increasing identifier issued by consensus layer.
|
||||
|
||||
@ -8,15 +8,15 @@ use core::{cmp::Ordering, ops::Deref};
|
||||
use derive_more::{Deref, DerefMut, From, IntoIterator};
|
||||
#[cfg(feature = "zstd-codec")]
|
||||
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};
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::{vec, vec::Vec};
|
||||
|
||||
/// Receipt containing result of transaction execution.
|
||||
#[cfg_attr(feature = "zstd-codec", main_codec(no_arbitrary, zstd))]
|
||||
#[cfg_attr(not(feature = "zstd-codec"), main_codec(no_arbitrary))]
|
||||
#[cfg_attr(feature = "zstd-codec", reth_codec(no_arbitrary, zstd))]
|
||||
#[cfg_attr(not(feature = "zstd-codec"), reth_codec(no_arbitrary))]
|
||||
#[add_arbitrary_tests]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Default, RlpEncodable, RlpDecodable)]
|
||||
#[rlp(trailing)]
|
||||
@ -142,7 +142,7 @@ impl From<Receipt> for ReceiptWithBloom {
|
||||
}
|
||||
|
||||
/// [`Receipt`] with calculated bloom filter.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Default)]
|
||||
pub struct ReceiptWithBloom {
|
||||
/// Bloom filter build from logs.
|
||||
|
||||
@ -11,11 +11,11 @@ mod tests {
|
||||
use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper};
|
||||
use proptest::proptest;
|
||||
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
|
||||
/// AccessList type natively
|
||||
#[main_codec(rlp)]
|
||||
#[reth_codec(rlp)]
|
||||
#[derive(
|
||||
Clone, Debug, PartialEq, Eq, Hash, Default, RlpDecodableWrapper, RlpEncodableWrapper,
|
||||
)]
|
||||
@ -28,7 +28,7 @@ mod tests {
|
||||
}
|
||||
|
||||
// This
|
||||
#[main_codec(rlp)]
|
||||
#[reth_codec(rlp)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default, RlpDecodable, RlpEncodable)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct RethAccessListItem {
|
||||
|
||||
@ -2,13 +2,13 @@ use super::access_list::AccessList;
|
||||
use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256};
|
||||
use alloy_rlp::{length_of_length, Decodable, Encodable, Header};
|
||||
use core::mem;
|
||||
use reth_codecs::{main_codec, Compact};
|
||||
use reth_codecs::{reth_codec, Compact};
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
|
||||
/// 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)]
|
||||
pub struct TxEip1559 {
|
||||
/// Added as EIP-155: Simple replay attack protection
|
||||
|
||||
@ -2,13 +2,13 @@ use super::access_list::AccessList;
|
||||
use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256};
|
||||
use alloy_rlp::{length_of_length, Decodable, Encodable, Header};
|
||||
use core::mem;
|
||||
use reth_codecs::{main_codec, Compact};
|
||||
use reth_codecs::{reth_codec, Compact};
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
|
||||
/// Transaction with an [`AccessList`] ([EIP-2930](https://eips.ethereum.org/EIPS/eip-2930)).
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
|
||||
pub struct TxEip2930 {
|
||||
/// Added as EIP-155: Simple replay attack protection
|
||||
|
||||
@ -5,7 +5,7 @@ use crate::{
|
||||
};
|
||||
use alloy_rlp::{length_of_length, Decodable, Encodable, Header};
|
||||
use core::mem;
|
||||
use reth_codecs::{main_codec, Compact, CompactPlaceholder};
|
||||
use reth_codecs::{reth_codec, Compact, CompactPlaceholder};
|
||||
|
||||
#[cfg(feature = "c-kzg")]
|
||||
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)
|
||||
///
|
||||
/// A transaction with blob hashes and max blob fee
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
|
||||
pub struct TxEip4844 {
|
||||
/// Added as EIP-155: Simple replay attack protection
|
||||
|
||||
@ -4,7 +4,7 @@ use crate::{
|
||||
};
|
||||
use alloy_rlp::{length_of_length, Decodable, Encodable, Header};
|
||||
use core::mem;
|
||||
use reth_codecs::{main_codec, Compact};
|
||||
use reth_codecs::{reth_codec, Compact};
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
@ -12,7 +12,7 @@ use alloc::vec::Vec;
|
||||
/// [EIP-7702 Set Code Transaction](https://eips.ethereum.org/EIPS/eip-7702)
|
||||
///
|
||||
/// 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)]
|
||||
pub struct TxEip7702 {
|
||||
/// Added as EIP-155: Simple replay attack protection
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
use crate::{keccak256, Bytes, ChainId, Signature, TxKind, TxType, B256, U256};
|
||||
use alloy_rlp::{length_of_length, Encodable, Header};
|
||||
use core::mem;
|
||||
use reth_codecs::{main_codec, Compact};
|
||||
use reth_codecs::{reth_codec, Compact};
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
|
||||
/// Legacy transaction.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
|
||||
pub struct TxLegacy {
|
||||
/// Added as EIP-155: Simple replay attack protection
|
||||
|
||||
@ -3,11 +3,11 @@ use alloy_rlp::{
|
||||
length_of_length, Decodable, Encodable, Error as DecodeError, Header, EMPTY_STRING_CODE,
|
||||
};
|
||||
use bytes::Buf;
|
||||
use reth_codecs::{main_codec, Compact};
|
||||
use reth_codecs::{reth_codec, Compact};
|
||||
use std::mem;
|
||||
|
||||
/// 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)]
|
||||
pub struct TxDeposit {
|
||||
/// Hash that uniquely identifies the source of the deposit.
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
use crate::PruneMode;
|
||||
use alloy_primitives::{BlockNumber, TxNumber};
|
||||
use reth_codecs::{main_codec, Compact};
|
||||
use reth_codecs::{reth_codec, Compact};
|
||||
|
||||
/// Saves the pruning progress of a stage.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
#[cfg_attr(test, derive(Default))]
|
||||
pub struct PruneCheckpoint {
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
use crate::{segment::PrunePurpose, PruneSegment, PruneSegmentError};
|
||||
use alloy_primitives::BlockNumber;
|
||||
use reth_codecs::{main_codec, Compact};
|
||||
use reth_codecs::{reth_codec, Compact};
|
||||
|
||||
/// Prune mode.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum PruneMode {
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
use crate::MINIMUM_PRUNING_DISTANCE;
|
||||
use derive_more::Display;
|
||||
use reth_codecs::{main_codec, Compact};
|
||||
use reth_codecs::{reth_codec, Compact};
|
||||
use thiserror::Error;
|
||||
|
||||
/// Segment of the data that can be pruned.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, Display, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
pub enum PruneSegment {
|
||||
/// Prune segment responsible for the `TransactionSenders` table.
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
use alloy_primitives::{Address, BlockNumber, B256};
|
||||
use bytes::Buf;
|
||||
use reth_codecs::{main_codec, Compact};
|
||||
use reth_codecs::{reth_codec, Compact};
|
||||
use reth_trie_common::{hash_builder::HashBuilderState, StoredSubNode};
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
@ -74,7 +74,7 @@ impl Compact for MerkleCheckpoint {
|
||||
}
|
||||
|
||||
/// Saves the progress of AccountHashing stage.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub struct AccountHashingCheckpoint {
|
||||
/// The next account to start hashing from.
|
||||
@ -86,7 +86,7 @@ pub struct AccountHashingCheckpoint {
|
||||
}
|
||||
|
||||
/// Saves the progress of StorageHashing stage.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub struct StorageHashingCheckpoint {
|
||||
/// The next account to start hashing from.
|
||||
@ -100,7 +100,7 @@ pub struct StorageHashingCheckpoint {
|
||||
}
|
||||
|
||||
/// Saves the progress of Execution stage.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub struct ExecutionCheckpoint {
|
||||
/// Block range which this checkpoint is valid for.
|
||||
@ -110,7 +110,7 @@ pub struct ExecutionCheckpoint {
|
||||
}
|
||||
|
||||
/// Saves the progress of Headers stage.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub struct HeadersCheckpoint {
|
||||
/// Block range which this checkpoint is valid for.
|
||||
@ -120,7 +120,7 @@ pub struct HeadersCheckpoint {
|
||||
}
|
||||
|
||||
/// Saves the progress of Index History stages.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub struct IndexHistoryCheckpoint {
|
||||
/// 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.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)]
|
||||
pub struct EntitiesCheckpoint {
|
||||
/// 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
|
||||
/// multiple executions.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub struct CheckpointBlockRange {
|
||||
/// The first block of the range, inclusive.
|
||||
@ -180,7 +180,7 @@ impl From<&RangeInclusive<BlockNumber>> for CheckpointBlockRange {
|
||||
}
|
||||
|
||||
/// Saves the progress of a stage.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, Default, PartialEq, Eq, Clone, Copy)]
|
||||
pub struct StageCheckpoint {
|
||||
/// 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`]
|
||||
// is not a Copy type.
|
||||
/// Stage-specific checkpoint metrics.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub enum StageUnitCheckpoint {
|
||||
/// Saves the progress of AccountHashing stage.
|
||||
|
||||
@ -2,18 +2,18 @@
|
||||
|
||||
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:
|
||||
* [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
|
||||
|
||||
Provides derive macros that can be added and configured to stored data structs/enums
|
||||
* `#[main_codec]`: Implements `Compact` as well as `#[derive_arbitrary(compact)]`
|
||||
* `#[main_codec(rlp)]`: Implements `Compact` as well as `#[derive_arbitrary(compact, rlp)]`
|
||||
* `#[main_codec(no_arbitrary)]`: Implements `Compact` without `derive_arbitrary`.
|
||||
* `#[reth_codec]`: Implements `Compact` as well as `#[derive_arbitrary(compact)]`
|
||||
* `#[reth_codec(rlp)]`: Implements `Compact` as well as `#[derive_arbitrary(compact, rlp)]`
|
||||
* `#[reth_codec(no_arbitrary)]`: Implements `Compact` without `derive_arbitrary`.
|
||||
|
||||
* `#[derive_arbitrary]`: will derive arbitrary `Arbitrary` and `proptest::Arbitrary` with no generated tests.
|
||||
* `#[derive_arbitrary(rlp)]`: will derive arbitrary and generate rlp roundtrip proptests.
|
||||
|
||||
@ -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.
|
||||
///
|
||||
/// Example usage:
|
||||
/// * `#[main_codec(rlp)]`: will implement `derive_arbitrary(rlp)` or `derive_arbitrary(compact, rlp)`, if `compact` is the `main_codec`.
|
||||
/// * `#[main_codec(no_arbitrary)]`: will skip `derive_arbitrary` (both trait implementations and tests)
|
||||
/// * `#[reth_codec(rlp)]`: will implement `derive_arbitrary(rlp)` or `derive_arbitrary(compact, rlp)`, if `compact` is the `reth_codec`.
|
||||
/// * `#[reth_codec(no_arbitrary)]`: will skip `derive_arbitrary` (both trait implementations and tests)
|
||||
#[proc_macro_attribute]
|
||||
#[rustfmt::skip]
|
||||
#[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 with_zstd = args.clone().into_iter().any(|tk| tk.to_string() == "zstd");
|
||||
|
||||
@ -2,12 +2,12 @@ use crate::Compact;
|
||||
use alloy_eips::eip7702::{Authorization as AlloyAuthorization, SignedAuthorization};
|
||||
use alloy_primitives::{Address, ChainId, U256};
|
||||
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.
|
||||
///
|
||||
/// Notice: Make sure this struct is 1:1 with `alloy_eips::eip7702::Authorization`
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
struct Authorization {
|
||||
chain_id: ChainId,
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
use crate::Compact;
|
||||
use alloy_genesis::GenesisAccount as AlloyGenesisAccount;
|
||||
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.
|
||||
///
|
||||
/// Notice: Make sure this struct is 1:1 with `alloy_genesis::GenesisAccount`
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
struct GenesisAccount {
|
||||
/// The nonce of the account at genesis.
|
||||
@ -21,13 +21,13 @@ struct GenesisAccount {
|
||||
private_key: Option<B256>,
|
||||
}
|
||||
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
struct StorageEntries {
|
||||
entries: Vec<StorageEntry>,
|
||||
}
|
||||
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
struct StorageEntry {
|
||||
key: B256,
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
use crate::Compact;
|
||||
use alloy_eips::eip4895::Withdrawal as AlloyWithdrawal;
|
||||
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.
|
||||
///
|
||||
/// Notice: Make sure this struct is 1:1 with `alloy_eips::eip4895::Withdrawal`
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Default)]
|
||||
struct Withdrawal {
|
||||
/// Monotonically increasing identifier issued by consensus layer.
|
||||
|
||||
@ -555,7 +555,7 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
struct TestStruct {
|
||||
f_u64: u64,
|
||||
@ -607,7 +607,7 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, PartialEq, Clone, Default)]
|
||||
enum TestEnum {
|
||||
#[default]
|
||||
|
||||
@ -23,7 +23,7 @@ pub struct AccountBeforeTx {
|
||||
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
|
||||
// over whole value (Even SubKey) that would mess up fetching of values with seek_by_key_subkey
|
||||
impl Compact for AccountBeforeTx {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
//! 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 std::ops::Range;
|
||||
|
||||
@ -12,7 +12,7 @@ pub type NumTransactions = u64;
|
||||
/// It has the pointer to the transaction Number of the first
|
||||
/// transaction in the block and the total number of transactions.
|
||||
#[derive(Debug, Default, Eq, PartialEq, Clone)]
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
pub struct StoredBlockBodyIndices {
|
||||
/// The number of the first transaction in this block
|
||||
///
|
||||
@ -68,7 +68,7 @@ impl StoredBlockBodyIndices {
|
||||
/// The storage representation of a block's ommers.
|
||||
///
|
||||
/// It is stored as the headers of the block's uncles.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, Default, Eq, PartialEq, Clone)]
|
||||
pub struct StoredBlockOmmers {
|
||||
/// The block headers of this block's uncles.
|
||||
@ -76,7 +76,7 @@ pub struct StoredBlockOmmers {
|
||||
}
|
||||
|
||||
/// The storage representation of block withdrawals.
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, Default, Eq, PartialEq, Clone)]
|
||||
pub struct StoredBlockWithdrawals {
|
||||
/// The block withdrawals.
|
||||
|
||||
@ -4,7 +4,7 @@ use crate::{
|
||||
table::{Compress, Decode, Decompress, Encode},
|
||||
DatabaseError,
|
||||
};
|
||||
use reth_codecs::{main_codec, Compact};
|
||||
use reth_codecs::{reth_codec, Compact};
|
||||
use reth_primitives::{Address, B256, *};
|
||||
use reth_prune_types::{PruneCheckpoint, PruneSegment};
|
||||
use reth_stages_types::StageCheckpoint;
|
||||
@ -263,7 +263,7 @@ macro_rules! add_wrapper_struct {
|
||||
($(($name:tt, $wrapper:tt)),+) => {
|
||||
$(
|
||||
/// 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)]
|
||||
pub struct $wrapper(pub $name);
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ pub struct StorageTrieEntry {
|
||||
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
|
||||
// over whole value (Even SubKey) that would mess up fetching of values with seek_by_key_subkey
|
||||
impl Compact for StorageTrieEntry {
|
||||
|
||||
@ -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)
|
||||
```rust, ignore
|
||||
#[main_codec]
|
||||
#[reth_codec]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref, Default)]
|
||||
pub struct TransactionSigned {
|
||||
pub hash: TxHash,
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
- [Scale Encoding](https://github.com/paritytech/parity-scale-codec)
|
||||
- [Postcard Encoding](https://github.com/jamesmunns/postcard)
|
||||
- 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user