Skip to content

Commit

Permalink
Debug trace diffs (#75)
Browse files Browse the repository at this point in the history
* initial commit for debug trace diffs

* add geth call traces
  • Loading branch information
sslivkoff authored Oct 16, 2023
1 parent a267001 commit e3a5cf9
Show file tree
Hide file tree
Showing 17 changed files with 976 additions and 36 deletions.
6 changes: 6 additions & 0 deletions crates/cli/src/parse/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ fn parse_datatypes(raw_inputs: &Vec<String>) -> Result<Vec<Datatype>, ParseError
datatypes.push(Datatype::NonceDiffs);
datatypes.push(Datatype::StorageDiffs);
}
"geth_state_diffs" => {
datatypes.push(Datatype::GethBalanceDiffs);
datatypes.push(Datatype::GethCodeDiffs);
datatypes.push(Datatype::GethNonceDiffs);
datatypes.push(Datatype::GethStorageDiffs);
}
datatype_str => datatypes.push(Datatype::from_str(datatype_str)?),
}
}
Expand Down
16 changes: 8 additions & 8 deletions crates/freeze/src/datasets/balance_diffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use std::collections::HashMap;
#[cryo_to_df::to_df(Datatype::BalanceDiffs)]
#[derive(Default)]
pub struct BalanceDiffs {
n_rows: u64,
block_number: Vec<Option<u32>>,
transaction_index: Vec<Option<u32>>,
transaction_hash: Vec<Option<Vec<u8>>>,
address: Vec<Vec<u8>>,
from_value: Vec<U256>,
to_value: Vec<U256>,
chain_id: Vec<u64>,
pub(crate) n_rows: u64,
pub(crate) block_number: Vec<Option<u32>>,
pub(crate) transaction_index: Vec<Option<u32>>,
pub(crate) transaction_hash: Vec<Option<Vec<u8>>>,
pub(crate) address: Vec<Vec<u8>>,
pub(crate) from_value: Vec<U256>,
pub(crate) to_value: Vec<U256>,
pub(crate) chain_id: Vec<u64>,
}

type BlockTxsTraces = (Option<u32>, Vec<Option<Vec<u8>>>, Vec<ethers::types::BlockTrace>);
Expand Down
16 changes: 8 additions & 8 deletions crates/freeze/src/datasets/code_diffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use std::collections::HashMap;
#[cryo_to_df::to_df(Datatype::CodeDiffs)]
#[derive(Default)]
pub struct CodeDiffs {
n_rows: u64,
block_number: Vec<Option<u32>>,
transaction_index: Vec<Option<u32>>,
transaction_hash: Vec<Option<Vec<u8>>>,
address: Vec<Vec<u8>>,
from_value: Vec<Vec<u8>>,
to_value: Vec<Vec<u8>>,
chain_id: Vec<u64>,
pub(crate) n_rows: u64,
pub(crate) block_number: Vec<Option<u32>>,
pub(crate) transaction_index: Vec<Option<u32>>,
pub(crate) transaction_hash: Vec<Option<Vec<u8>>>,
pub(crate) address: Vec<Vec<u8>>,
pub(crate) from_value: Vec<Vec<u8>>,
pub(crate) to_value: Vec<Vec<u8>>,
pub(crate) chain_id: Vec<u64>,
}

#[async_trait::async_trait]
Expand Down
65 changes: 65 additions & 0 deletions crates/freeze/src/datasets/geth_balance_diffs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use crate::*;
use ethers::prelude::*;
use polars::prelude::*;
use std::collections::HashMap;

/// columns for transactions
#[cryo_to_df::to_df(Datatype::GethBalanceDiffs)]
#[derive(Default)]
pub struct GethBalanceDiffs {
pub(crate) n_rows: u64,
pub(crate) block_number: Vec<Option<u32>>,
pub(crate) transaction_index: Vec<Option<u64>>,
pub(crate) transaction_hash: Vec<Option<Vec<u8>>>,
pub(crate) address: Vec<Vec<u8>>,
pub(crate) from_value: Vec<U256>,
pub(crate) to_value: Vec<U256>,
pub(crate) chain_id: Vec<u64>,
}

type Result<T> = ::core::result::Result<T, CollectError>;

