Skip to content

Commit

Permalink
remove creation_traces
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisCarriere committed Nov 26, 2024
1 parent 13fa5e3 commit 0f5dec7
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 133 deletions.
2 changes: 1 addition & 1 deletion blocks/evm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ parquet:

.PHONY: s3
s3:
substreams-sink-files run eth.substreams.pinax.network:443 substreams.yaml map_events s3://pinax/eth/323b41131b4f2dc97705d80cc0b859d4a33c52de?region=us-east-1 21200000: --encoder parquet --development-mode --parquet-default-column-compression snappy --file-block-count 1
substreams-sink-files run eth.substreams.pinax.network:443 substreams.yaml map_events s3://pinax/eth/a7483e216fa6fc6753e7d6a9809620036fcd077d?region=us-east-1 21200000: --encoder parquet --development-mode --parquet-default-column-compression snappy --file-block-count 1

.PHONY: hash
hash:
Expand Down
3 changes: 1 addition & 2 deletions blocks/evm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
- [x] **Account Creation**
- [x] **Gas Changes**
- [x] **Nonce Changes**
- [x] **Creation Traces**

## Graph

Expand All @@ -36,5 +35,5 @@ Kind: map
Input: source: sf.substreams.v1.Clock
Input: source: sf.ethereum.type.v2.Block
Output Type: proto:evm.Events
Hash: 323b41131b4f2dc97705d80cc0b859d4a33c52de
Hash: a7483e216fa6fc6753e7d6a9809620036fcd077d
```
17 changes: 16 additions & 1 deletion blocks/evm/schema.snowflake.sql
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,19 @@ FROM "v1.0.0-traces";
CREATE OR REPLACE SECURE VIEW v1_logs AS
SELECT
*
FROM "v1.0.0-logs";
FROM "v1.0.0-logs";

CREATE OR REPLACE SECURE VIEW v1_account_creations AS
SELECT
*
FROM "v1.0.0-account_creations";

CREATE OR REPLACE SECURE VIEW v1_storage_changes AS
SELECT
*
FROM "v1.0.0-storage_changes";

CREATE OR REPLACE SECURE VIEW v1_code_changes AS
SELECT
*
FROM "v1.0.0-code_changes";
29 changes: 14 additions & 15 deletions blocks/evm/src/code_changes.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
use common::structs::BlockTimestamp;
use common::utils::bytes_to_hex;
use substreams_ethereum::pb::eth::v2::{Block, CodeChange, TransactionTrace};
use substreams_ethereum::pb::eth::v2::{Block, CodeChange as CodeChangeSource, TransactionTrace};

use crate::pb::pinax::evm::v1::CodeChange as CodeChangeEvent;
use crate::pb::pinax::evm::v1::CodeChange;

// https://github.com/streamingfast/firehose-ethereum/blob/1bcb32a8eb3e43347972b6b5c9b1fcc4a08c751e/proto/sf/ethereum/type/v2/type.proto#L744
// DetailLevel: EXTENDED
pub fn collect_code_changes(block: &Block, timestamp: &BlockTimestamp) -> Vec<CodeChangeEvent> {
let mut code_changes: Vec<CodeChangeEvent> = vec![];
pub fn collect_code_changes(block: &Block, timestamp: &BlockTimestamp) -> Vec<CodeChange> {
let mut code_changes: Vec<CodeChange> = vec![];

// Collect code changes from system calls
for call in &block.system_calls {
for code_change in &call.code_changes {
code_changes.push(parse_code_change(code_change, &TransactionTrace::default(), timestamp));
code_changes.push(parse_creation_trace(code_change, &TransactionTrace::default(), timestamp));
}
}

// Collect code changes from transaction traces
for transaction in &block.transaction_traces {
for call in &transaction.calls {
for code_change in &call.code_changes {
code_changes.push(parse_code_change(code_change, transaction, timestamp));
code_changes.push(parse_creation_trace(code_change, transaction, timestamp));
}
}
}

code_changes
}

pub fn parse_code_change(code_change: &CodeChange, transaction: &TransactionTrace, timestamp: &BlockTimestamp) -> CodeChangeEvent {
CodeChangeEvent {
pub fn parse_creation_trace(code_change: &CodeChangeSource, transaction: &TransactionTrace, timestamp: &BlockTimestamp) -> CodeChange {
let factory = if transaction.to == code_change.address { "".to_string() } else { bytes_to_hex(&transaction.to) };
CodeChange {
// block
block_time: timestamp.time.to_string(),
block_number: timestamp.number,
block_hash: timestamp.hash.clone(),
block_date: timestamp.date.clone(),

// transaction
tx_hash: Some(bytes_to_hex(&transaction.hash)),
tx_hash: bytes_to_hex(&transaction.hash),

// code changes
// creation trace
from: bytes_to_hex(&transaction.from),
address: bytes_to_hex(&code_change.address),
old_hash: bytes_to_hex(&code_change.old_hash),
old_code: bytes_to_hex(&code_change.old_code),
new_hash: bytes_to_hex(&code_change.new_hash),
new_code: bytes_to_hex(&code_change.new_code),
ordinal: code_change.ordinal,
factory: factory.to_string(),
code: bytes_to_hex(&code_change.new_code),
}
}
41 changes: 0 additions & 41 deletions blocks/evm/src/creation_traces.rs

This file was deleted.

2 changes: 0 additions & 2 deletions blocks/evm/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::account_creations::collect_account_creations;
use crate::balance_changes::collect_balance_changes;
use crate::blocks::collect_block;
use crate::code_changes::collect_code_changes;
use crate::creation_traces::collect_creation_traces;
use crate::gas_changes::collect_gas_changes;
use crate::logs::collect_logs;
use crate::nonce_changes::collect_nonce_changes;
Expand All @@ -32,6 +31,5 @@ pub fn map_events(clock: Clock, block: Block) -> Result<Events, Error> {
account_creations: collect_account_creations(&block, &timestamp),
nonce_changes: collect_nonce_changes(&block, &timestamp),
gas_changes: collect_gas_changes(&block, &timestamp),
creation_traces: collect_creation_traces(&block, &timestamp),
})
}
1 change: 0 additions & 1 deletion blocks/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ mod account_creations;
mod balance_changes;
mod blocks;
mod code_changes;
mod creation_traces;
mod events;
mod gas_changes;
mod logs;
Expand Down
53 changes: 10 additions & 43 deletions blocks/evm/src/pb/pinax.evm.v1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @generated
// This file is @generated by prost-build.
// import "google/protobuf/timestamp.proto";

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Events {
Expand All @@ -23,8 +25,6 @@ pub struct Events {
pub nonce_changes: ::prost::alloc::vec::Vec<NonceChange>,
#[prost(message, repeated, tag="10")]
pub gas_changes: ::prost::alloc::vec::Vec<GasChange>,
#[prost(message, repeated, tag="11")]
pub creation_traces: ::prost::alloc::vec::Vec<CreationTrace>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down Expand Up @@ -419,23 +419,17 @@ pub struct CodeChange {
#[prost(string, tag="4")]
pub block_date: ::prost::alloc::string::String,
/// -- transaction --
#[prost(string, optional, tag="5")]
pub tx_hash: ::core::option::Option<::prost::alloc::string::String>,
/// -- code change --
///
/// block global ordinal
#[prost(uint64, tag="6")]
pub ordinal: u64,
#[prost(string, tag="7")]
#[prost(string, tag="5")]
pub tx_hash: ::prost::alloc::string::String,
/// -- creation trace --
#[prost(string, tag="6")]
pub address: ::prost::alloc::string::String,
#[prost(string, tag="7")]
pub from: ::prost::alloc::string::String,
#[prost(string, tag="8")]
pub old_hash: ::prost::alloc::string::String,
pub factory: ::prost::alloc::string::String,
#[prost(string, tag="9")]
pub old_code: ::prost::alloc::string::String,
#[prost(string, tag="10")]
pub new_hash: ::prost::alloc::string::String,
#[prost(string, tag="11")]
pub new_code: ::prost::alloc::string::String,
pub code: ::prost::alloc::string::String,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand Down Expand Up @@ -522,31 +516,4 @@ pub struct GasChange {
#[prost(uint32, tag="10")]
pub reason_code: u32,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct CreationTrace {
/// -- block --
///
/// TIMESTAMP
#[prost(string, tag="1")]
pub block_time: ::prost::alloc::string::String,
#[prost(uint64, tag="2")]
pub block_number: u64,
#[prost(string, tag="3")]
pub block_hash: ::prost::alloc::string::String,
#[prost(string, tag="4")]
pub block_date: ::prost::alloc::string::String,
/// -- transaction --
#[prost(string, tag="5")]
pub tx_hash: ::prost::alloc::string::String,
/// -- creation trace --
#[prost(string, tag="6")]
pub address: ::prost::alloc::string::String,
#[prost(string, tag="7")]
pub from: ::prost::alloc::string::String,
#[prost(string, tag="8")]
pub factory: ::prost::alloc::string::String,
#[prost(string, tag="9")]
pub code: ::prost::alloc::string::String,
}
// @@protoc_insertion_point(module)
34 changes: 7 additions & 27 deletions proto/evm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ syntax = "proto3";

package pinax.evm.v1;

import "google/protobuf/timestamp.proto";
// import "google/protobuf/timestamp.proto";

message Events {
repeated Block blocks = 1;
Expand All @@ -15,7 +15,6 @@ message Events {
repeated AccountCreation account_creations = 8;
repeated NonceChange nonce_changes = 9;
repeated GasChange gas_changes = 10;
repeated CreationTrace creation_traces = 11;
}

message Block {
Expand Down Expand Up @@ -228,15 +227,13 @@ message CodeChange {
string block_date = 4;

// -- transaction --
optional string tx_hash = 5;
string tx_hash = 5;

// -- code change --
uint64 ordinal = 6; // block global ordinal
string address = 7;
string old_hash = 8;
string old_code = 9;
string new_hash = 10;
string new_code = 11;
// -- creation trace --
string address = 6;
string from = 7;
string factory = 8;
string code = 9;
}

message AccountCreation {
Expand Down Expand Up @@ -288,20 +285,3 @@ message GasChange {
string reason = 9;
uint32 reason_code = 10;
}

message CreationTrace {
// -- block --
string block_time = 1; // TIMESTAMP
uint64 block_number = 2;
string block_hash = 3;
string block_date = 4;

// -- transaction --
string tx_hash = 5;

// -- creation trace --
string address = 6;
string from = 7;
string factory = 8;
string code = 9;
}

0 comments on commit 0f5dec7

Please sign in to comment.