Skip to content

Commit

Permalink
fix(tracer): Change block structure
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed Oct 14, 2024
1 parent 114834f commit 4f5a883
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
9 changes: 5 additions & 4 deletions core/lib/types/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ pub use crate::transaction_request::{
Eip712Meta, SerializationTransactionError, TransactionRequest,
};
use crate::{
debug_flat_call::DebugCallFlat, protocol_version::L1VerifierConfig, Address, L2BlockNumber,
ProtocolVersionId,
debug_flat_call::{DebugCallFlat, ResultDebugCallFlat},
protocol_version::L1VerifierConfig,
Address, L2BlockNumber, ProtocolVersionId,
};

pub mod en;
Expand Down Expand Up @@ -763,11 +764,11 @@ pub enum BlockStatus {
#[serde(untagged)]
pub enum CallTracerBlockResult {
CallTrace(Vec<ResultDebugCall>),
FlatCallTrace(Vec<DebugCallFlat>),
FlatCallTrace(Vec<ResultDebugCallFlat>),
}

impl CallTracerBlockResult {
pub fn unwrap_flat(self) -> Vec<DebugCallFlat> {
pub fn unwrap_flat(self) -> Vec<ResultDebugCallFlat> {
match self {
Self::CallTrace(_) => panic!("Result is a FlatCallTrace"),
Self::FlatCallTrace(trace) => trace,
Expand Down
7 changes: 7 additions & 0 deletions core/lib/types/src/debug_flat_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ use zksync_basic_types::{web3::Bytes, U256};

use crate::{api::DebugCallType, Address, H256};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ResultDebugCallFlat {
pub tx_hash: H256,
pub result: Vec<DebugCallFlat>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DebugCallFlat {
Expand Down
36 changes: 22 additions & 14 deletions core/node/api_server/src/web3/namespaces/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use zksync_types::{
BlockId, BlockNumber, CallTracerBlockResult, CallTracerResult, DebugCall, DebugCallType,
ResultDebugCall, SupportedTracers, TracerConfig,
},
debug_flat_call::{Action, CallResult, DebugCallFlat},
debug_flat_call::{Action, CallResult, DebugCallFlat, ResultDebugCallFlat},
l2::L2Tx,
transaction_request::CallRequest,
web3, H256, U256,
Expand Down Expand Up @@ -158,6 +158,7 @@ impl DebugNamespace {

let mut connection = self.state.acquire_connection().await?;
let block_number = self.state.resolve_block(&mut connection, block_id).await?;
// let block_hash = block_hash self.state.
self.current_method()
.set_block_diff(self.state.last_sealed_l2_block.diff(block_number));

Expand All @@ -178,19 +179,26 @@ impl DebugNamespace {
.collect(),
),
SupportedTracers::FlatCallTracer => {
let mut flat_calls = vec![];
for (call, tx_hash, tx_index) in call_traces {
let mut traces = vec![tx_index];
Self::flatten_call(
call,
&mut flat_calls,
&mut traces,
options.tracer_config.only_top_call,
tx_index,
tx_hash,
);
}
CallTracerBlockResult::FlatCallTrace(flat_calls)
let res = call_traces
.into_iter()
.map(|(call, tx_hash, tx_index)| {
let mut traces = vec![tx_index];
let mut flat_calls = vec![];
Self::flatten_call(
call,
&mut flat_calls,
&mut traces,
options.tracer_config.only_top_call,
tx_index,
tx_hash,
);
ResultDebugCallFlat {
tx_hash,
result: flat_calls,
}
})
.collect();
CallTracerBlockResult::FlatCallTrace(res)
}
};
Ok(result)
Expand Down

0 comments on commit 4f5a883

Please sign in to comment.