#[async_trait::async_trait]
impl Dataset for GethBalanceDiffs {
fn name() -> &'static str {
"balance_diffs"
}

fn default_sort() -> Vec<String> {
vec!["block_number".to_string(), "transaction_index".to_string()]
}
}

#[async_trait::async_trait]
impl CollectByBlock for GethBalanceDiffs {
type Response = <GethStateDiffs as CollectByBlock>::Response;

async fn extract(
request: Params,
source: Arc<Source>,
schemas: Schemas,
) -> Result<Self::Response> {
<GethStateDiffs as CollectByBlock>::extract(request, source, schemas).await
}

fn transform(response: Self::Response, columns: &mut Self, schemas: &Schemas) -> Result<()> {
geth_state_diffs::process_geth_diffs(&response, Some(columns), None, None, None, schemas)
}
}

#[async_trait::async_trait]
impl CollectByTransaction for GethBalanceDiffs {
type Response = <GethStateDiffs as CollectByTransaction>::Response;

async fn extract(
request: Params,
source: Arc<Source>,
schemas: Schemas,
) -> Result<Self::Response> {
<GethStateDiffs as CollectByTransaction>::extract(request, source, schemas).await
}

fn transform(response: Self::Response, columns: &mut Self, schemas: &Schemas) -> Result<()> {
geth_state_diffs::process_geth_diffs(&response, Some(columns), None, None, None, schemas)
}
}
64 changes: 64 additions & 0 deletions crates/freeze/src/datasets/geth_code_diffs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use crate::*;
use polars::prelude::*;
use std::collections::HashMap;

/// columns for transactions
#[cryo_to_df::to_df(Datatype::GethCodeDiffs)]
#[derive(Default)]
pub struct GethCodeDiffs {
pub(crate) n_rows: u64,
pub(crate) block_number: Vec<Option<u32>>,
pub(crate) transaction_index: Vec<Option<u64>>,
pub(crate) transaction_hash: Vec<Option<Vec<u8>>>,
pub(crate) address: Vec<Vec<u8>>,
pub(crate) from_value: Vec<Vec<u8>>,
pub(crate) to_value: Vec<Vec<u8>>,
pub(crate) chain_id: Vec<u64>,
}

type Result<T> = ::core::result::Result<T, CollectError>;

#[async_trait::async_trait]
impl Dataset for GethCodeDiffs {
fn name() -> &'static str {
"code_diffs"
}

fn default_sort() -> Vec<String> {
vec!["block_number".to_string(), "transaction_index".to_string()]
}
}

#[async_trait::async_trait]
impl CollectByBlock for GethCodeDiffs {
type Response = <GethStateDiffs as CollectByBlock>::Response;

async fn extract(
request: Params,
source: Arc<Source>,
schemas: Schemas,
) -> Result<Self::Response> {
<GethStateDiffs as CollectByBlock>::extract(request, source, schemas).await
}

fn transform(response: Self::Response, columns: &mut Self, schemas: &Schemas) -> Result<()> {
geth_state_diffs::process_geth_diffs(&response, None, Some(columns), None, None, schemas)
}
}

#[async_trait::async_trait]
impl CollectByTransaction for GethCodeDiffs {
type Response = <GethStateDiffs as CollectByTransaction>::Response;

async fn extract(
request: Params,
source: Arc<Source>,
schemas: Schemas,
) -> Result<Self::Response> {
<GethStateDiffs as CollectByTransaction>::extract(request, source, schemas).await
}

fn transform(response: Self::Response, columns: &mut Self, schemas: &Schemas) -> Result<()> {
geth_state_diffs::process_geth_diffs(&response, None, Some(columns), None, None, schemas)
}
}
64 changes: 64 additions & 0 deletions crates/freeze/src/datasets/geth_nonce_diffs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use crate::*;
use ethers::prelude::*;
use polars::prelude::*;
use std::collections::HashMap;

