Skip to content

Commit

Permalink
Merge pull request #32 from matter-labs/remove-get_l1_processing_details
Browse files Browse the repository at this point in the history
feat: remove get_l1_processing_details method
  • Loading branch information
perekopskiy authored Dec 13, 2024
2 parents 962a6b2 + fa4d517 commit 44ac0ba
Show file tree
Hide file tree
Showing 16 changed files with 9 additions and 213 deletions.
1 change: 0 additions & 1 deletion core/bin/external_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,6 @@ impl From<&ExternalNodeConfig> for InternalApiConfig {
Self {
l1_chain_id: config.required.l1_chain_id,
l2_chain_id: config.required.l2_chain_id,
settlement_layer_url: None,
max_tx_size: config.optional.max_tx_size_bytes,
estimate_gas_scale_factor: config.optional.estimate_gas_scale_factor,
estimate_gas_acceptable_overestimation: config
Expand Down
4 changes: 0 additions & 4 deletions core/lib/config/src/configs/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,6 @@ pub struct Web3JsonRpcConfig {
/// (hundreds or thousands RPS).
#[serde(default)]
pub extended_api_tracing: bool,

#[serde(default)]
pub settlement_layer_url: Option<String>,
}

impl Web3JsonRpcConfig {
Expand Down Expand Up @@ -267,7 +264,6 @@ impl Web3JsonRpcConfig {
whitelisted_tokens_for_aa: vec![],
api_namespaces: None,
extended_api_tracing: false,
settlement_layer_url: None,
}
}

Expand Down
1 change: 0 additions & 1 deletion core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ impl Distribution<configs::api::Web3JsonRpcConfig> for EncodeDist {
api_namespaces: self
.sample_opt(|| self.sample_range(rng).map(|_| self.sample(rng)).collect()),
extended_api_tracing: self.sample(rng),
settlement_layer_url: self.sample(rng),
}
}
}
Expand Down
41 changes: 1 addition & 40 deletions core/lib/dal/src/eth_sender_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ use zksync_db_connection::{
};
use zksync_types::{
aggregated_operations::AggregatedActionType,
eth_sender::{BatchSettlementInfo, EthTx, EthTxBlobSidecar, TxHistory, TxHistoryToSend},
eth_sender::{EthTx, EthTxBlobSidecar, TxHistory, TxHistoryToSend},
Address, L1BatchNumber, SLChainId, H256, U256,
};

use crate::{
models::storage_eth_tx::{
L1BatchEthSenderStats, StorageEthTx, StorageTxHistory, StorageTxHistoryToSend,
StoredBatchSettlementInfo,
},
Core,
};
Expand Down Expand Up @@ -796,44 +795,6 @@ impl EthSenderDal<'_, '_> {

Ok(())
}

pub async fn get_batch_finalization_info(
&mut self,
batch_number: L1BatchNumber,
) -> DalResult<Option<BatchSettlementInfo>> {
let mut info = sqlx::query_as!(
StoredBatchSettlementInfo,
r#"
SELECT
number AS batch_number,
eth_txs.chain_id AS settlement_layer_id,
eth_txs_history.tx_hash AS settlement_layer_tx_hash
FROM
l1_batches
JOIN eth_txs ON l1_batches.eth_execute_tx_id = eth_txs.id
JOIN eth_txs_history
ON (
eth_txs.id = eth_txs_history.eth_tx_id
AND eth_txs_history.confirmed_at IS NOT NULL
)
WHERE
l1_batches.number = $1
"#,
i64::from(batch_number.0)
)
.instrument("get_batch_finalization_info")
.with_arg("batch_number", &batch_number)
.fetch_all(self.storage)
.await?;

assert!(
info.len() <= 1,
"Batch number must be unique in the database {:#?}",
info
);

Ok(info.pop().and_then(Into::into))
}
}

