Skip to content

Commit ccd265d

Browse files
committed
fix(api): Return correct flat call tracer
Signed-off-by: Danil <deniallugo@gmail.com>
1 parent ba21c6e commit ccd265d

15 files changed

+326
-371
lines changed

core/lib/dal/.sqlx/query-27bead20c61c5d90946630766d1e24353e59df82c62ddb90e2ecf355169c497f.json

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/lib/dal/.sqlx/query-34ea9042ca05af21601e0b065078ec515a8916a247d93e655dde3a5b43bda244.json

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/lib/dal/.sqlx/query-87f27295de500591f01ed76731df2aed7049c3f44a6d25556967ea867e0caf25.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

core/lib/dal/.sqlx/query-c37432fabd092fa235fc70e11430fb28594859564a0f888eae748ad1f9fcede5.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

core/lib/dal/src/blocks_web3_dal.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ impl BlocksWeb3Dal<'_, '_> {
527527
pub async fn get_traces_for_l2_block(
528528
&mut self,
529529
block_number: L2BlockNumber,
530-
) -> DalResult<Vec<Call>> {
530+
) -> DalResult<Vec<(Call, H256, usize)>> {
531531
let protocol_version = sqlx::query!(
532532
r#"
533533
SELECT
@@ -554,6 +554,8 @@ impl BlocksWeb3Dal<'_, '_> {
554554
CallTrace,
555555
r#"
556556
SELECT
557+
transactions.hash,
558+
transactions.index_in_block,
557559
call_trace
558560
FROM
559561
call_traces
@@ -570,7 +572,11 @@ impl BlocksWeb3Dal<'_, '_> {
570572
.fetch_all(self.storage)
571573
.await?
572574
.into_iter()
573-
.map(|call_trace| call_trace.into_call(protocol_version))
575+
.map(|call_trace| {
576+
let hash = H256::from_slice(&call_trace.hash);
577+
let index = call_trace.index_in_block.unwrap_or_default() as usize;
578+
(call_trace.into_call(protocol_version), hash, index)
579+
})
574580
.collect())
575581
}
576582

@@ -1084,8 +1090,9 @@ mod tests {
10841090
.await
10851091
.unwrap();
10861092
assert_eq!(traces.len(), 2);
1087-
for (trace, tx_result) in traces.iter().zip(&tx_results) {
1093+
for ((trace, hash, _index), tx_result) in traces.iter().zip(&tx_results) {
10881094
let expected_trace = tx_result.call_trace().unwrap();
1095+
assert_eq!(&tx_result.hash, hash);
10891096
assert_eq!(*trace, expected_trace);
10901097
}
10911098
}

core/lib/dal/src/models/storage_transaction.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ impl StorageApiTransaction {
561561
#[derive(Debug, Clone, sqlx::FromRow)]
562562
pub(crate) struct CallTrace {
563563
pub call_trace: Vec<u8>,
564+
pub hash: Vec<u8>,
565+
pub index_in_block: Option<i32>,
564566
}
565567

566568
impl CallTrace {
@@ -579,14 +581,12 @@ impl CallTrace {
579581
}
580582
}
581583

582-
pub(crate) fn from_call(call: Call, protocol_version: ProtocolVersionId) -> Self {
583-
let call_trace = if protocol_version.is_pre_1_5_0() {
584+
pub(crate) fn into_bytes(call: Call, protocol_version: ProtocolVersionId) -> Vec<u8> {
585+
if protocol_version.is_pre_1_5_0() {
584586
bincode::serialize(&LegacyCall::try_from(call).unwrap())
585587
} else {
586588
bincode::serialize(&call)
587589
}
588-
.unwrap();
589-
590-
Self { call_trace }
590+
.unwrap()
591591
}
592592
}

core/lib/dal/src/transactions_dal.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,7 @@ impl TransactionsDal<'_, '_> {
518518
let mut bytea_call_traces = Vec::with_capacity(transactions.len());
519519
for tx_res in transactions {
520520
if let Some(call_trace) = tx_res.call_trace() {
521-
bytea_call_traces
522-
.push(CallTrace::from_call(call_trace, protocol_version).call_trace);
521+
bytea_call_traces.push(CallTrace::into_bytes(call_trace, protocol_version));
523522
call_traces_tx_hashes.push(tx_res.hash.as_bytes());
524523
}
525524
}
@@ -2101,7 +2100,10 @@ impl TransactionsDal<'_, '_> {
21012100
Ok(data)
21022101
}
21032102

2104-
pub async fn get_call_trace(&mut self, tx_hash: H256) -> DalResult<Option<Call>> {
2103+
pub async fn get_call_trace(
2104+
&mut self,
2105+
tx_hash: H256,
2106+
) -> DalResult<Option<(Call, H256, usize)>> {
21052107
let row = sqlx::query!(
21062108
r#"
21072109
SELECT
@@ -2132,7 +2134,9 @@ impl TransactionsDal<'_, '_> {
21322134
CallTrace,
21332135
r#"
21342136
SELECT
2135-
call_trace
2137+
call_trace,
2138+
tx_hash AS hash,
2139+
0 AS index_in_block
21362140
FROM
21372141
call_traces
21382142
WHERE
@@ -2144,7 +2148,11 @@ impl TransactionsDal<'_, '_> {
21442148
.with_arg("tx_hash", &tx_hash)
21452149
.fetch_optional(self.storage)
21462150
.await?
2147-
.map(|call_trace| call_trace.into_call(protocol_version)))
2151+
.map(|call_trace| {
2152+
let hash = H256::from_slice(&call_trace.hash);
2153+
let index = call_trace.index_in_block.unwrap_or_default() as usize;
2154+
(call_trace.into_call(protocol_version), hash, index)
2155+
}))
21482156
}
21492157

21502158
pub(crate) async fn get_tx_by_hash(&mut self, hash: H256) -> DalResult<Option<Transaction>> {
@@ -2216,7 +2224,7 @@ mod tests {
22162224
.await
22172225
.unwrap();
22182226

2219-
let call_trace = conn
2227+
let (call_trace, _, _) = conn
22202228
.transactions_dal()
22212229
.get_call_trace(tx_hash)
22222230
.await

core/lib/types/src/api/mod.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use zksync_contracts::BaseSystemContractsHashes;
1212
pub use crate::transaction_request::{
1313
Eip712Meta, SerializationTransactionError, TransactionRequest,
1414
};
15-
use crate::{protocol_version::L1VerifierConfig, Address, L2BlockNumber, ProtocolVersionId};
15+
use crate::{
16+
debug_flat_call::DebugCallFlat, protocol_version::L1VerifierConfig, Address, L2BlockNumber,
17+
ProtocolVersionId,
18+
};
1619

1720
pub mod en;
1821
pub mod state_override;
@@ -597,7 +600,7 @@ pub struct GetLogsFilter {
597600
#[derive(Debug, Serialize, Deserialize, Clone)]
598601
#[serde(rename_all = "camelCase")]
599602
pub struct ResultDebugCall {
600-
pub result: DebugCall,
603+
pub result: CallTracerResult,
601604
}
602605

603606
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
@@ -700,19 +703,20 @@ impl ProtocolVersion {
700703
}
701704
}
702705

703-
#[derive(Debug, Serialize, Deserialize, Clone)]
706+
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
704707
#[serde(rename_all = "camelCase")]
705708
pub enum SupportedTracers {
706709
CallTracer,
710+
FlatCallTracer,
707711
}
708712

709-
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
713+
#[derive(Debug, Serialize, Deserialize, Clone, Default, Copy)]
710714
#[serde(rename_all = "camelCase")]
711715
pub struct CallTracerConfig {
712716
pub only_top_call: bool,
713717
}
714718

715-
#[derive(Debug, Serialize, Deserialize, Clone)]
719+
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
716720
#[serde(rename_all = "camelCase")]
717721
pub struct TracerConfig {
718722
pub tracer: SupportedTracers,
@@ -727,6 +731,22 @@ pub enum BlockStatus {
727731
Verified,
728732
}
729733

734+
/// FlatTracer is always more than one trace, so when we have to trace one transaction it also appeared as many traces
735+
#[derive(Debug, Serialize, Deserialize, Clone)]
736+
#[serde(rename_all = "camelCase", untagged)]
737+
pub enum CallTracerResult {
738+
CallTrace(DebugCall),
739+
FlattCallTrace(Box<Vec<DebugCallFlat>>),
740+
}
741+
742+
/// For tracing blocks we need to have all traces being combined all together without separation.
743+
#[derive(Debug, Serialize, Deserialize, Clone)]
744+
#[serde(rename_all = "camelCase", untagged)]
745+
pub enum CallTracerOption {
746+
CallTrace(DebugCall),
747+
FlattCallTrace(Box<DebugCallFlat>),
748+
}
749+
730750
#[derive(Debug, Clone, Serialize, Deserialize)]
731751
#[serde(rename_all = "camelCase")]
732752
pub struct BlockDetailsBase {

0 commit comments

Comments
 (0)