Skip to content

Commit

Permalink
Rename result strcuts
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed Sep 23, 2024
1 parent e289966 commit 0b807d1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 41 deletions.
8 changes: 4 additions & 4 deletions core/lib/types/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,18 +733,18 @@ pub enum BlockStatus {
Verified,
}

/// FlatTracer is always more than one trace, so when we have to trace one transaction it also appeared as many traces
/// Result tracers need to have a nested result field for compatibility. So we have two different
/// structs 1 for blocks tracing and one for txs and call tracing
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(untagged)]
pub enum CallTracerResult {
pub enum CallTracerResultWithNestedResult {
CallTrace(ResultDebugCall),
FlattCallTrace(Vec<DebugCallFlat>),
}

/// For tracing blocks we need to have all traces being combined all together without separation.
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(untagged)]
pub enum CallTracerOption {
pub enum CallTracerResult {
CallTrace(DebugCall),
FlattCallTrace(Vec<DebugCallFlat>),
}
Expand Down
10 changes: 5 additions & 5 deletions core/lib/web3_decl/src/namespaces/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use jsonrpsee::core::RpcResult;
use jsonrpsee::proc_macros::rpc;
use zksync_types::{
api::{BlockId, BlockNumber, CallTracerOption, CallTracerResult, TracerConfig},
api::{BlockId, BlockNumber, CallTracerResult, CallTracerResultWithNestedResult, TracerConfig},
transaction_request::CallRequest,
};

Expand All @@ -25,27 +25,27 @@ pub trait DebugNamespace {
&self,
block: BlockNumber,
options: Option<TracerConfig>,
) -> RpcResult<Vec<CallTracerResult>>;
) -> RpcResult<Vec<CallTracerResultWithNestedResult>>;

#[method(name = "traceBlockByHash")]
async fn trace_block_by_hash(
&self,
hash: H256,
options: Option<TracerConfig>,
) -> RpcResult<Vec<CallTracerResult>>;
) -> RpcResult<Vec<CallTracerResultWithNestedResult>>;

#[method(name = "traceCall")]
async fn trace_call(
&self,
request: CallRequest,
block: Option<BlockId>,
options: Option<TracerConfig>,
) -> RpcResult<CallTracerOption>;
) -> RpcResult<CallTracerResult>;

