Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(call_tracer): Flat call tracer fixes for blocks #3095

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

32 changes: 23 additions & 9 deletions core/lib/dal/src/blocks_web3_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use zksync_db_connection::{
use zksync_system_constants::EMPTY_UNCLES_HASH;
use zksync_types::{
api,
debug_flat_call::CallTraceMeta,
fee_model::BatchFeeInput,
l2_to_l1_log::L2ToL1Log,
web3::{BlockHeader, Bytes},
Expand Down Expand Up @@ -531,26 +532,33 @@ impl BlocksWeb3Dal<'_, '_> {
pub async fn get_traces_for_l2_block(
&mut self,
block_number: L2BlockNumber,
) -> DalResult<Vec<(Call, H256, usize)>> {
let protocol_version = sqlx::query!(
) -> DalResult<Vec<(Call, CallTraceMeta)>> {
let row = sqlx::query!(
r#"
SELECT
protocol_version
protocol_version,
hash
FROM
miniblocks
WHERE
number = $1
"#,
i64::from(block_number.0)
)
.try_map(|row| row.protocol_version.map(parse_protocol_version).transpose())
.try_map(|row| {
row.protocol_version
.map(parse_protocol_version)
.transpose()
.map(|val| (val, H256::from_slice(&row.hash)))
})
.instrument("get_traces_for_l2_block#get_l2_block_protocol_version_id")
.with_arg("l2_block_number", &block_number)
.fetch_optional(self.storage)
.await?;
let Some(protocol_version) = protocol_version else {
let Some((protocol_version, block_hash)) = row else {
return Ok(Vec::new());
};

let protocol_version =
protocol_version.unwrap_or_else(ProtocolVersionId::last_potentially_undefined);

Expand All @@ -577,9 +585,15 @@ impl BlocksWeb3Dal<'_, '_> {
.await?
.into_iter()
.map(|call_trace| {
let hash = H256::from_slice(&call_trace.tx_hash);
let tx_hash = H256::from_slice(&call_trace.tx_hash);
let index = call_trace.tx_index_in_block.unwrap_or_default() as usize;
(call_trace.into_call(protocol_version), hash, index)
let meta = CallTraceMeta {
index_in_block: index,
tx_hash,
block_number: block_number.0,
block_hash,
};
(call_trace.into_call(protocol_version), meta)
})
.collect())
}
Expand Down Expand Up @@ -1105,9 +1119,9 @@ mod tests {
.await
.unwrap();
assert_eq!(traces.len(), 2);
for ((trace, hash, _index), tx_result) in traces.iter().zip(&tx_results) {
for ((trace, meta), tx_result) in traces.iter().zip(&tx_results) {
let expected_trace = tx_result.call_trace().unwrap();
assert_eq!(&tx_result.hash, hash);
assert_eq!(tx_result.hash, meta.tx_hash);
assert_eq!(*trace, expected_trace);
}
}
Expand Down
23 changes: 17 additions & 6 deletions core/lib/dal/src/transactions_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use zksync_db_connection::{
utils::pg_interval_from_duration,
};
use zksync_types::{
block::L2BlockExecutionData, l1::L1Tx, l2::L2Tx, protocol_upgrade::ProtocolUpgradeTx, Address,
ExecuteTransactionCommon, L1BatchNumber, L1BlockNumber, L2BlockNumber, PriorityOpId,
ProtocolVersionId, Transaction, H256, PROTOCOL_UPGRADE_TX_TYPE, U256,
block::L2BlockExecutionData, debug_flat_call::CallTraceMeta, l1::L1Tx, l2::L2Tx,
protocol_upgrade::ProtocolUpgradeTx, Address, ExecuteTransactionCommon, L1BatchNumber,
L1BlockNumber, L2BlockNumber, PriorityOpId, ProtocolVersionId, Transaction, H256,
PROTOCOL_UPGRADE_TX_TYPE, U256,
};
use zksync_utils::u256_to_big_decimal;
use zksync_vm_interface::{
Expand Down Expand Up @@ -2131,12 +2132,17 @@ impl TransactionsDal<'_, '_> {
Ok(data)
}

pub async fn get_call_trace(&mut self, tx_hash: H256) -> DalResult<Option<(Call, usize)>> {
pub async fn get_call_trace(
&mut self,
tx_hash: H256,
) -> DalResult<Option<(Call, CallTraceMeta)>> {
let row = sqlx::query!(
r#"
SELECT
protocol_version,
index_in_block
index_in_block,
miniblocks.number AS "miniblock_number!",
miniblocks.hash AS "miniblocks_hash!"
FROM
transactions
INNER JOIN miniblocks ON transactions.miniblock_number = miniblocks.number
Expand Down Expand Up @@ -2177,7 +2183,12 @@ impl TransactionsDal<'_, '_> {
.map(|call_trace| {
(
parse_call_trace(&call_trace.call_trace, protocol_version),
row.index_in_block.unwrap_or_default() as usize,
CallTraceMeta {
index_in_block: row.index_in_block.unwrap_or_default() as usize,
tx_hash,
block_number: row.miniblock_number as u32,
block_hash: H256::from_slice(&row.miniblocks_hash),
},
)
}))
}
Expand Down
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
17 changes: 17 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 All @@ -12,6 +19,8 @@ pub struct DebugCallFlat {
pub trace_address: Vec<usize>,
pub transaction_position: usize,
pub transaction_hash: H256,
pub block_number: u32,
pub block_hash: H256,
pub r#type: DebugCallType,
}

Expand All @@ -32,3 +41,11 @@ pub struct CallResult {
pub output: Bytes,
pub gas_used: U256,
}

#[derive(Debug, Clone, PartialEq, Default)]
pub struct CallTraceMeta {
pub index_in_block: usize,
pub tx_hash: H256,
pub block_number: u32,
pub block_hash: H256,
}
Loading
Loading