Skip to content

Commit df636c9

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

15 files changed

+341
-379
lines changed

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-96ef4ff06739b249eeafc987dcbad918a7d282b6f18d2bd02b020afbd1cde19b.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-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: 12 additions & 9 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 {
@@ -578,15 +580,16 @@ impl CallTrace {
578580
bincode::deserialize(&self.call_trace).unwrap()
579581
}
580582
}
583+
}
581584

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-
bincode::serialize(&LegacyCall::try_from(call).unwrap())
585-
} else {
586-
bincode::serialize(&call)
587-
}
588-
.unwrap();
589-
590-
Self { call_trace }
585+
pub(crate) fn serialize_call_into_bytes(
586+
call: Call,
587+
protocol_version: ProtocolVersionId,
588+
) -> Vec<u8> {
589+
if protocol_version.is_pre_1_5_0() {
590+
bincode::serialize(&LegacyCall::try_from(call).unwrap())
591+
} else {
592+
bincode::serialize(&call)
591593
}
594+
.unwrap()
592595
}

core/lib/dal/src/transactions_dal.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use zksync_vm_interface::{
2020
};
2121

2222
use crate::{
23-
models::storage_transaction::{CallTrace, StorageTransaction},
23+
models::storage_transaction::{serialize_call_into_bytes, CallTrace, StorageTransaction},
2424
Core, CoreDal,
2525
};
2626

@@ -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(serialize_call_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: 26 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,10 +600,11 @@ 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)]
607+
#[serde(rename_all = "camelCase")]
604608
pub enum DebugCallType {
605609
#[default]
606610
Call,
@@ -700,19 +704,20 @@ impl ProtocolVersion {
700704
}
701705
}
702706

703-
#[derive(Debug, Serialize, Deserialize, Clone)]
707+
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
704708
#[serde(rename_all = "camelCase")]
705709
pub enum SupportedTracers {
706710
CallTracer,
711+
FlatCallTracer,
707712
}
708713

709-
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
714+
#[derive(Debug, Serialize, Deserialize, Clone, Default, Copy)]
710715
#[serde(rename_all = "camelCase")]
711716
pub struct CallTracerConfig {
712717
pub only_top_call: bool,
713718
}
714719

715-
#[derive(Debug, Serialize, Deserialize, Clone)]
720+
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
716721
#[serde(rename_all = "camelCase")]
717722
pub struct TracerConfig {
718723
pub tracer: SupportedTracers,
@@ -727,6 +732,22 @@ pub enum BlockStatus {
727732
Verified,
728733
}
729734

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

0 commit comments

Comments
 (0)