/// columns for transactions
#[cryo_to_df::to_df(Datatype::GethNonceDiffs)]
#[derive(Default)]
pub struct GethNonceDiffs {
pub(crate) n_rows: u64,
pub(crate) block_number: Vec<Option<u32>>,
pub(crate) transaction_index: Vec<Option<u64>>,
pub(crate) transaction_hash: Vec<Option<Vec<u8>>>,
pub(crate) address: Vec<Vec<u8>>,
pub(crate) from_value: Vec<U256>,
pub(crate) to_value: Vec<U256>,
pub(crate) chain_id: Vec<u64>,
}
type Result<T> = ::core::result::Result<T, CollectError>;

#[async_trait::async_trait]
impl Dataset for GethNonceDiffs {
fn name() -> &'static str {
"nonce_diffs"
}

fn default_sort() -> Vec<String> {
vec!["block_number".to_string(), "transaction_index".to_string()]
}
}

#[async_trait::async_trait]
impl CollectByBlock for GethNonceDiffs {
type Response = <GethStateDiffs as CollectByBlock>::Response;

async fn extract(
request: Params,
source: Arc<Source>,
schemas: Schemas,
) -> Result<Self::Response> {
<GethStateDiffs as CollectByBlock>::extract(request, source, schemas).await
}

fn transform(response: Self::Response, columns: &mut Self, schemas: &Schemas) -> Result<()> {
geth_state_diffs::process_geth_diffs(&response, None, None, Some(columns), None, schemas)
}
}

#[async_trait::async_trait]
impl CollectByTransaction for GethNonceDiffs {
type Response = <GethStateDiffs as CollectByTransaction>::Response;

async fn extract(
request: Params,
source: Arc<Source>,
schemas: Schemas,
) -> Result<Self::Response> {
<GethStateDiffs as CollectByTransaction>::extract(request, source, schemas).await
}

fn transform(response: Self::Response, columns: &mut Self, schemas: &Schemas) -> Result<()> {
geth_state_diffs::process_geth_diffs(&response, None, None, Some(columns), None, schemas)
}
}
65 changes: 65 additions & 0 deletions crates/freeze/src/datasets/geth_storage_diffs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use crate::*;
use polars::prelude::*;
use std::collections::HashMap;

/// columns for transactions
#[cryo_to_df::to_df(Datatype::GethStorageDiffs)]
#[derive(Default)]
pub struct GethStorageDiffs {
pub(crate) n_rows: u64,
pub(crate) block_number: Vec<Option<u32>>,
pub(crate) transaction_index: Vec<Option<u64>>,
pub(crate) transaction_hash: Vec<Option<Vec<u8>>>,
pub(crate) address: Vec<Vec<u8>>,
pub(crate) slot: Vec<Vec<u8>>,
pub(crate) from_value: Vec<Vec<u8>>,
pub(crate) to_value: Vec<Vec<u8>>,
pub(crate) chain_id: Vec<u64>,
}

#[async_trait::async_trait]
impl Dataset for GethStorageDiffs {
fn name() -> &'static str {
"geth_storage_diffs"
}

fn default_sort() -> Vec<String> {
vec!["block_number".to_string(), "transaction_index".to_string()]
}
}

type Result<T> = ::core::result::Result<T, CollectError>;

#[async_trait::async_trait]
impl CollectByBlock for GethStorageDiffs {
type Response = <GethStateDiffs as CollectByBlock>::Response;

async fn extract(
request: Params,
source: Arc<Source>,
schemas: Schemas,
) -> Result<Self::Response> {
<GethStateDiffs as CollectByBlock>::extract(request, source, schemas).await
}

fn transform(response: Self::Response, columns: &mut Self, schemas: &Schemas) -> Result<()> {
geth_state_diffs::process_geth_diffs(&response, None, None, None, Some(columns), schemas)
}
}

#[async_trait::async_trait]
impl CollectByTransaction for GethStorageDiffs {
type Response = <GethStateDiffs as CollectByTransaction>::Response;

async fn extract(
request: Params,
source: Arc<Source>,
schemas: Schemas,
) -> Result<Self::Response> {
<GethStateDiffs as CollectByTransaction>::extract(request, source, schemas).await
}

fn transform(response: Self::Response, columns: &mut Self, schemas: &Schemas) -> Result<()> {
geth_state_diffs::process_geth_diffs(&response, None, None, None, Some(columns), schemas)
}
}
Loading

0 comments on commit e3a5cf9

Please sign in to comment.