From 0b807d1f341c383a16242b114f82e4702318e05e Mon Sep 17 00:00:00 2001 From: Danil Date: Mon, 23 Sep 2024 14:04:42 +0200 Subject: [PATCH] Rename result strcuts Signed-off-by: Danil --- core/lib/types/src/api/mod.rs | 8 +++--- core/lib/web3_decl/src/namespaces/debug.rs | 10 +++---- .../backend_jsonrpsee/namespaces/debug.rs | 10 +++---- .../api_server/src/web3/namespaces/debug.rs | 28 +++++++++---------- core/node/api_server/src/web3/tests/debug.rs | 13 +++++---- core/node/api_server/src/web3/tests/vm.rs | 14 +++++----- 6 files changed, 42 insertions(+), 41 deletions(-) diff --git a/core/lib/types/src/api/mod.rs b/core/lib/types/src/api/mod.rs index 3b8c139e681..4419b4fb36c 100644 --- a/core/lib/types/src/api/mod.rs +++ b/core/lib/types/src/api/mod.rs @@ -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), } -/// 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), } diff --git a/core/lib/web3_decl/src/namespaces/debug.rs b/core/lib/web3_decl/src/namespaces/debug.rs index 16e9a431f1f..857102c688b 100644 --- a/core/lib/web3_decl/src/namespaces/debug.rs +++ b/core/lib/web3_decl/src/namespaces/debug.rs @@ -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, }; @@ -25,14 +25,14 @@ pub trait DebugNamespace { &self, block: BlockNumber, options: Option, - ) -> RpcResult>; + ) -> RpcResult>; #[method(name = "traceBlockByHash")] async fn trace_block_by_hash( &self, hash: H256, options: Option, - ) -> RpcResult>; + ) -> RpcResult>; #[method(name = "traceCall")] async fn trace_call( @@ -40,12 +40,12 @@ pub trait DebugNamespace { request: CallRequest, block: Option, options: Option, - ) -> RpcResult; + ) -> RpcResult; #[method(name = "traceTransaction")] async fn trace_transaction( &self, tx_hash: H256, options: Option, - ) -> RpcResult>; + ) -> RpcResult>; } diff --git a/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/debug.rs b/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/debug.rs index 3696c6b5d7c..d261b396172 100644 --- a/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/debug.rs +++ b/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/debug.rs @@ -1,5 +1,5 @@ use zksync_types::{ - api::{BlockId, BlockNumber, CallTracerOption, CallTracerResult, TracerConfig}, + api::{BlockId, BlockNumber, CallTracerResult, CallTracerResultWithNestedResult, TracerConfig}, transaction_request::CallRequest, H256, }; @@ -16,7 +16,7 @@ impl DebugNamespaceServer for DebugNamespace { &self, block: BlockNumber, options: Option, - ) -> RpcResult> { + ) -> RpcResult> { self.debug_trace_block_impl(BlockId::Number(block), options) .await .map_err(|err| self.current_method().map_err(err)) @@ -26,7 +26,7 @@ impl DebugNamespaceServer for DebugNamespace { &self, hash: H256, options: Option, - ) -> RpcResult> { + ) -> RpcResult> { self.debug_trace_block_impl(BlockId::Hash(hash), options) .await .map_err(|err| self.current_method().map_err(err)) @@ -37,7 +37,7 @@ impl DebugNamespaceServer for DebugNamespace { request: CallRequest, block: Option, options: Option, - ) -> RpcResult { + ) -> RpcResult { self.debug_trace_call_impl(request, block, options) .await .map_err(|err| self.current_method().map_err(err)) @@ -47,7 +47,7 @@ impl DebugNamespaceServer for DebugNamespace { &self, tx_hash: H256, options: Option, - ) -> RpcResult> { + ) -> RpcResult> { self.debug_trace_transaction_impl(tx_hash, options) .await .map_err(|err| self.current_method().map_err(err)) diff --git a/core/node/api_server/src/web3/namespaces/debug.rs b/core/node/api_server/src/web3/namespaces/debug.rs index e780c4475a3..8095e8153cb 100644 --- a/core/node/api_server/src/web3/namespaces/debug.rs +++ b/core/node/api_server/src/web3/namespaces/debug.rs @@ -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, @@ -50,7 +50,7 @@ impl DebugNamespace { index: usize, transaction_hash: H256, tracer_option: Option, - ) -> CallTracerOption { + ) -> CallTracerResult { let (only_top_call, flatten) = tracer_option .map(|options| { ( @@ -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 { @@ -171,7 +171,7 @@ impl DebugNamespace { &self, block_id: BlockId, options: Option, - ) -> Result, Web3Error> { + ) -> Result, 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. @@ -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) @@ -212,7 +210,7 @@ impl DebugNamespace { &self, tx_hash: H256, options: Option, - ) -> Result, Web3Error> { + ) -> Result, Web3Error> { let mut connection = self.state.acquire_connection().await?; let call_trace = connection .transactions_dal() @@ -228,7 +226,7 @@ impl DebugNamespace { mut request: CallRequest, block_id: Option, options: Option, - ) -> Result { + ) -> Result { let block_id = block_id.unwrap_or(BlockId::Number(BlockNumber::Pending)); self.current_method().set_block_id(block_id); diff --git a/core/node/api_server/src/web3/tests/debug.rs b/core/node/api_server/src/web3/tests/debug.rs index b1d6a1aed0e..47827fb65b9 100644 --- a/core/node/api_server/src/web3/tests/debug.rs +++ b/core/node/api_server/src/web3/tests/debug.rs @@ -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, }; @@ -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()); @@ -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(); @@ -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")? diff --git a/core/node/api_server/src/web3/tests/vm.rs b/core/node/api_server/src/web3/tests/vm.rs index 7e818ff6630..f1fa7c86b74 100644 --- a/core/node/api_server/src/web3/tests/vm.rs +++ b/core/node/api_server/src/web3/tests/vm.rs @@ -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, @@ -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 { @@ -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)), @@ -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 { @@ -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 {