From f07555b6221c311524ca2af47b86b0bf4bf75d1f Mon Sep 17 00:00:00 2001 From: sslivkoff Date: Sun, 2 Jul 2023 16:47:29 +0000 Subject: [PATCH] cargo fmt --- crates/cli/src/args.rs | 2 -- crates/cli/src/main.rs | 10 ++++-- crates/cli/src/parse.rs | 11 +++---- crates/cli/src/summaries.rs | 8 +++-- crates/freezer/src/datasets/code_diffs.rs | 2 +- crates/freezer/src/datasets/logs.rs | 6 ++-- crates/freezer/src/datasets/nonce_diffs.rs | 2 +- crates/freezer/src/datasets/state_diffs.rs | 36 ++++++++++----------- crates/freezer/src/datasets/transactions.rs | 3 +- crates/freezer/src/datasets/vm_traces.rs | 7 ++-- crates/freezer/src/fetch.rs | 16 ++++++--- crates/freezer/src/freeze.rs | 12 ++++--- crates/freezer/src/lib.rs | 11 +++---- crates/freezer/src/outputs/files.rs | 5 +-- crates/freezer/src/types/cli_types.rs | 1 - crates/freezer/src/types/conversions.rs | 5 +-- crates/freezer/src/types/data_types.rs | 2 +- crates/freezer/src/types/error_types.rs | 2 -- crates/freezer/src/types/mod.rs | 17 +++++----- crates/freezer/src/types/output_types.rs | 2 -- 20 files changed, 85 insertions(+), 75 deletions(-) diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index 5ccadbe3..bf1d7895 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -34,7 +34,6 @@ pub struct Args { // help = "Select by data transaction instead of by block,\ncan be a list or a file, see syntax below", // )] // pub txs: Vec, - /// Columns to include in output #[arg(short, long, value_name="COLS", num_args(0..), help_heading="Content Options")] pub include_columns: Option>, @@ -213,4 +212,3 @@ fn get_datatype_help() -> &'static str { - opcode_traces"# ) } - diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 286f9f97..876cf9ff 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -22,8 +22,14 @@ async fn main() -> Result<()> { Ok(freeze_summary) => { let t_data_done = SystemTime::now(); println!("...done\n\n"); - summaries::print_cryo_conclusion(t_start, t_parse_done, t_data_done, &opts, &freeze_summary); - }, + summaries::print_cryo_conclusion( + t_start, + t_parse_done, + t_data_done, + &opts, + &freeze_summary, + ); + } Err(e) => { println!("{}", e) } diff --git a/crates/cli/src/parse.rs b/crates/cli/src/parse.rs index 7c60b0da..ef89d6a8 100644 --- a/crates/cli/src/parse.rs +++ b/crates/cli/src/parse.rs @@ -103,12 +103,11 @@ pub async fn parse_opts() -> Result { let parquet_compression = parse_compression(&args.compression)?; - let chunk_size = block_chunks.first().map(cryo_freezer::get_chunk_block_numbers).map(|x| x.len()); - let row_group_size = parse_row_group_size( - args.row_group_size, - args.n_row_groups, - chunk_size, - ); + let chunk_size = block_chunks + .first() + .map(cryo_freezer::get_chunk_block_numbers) + .map(|x| x.len()); + let row_group_size = parse_row_group_size(args.row_group_size, args.n_row_groups, chunk_size); // compile opts let opts = FreezeOpts { diff --git a/crates/cli/src/summaries.rs b/crates/cli/src/summaries.rs index 50f226f4..3f7cc6be 100644 --- a/crates/cli/src/summaries.rs +++ b/crates/cli/src/summaries.rs @@ -89,7 +89,11 @@ pub fn print_schema(name: &Datatype, schema: &Schema, sort: Option<&Vec> }); println!(); if let Some(sort_cols) = sort { - println!("sorting {} by: {}", name.dataset().name(), sort_cols.join(", ")); + println!( + "sorting {} by: {}", + name.dataset().name(), + sort_cols.join(", ") + ); } } @@ -107,7 +111,7 @@ pub fn print_cryo_conclusion( Ok(duration) => duration, Err(_e) => { println!("error computing system time, aborting"); - return + return; } }; let seconds = duration.as_secs(); diff --git a/crates/freezer/src/datasets/code_diffs.rs b/crates/freezer/src/datasets/code_diffs.rs index e47bf2eb..f0d7ece1 100644 --- a/crates/freezer/src/datasets/code_diffs.rs +++ b/crates/freezer/src/datasets/code_diffs.rs @@ -3,8 +3,8 @@ use std::collections::HashMap; use polars::prelude::*; use super::state_diffs; -use crate::types::CodeDiffs; use crate::types::BlockChunk; +use crate::types::CodeDiffs; use crate::types::CollectError; use crate::types::ColumnType; use crate::types::Dataset; diff --git a/crates/freezer/src/datasets/logs.rs b/crates/freezer/src/datasets/logs.rs index d5e35750..128296b3 100644 --- a/crates/freezer/src/datasets/logs.rs +++ b/crates/freezer/src/datasets/logs.rs @@ -83,7 +83,8 @@ impl Dataset for Logs { let df = logs_to_df(logs, &opts.schemas[&Datatype::Logs]); if let Some(sort_keys) = opts.sort.get(&Datatype::Logs) { - df.map(|x| x.sort(sort_keys, false))?.map_err(CollectError::PolarsError) + df.map(|x| x.sort(sort_keys, false))? + .map_err(CollectError::PolarsError) } else { df } @@ -205,5 +206,6 @@ pub fn logs_to_df(logs: Vec, _schema: &Schema) -> Result topic2, "topic3" => topic3, "data" => data, - ).map_err(CollectError::PolarsError) + ) + .map_err(CollectError::PolarsError) } diff --git a/crates/freezer/src/datasets/nonce_diffs.rs b/crates/freezer/src/datasets/nonce_diffs.rs index 963c1619..4ad58b2f 100644 --- a/crates/freezer/src/datasets/nonce_diffs.rs +++ b/crates/freezer/src/datasets/nonce_diffs.rs @@ -3,13 +3,13 @@ use std::collections::HashMap; use polars::prelude::*; use super::state_diffs; -use crate::types::NonceDiffs; use crate::types::BlockChunk; use crate::types::CollectError; use crate::types::ColumnType; use crate::types::Dataset; use crate::types::Datatype; use crate::types::FreezeOpts; +use crate::types::NonceDiffs; #[async_trait::async_trait] impl Dataset for NonceDiffs { diff --git a/crates/freezer/src/datasets/state_diffs.rs b/crates/freezer/src/datasets/state_diffs.rs index 679b9015..fd5995b4 100644 --- a/crates/freezer/src/datasets/state_diffs.rs +++ b/crates/freezer/src/datasets/state_diffs.rs @@ -7,9 +7,9 @@ use crate::chunks; use crate::fetch; use crate::types::BlockChunk; use crate::types::CollectError; +use crate::types::Datatype; use crate::types::FreezeOpts; use crate::types::Schema; -use crate::types::Datatype; pub async fn collect_single( datatype: &Datatype, @@ -17,12 +17,8 @@ pub async fn collect_single( opts: &FreezeOpts, ) -> Result { let block_numbers = chunks::get_chunk_block_numbers(block_chunk); - let diffs = fetch::fetch_state_diffs( - block_chunk, - &opts.provider, - &opts.max_concurrent_blocks, - ) - .await?; + let diffs = + fetch::fetch_state_diffs(block_chunk, &opts.provider, &opts.max_concurrent_blocks).await?; let df = match state_diffs_to_df(diffs, block_numbers, &opts.schemas) { Ok(mut dfs) => match dfs.remove(datatype) { Some(df) => Ok(df), @@ -31,7 +27,8 @@ pub async fn collect_single( Err(e) => Err(CollectError::PolarsError(e)), }; if let Some(sort_keys) = opts.sort.get(datatype) { - df.map(|x| x.sort(sort_keys, false))?.map_err(CollectError::PolarsError) + df.map(|x| x.sort(sort_keys, false))? + .map_err(CollectError::PolarsError) } else { df } @@ -42,7 +39,6 @@ pub fn state_diffs_to_df( block_numbers: Vec, schemas: &HashMap, ) -> Result, PolarsError> { - let include_storage = schemas.contains_key(&Datatype::StorageDiffs); let include_balance = schemas.contains_key(&Datatype::BalanceDiffs); let include_nonce = schemas.contains_key(&Datatype::NonceDiffs); @@ -50,7 +46,8 @@ pub fn state_diffs_to_df( // storage let include_storage_block_number = included(schemas, Datatype::StorageDiffs, "block_number"); - let include_storage_transaction_hash = included(schemas, Datatype::StorageDiffs, "transaction_hash"); + let include_storage_transaction_hash = + included(schemas, Datatype::StorageDiffs, "transaction_hash"); let include_storage_address = included(schemas, Datatype::StorageDiffs, "address"); let include_storage_slot = included(schemas, Datatype::StorageDiffs, "slot"); let include_storage_from_value = included(schemas, Datatype::StorageDiffs, "from_value"); @@ -64,7 +61,8 @@ pub fn state_diffs_to_df( // balance let include_balance_block_number = included(schemas, Datatype::BalanceDiffs, "block_number"); - let include_balance_transaction_hash = included(schemas, Datatype::BalanceDiffs, "transaction_hash"); + let include_balance_transaction_hash = + included(schemas, Datatype::BalanceDiffs, "transaction_hash"); let include_balance_address = included(schemas, Datatype::BalanceDiffs, "address"); let include_balance_from_value = included(schemas, Datatype::BalanceDiffs, "from_value"); let include_balance_to_value = included(schemas, Datatype::BalanceDiffs, "to_value"); @@ -76,7 +74,8 @@ pub fn state_diffs_to_df( // nonce let include_nonce_block_number = included(schemas, Datatype::NonceDiffs, "block_number"); - let include_nonce_transaction_hash = included(schemas, Datatype::NonceDiffs, "transaction_hash"); + let include_nonce_transaction_hash = + included(schemas, Datatype::NonceDiffs, "transaction_hash"); let include_nonce_address = included(schemas, Datatype::NonceDiffs, "address"); let include_nonce_from_value = included(schemas, Datatype::NonceDiffs, "from_value"); let include_nonce_to_value = included(schemas, Datatype::NonceDiffs, "to_value"); @@ -98,11 +97,9 @@ pub fn state_diffs_to_df( let mut code_from_value: Vec> = Vec::with_capacity(blocks_traces.len()); let mut code_to_value: Vec> = Vec::with_capacity(blocks_traces.len()); - for (block_num, ts) in block_numbers.iter().zip(blocks_traces) { if let (Some(tx), Some(StateDiff(state_diff))) = (ts.transaction_hash, ts.state_diff) { for (addr, addr_diff) in state_diff.iter() { - // storage if include_storage { for (s, diff) in addr_diff.storage.iter() { @@ -139,7 +136,9 @@ pub fn state_diffs_to_df( Diff::Same => ("0".to_string(), "0".to_string()), Diff::Born(value) => ("0".to_string(), value.to_string()), Diff::Died(value) => (value.to_string(), "0".to_string()), - Diff::Changed(ChangedType { from, to }) => (from.to_string(), to.to_string()), + Diff::Changed(ChangedType { from, to }) => { + (from.to_string(), to.to_string()) + } }; if include_balance_block_number { balance_block_number.push(*block_num); @@ -186,7 +185,10 @@ pub fn state_diffs_to_df( // code if include_code { let (from, to) = match &addr_diff.code { - Diff::Same => (H256::zero().as_bytes().to_vec(), H256::zero().as_bytes().to_vec()), + Diff::Same => ( + H256::zero().as_bytes().to_vec(), + H256::zero().as_bytes().to_vec(), + ), Diff::Born(value) => (H256::zero().as_bytes().to_vec(), value.to_vec()), Diff::Died(value) => (value.to_vec(), H256::zero().as_bytes().to_vec()), Diff::Changed(ChangedType { from, to }) => (from.to_vec(), to.to_vec()), @@ -207,7 +209,6 @@ pub fn state_diffs_to_df( code_to_value.push(to); }; } - } } } @@ -319,4 +320,3 @@ fn included( false } } - diff --git a/crates/freezer/src/datasets/transactions.rs b/crates/freezer/src/datasets/transactions.rs index 79bafddd..f3c413f0 100644 --- a/crates/freezer/src/datasets/transactions.rs +++ b/crates/freezer/src/datasets/transactions.rs @@ -76,7 +76,8 @@ impl Dataset for Transactions { let transactions = fetch_transactions(block_numbers, opts).await?; let df = txs_to_df(transactions).map_err(CollectError::PolarsError); if let Some(sort_keys) = opts.sort.get(&Datatype::Blocks) { - df.map(|x| x.sort(sort_keys, false))?.map_err(CollectError::PolarsError) + df.map(|x| x.sort(sort_keys, false))? + .map_err(CollectError::PolarsError) } else { df } diff --git a/crates/freezer/src/datasets/vm_traces.rs b/crates/freezer/src/datasets/vm_traces.rs index c5aa9078..97a4a61b 100644 --- a/crates/freezer/src/datasets/vm_traces.rs +++ b/crates/freezer/src/datasets/vm_traces.rs @@ -11,8 +11,8 @@ use crate::types::Dataset; use crate::types::Datatype; use crate::types::FreezeOpts; use crate::types::Schema; -use crate::types::VmTraces; use crate::types::ToVecU8; +use crate::types::VmTraces; #[async_trait::async_trait] impl Dataset for VmTraces { @@ -57,7 +57,8 @@ impl Dataset for VmTraces { let df = vm_traces_to_df(vm_traces, &opts.schemas[&Datatype::VmTraces]) .map_err(CollectError::PolarsError); if let Some(sort_keys) = opts.sort.get(&Datatype::Blocks) { - df.map(|x| x.sort(sort_keys, false))?.map_err(CollectError::PolarsError) + df.map(|x| x.sort(sort_keys, false))? + .map_err(CollectError::PolarsError) } else { df } @@ -131,7 +132,6 @@ struct VmTraceColumns { fn add_ops(vm_trace: VMTrace, schema: &Schema, columns: &mut VmTraceColumns) { for opcode in vm_trace.ops { - if schema.contains_key("pc") { columns.pc.push(opcode.pc as u64); }; @@ -208,4 +208,3 @@ fn add_ops(vm_trace: VMTrace, schema: &Schema, columns: &mut VmTraceColumns) { } } } - diff --git a/crates/freezer/src/fetch.rs b/crates/freezer/src/fetch.rs index 2674aa4f..9f7110cd 100644 --- a/crates/freezer/src/fetch.rs +++ b/crates/freezer/src/fetch.rs @@ -14,8 +14,12 @@ pub async fn fetch_state_diffs( max_concurrent_blocks: &u64, ) -> Result, CollectError> { fetch_block_traces( - block_chunk, provider, max_concurrent_blocks, &[TraceType::StateDiff], - ).await + block_chunk, + provider, + max_concurrent_blocks, + &[TraceType::StateDiff], + ) + .await } pub async fn fetch_vm_traces( @@ -24,8 +28,12 @@ pub async fn fetch_vm_traces( max_concurrent_blocks: &u64, ) -> Result, CollectError> { fetch_block_traces( - block_chunk, provider, max_concurrent_blocks, &[TraceType::VmTrace], - ).await + block_chunk, + provider, + max_concurrent_blocks, + &[TraceType::VmTrace], + ) + .await } async fn fetch_block_traces( diff --git a/crates/freezer/src/freeze.rs b/crates/freezer/src/freeze.rs index d2137449..e9739ce4 100644 --- a/crates/freezer/src/freeze.rs +++ b/crates/freezer/src/freeze.rs @@ -58,12 +58,14 @@ async fn freeze_chunk( }; } else { match ds.collect_chunk(&block_chunk, &opts).await { - Ok(mut df) => if let Err(_e) = outputs::df_to_file(&mut df, &path, &opts) { - return FreezeChunkSummary { - skipped: false, - errored: true, + Ok(mut df) => { + if let Err(_e) = outputs::df_to_file(&mut df, &path, &opts) { + return FreezeChunkSummary { + skipped: false, + errored: true, + }; } - }, + } Err(_e) => { return FreezeChunkSummary { skipped: false, diff --git a/crates/freezer/src/lib.rs b/crates/freezer/src/lib.rs index fd14ee7a..5ff445b8 100644 --- a/crates/freezer/src/lib.rs +++ b/crates/freezer/src/lib.rs @@ -9,12 +9,11 @@ mod freeze; mod outputs; mod types; -pub use freeze::freeze; -pub use types::*; -pub use chunks::get_total_blocks; -pub use chunks::get_min_block; +pub use chunks::get_chunk_block_numbers; pub use chunks::get_max_block; +pub use chunks::get_min_block; pub use chunks::get_subchunks_by_count; pub use chunks::get_subchunks_by_size; -pub use chunks::get_chunk_block_numbers; - +pub use chunks::get_total_blocks; +pub use freeze::freeze; +pub use types::*; diff --git a/crates/freezer/src/outputs/files.rs b/crates/freezer/src/outputs/files.rs index 42796a91..2e41e08a 100644 --- a/crates/freezer/src/outputs/files.rs +++ b/crates/freezer/src/outputs/files.rs @@ -35,9 +35,7 @@ pub fn df_to_file(df: &mut DataFrame, filename: &str, opts: &FreezeOpts) -> Resu _ => return Err(FileError::FileWriteError), }; match result { - Ok(()) => { - std::fs::rename(tmp_filename, filename).map_err(|_e| FileError::FileWriteError) - }, + Ok(()) => std::fs::rename(tmp_filename, filename).map_err(|_e| FileError::FileWriteError), Err(_e) => Err(FileError::FileWriteError), } } @@ -75,4 +73,3 @@ fn df_to_json(df: &mut DataFrame, filename: &str) -> Result<(), FileError> { _ => Ok(()), } } - diff --git a/crates/freezer/src/types/cli_types.rs b/crates/freezer/src/types/cli_types.rs index 2dad9a15..fcadae9b 100644 --- a/crates/freezer/src/types/cli_types.rs +++ b/crates/freezer/src/types/cli_types.rs @@ -51,4 +51,3 @@ pub struct FreezeChunkSummary { pub skipped: bool, pub errored: bool, } - diff --git a/crates/freezer/src/types/conversions.rs b/crates/freezer/src/types/conversions.rs index e6f54bf5..054d2f83 100644 --- a/crates/freezer/src/types/conversions.rs +++ b/crates/freezer/src/types/conversions.rs @@ -55,7 +55,8 @@ impl ToVecHex for Vec>> { type Output = Vec>; fn to_vec_hex(&self) -> Self::Output { - self.iter().map(|opt| opt.as_ref().map(|v| prefix_hex::encode(v.clone()))).collect() + self.iter() + .map(|opt| opt.as_ref().map(|v| prefix_hex::encode(v.clone()))) + .collect() } } - diff --git a/crates/freezer/src/types/data_types.rs b/crates/freezer/src/types/data_types.rs index f5b45cce..ab592a38 100644 --- a/crates/freezer/src/types/data_types.rs +++ b/crates/freezer/src/types/data_types.rs @@ -4,10 +4,10 @@ use std::collections::HashMap; use async_trait; use polars::prelude::*; +use crate::types::error_types; use crate::types::BlockChunk; use crate::types::ColumnType; use crate::types::FreezeOpts; -use crate::types::error_types; pub struct BalanceDiffs; pub struct Blocks; diff --git a/crates/freezer/src/types/error_types.rs b/crates/freezer/src/types/error_types.rs index 8e575dfc..5d5a7b6a 100644 --- a/crates/freezer/src/types/error_types.rs +++ b/crates/freezer/src/types/error_types.rs @@ -37,7 +37,6 @@ pub enum CollectError { #[derive(Error, Debug)] pub enum ChunkError { - #[error("Block chunk not valid")] InvalidChunk, @@ -53,4 +52,3 @@ pub enum FileError { #[error("Error writing file")] FileWriteError, } - diff --git a/crates/freezer/src/types/mod.rs b/crates/freezer/src/types/mod.rs index 69c43506..6c70e64e 100644 --- a/crates/freezer/src/types/mod.rs +++ b/crates/freezer/src/types/mod.rs @@ -1,23 +1,22 @@ - -pub mod conversions; pub mod cli_types; +pub mod conversions; pub mod data_types; pub mod error_types; pub mod output_types; pub mod schema_types; -pub use conversions::ToVecU8; -pub use conversions::ToVecHex; -pub use cli_types::FreezeOpts; pub use cli_types::FreezeChunkSummary; +pub use cli_types::FreezeOpts; pub use cli_types::FreezeSummary; +pub use conversions::ToVecHex; +pub use conversions::ToVecU8; pub use data_types::*; -pub use output_types::FileFormat; -pub use output_types::ColumnEncoding; pub use output_types::BlockChunk; -pub use schema_types::Schema; +pub use output_types::ColumnEncoding; +pub use output_types::FileFormat; pub use schema_types::ColumnType; +pub use schema_types::Schema; pub use error_types::CollectError; -pub use error_types::FreezeError; pub use error_types::FileError; +pub use error_types::FreezeError; diff --git a/crates/freezer/src/types/output_types.rs b/crates/freezer/src/types/output_types.rs index 5fc8337f..755b4b7e 100644 --- a/crates/freezer/src/types/output_types.rs +++ b/crates/freezer/src/types/output_types.rs @@ -1,5 +1,3 @@ - - #[derive(Clone, Eq, PartialEq)] pub enum FileFormat { Parquet,