#[method(name = "traceTransaction")]
async fn trace_transaction(
&self,
tx_hash: H256,
options: Option<TracerConfig>,
) -> RpcResult<Option<CallTracerOption>>;
) -> RpcResult<Option<CallTracerResult>>;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use zksync_types::{
api::{BlockId, BlockNumber, CallTracerOption, CallTracerResult, TracerConfig},
api::{BlockId, BlockNumber, CallTracerResult, CallTracerResultWithNestedResult, TracerConfig},
transaction_request::CallRequest,
H256,
};
Expand All @@ -16,7 +16,7 @@ impl DebugNamespaceServer for DebugNamespace {
&self,
block: BlockNumber,
options: Option<TracerConfig>,
) -> RpcResult<Vec<CallTracerResult>> {
) -> RpcResult<Vec<CallTracerResultWithNestedResult>> {
self.debug_trace_block_impl(BlockId::Number(block), options)
.await
.map_err(|err| self.current_method().map_err(err))
Expand All @@ -26,7 +26,7 @@ impl DebugNamespaceServer for DebugNamespace {
&self,
hash: H256,
options: Option<TracerConfig>,
) -> RpcResult<Vec<CallTracerResult>> {
) -> RpcResult<Vec<CallTracerResultWithNestedResult>> {
self.debug_trace_block_impl(BlockId::Hash(hash), options)
.await
.map_err(|err| self.current_method().map_err(err))
Expand All @@ -37,7 +37,7 @@ impl DebugNamespaceServer for DebugNamespace {
request: CallRequest,
block: Option<BlockId>,
options: Option<TracerConfig>,
) -> RpcResult<CallTracerOption> {
) -> RpcResult<CallTracerResult> {
self.debug_trace_call_impl(request, block, options)
.await
.map_err(|err| self.current_method().map_err(err))
Expand All @@ -47,7 +47,7 @@ impl DebugNamespaceServer for DebugNamespace {
&self,
tx_hash: H256,
options: Option<TracerConfig>,
) -> RpcResult<Option<CallTracerOption>> {
) -> RpcResult<Option<CallTracerResult>> {
self.debug_trace_transaction_impl(tx_hash, options)
.await
.map_err(|err| self.current_method().map_err(err))
Expand Down
28 changes: 13 additions & 15 deletions core/node/api_server/src/web3/namespaces/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use zksync_multivm::interface::{Call, CallType, ExecutionResult, OneshotTracingP
use zksync_system_constants::MAX_ENCODED_TX_SIZE;
use zksync_types::{
api::{
BlockId, BlockNumber, CallTracerOption, CallTracerResult, DebugCall, DebugCallType,
ResultDebugCall, SupportedTracers, TracerConfig,
BlockId, BlockNumber, CallTracerResult, CallTracerResultWithNestedResult, DebugCall,
DebugCallType, ResultDebugCall, SupportedTracers, TracerConfig,
},
debug_flat_call::{Action, CallResult, DebugCallFlat},
fee_model::BatchFeeInput,
Expand Down Expand Up @@ -50,7 +50,7 @@ impl DebugNamespace {
index: usize,
transaction_hash: H256,
tracer_option: Option<TracerConfig>,
) -> CallTracerOption {
) -> CallTracerResult {
let (only_top_call, flatten) = tracer_option
.map(|options| {
(
Expand All @@ -70,9 +70,9 @@ impl DebugNamespace {
index,
transaction_hash,
);
CallTracerOption::FlattCallTrace(calls)
CallTracerResult::FlattCallTrace(calls)
} else {
CallTracerOption::CallTrace(Self::map_default_call(call, only_top_call))
CallTracerResult::CallTrace(Self::map_default_call(call, only_top_call))
}
}
pub(crate) fn map_default_call(call: Call, only_top_call: bool) -> DebugCall {
Expand Down Expand Up @@ -171,7 +171,7 @@ impl DebugNamespace {
&self,
block_id: BlockId,
options: Option<TracerConfig>,
) -> Result<Vec<CallTracerResult>, Web3Error> {
) -> Result<Vec<CallTracerResultWithNestedResult>, Web3Error> {
self.current_method().set_block_id(block_id);
if matches!(block_id, BlockId::Number(BlockNumber::Pending)) {
// See `EthNamespace::get_block_impl()` for an explanation why this check is needed.
Expand All @@ -193,16 +193,14 @@ impl DebugNamespace {
let mut flat_calls = vec![];
for (call_trace, hash, index) in call_traces {
match Self::map_call(call_trace, index, hash, options) {
CallTracerOption::CallTrace(call) => {
calls.push(CallTracerResult::CallTrace(ResultDebugCall {
result: call,
}))
}
CallTracerOption::FlattCallTrace(mut call) => flat_calls.append(&mut call),
CallTracerResult::CallTrace(call) => calls.push(
CallTracerResultWithNestedResult::CallTrace(ResultDebugCall { result: call }),
),
CallTracerResult::FlattCallTrace(mut call) => flat_calls.append(&mut call),
}
}
if calls.is_empty() && !flat_calls.is_empty() {
calls.push(CallTracerResult::FlattCallTrace(flat_calls))
calls.push(CallTracerResultWithNestedResult::FlattCallTrace(flat_calls))
}

Ok(calls)
Expand All @@ -212,7 +210,7 @@ impl DebugNamespace {
&self,
tx_hash: H256,
options: Option<TracerConfig>,
) -> Result<Option<CallTracerOption>, Web3Error> {
) -> Result<Option<CallTracerResult>, Web3Error> {
let mut connection = self.state.acquire_connection().await?;
let call_trace = connection
.transactions_dal()
Expand All @@ -228,7 +226,7 @@ impl DebugNamespace {
mut request: CallRequest,
block_id: Option<BlockId>,
options: Option<TracerConfig>,
) -> Result<CallTracerOption, Web3Error> {
) -> Result<CallTracerResult, Web3Error> {
let block_id = block_id.unwrap_or(BlockId::Number(BlockNumber::Pending));
self.current_method().set_block_id(block_id);

Expand Down
13 changes: 8 additions & 5 deletions core/node/api_server/src/web3/tests/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use zksync_multivm::interface::{Call, TransactionExecutionResult};
use zksync_types::{
api::{
CallTracerConfig, CallTracerOption, CallTracerResult, ResultDebugCall, SupportedTracers,
TracerConfig,
CallTracerConfig, CallTracerResult, CallTracerResultWithNestedResult, ResultDebugCall,
SupportedTracers, TracerConfig,
},
BOOTLOADER_ADDRESS,
};
Expand Down Expand Up @@ -68,7 +68,8 @@ impl HttpTest for TraceBlockTest {

assert_eq!(block_traces.len(), tx_results.len()); // equals to the number of transactions in the block
for (trace, tx_result) in block_traces.iter().zip(&tx_results) {
let CallTracerResult::CallTrace(ResultDebugCall { result }) = trace else {
let CallTracerResultWithNestedResult::CallTrace(ResultDebugCall { result }) = trace
else {
unreachable!()
};
assert_eq!(result.from, Address::zero());
Expand Down Expand Up @@ -162,7 +163,9 @@ impl HttpTest for TraceBlockFlatTest {
.map(|&i| block_traces[i].clone());

for (top_level_trace, tx_result) in top_level_traces.zip(&tx_results) {
let CallTracerResult::FlattCallTrace(top_level_trace) = top_level_trace else {
let CallTracerResultWithNestedResult::FlattCallTrace(top_level_trace) =
top_level_trace
else {
unreachable!()
};
let top_level_trace = top_level_trace.first().unwrap();
Expand Down Expand Up @@ -231,7 +234,7 @@ impl HttpTest for TraceTransactionTest {
.map(|call| DebugNamespace::map_default_call(call.clone(), false))
.collect();

let CallTracerOption::CallTrace(result) = client
let CallTracerResult::CallTrace(result) = client
.trace_transaction(tx_results[0].hash, None)
.await?
.context("no transaction traces")?
Expand Down
14 changes: 7 additions & 7 deletions core/node/api_server/src/web3/tests/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use zksync_multivm::interface::{
};
use zksync_node_fee_model::BatchFeeModelInputProvider;
use zksync_types::{
api::{ApiStorageLog, CallTracerOption},
api::{ApiStorageLog, CallTracerResult},
fee_model::{BatchFeeInput, FeeParams},
get_intrinsic_constants,
transaction_request::CallRequest,
Expand Down Expand Up @@ -488,14 +488,14 @@ impl HttpTest for TraceCallTest {

self.fee_input.expect_default(Self::FEE_SCALE);
let call_request = CallTest::call_request(b"pending");
let CallTracerOption::CallTrace(call_result) =
let CallTracerResult::CallTrace(call_result) =
client.trace_call(call_request.clone(), None, None).await?
else {
unreachable!()
};
Self::assert_debug_call(&call_request, &call_result);
let pending_block_number = api::BlockId::Number(api::BlockNumber::Pending);
let CallTracerOption::CallTrace(call_result) = client
let CallTracerResult::CallTrace(call_result) = client
.trace_call(call_request.clone(), Some(pending_block_number), None)
.await?
else {
Expand All @@ -507,7 +507,7 @@ impl HttpTest for TraceCallTest {
let call_request = CallTest::call_request(b"latest");
for number in latest_block_numbers {
self.fee_input.expect_for_block(number, Self::FEE_SCALE);
let CallTracerOption::CallTrace(call_result) = client
let CallTracerResult::CallTrace(call_result) = client
.trace_call(
call_request.clone(),
Some(api::BlockId::Number(number)),
Expand Down Expand Up @@ -567,14 +567,14 @@ impl HttpTest for TraceCallTestAfterSnapshotRecovery {
) -> anyhow::Result<()> {
self.fee_input.expect_default(TraceCallTest::FEE_SCALE);
let call_request = CallTest::call_request(b"pending");
let CallTracerOption::CallTrace(call_result) =
let CallTracerResult::CallTrace(call_result) =
client.trace_call(call_request.clone(), None, None).await?
else {
unreachable!()
};
TraceCallTest::assert_debug_call(&call_request, &call_result);
let pending_block_number = api::BlockId::Number(api::BlockNumber::Pending);
let CallTracerOption::CallTrace(call_result) = client
let CallTracerResult::CallTrace(call_result) = client
.trace_call(call_request.clone(), Some(pending_block_number), None)
.await?
else {
Expand All @@ -599,7 +599,7 @@ impl HttpTest for TraceCallTestAfterSnapshotRecovery {
self.fee_input
.expect_for_block(number, TraceCallTest::FEE_SCALE);
let number = api::BlockId::Number(number);
let CallTracerOption::CallTrace(call_result) = client
let CallTracerResult::CallTrace(call_result) = client
.trace_call(call_request.clone(), Some(number), None)
.await?
else {
Expand Down

0 comments on commit 0b807d1

Please sign in to comment.