/// These methods should only be used for tests.
Expand Down
23 changes: 1 addition & 22 deletions core/lib/dal/src/models/storage_eth_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::str::FromStr;
use sqlx::types::chrono::NaiveDateTime;
use zksync_types::{
aggregated_operations::AggregatedActionType,
eth_sender::{BatchSettlementInfo, EthTx, TxHistory, TxHistoryToSend},
eth_sender::{EthTx, TxHistory, TxHistoryToSend},
Address, L1BatchNumber, Nonce, SLChainId, H256,
};

Expand Down Expand Up @@ -126,24 +126,3 @@ impl From<StorageTxHistoryToSend> for TxHistoryToSend {
}
}
}

#[derive(Debug)]
pub struct StoredBatchSettlementInfo {
pub batch_number: i64,
pub settlement_layer_id: Option<i64>,
pub settlement_layer_tx_hash: Option<String>,
}

impl From<StoredBatchSettlementInfo> for Option<BatchSettlementInfo> {
fn from(info: StoredBatchSettlementInfo) -> Option<BatchSettlementInfo> {
let settlement_layer_id = info.settlement_layer_id?;
let settlement_layer_tx_hash = info.settlement_layer_tx_hash?;

Some(BatchSettlementInfo {
batch_number: info.batch_number as u32,
settlement_layer_id: SLChainId(settlement_layer_id as u64),
settlement_layer_tx_hash: H256::from_str(&settlement_layer_tx_hash)
.expect("Incorrect hash"),
})
}
}
2 changes: 0 additions & 2 deletions core/lib/env_config/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ mod tests {
],
api_namespaces: Some(vec!["debug".to_string()]),
extended_api_tracing: true,
settlement_layer_url: Some("http://127.0.0.1:9011".into()),
},
prometheus: PrometheusConfig {
listener_port: 3312,
Expand Down Expand Up @@ -144,7 +143,6 @@ mod tests {
API_WEB3_JSON_RPC_WEBSOCKET_REQUESTS_PER_MINUTE_LIMIT=10
API_WEB3_JSON_RPC_MEMPOOL_CACHE_SIZE=10000
API_WEB3_JSON_RPC_MEMPOOL_CACHE_UPDATE_INTERVAL=50
API_WEB3_JSON_RPC_SETTLEMENT_LAYER_URL="http://127.0.0.1:9011"
API_CONTRACT_VERIFICATION_PORT="3070"
API_CONTRACT_VERIFICATION_URL="http://127.0.0.1:3070"
API_WEB3_JSON_RPC_MAX_RESPONSE_BODY_SIZE_MB=10
Expand Down
2 changes: 0 additions & 2 deletions core/lib/protobuf_config/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ impl ProtoRepr for proto::Web3JsonRpc {
.context("whitelisted_tokens_for_aa")?,
extended_api_tracing: self.extended_api_tracing.unwrap_or_default(),
api_namespaces,
settlement_layer_url: self.settlement_layer_url.clone(),
})
}

