Skip to content

Commit

Permalink
refactor: light refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
0xaatif committed Jun 13, 2024
1 parent ce11041 commit e524c0a
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 410 deletions.
258 changes: 7 additions & 251 deletions Cargo.lock

Large diffs are not rendered by default.

37 changes: 15 additions & 22 deletions trace_decoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,24 @@ homepage.workspace = true
keywords.workspace = true

[dependencies]
bytes = { workspace = true }
ciborium = "0.2.1"
ciborium-io = "0.2.1"
enum-as-inner = { workspace = true }
enumn = "0.1.12"
ethereum-types = { workspace = true }
hex = { workspace = true }
hex-literal = { workspace = true }
keccak-hash = { workspace = true }
log = { workspace = true }
rlp = { workspace = true }
rlp-derive = { workspace = true }
serde = { workspace = true }
serde_with = "3.4.0"
thiserror = { workspace = true }
mpt_trie_type_1.workspace = true
evm_arithmetization_type_1.workspace = true
winnow = "0.6.11"
bitflags = "2.5.0"
nunny = { version = "0.2.1", features = ["serde"] }
either = "1.12.0"
anyhow = "1.0.86"
bitflags = "2.5.0"
bitvec = "1.0.1"
primitive-types = "0.12.2"
bytes.workspace = true
ciborium = "0.2.1"
either = "1.12.0"
ethereum-types.workspace = true
evm_arithmetization_type_1.workspace = true
hex.workspace = true
itertools = "0.13.0"
keccak-hash.workspace = true
log.workspace = true
mpt_trie_type_1.workspace = true
nunny = { version = "0.2.1", features = ["serde"] }
rlp.workspace = true
serde.workspace = true
thiserror.workspace = true
winnow = "0.6.11"

[dev-dependencies]
# enable this feature if you're debugging binary decoding
Expand Down
31 changes: 14 additions & 17 deletions trace_decoder/src/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use evm_arithmetization_type_1::{
proof::{ExtraBlockData, TrieRoots},
};
use log::trace;
use mpt_trie_type_1::nibbles::Nibbles;
use mpt_trie_type_1::{
nibbles::Nibbles,
partial_trie::{HashedPartialTrie, Node, PartialTrie},
special_query::path_for_query,
trie_ops::{TrieOpError, TrieOpResult},
Expand All @@ -25,16 +25,13 @@ use crate::{
processed_block_trace::{
NodesUsedByTxn, ProcessedBlockTrace, ProcessedTxnInfo, StateTrieWrites, TxnMetaState,
},
types::{
HashedAccountAddr, HashedNodeAddr, HashedStorageAddr, HashedStorageAddrNibbles,
TrieRootHash, TxnIdx, EMPTY_ACCOUNT_BYTES_RLPED, ZERO_STORAGE_SLOT_VAL_RLPED,
},
types::*,
OtherBlockData,
};

/// Stores the result of parsing tries. Returns a [TraceParsingError] upon
/// failure.
pub type TraceParsingResult<T> = Result<T, Box<TraceParsingError>>;
type TraceParsingResult<T> = Result<T, Box<TraceParsingError>>;

/// Represents errors that can occur during the processing of a block trace.
///
Expand Down Expand Up @@ -82,7 +79,7 @@ impl std::error::Error for TraceParsingError {}

impl TraceParsingError {
/// Function to create a new TraceParsingError with mandatory fields
pub(crate) fn new(reason: TraceParsingErrorReason) -> Self {
fn new(reason: TraceParsingErrorReason) -> Self {
Self {
block_num: None,
block_chain_id: None,
Expand All @@ -96,51 +93,51 @@ impl TraceParsingError {
}

/// Builder method to set block_num
pub(crate) fn block_num(&mut self, block_num: U256) -> &mut Self {
fn block_num(&mut self, block_num: U256) -> &mut Self {
self.block_num = Some(block_num);
self
}

/// Builder method to set block_chain_id
pub(crate) fn block_chain_id(&mut self, block_chain_id: U256) -> &mut Self {
fn block_chain_id(&mut self, block_chain_id: U256) -> &mut Self {
self.block_chain_id = Some(block_chain_id);
self
}

/// Builder method to set txn_idx
pub fn txn_idx(&mut self, txn_idx: usize) -> &mut Self {
fn txn_idx(&mut self, txn_idx: usize) -> &mut Self {
self.txn_idx = Some(txn_idx);
self
}

/// Builder method to set addr
pub fn addr(&mut self, addr: Address) -> &mut Self {
fn addr(&mut self, addr: Address) -> &mut Self {
self.addr = Some(addr);
self
}

/// Builder method to set h_addr
pub fn h_addr(&mut self, h_addr: H256) -> &mut Self {
fn h_addr(&mut self, h_addr: H256) -> &mut Self {
self.h_addr = Some(h_addr);
self
}

/// Builder method to set slot
pub fn slot(&mut self, slot: U512) -> &mut Self {
fn slot(&mut self, slot: U512) -> &mut Self {
self.slot = Some(slot);
self
}

/// Builder method to set slot_value
pub fn slot_value(&mut self, slot_value: U512) -> &mut Self {
fn slot_value(&mut self, slot_value: U512) -> &mut Self {
self.slot_value = Some(slot_value);
self
}
}

/// An error reason for trie parsing.
#[derive(Debug, Error)]
pub enum TraceParsingErrorReason {
enum TraceParsingErrorReason {
/// Failure to decode an Ethereum [Account].
#[error("Failed to decode RLP bytes ({0}) as an Ethereum account due to the error: {1}")]
AccountDecode(String, String),
Expand Down Expand Up @@ -289,7 +286,7 @@ impl ProcessedBlockTrace {
fn update_txn_and_receipt_tries(
trie_state: &mut PartialTrieState,
meta: &TxnMetaState,
txn_idx: TxnIdx,
txn_idx: usize,
) -> TrieOpResult<()> {
let txn_k = Nibbles::from_bytes_be(&rlp::encode(&txn_idx)).unwrap();
trie_state.txn.insert(txn_k, meta.txn_bytes())?;
Expand Down Expand Up @@ -325,7 +322,7 @@ impl ProcessedBlockTrace {
fn create_minimal_partial_tries_needed_by_txn(
curr_block_tries: &PartialTrieState,
nodes_used_by_txn: &NodesUsedByTxn,
txn_idx: TxnIdx,
txn_idx: usize,
delta_application_out: TrieDeltaApplicationOutput,
_coin_base_addr: &Address,
) -> TraceParsingResult<TrieInputs> {
Expand Down
79 changes: 0 additions & 79 deletions trace_decoder/src/deserializers.rs

This file was deleted.

Loading

0 comments on commit e524c0a

Please sign in to comment.