Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
sslivkoff committed Jul 2, 2023
1 parent 4c5f772 commit f07555b
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 75 deletions.
2 changes: 0 additions & 2 deletions crates/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// Columns to include in output
#[arg(short, long, value_name="COLS", num_args(0..), help_heading="Content Options")]
pub include_columns: Option<Vec<String>>,
Expand Down Expand Up @@ -213,4 +212,3 @@ fn get_datatype_help() -> &'static str {
- <white><bold>opcode_traces</bold></white>"#
)
}

10 changes: 8 additions & 2 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 5 additions & 6 deletions crates/cli/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,11 @@ pub async fn parse_opts() -> Result<FreezeOpts> {

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 {
Expand Down
8 changes: 6 additions & 2 deletions crates/cli/src/summaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ pub fn print_schema(name: &Datatype, schema: &Schema, sort: Option<&Vec<String>>
});
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(", ")
);
}
}

Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion crates/freezer/src/datasets/code_diffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions crates/freezer/src/datasets/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -205,5 +206,6 @@ pub fn logs_to_df(logs: Vec<Log>, _schema: &Schema) -> Result<DataFrame, Collect
"topic2" => topic2,
"topic3" => topic3,
"data" => data,
).map_err(CollectError::PolarsError)
)
.map_err(CollectError::PolarsError)
}
2 changes: 1 addition & 1 deletion crates/freezer/src/datasets/nonce_diffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
36 changes: 18 additions & 18 deletions crates/freezer/src/datasets/state_diffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@ 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,
block_chunk: &BlockChunk,
opts: &FreezeOpts,
) -> Result<DataFrame, CollectError> {
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),
Expand All @@ -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
}
Expand All @@ -42,15 +39,15 @@ pub fn state_diffs_to_df(
block_numbers: Vec<u64>,
schemas: &HashMap<Datatype, Schema>,
) -> Result<HashMap<Datatype, DataFrame>, 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);
let include_code = schemas.contains_key(&Datatype::CodeDiffs);

// 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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -98,11 +97,9 @@ pub fn state_diffs_to_df(
let mut code_from_value: Vec<Vec<u8>> = Vec::with_capacity(blocks_traces.len());
let mut code_to_value: Vec<Vec<u8>> = 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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()),
Expand All @@ -207,7 +209,6 @@ pub fn state_diffs_to_df(
code_to_value.push(to);
};
}

}
}
}
Expand Down Expand Up @@ -319,4 +320,3 @@ fn included(
false
}
}

3 changes: 2 additions & 1 deletion crates/freezer/src/datasets/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 3 additions & 4 deletions crates/freezer/src/datasets/vm_traces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -208,4 +208,3 @@ fn add_ops(vm_trace: VMTrace, schema: &Schema, columns: &mut VmTraceColumns) {
}
}
}

16 changes: 12 additions & 4 deletions crates/freezer/src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ pub async fn fetch_state_diffs(
max_concurrent_blocks: &u64,
) -> Result<Vec<BlockTrace>, 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(
Expand All @@ -24,8 +28,12 @@ pub async fn fetch_vm_traces(
max_concurrent_blocks: &u64,
) -> Result<Vec<BlockTrace>, 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(
Expand Down
12 changes: 7 additions & 5 deletions crates/freezer/src/freeze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 5 additions & 6 deletions crates/freezer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
5 changes: 1 addition & 4 deletions crates/freezer/src/outputs/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand Down Expand Up @@ -75,4 +73,3 @@ fn df_to_json(df: &mut DataFrame, filename: &str) -> Result<(), FileError> {
_ => Ok(()),
}
}

1 change: 0 additions & 1 deletion crates/freezer/src/types/cli_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@ pub struct FreezeChunkSummary {
pub skipped: bool,
pub errored: bool,
}

5 changes: 3 additions & 2 deletions crates/freezer/src/types/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ impl ToVecHex for Vec<Option<Vec<u8>>> {
type Output = Vec<Option<String>>;

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()
}
}

2 changes: 1 addition & 1 deletion crates/freezer/src/types/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit f07555b

Please sign in to comment.