diff --git a/crates/flat-files-decoder/src/dbin/mod.rs b/crates/flat-files-decoder/src/dbin/mod.rs index ac9b5d75..25900422 100644 --- a/crates/flat-files-decoder/src/dbin/mod.rs +++ b/crates/flat-files-decoder/src/dbin/mod.rs @@ -115,7 +115,7 @@ impl DbinFile { impl DbinFile { /// Reads a single message - pub fn read_message(read: &mut R) -> Result, DbinFileError> { + fn read_message(read: &mut R) -> Result, DbinFileError> { let mut size: [u8; 4] = [0; 4]; read.read_exact(&mut size)?; diff --git a/crates/flat-files-decoder/src/error.rs b/crates/flat-files-decoder/src/error.rs index e2ce8862..193c9ac4 100644 --- a/crates/flat-files-decoder/src/error.rs +++ b/crates/flat-files-decoder/src/error.rs @@ -29,12 +29,10 @@ pub enum DecodeError { JoinError(JoinError), } -// Define an enum for all possible error types #[derive(Debug)] pub enum CheckError { - ReceiptError(ReceiptError), // Replace with actual error types + ReceiptError(ReceiptError), TransactionError(TransactionError), - // Add more as needed } impl std::fmt::Display for CheckError { @@ -42,7 +40,6 @@ impl std::fmt::Display for CheckError { match self { CheckError::ReceiptError(e) => write!(f, "Receipt Error: {}", e), CheckError::TransactionError(e) => write!(f, "Transaction Error: {}", e), - // Handle other errors } } } diff --git a/crates/flat-files-decoder/src/headers/error.rs b/crates/flat-files-decoder/src/headers/error.rs index 4a7fcf11..3f613974 100644 --- a/crates/flat-files-decoder/src/headers/error.rs +++ b/crates/flat-files-decoder/src/headers/error.rs @@ -7,8 +7,6 @@ pub enum BlockHeaderError { ReadError(#[from] std::io::Error), #[error("JSON Error")] JsonError(#[from] serde_json::Error), - #[error("Invalid input")] - InvalidInput, #[error("Mismatched roots")] MismatchedRoots(Box<(BlockHeaderRoots, BlockHeaderRoots)>), #[error("Missing header")] diff --git a/crates/flat-files-decoder/src/headers/mod.rs b/crates/flat-files-decoder/src/headers/mod.rs index 20c3b571..847cc326 100644 --- a/crates/flat-files-decoder/src/headers/mod.rs +++ b/crates/flat-files-decoder/src/headers/mod.rs @@ -26,7 +26,7 @@ impl TryFrom for BlockHeaderRoots { } } -pub fn check_valid_header(block: &Block, header_dir: &str) -> Result<(), BlockHeaderError> { +pub(crate) fn check_valid_header(block: &Block, header_dir: &str) -> Result<(), BlockHeaderError> { let header_file_path = format!("{}/{}.json", header_dir, block.number); let header_file = File::open(header_file_path)?; @@ -49,7 +49,7 @@ pub fn check_valid_header(block: &Block, header_dir: &str) -> Result<(), BlockHe } #[derive(Serialize, Deserialize)] -pub struct HeaderRecordWithNumber { +pub(crate) struct HeaderRecordWithNumber { pub block_hash: Vec, pub total_difficulty: Vec, pub block_number: u64, diff --git a/crates/flat-files-decoder/src/lib.rs b/crates/flat-files-decoder/src/lib.rs index 8c24e917..f31fd16d 100644 --- a/crates/flat-files-decoder/src/lib.rs +++ b/crates/flat-files-decoder/src/lib.rs @@ -18,7 +18,6 @@ use error::CheckError; use firehose_protos::ethereum_v2::Block; use headers::HeaderRecordWithNumber; use prost::Message; -use rayon::prelude::*; use receipts::check_receipt_root; use simple_log::log; use std::{ @@ -37,31 +36,16 @@ pub enum Decompression { None, } -impl From for Decompression { - fn from(value: bool) -> Self { - if value { - Decompression::Zstd - } else { - Decompression::None - } - } -} - impl From<&str> for Decompression { fn from(value: &str) -> Self { match value { - "true" => Decompression::Zstd, - "false" => Decompression::None, + "true" | "1" => Decompression::Zstd, + "false" | "0" => Decompression::None, _ => Decompression::None, } } } -pub enum DecodeInput { - Path(String), - Reader(Box), -} - /// Decodes and optionally verifies block flat files from a given directory or single file. /// /// This function processes input which can be a file or a directory containing multiple `.dbin` files. @@ -185,7 +169,7 @@ pub fn handle_file( /// Decodes a flat file from a buffer containing its contents and optionally decompresses it. /// -/// Decodes flat files that are already loaded into memory, without direct file system ac cess. +/// Decodes flat files that are already loaded into memory, without direct file system access. /// It can handle both compressed (if `zstd` decompression is specified) and uncompressed data. Upon successful /// decoding, it returns a vector of all the blocks contained within the flat file. The actual number of blocks /// returned depends on the format and content of the flat file—ranging from a single block to multiple blocks. @@ -241,20 +225,6 @@ fn handle_block( Ok(block) } -/// Gets a vector of blocks from a single .dbin file -pub fn extract_blocks(mut reader: R) -> Result, DecodeError> { - log::debug!("Reading messages"); - let dbin_file = DbinFile::try_from_read(&mut reader)?; - log::debug!("Validating blocks"); - - // Parallel processing of block headers - dbin_file - .messages - .par_iter() - .map(|message| handle_block(message, None, None)) - .collect() -} - /// Decode blocks from a reader and writes them, serialized, to a writer /// /// data can be piped into this function from stdin via `cargo run stream < ./example0017686312.dbin`. diff --git a/crates/flat-files-decoder/src/receipts/logs.rs b/crates/flat-files-decoder/src/receipts/logs.rs index 217ff18a..13863d4e 100644 --- a/crates/flat-files-decoder/src/receipts/logs.rs +++ b/crates/flat-files-decoder/src/receipts/logs.rs @@ -6,11 +6,11 @@ use std::convert::TryInto; use firehose_protos::ethereum_v2::Log as BlockLog; -pub fn map_logs(logs: &[BlockLog]) -> Result, ReceiptError> { +pub(crate) fn map_logs(logs: &[BlockLog]) -> Result, ReceiptError> { logs.iter().map(block_log_to_log).collect() } -pub fn block_log_to_log(log: &BlockLog) -> Result { +pub(crate) fn block_log_to_log(log: &BlockLog) -> Result { let slice: [u8; 20] = log .address .as_slice() @@ -26,7 +26,7 @@ pub fn block_log_to_log(log: &BlockLog) -> Result { Ok(Log { address, data }) } -fn map_topics(topics: &[Vec]) -> Result, ReceiptError> { +pub(crate) fn map_topics(topics: &[Vec]) -> Result, ReceiptError> { topics.iter().map(map_topic).collect() } diff --git a/crates/flat-files-decoder/src/receipts/receipt.rs b/crates/flat-files-decoder/src/receipts/receipt.rs index 2e9575d4..96e0233f 100644 --- a/crates/flat-files-decoder/src/receipts/receipt.rs +++ b/crates/flat-files-decoder/src/receipts/receipt.rs @@ -6,7 +6,7 @@ use firehose_protos::ethereum_v2::TransactionTrace; use reth_primitives::{Log, Receipt, ReceiptWithBloom}; use revm_primitives::hex; -pub struct FullReceipt { +pub(crate) struct FullReceipt { pub receipt: ReceiptWithBloom, pub state_root: Vec, } diff --git a/crates/flat-files-decoder/src/transactions/access_list.rs b/crates/flat-files-decoder/src/transactions/access_list.rs index 36ae6327..307476d4 100644 --- a/crates/flat-files-decoder/src/transactions/access_list.rs +++ b/crates/flat-files-decoder/src/transactions/access_list.rs @@ -16,7 +16,7 @@ pub(crate) fn compute_access_list( Ok(AccessList(access_list_items)) } -pub fn atuple_to_alist_item(tuple: &AccessTuple) -> Result { +fn atuple_to_alist_item(tuple: &AccessTuple) -> Result { let address: Address = Address::from_slice(tuple.address.as_slice()); let storage_keys = tuple .storage_keys diff --git a/crates/flat-files-decoder/src/transactions/mod.rs b/crates/flat-files-decoder/src/transactions/mod.rs index 2095723a..16e230c0 100644 --- a/crates/flat-files-decoder/src/transactions/mod.rs +++ b/crates/flat-files-decoder/src/transactions/mod.rs @@ -38,7 +38,7 @@ pub fn check_transaction_root(block: &Block) -> Result<(), TransactionError> { Ok(()) } -pub fn bigint_to_u128(value: BigInt) -> Result { +pub(crate) fn bigint_to_u128(value: BigInt) -> Result { let slice = value.bytes.as_slice(); let n = U128::try_from_be_slice(slice) .ok_or(TransactionError::InvalidBigInt(hex::encode(slice)))?; diff --git a/crates/flat-files-decoder/src/transactions/signature.rs b/crates/flat-files-decoder/src/transactions/signature.rs index 8cd2841a..e18344c9 100644 --- a/crates/flat-files-decoder/src/transactions/signature.rs +++ b/crates/flat-files-decoder/src/transactions/signature.rs @@ -14,7 +14,9 @@ pub enum InvalidSignatureError { V(u8), } -pub fn signature_from_trace(trace: &TransactionTrace) -> Result { +pub(crate) fn signature_from_trace( + trace: &TransactionTrace, +) -> Result { let r_bytes: [u8; 32] = trace .r .as_slice() diff --git a/crates/flat-files-decoder/src/transactions/transaction.rs b/crates/flat-files-decoder/src/transactions/transaction.rs index 6fc0d188..dc456314 100644 --- a/crates/flat-files-decoder/src/transactions/transaction.rs +++ b/crates/flat-files-decoder/src/transactions/transaction.rs @@ -12,7 +12,9 @@ use super::bigint_to_u128; pub const CHAIN_ID: ChainId = 1; -pub fn trace_to_transaction(trace: &TransactionTrace) -> Result { +pub(crate) fn trace_to_transaction( + trace: &TransactionTrace, +) -> Result { let tx_type = map_tx_type(&trace.r#type)?; let nonce = trace.nonce; @@ -102,7 +104,7 @@ pub fn trace_to_transaction(trace: &TransactionTrace) -> Result Result { +fn get_tx_kind(trace: &TransactionTrace) -> Result { let first_call = trace.calls.first().ok_or(TransactionError::MissingCall)?; let call_type = first_call.call_type(); diff --git a/crates/flat-files-decoder/src/transactions/transaction_signed.rs b/crates/flat-files-decoder/src/transactions/transaction_signed.rs index 05040b61..5e21aa9e 100644 --- a/crates/flat-files-decoder/src/transactions/transaction_signed.rs +++ b/crates/flat-files-decoder/src/transactions/transaction_signed.rs @@ -7,7 +7,9 @@ use std::str::FromStr; use super::{signature::signature_from_trace, transaction::trace_to_transaction}; -pub fn trace_to_signed(trace: &TransactionTrace) -> Result { +pub(crate) fn trace_to_signed( + trace: &TransactionTrace, +) -> Result { let transaction = trace_to_transaction(trace)?; let signature = signature_from_trace(trace)?; let hash = FixedBytes::from_str(&hex::encode(trace.hash.as_slice())) diff --git a/crates/flat-files-decoder/src/transactions/tx_type.rs b/crates/flat-files-decoder/src/transactions/tx_type.rs index f758c883..6ad5da09 100644 --- a/crates/flat-files-decoder/src/transactions/tx_type.rs +++ b/crates/flat-files-decoder/src/transactions/tx_type.rs @@ -8,7 +8,7 @@ pub enum TransactionTypeError { Missing, } -pub fn map_tx_type(tx_type: &i32) -> Result { - let tx_type = Type::try_from(*tx_type).map_err(|_| TransactionTypeError::Missing)?; // 1 +pub(crate) fn map_tx_type(tx_type: &i32) -> Result { + let tx_type = Type::try_from(*tx_type).map_err(|_| TransactionTypeError::Missing)?; Ok(TxType::from(tx_type)) }