From feea4d3e1fdb724b22373fb9d4a1876208a54211 Mon Sep 17 00:00:00 2001 From: mm Date: Wed, 26 Jun 2024 14:48:30 +0200 Subject: [PATCH 01/10] adding empty interface --- core/lib/types/src/api/mod.rs | 5 ++++ core/lib/web3_decl/src/namespaces/mod.rs | 7 +++--- core/lib/web3_decl/src/namespaces/unstable.rs | 23 +++++++++++++++++ .../web3/backend_jsonrpsee/namespaces/mod.rs | 1 + .../backend_jsonrpsee/namespaces/unstable.rs | 19 ++++++++++++++ core/node/api_server/src/web3/mod.rs | 15 ++++++++--- .../api_server/src/web3/namespaces/mod.rs | 4 ++- .../src/web3/namespaces/unstable.rs | 25 +++++++++++++++++++ 8 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 core/lib/web3_decl/src/namespaces/unstable.rs create mode 100644 core/node/api_server/src/web3/backend_jsonrpsee/namespaces/unstable.rs create mode 100644 core/node/api_server/src/web3/namespaces/unstable.rs diff --git a/core/lib/types/src/api/mod.rs b/core/lib/types/src/api/mod.rs index 0617f47268aa..2f92b48f561f 100644 --- a/core/lib/types/src/api/mod.rs +++ b/core/lib/types/src/api/mod.rs @@ -821,6 +821,11 @@ pub struct ApiStorageLog { pub written_value: U256, } +// Coming from TransactionExecutionMetrics +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ApiTransactionExecutionInfo {} + #[cfg(test)] mod tests { use super::*; diff --git a/core/lib/web3_decl/src/namespaces/mod.rs b/core/lib/web3_decl/src/namespaces/mod.rs index 76445f9a4fd8..f3b5c8a9aaee 100644 --- a/core/lib/web3_decl/src/namespaces/mod.rs +++ b/core/lib/web3_decl/src/namespaces/mod.rs @@ -1,13 +1,13 @@ pub use self::{ debug::DebugNamespaceClient, en::EnNamespaceClient, eth::EthNamespaceClient, - net::NetNamespaceClient, snapshots::SnapshotsNamespaceClient, web3::Web3NamespaceClient, - zks::ZksNamespaceClient, + net::NetNamespaceClient, snapshots::SnapshotsNamespaceClient, + unstable::UnstableNamespaceClient, web3::Web3NamespaceClient, zks::ZksNamespaceClient, }; #[cfg(feature = "server")] pub use self::{ debug::DebugNamespaceServer, en::EnNamespaceServer, eth::EthNamespaceServer, eth::EthPubSubServer, net::NetNamespaceServer, snapshots::SnapshotsNamespaceServer, - web3::Web3NamespaceServer, zks::ZksNamespaceServer, + unstable::UnstableNamespaceServer, web3::Web3NamespaceServer, zks::ZksNamespaceServer, }; mod debug; @@ -15,5 +15,6 @@ mod en; mod eth; mod net; mod snapshots; +mod unstable; mod web3; mod zks; diff --git a/core/lib/web3_decl/src/namespaces/unstable.rs b/core/lib/web3_decl/src/namespaces/unstable.rs new file mode 100644 index 000000000000..c647c26e768c --- /dev/null +++ b/core/lib/web3_decl/src/namespaces/unstable.rs @@ -0,0 +1,23 @@ +#[cfg_attr(not(feature = "server"), allow(unused_imports))] +use jsonrpsee::core::RpcResult; +use jsonrpsee::proc_macros::rpc; +use zksync_types::{api::ApiTransactionExecutionInfo, H256}; + +use crate::client::{ForNetwork, L2}; + +/// RPCs in this namespace are experimental, and their interface is unstable, and it WILL change. +#[cfg_attr( + feature = "server", + rpc(server, client, namespace = "unstable", client_bounds(Self: ForNetwork)) +)] +#[cfg_attr( + not(feature = "server"), + rpc(client, namespace = "unstable", client_bounds(Self: ForNetwork)) +)] +pub trait UnstableNamespace { + #[method(name = "getTransactionExecutionInfo")] + async fn transaction_execution_info( + &self, + hash: H256, + ) -> RpcResult; +} diff --git a/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/mod.rs b/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/mod.rs index 3f0f043f8d4a..1d00e90b0e84 100644 --- a/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/mod.rs +++ b/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/mod.rs @@ -3,5 +3,6 @@ pub mod en; pub mod eth; pub mod net; pub mod snapshots; +pub mod unstable; pub mod web3; pub mod zks; diff --git a/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/unstable.rs b/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/unstable.rs new file mode 100644 index 000000000000..4503917446ef --- /dev/null +++ b/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/unstable.rs @@ -0,0 +1,19 @@ +use zksync_types::{api::ApiTransactionExecutionInfo, H256}; +use zksync_web3_decl::{ + jsonrpsee::core::{async_trait, RpcResult}, + namespaces::UnstableNamespaceServer, +}; + +use crate::web3::namespaces::UnstableNamespace; + +#[async_trait] +impl UnstableNamespaceServer for UnstableNamespace { + async fn transaction_execution_info( + &self, + hash: H256, + ) -> RpcResult { + self.transaction_execution_info_impl(hash) + .await + .map_err(|err| self.current_method().map_err(err)) + } +} diff --git a/core/node/api_server/src/web3/mod.rs b/core/node/api_server/src/web3/mod.rs index 7b2dec7abb35..d3f6282c3583 100644 --- a/core/node/api_server/src/web3/mod.rs +++ b/core/node/api_server/src/web3/mod.rs @@ -24,7 +24,8 @@ use zksync_web3_decl::{ }, namespaces::{ DebugNamespaceServer, EnNamespaceServer, EthNamespaceServer, EthPubSubServer, - NetNamespaceServer, SnapshotsNamespaceServer, Web3NamespaceServer, ZksNamespaceServer, + NetNamespaceServer, SnapshotsNamespaceServer, UnstableNamespaceServer, Web3NamespaceServer, + ZksNamespaceServer, }, types::Filter, }; @@ -37,8 +38,8 @@ use self::{ mempool_cache::MempoolCache, metrics::API_METRICS, namespaces::{ - DebugNamespace, EnNamespace, EthNamespace, NetNamespace, SnapshotsNamespace, Web3Namespace, - ZksNamespace, + DebugNamespace, EnNamespace, EthNamespace, NetNamespace, SnapshotsNamespace, + UnstableNamespace, Web3Namespace, ZksNamespace, }, pubsub::{EthSubscribe, EthSubscriptionIdProvider, PubSubEvent}, state::{Filters, InternalApiConfig, RpcState, SealedL2BlockNumber}, @@ -98,6 +99,7 @@ pub enum Namespace { En, Pubsub, Snapshots, + Unstable, } impl Namespace { @@ -108,6 +110,7 @@ impl Namespace { Self::Zks, Self::En, Self::Pubsub, + Self::Unstable, ]; } @@ -407,9 +410,13 @@ impl ApiServer { .context("cannot merge en namespace")?; } if namespaces.contains(&Namespace::Snapshots) { - rpc.merge(SnapshotsNamespace::new(rpc_state).into_rpc()) + rpc.merge(SnapshotsNamespace::new(rpc_state.clone()).into_rpc()) .context("cannot merge snapshots namespace")?; } + if namespaces.contains(&Namespace::Unstable) { + rpc.merge(UnstableNamespace::new(rpc_state).into_rpc()) + .context("cannot merge unstable namespace")?; + } Ok(rpc) } diff --git a/core/node/api_server/src/web3/namespaces/mod.rs b/core/node/api_server/src/web3/namespaces/mod.rs index b9355f7181ff..bf35cac0409e 100644 --- a/core/node/api_server/src/web3/namespaces/mod.rs +++ b/core/node/api_server/src/web3/namespaces/mod.rs @@ -6,10 +6,12 @@ mod en; pub(crate) mod eth; mod net; mod snapshots; +mod unstable; mod web3; mod zks; pub(super) use self::{ debug::DebugNamespace, en::EnNamespace, eth::EthNamespace, net::NetNamespace, - snapshots::SnapshotsNamespace, web3::Web3Namespace, zks::ZksNamespace, + snapshots::SnapshotsNamespace, unstable::UnstableNamespace, web3::Web3Namespace, + zks::ZksNamespace, }; diff --git a/core/node/api_server/src/web3/namespaces/unstable.rs b/core/node/api_server/src/web3/namespaces/unstable.rs new file mode 100644 index 000000000000..f6f432ffff5b --- /dev/null +++ b/core/node/api_server/src/web3/namespaces/unstable.rs @@ -0,0 +1,25 @@ +use zksync_types::api::ApiTransactionExecutionInfo; +use zksync_web3_decl::{error::Web3Error, types::H256}; + +use crate::web3::{backend_jsonrpsee::MethodTracer, RpcState}; + +#[derive(Debug)] +pub(crate) struct UnstableNamespace { + state: RpcState, +} + +impl UnstableNamespace { + pub fn new(state: RpcState) -> Self { + Self { state } + } + pub(crate) fn current_method(&self) -> &MethodTracer { + &self.state.current_method + } + + pub async fn transaction_execution_info_impl( + &self, + request: H256, + ) -> Result { + todo!(); + } +} From fccf129714ecfde110ce992190b4573202c1a6b7 Mon Sep 17 00:00:00 2001 From: mm Date: Wed, 26 Jun 2024 16:44:20 +0200 Subject: [PATCH 02/10] added missing logic --- ...13cd5428eaed485b9094fcd8a5f65c5ffba94.json | 22 ++++++++++++++++ .../lib/dal/src/models/storage_transaction.rs | 8 ++++++ core/lib/dal/src/transactions_web3_dal.rs | 25 ++++++++++++++++++- core/lib/types/src/api/mod.rs | 5 +++- core/lib/web3_decl/src/namespaces/unstable.rs | 2 +- .../backend_jsonrpsee/namespaces/unstable.rs | 2 +- .../src/web3/namespaces/unstable.rs | 18 ++++++++++--- 7 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 core/lib/dal/.sqlx/query-3476550b4d08a336e3fc5efe0e813cd5428eaed485b9094fcd8a5f65c5ffba94.json diff --git a/core/lib/dal/.sqlx/query-3476550b4d08a336e3fc5efe0e813cd5428eaed485b9094fcd8a5f65c5ffba94.json b/core/lib/dal/.sqlx/query-3476550b4d08a336e3fc5efe0e813cd5428eaed485b9094fcd8a5f65c5ffba94.json new file mode 100644 index 000000000000..e65555be7f24 --- /dev/null +++ b/core/lib/dal/.sqlx/query-3476550b4d08a336e3fc5efe0e813cd5428eaed485b9094fcd8a5f65c5ffba94.json @@ -0,0 +1,22 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT\n transactions.execution_info\n FROM\n transactions\n \n WHERE\n transactions.hash = $1\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "execution_info", + "type_info": "Jsonb" + } + ], + "parameters": { + "Left": [ + "Bytea" + ] + }, + "nullable": [ + false + ] + }, + "hash": "3476550b4d08a336e3fc5efe0e813cd5428eaed485b9094fcd8a5f65c5ffba94" +} diff --git a/core/lib/dal/src/models/storage_transaction.rs b/core/lib/dal/src/models/storage_transaction.rs index 1dfd5f4b6a0e..4714fb23ada1 100644 --- a/core/lib/dal/src/models/storage_transaction.rs +++ b/core/lib/dal/src/models/storage_transaction.rs @@ -1,6 +1,7 @@ use std::{convert::TryInto, str::FromStr}; use bigdecimal::Zero; +use serde_json::Value; use sqlx::types::chrono::{DateTime, NaiveDateTime, Utc}; use zksync_types::{ api::{self, TransactionDetails, TransactionReceipt, TransactionStatus}, @@ -396,6 +397,13 @@ impl From for TransactionReceipt { } } +// Details of the transaction execution. +#[derive(Debug, Clone, sqlx::FromRow)] +pub struct StorageTransactionExecutionInfo { + // This is an opaque JSON field, with VM version specific contents. + pub execution_info: Value, +} + #[derive(Debug, Clone, sqlx::FromRow)] pub(crate) struct StorageTransactionDetails { pub is_priority: bool, diff --git a/core/lib/dal/src/transactions_web3_dal.rs b/core/lib/dal/src/transactions_web3_dal.rs index 2d380a8059a6..ff026d48230e 100644 --- a/core/lib/dal/src/transactions_web3_dal.rs +++ b/core/lib/dal/src/transactions_web3_dal.rs @@ -16,7 +16,7 @@ use zksync_types::{ use crate::{ models::storage_transaction::{ StorageApiTransaction, StorageTransaction, StorageTransactionDetails, - StorageTransactionReceipt, + StorageTransactionExecutionInfo, StorageTransactionReceipt, }, Core, CoreDal, }; @@ -151,6 +151,29 @@ impl TransactionsWeb3Dal<'_, '_> { .await } + pub async fn get_unstable_transaction_execution_info( + &mut self, + hash: H256, + ) -> DalResult> { + let row = sqlx::query_as!( + StorageTransactionExecutionInfo, + r#" + SELECT + transactions.execution_info + FROM + transactions + WHERE + transactions.hash = $1 + "#, + hash.as_bytes() + ) + .instrument("get_unstable_transaction_execution_info") + .with_arg("hash", &hash) + .fetch_optional(self.storage) + .await?; + Ok(row) + } + async fn get_transactions_inner( &mut self, selector: TransactionSelector<'_>, diff --git a/core/lib/types/src/api/mod.rs b/core/lib/types/src/api/mod.rs index 2f92b48f561f..3a79dcbce716 100644 --- a/core/lib/types/src/api/mod.rs +++ b/core/lib/types/src/api/mod.rs @@ -1,5 +1,6 @@ use chrono::{DateTime, Utc}; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; +use serde_json::Value; use strum::Display; use zksync_basic_types::{ web3::{AccessList, Bytes, Index}, @@ -824,7 +825,9 @@ pub struct ApiStorageLog { // Coming from TransactionExecutionMetrics #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct ApiTransactionExecutionInfo {} +pub struct ApiTransactionExecutionInfo { + pub execution_info: Value, +} #[cfg(test)] mod tests { diff --git a/core/lib/web3_decl/src/namespaces/unstable.rs b/core/lib/web3_decl/src/namespaces/unstable.rs index c647c26e768c..2081aac6b048 100644 --- a/core/lib/web3_decl/src/namespaces/unstable.rs +++ b/core/lib/web3_decl/src/namespaces/unstable.rs @@ -19,5 +19,5 @@ pub trait UnstableNamespace { async fn transaction_execution_info( &self, hash: H256, - ) -> RpcResult; + ) -> RpcResult>; } diff --git a/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/unstable.rs b/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/unstable.rs index 4503917446ef..1875b6ea5ca0 100644 --- a/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/unstable.rs +++ b/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/unstable.rs @@ -11,7 +11,7 @@ impl UnstableNamespaceServer for UnstableNamespace { async fn transaction_execution_info( &self, hash: H256, - ) -> RpcResult { + ) -> RpcResult> { self.transaction_execution_info_impl(hash) .await .map_err(|err| self.current_method().map_err(err)) diff --git a/core/node/api_server/src/web3/namespaces/unstable.rs b/core/node/api_server/src/web3/namespaces/unstable.rs index f6f432ffff5b..b6253b6aa3dc 100644 --- a/core/node/api_server/src/web3/namespaces/unstable.rs +++ b/core/node/api_server/src/web3/namespaces/unstable.rs @@ -1,3 +1,4 @@ +use zksync_dal::{CoreDal, DalError}; use zksync_types::api::ApiTransactionExecutionInfo; use zksync_web3_decl::{error::Web3Error, types::H256}; @@ -18,8 +19,19 @@ impl UnstableNamespace { pub async fn transaction_execution_info_impl( &self, - request: H256, - ) -> Result { - todo!(); + hash: H256, + ) -> Result, Web3Error> { + let mut storage = self.state.acquire_connection().await?; + let foo = storage + .transactions_web3_dal() + .get_unstable_transaction_execution_info(hash) + .await + .map_err(DalError::generalize)?; + + Ok(foo.map(|x| { + return ApiTransactionExecutionInfo { + execution_info: x.execution_info, + }; + })) } } From d0b7722bcb486f9006914993f3a953bcf73b72f8 Mon Sep 17 00:00:00 2001 From: mm Date: Wed, 26 Jun 2024 17:29:20 +0200 Subject: [PATCH 03/10] updated query and added test. --- ...18f31a9a184779646a16537df5b7cc54d0b4175d24.json} | 4 ++-- core/lib/dal/src/transactions_web3_dal.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) rename core/lib/dal/.sqlx/{query-3476550b4d08a336e3fc5efe0e813cd5428eaed485b9094fcd8a5f65c5ffba94.json => query-53ab91ac4daebeb7d9d38018f31a9a184779646a16537df5b7cc54d0b4175d24.json} (70%) diff --git a/core/lib/dal/.sqlx/query-3476550b4d08a336e3fc5efe0e813cd5428eaed485b9094fcd8a5f65c5ffba94.json b/core/lib/dal/.sqlx/query-53ab91ac4daebeb7d9d38018f31a9a184779646a16537df5b7cc54d0b4175d24.json similarity index 70% rename from core/lib/dal/.sqlx/query-3476550b4d08a336e3fc5efe0e813cd5428eaed485b9094fcd8a5f65c5ffba94.json rename to core/lib/dal/.sqlx/query-53ab91ac4daebeb7d9d38018f31a9a184779646a16537df5b7cc54d0b4175d24.json index e65555be7f24..9694b9c662c1 100644 --- a/core/lib/dal/.sqlx/query-3476550b4d08a336e3fc5efe0e813cd5428eaed485b9094fcd8a5f65c5ffba94.json +++ b/core/lib/dal/.sqlx/query-53ab91ac4daebeb7d9d38018f31a9a184779646a16537df5b7cc54d0b4175d24.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT\n transactions.execution_info\n FROM\n transactions\n \n WHERE\n transactions.hash = $1\n ", + "query": "\n SELECT\n transactions.execution_info\n FROM\n transactions\n WHERE\n transactions.hash = $1\n ", "describe": { "columns": [ { @@ -18,5 +18,5 @@ false ] }, - "hash": "3476550b4d08a336e3fc5efe0e813cd5428eaed485b9094fcd8a5f65c5ffba94" + "hash": "53ab91ac4daebeb7d9d38018f31a9a184779646a16537df5b7cc54d0b4175d24" } diff --git a/core/lib/dal/src/transactions_web3_dal.rs b/core/lib/dal/src/transactions_web3_dal.rs index ff026d48230e..8d41344f61fc 100644 --- a/core/lib/dal/src/transactions_web3_dal.rs +++ b/core/lib/dal/src/transactions_web3_dal.rs @@ -573,6 +573,19 @@ mod tests { .get_transaction_by_hash(H256::zero(), L2ChainId::from(270)) .await; assert!(web3_tx.unwrap().is_none()); + + let execution_info = conn + .transactions_web3_dal() + .get_unstable_transaction_execution_info(tx_hash) + .await + .unwrap() + .unwrap(); + + // Check that execution info has at least the circuit statistics field. + assert!(execution_info + .execution_info + .get("circuit_statistic") + .is_some()); } #[tokio::test] From f786566542251007b0a6a6b09e47ff75ff89d080 Mon Sep 17 00:00:00 2001 From: mm-zk Date: Wed, 26 Jun 2024 19:32:48 +0200 Subject: [PATCH 04/10] better name --- core/node/api_server/src/web3/namespaces/unstable.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/node/api_server/src/web3/namespaces/unstable.rs b/core/node/api_server/src/web3/namespaces/unstable.rs index b6253b6aa3dc..ac2499db9ce3 100644 --- a/core/node/api_server/src/web3/namespaces/unstable.rs +++ b/core/node/api_server/src/web3/namespaces/unstable.rs @@ -22,15 +22,13 @@ impl UnstableNamespace { hash: H256, ) -> Result, Web3Error> { let mut storage = self.state.acquire_connection().await?; - let foo = storage + Ok(storage .transactions_web3_dal() .get_unstable_transaction_execution_info(hash) .await - .map_err(DalError::generalize)?; - - Ok(foo.map(|x| { + .map_err(DalError::generalize)?.map(|info| { return ApiTransactionExecutionInfo { - execution_info: x.execution_info, + execution_info: info.execution_info, }; })) } From 938710bc40310b2bef69832f151452b4d31e5fde Mon Sep 17 00:00:00 2001 From: mm-zk Date: Wed, 26 Jun 2024 20:48:00 +0200 Subject: [PATCH 05/10] fmt --- core/node/api_server/src/web3/namespaces/unstable.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/node/api_server/src/web3/namespaces/unstable.rs b/core/node/api_server/src/web3/namespaces/unstable.rs index ac2499db9ce3..82d833f6d91d 100644 --- a/core/node/api_server/src/web3/namespaces/unstable.rs +++ b/core/node/api_server/src/web3/namespaces/unstable.rs @@ -26,10 +26,11 @@ impl UnstableNamespace { .transactions_web3_dal() .get_unstable_transaction_execution_info(hash) .await - .map_err(DalError::generalize)?.map(|info| { - return ApiTransactionExecutionInfo { - execution_info: info.execution_info, - }; - })) + .map_err(DalError::generalize)? + .map(|info| { + return ApiTransactionExecutionInfo { + execution_info: info.execution_info, + }; + })) } } From 316864600a1dc612389f6fa744660acb1ae8aa57 Mon Sep 17 00:00:00 2001 From: mm-zk Date: Wed, 26 Jun 2024 21:03:40 +0200 Subject: [PATCH 06/10] clippy --- core/node/api_server/src/web3/namespaces/unstable.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/node/api_server/src/web3/namespaces/unstable.rs b/core/node/api_server/src/web3/namespaces/unstable.rs index 82d833f6d91d..bc5cef6cd9d9 100644 --- a/core/node/api_server/src/web3/namespaces/unstable.rs +++ b/core/node/api_server/src/web3/namespaces/unstable.rs @@ -28,9 +28,9 @@ impl UnstableNamespace { .await .map_err(DalError::generalize)? .map(|info| { - return ApiTransactionExecutionInfo { + ApiTransactionExecutionInfo { execution_info: info.execution_info, - }; + } })) } } From 83aa9d0a0ba787cbdcd1a5605c9be13bc5e29c15 Mon Sep 17 00:00:00 2001 From: mm-zk Date: Wed, 26 Jun 2024 21:37:33 +0200 Subject: [PATCH 07/10] lint again --- core/node/api_server/src/web3/namespaces/unstable.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/node/api_server/src/web3/namespaces/unstable.rs b/core/node/api_server/src/web3/namespaces/unstable.rs index bc5cef6cd9d9..a0b55f5a6f4e 100644 --- a/core/node/api_server/src/web3/namespaces/unstable.rs +++ b/core/node/api_server/src/web3/namespaces/unstable.rs @@ -27,10 +27,8 @@ impl UnstableNamespace { .get_unstable_transaction_execution_info(hash) .await .map_err(DalError::generalize)? - .map(|info| { - ApiTransactionExecutionInfo { - execution_info: info.execution_info, - } + .map(|info| ApiTransactionExecutionInfo { + execution_info: info.execution_info, })) } } From 31fd0c6f614d1aefbe0bae6fd2289ac09d29885a Mon Sep 17 00:00:00 2001 From: mm-zk Date: Thu, 27 Jun 2024 18:38:28 +0200 Subject: [PATCH 08/10] review comments --- core/lib/dal/src/models/storage_transaction.rs | 4 ++-- core/lib/dal/src/transactions_web3_dal.rs | 16 +++++++++------- core/lib/types/src/api/mod.rs | 3 ++- .../api_server/src/web3/namespaces/unstable.rs | 5 ++--- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/core/lib/dal/src/models/storage_transaction.rs b/core/lib/dal/src/models/storage_transaction.rs index 4714fb23ada1..01bbf4b4ff45 100644 --- a/core/lib/dal/src/models/storage_transaction.rs +++ b/core/lib/dal/src/models/storage_transaction.rs @@ -397,10 +397,10 @@ impl From for TransactionReceipt { } } -// Details of the transaction execution. +/// Details of the transaction execution. #[derive(Debug, Clone, sqlx::FromRow)] pub struct StorageTransactionExecutionInfo { - // This is an opaque JSON field, with VM version specific contents. + /// This is an opaque JSON field, with VM version specific contents. pub execution_info: Value, } diff --git a/core/lib/dal/src/transactions_web3_dal.rs b/core/lib/dal/src/transactions_web3_dal.rs index 8d41344f61fc..a73a383ff640 100644 --- a/core/lib/dal/src/transactions_web3_dal.rs +++ b/core/lib/dal/src/transactions_web3_dal.rs @@ -154,7 +154,7 @@ impl TransactionsWeb3Dal<'_, '_> { pub async fn get_unstable_transaction_execution_info( &mut self, hash: H256, - ) -> DalResult> { + ) -> DalResult> { let row = sqlx::query_as!( StorageTransactionExecutionInfo, r#" @@ -171,7 +171,7 @@ impl TransactionsWeb3Dal<'_, '_> { .with_arg("hash", &hash) .fetch_optional(self.storage) .await?; - Ok(row) + Ok(row.map(|entry| entry.execution_info)) } async fn get_transactions_inner( @@ -579,13 +579,15 @@ mod tests { .get_unstable_transaction_execution_info(tx_hash) .await .unwrap() - .unwrap(); + .expect("Transaction execution info is missing in the DAL"); // Check that execution info has at least the circuit statistics field. - assert!(execution_info - .execution_info - .get("circuit_statistic") - .is_some()); + // If this assertion fails because the transaction execution info format + // has changed, replace circuit_statistic with any other valid field + assert!( + execution_info.get("circuit_statistic").is_some(), + "Missing circuit_statistics field" + ); } #[tokio::test] diff --git a/core/lib/types/src/api/mod.rs b/core/lib/types/src/api/mod.rs index 3a79dcbce716..d13cf0543935 100644 --- a/core/lib/types/src/api/mod.rs +++ b/core/lib/types/src/api/mod.rs @@ -822,7 +822,8 @@ pub struct ApiStorageLog { pub written_value: U256, } -// Coming from TransactionExecutionMetrics +/// Raw transaction execution data. +/// Data is taken from `TransactionExecutionMetrics`. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct ApiTransactionExecutionInfo { diff --git a/core/node/api_server/src/web3/namespaces/unstable.rs b/core/node/api_server/src/web3/namespaces/unstable.rs index a0b55f5a6f4e..30afd2c6fc46 100644 --- a/core/node/api_server/src/web3/namespaces/unstable.rs +++ b/core/node/api_server/src/web3/namespaces/unstable.rs @@ -13,6 +13,7 @@ impl UnstableNamespace { pub fn new(state: RpcState) -> Self { Self { state } } + pub(crate) fn current_method(&self) -> &MethodTracer { &self.state.current_method } @@ -27,8 +28,6 @@ impl UnstableNamespace { .get_unstable_transaction_execution_info(hash) .await .map_err(DalError::generalize)? - .map(|info| ApiTransactionExecutionInfo { - execution_info: info.execution_info, - })) + .map(|execution_info| ApiTransactionExecutionInfo { execution_info })) } } From cd1a735390a2aeaaca1bd6c5ccf90304399a2d37 Mon Sep 17 00:00:00 2001 From: mm-zk Date: Thu, 27 Jun 2024 18:40:22 +0200 Subject: [PATCH 09/10] removed from default --- core/node/api_server/src/web3/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/core/node/api_server/src/web3/mod.rs b/core/node/api_server/src/web3/mod.rs index d3f6282c3583..19e103c97998 100644 --- a/core/node/api_server/src/web3/mod.rs +++ b/core/node/api_server/src/web3/mod.rs @@ -110,7 +110,6 @@ impl Namespace { Self::Zks, Self::En, Self::Pubsub, - Self::Unstable, ]; } From 17a6cc3c846600630e71d954b1d738152d716570 Mon Sep 17 00:00:00 2001 From: mm-zk Date: Thu, 27 Jun 2024 18:43:54 +0200 Subject: [PATCH 10/10] rename --- core/lib/types/src/api/mod.rs | 2 +- core/lib/web3_decl/src/namespaces/unstable.rs | 4 ++-- .../src/web3/backend_jsonrpsee/namespaces/unstable.rs | 4 ++-- core/node/api_server/src/web3/namespaces/unstable.rs | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/lib/types/src/api/mod.rs b/core/lib/types/src/api/mod.rs index d13cf0543935..abf8288a8327 100644 --- a/core/lib/types/src/api/mod.rs +++ b/core/lib/types/src/api/mod.rs @@ -826,7 +826,7 @@ pub struct ApiStorageLog { /// Data is taken from `TransactionExecutionMetrics`. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct ApiTransactionExecutionInfo { +pub struct TransactionExecutionInfo { pub execution_info: Value, } diff --git a/core/lib/web3_decl/src/namespaces/unstable.rs b/core/lib/web3_decl/src/namespaces/unstable.rs index 2081aac6b048..4996813a9855 100644 --- a/core/lib/web3_decl/src/namespaces/unstable.rs +++ b/core/lib/web3_decl/src/namespaces/unstable.rs @@ -1,7 +1,7 @@ #[cfg_attr(not(feature = "server"), allow(unused_imports))] use jsonrpsee::core::RpcResult; use jsonrpsee::proc_macros::rpc; -use zksync_types::{api::ApiTransactionExecutionInfo, H256}; +use zksync_types::{api::TransactionExecutionInfo, H256}; use crate::client::{ForNetwork, L2}; @@ -19,5 +19,5 @@ pub trait UnstableNamespace { async fn transaction_execution_info( &self, hash: H256, - ) -> RpcResult>; + ) -> RpcResult>; } diff --git a/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/unstable.rs b/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/unstable.rs index 1875b6ea5ca0..6abaa718a050 100644 --- a/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/unstable.rs +++ b/core/node/api_server/src/web3/backend_jsonrpsee/namespaces/unstable.rs @@ -1,4 +1,4 @@ -use zksync_types::{api::ApiTransactionExecutionInfo, H256}; +use zksync_types::{api::TransactionExecutionInfo, H256}; use zksync_web3_decl::{ jsonrpsee::core::{async_trait, RpcResult}, namespaces::UnstableNamespaceServer, @@ -11,7 +11,7 @@ impl UnstableNamespaceServer for UnstableNamespace { async fn transaction_execution_info( &self, hash: H256, - ) -> RpcResult> { + ) -> RpcResult> { self.transaction_execution_info_impl(hash) .await .map_err(|err| self.current_method().map_err(err)) diff --git a/core/node/api_server/src/web3/namespaces/unstable.rs b/core/node/api_server/src/web3/namespaces/unstable.rs index 30afd2c6fc46..b46ecd6dc530 100644 --- a/core/node/api_server/src/web3/namespaces/unstable.rs +++ b/core/node/api_server/src/web3/namespaces/unstable.rs @@ -1,5 +1,5 @@ use zksync_dal::{CoreDal, DalError}; -use zksync_types::api::ApiTransactionExecutionInfo; +use zksync_types::api::TransactionExecutionInfo; use zksync_web3_decl::{error::Web3Error, types::H256}; use crate::web3::{backend_jsonrpsee::MethodTracer, RpcState}; @@ -21,13 +21,13 @@ impl UnstableNamespace { pub async fn transaction_execution_info_impl( &self, hash: H256, - ) -> Result, Web3Error> { + ) -> Result, Web3Error> { let mut storage = self.state.acquire_connection().await?; Ok(storage .transactions_web3_dal() .get_unstable_transaction_execution_info(hash) .await .map_err(DalError::generalize)? - .map(|execution_info| ApiTransactionExecutionInfo { execution_info })) + .map(|execution_info| TransactionExecutionInfo { execution_info })) } }