Expand Down Expand Up @@ -218,7 +217,6 @@ impl ProtoRepr for proto::Web3JsonRpc {
.collect(),
extended_api_tracing: Some(this.extended_api_tracing),
api_namespaces: this.api_namespaces.clone().unwrap_or_default(),
settlement_layer_url: this.settlement_layer_url.clone(),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion core/lib/protobuf_config/src/proto/config/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ message Web3JsonRpc {
optional bool extended_api_tracing = 33; // optional, default false
optional bool estimate_gas_optimize_search = 34; // optional, default false
optional uint32 latest_values_max_block_lag = 35; // optional
optional string settlement_layer_url = 36; // optional

reserved 15; reserved "l1_to_l2_transactions_compatibility_mode";
reserved 11; reserved "request_timeout";
Expand Down
11 changes: 0 additions & 11 deletions core/lib/types/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,17 +898,6 @@ pub struct L1BatchDetails {
pub base: BlockDetailsBase,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct L1ProcessingDetails {
pub commit_tx_hash: Option<H256>,
pub committed_at: Option<DateTime<Utc>>,
pub prove_tx_hash: Option<H256>,
pub proven_at: Option<DateTime<Utc>>,
pub execute_tx_hash: Option<H256>,
pub executed_at: Option<DateTime<Utc>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StorageProof {
Expand Down
7 changes: 0 additions & 7 deletions core/lib/types/src/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,3 @@ pub struct TxHistoryToSend {
pub signed_raw_tx: Vec<u8>,
pub nonce: Nonce,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct BatchSettlementInfo {
pub batch_number: u32,
pub settlement_layer_id: SLChainId,
pub settlement_layer_tx_hash: H256,
}
9 changes: 1 addition & 8 deletions core/lib/web3_decl/src/namespaces/zks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use jsonrpsee::proc_macros::rpc;
use zksync_types::{
api::{
state_override::StateOverride, BlockDetails, BridgeAddresses, L1BatchDetails,
L1ProcessingDetails, L2ToL1LogProof, Proof, ProtocolVersion, TransactionDetailedResult,
TransactionDetails,
L2ToL1LogProof, Proof, ProtocolVersion, TransactionDetailedResult, TransactionDetails,
},
fee::Fee,
fee_model::{FeeParams, PubdataIndependentBatchFeeModelInput},
Expand Down Expand Up @@ -112,12 +111,6 @@ pub trait ZksNamespace {
async fn get_l1_batch_details(&self, batch: L1BatchNumber)
-> RpcResult<Option<L1BatchDetails>>;

#[method(name = "getL1ProcessingDetails")]
async fn get_l1_processing_details(
&self,
batch: L1BatchNumber,
) -> RpcResult<Option<L1ProcessingDetails>>;

#[method(name = "getBytecodeByHash")]
async fn get_bytecode_by_hash(&self, hash: H256) -> RpcResult<Option<Vec<u8>>>;

Expand Down
13 changes: 2 additions & 11 deletions core/node/api_server/src/web3/backend_jsonrpsee/namespaces/zks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use zksync_multivm::interface::VmEvent;
use zksync_types::{
api::{
state_override::StateOverride, ApiStorageLog, BlockDetails, BridgeAddresses,
L1BatchDetails, L1ProcessingDetails, L2ToL1LogProof, Log, Proof, ProtocolVersion,
TransactionDetailedResult, TransactionDetails,
L1BatchDetails, L2ToL1LogProof, Log, Proof, ProtocolVersion, TransactionDetailedResult,
TransactionDetails,
},
fee::Fee,
fee_model::{FeeParams, PubdataIndependentBatchFeeModelInput},
Expand Down Expand Up @@ -148,15 +148,6 @@ impl ZksNamespaceServer for ZksNamespace {
.map_err(|err| self.current_method().map_err(err))
}

async fn get_l1_processing_details(
&self,
batch_number: L1BatchNumber,
) -> RpcResult<Option<L1ProcessingDetails>> {
self.get_l1_processing_details_impl(batch_number)
.await
.map_err(|err| self.current_method().map_err(err))
}

async fn get_bytecode_by_hash(&self, hash: H256) -> RpcResult<Option<Vec<u8>>> {
self.get_bytecode_by_hash_impl(hash)
.await
Expand Down
101 changes: 4 additions & 97 deletions core/node/api_server/src/web3/namespaces/zks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use zksync_types::{
address_to_h256,
api::{
state_override::StateOverride, BlockDetails, BridgeAddresses, GetLogsFilter,
L1BatchDetails, L1ProcessingDetails, L2ToL1LogProof, Proof, ProtocolVersion, StorageProof,
TransactionDetails,
L1BatchDetails, L2ToL1LogProof, Proof, ProtocolVersion, StorageProof, TransactionDetails,
},
fee::Fee,
fee_model::{FeeParams, PubdataIndependentBatchFeeModelInput},
Expand All @@ -24,14 +23,12 @@ use zksync_types::{
transaction_request::CallRequest,
utils::storage_key_for_standard_token_balance,
web3::Bytes,
AccountTreeId, L1BatchNumber, L2BlockNumber, L2ChainId, ProtocolVersionId, StorageKey,
Transaction, L1_MESSENGER_ADDRESS, L2_BASE_TOKEN_ADDRESS,
REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE, U256, U64,
AccountTreeId, L1BatchNumber, L2BlockNumber, ProtocolVersionId, StorageKey, Transaction,
L1_MESSENGER_ADDRESS, L2_BASE_TOKEN_ADDRESS, REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE, U256, U64,
};
use zksync_web3_decl::{
client::{Client, L2},
error::{ClientRpcContext, Web3Error},
namespaces::{EthNamespaceClient, ZksNamespaceClient},
namespaces::ZksNamespaceClient,
types::{Address, Token, H256},
};

Expand Down Expand Up @@ -563,96 +560,6 @@ impl ZksNamespace {
.map_err(DalError::generalize)?)
}

pub async fn get_l1_processing_details_impl(
&self,
batch_number: L1BatchNumber,
) -> Result<Option<L1ProcessingDetails>, Web3Error> {
let mut storage = self.state.acquire_connection().await?;
self.state
.start_info
.ensure_not_pruned(batch_number, &mut storage)
.await?;

let batch_details = storage
.blocks_web3_dal()
.get_l1_batch_details(batch_number)
.await
.map_err(DalError::generalize)?;

let Some(batch_details) = batch_details else {
return Ok(None);
};

let settlement_info = storage
.eth_sender_dal()
.get_batch_finalization_info(batch_number)
.await
.map_err(DalError::generalize)?;

let Some(info) = settlement_info else {
return Ok(None);
};

// FIXME: this method should eventually also provide data about L1 commit and L1 prove.

let (execute_tx_hash, executed_at) =
if info.settlement_layer_id.0 == self.state.api_config.l1_chain_id.0 {
(
batch_details.base.execute_tx_hash,
batch_details.base.executed_at,
)
} else {
// It is sl-based chain, we need to query the batch info from the SL
// Create a client for pinging the RPC.
let client: Client<L2> = Client::http(
self.state
.api_config
.settlement_layer_url
.clone()
.unwrap()
.parse()
.unwrap(),
)?
.for_network(L2::from(L2ChainId(self.state.api_config.l1_chain_id.0)))
.build();

let info = client
.get_transaction_receipt(info.settlement_layer_tx_hash)
.await
.expect("Failed to query the SL");
let Some(info) = info else {
return Ok(None);
};
let sl_l1_batch_number = info.l1_batch_number;
let Some(sl_l1_batch_number) = sl_l1_batch_number else {
return Ok(None);
};
let batch_details = client
.get_l1_batch_details(L1BatchNumber(sl_l1_batch_number.as_u32()))
.await
.expect("Failed to query the SL2");
let Some(batch_details) = batch_details else {
return Ok(None);
};

(
batch_details.base.execute_tx_hash,
batch_details.base.executed_at,
)
};

let details = L1ProcessingDetails {
commit_tx_hash: None,
committed_at: None,
prove_tx_hash: None,
proven_at: None,
execute_tx_hash,
executed_at,
};

Ok(Some(details))
}

pub async fn get_bytecode_by_hash_impl(
&self,
hash: H256,
Expand Down
2 changes: 0 additions & 2 deletions core/node/api_server/src/web3/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ pub struct InternalApiConfig {
/// Chain ID of the L1 network. Note, that it may be different from the chain id of the settlement layer.
pub l1_chain_id: L1ChainId,
pub l2_chain_id: L2ChainId,
pub settlement_layer_url: Option<String>,
pub max_tx_size: usize,
pub estimate_gas_scale_factor: f64,
pub estimate_gas_acceptable_overestimation: u32,
Expand Down Expand Up @@ -132,7 +131,6 @@ impl InternalApiConfig {
Self {
l1_chain_id: genesis_config.l1_chain_id,
l2_chain_id: genesis_config.l2_chain_id,
settlement_layer_url: web3_config.settlement_layer_url.clone(),
max_tx_size: web3_config.max_tx_size,
estimate_gas_scale_factor: web3_config.estimate_gas_scale_factor,
estimate_gas_acceptable_overestimation: web3_config
Expand Down
Loading

0 comments on commit 44ac0ba

Please sign in to comment.