Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ya-gpu-checker
Browse files Browse the repository at this point in the history
  • Loading branch information
yorik committed Feb 6, 2025
2 parents 3282571 + 4179711 commit a7a6d83
Show file tree
Hide file tree
Showing 72 changed files with 1,831 additions and 1,093 deletions.
19 changes: 13 additions & 6 deletions core/Cargo.lock

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

2 changes: 2 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ members = [
"lib/snapshots_applier",
"lib/crypto_primitives",
"lib/external_price_api",
"lib/task_management",
"lib/test_contracts",
# Test infrastructure
"tests/loadnext",
Expand Down Expand Up @@ -296,6 +297,7 @@ zksync_utils = { version = "26.2.1-non-semver-compat", path = "lib/utils" }
zksync_web3_decl = { version = "26.2.1-non-semver-compat", path = "lib/web3_decl" }
zksync_crypto_primitives = { version = "26.2.1-non-semver-compat", path = "lib/crypto_primitives" }
zksync_external_price_api = { version = "26.2.1-non-semver-compat", path = "lib/external_price_api" }
zksync_task_management = { version = "26.2.1-non-semver-compat", path = "lib/task_management" }

# Framework and components
zksync_node_framework = { version = "26.2.1-non-semver-compat", path = "node/node_framework" }
Expand Down
2 changes: 1 addition & 1 deletion core/bin/contract-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ zksync_dal.workspace = true
zksync_config = { workspace = true, features = ["observability_ext"] }
zksync_contract_verifier_lib.workspace = true
zksync_queued_job_processor.workspace = true
zksync_utils.workspace = true
zksync_task_management.workspace = true
zksync_vlog.workspace = true
zksync_core_leftovers.workspace = true

Expand Down
2 changes: 1 addition & 1 deletion core/bin/contract-verifier/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use zksync_contract_verifier_lib::ContractVerifier;
use zksync_core_leftovers::temp_config_store::{load_database_secrets, load_general_config};
use zksync_dal::{ConnectionPool, Core, CoreDal};
use zksync_queued_job_processor::JobProcessor;
use zksync_utils::wait_for_tasks::ManagedTasks;
use zksync_task_management::ManagedTasks;
use zksync_vlog::prometheus::PrometheusExporterConfig;

#[derive(Debug, Parser)]
Expand Down
2 changes: 1 addition & 1 deletion core/lib/basic_types/src/protocol_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl ProtocolVersionId {
}

pub fn is_pre_fflonk(&self) -> bool {
self < &Self::Version28
self < &Self::Version27
}

pub fn is_1_4_0(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion core/lib/contract_verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ impl ContractVerifier {
if selector == create_acc.short_signature()
|| selector == create2_acc.short_signature() =>
{
let tokens = create
let tokens = create_acc
.decode_input(token_data)
.context("failed to decode `createAccount` / `create2Account` input")?;
// Constructor arguments are in the third parameter.
Expand Down

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.

45 changes: 44 additions & 1 deletion core/lib/dal/src/events_web3_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ use sqlx::{
Postgres, Row,
};
use zksync_db_connection::{connection::Connection, error::DalResult, instrument::InstrumentExt};
use zksync_system_constants::CONTRACT_DEPLOYER_ADDRESS;
use zksync_types::{
api::{GetLogsFilter, Log},
Address, L2BlockNumber, H256,
h256_to_address, Address, L2BlockNumber, H256,
};
use zksync_vm_interface::VmEvent;

use crate::{models::storage_event::StorageWeb3Log, Core};

#[derive(Debug, PartialEq)]
pub struct ContractDeploymentLog {
pub transaction_index_in_block: u64,
pub deployer: Address,
pub deployed_address: Address,
}

#[derive(Debug)]
pub struct EventsWeb3Dal<'a, 'c> {
pub(crate) storage: &'a mut Connection<'c, Core>,
Expand Down Expand Up @@ -242,6 +251,40 @@ impl EventsWeb3Dal<'_, '_> {
let logs = db_logs.into_iter().map(Into::into).collect();
Ok(logs)
}

/// Gets all contract deployment logs for the specified block. The returned logs are ordered by their execution order.
pub async fn get_contract_deployment_logs(
&mut self,
block: L2BlockNumber,
) -> DalResult<Vec<ContractDeploymentLog>> {
let rows = sqlx::query!(
r#"
SELECT
tx_index_in_block AS "transaction_index!",
topic2 AS "deployer!",
topic4 AS "deployed_address!"
FROM events
WHERE miniblock_number = $1 AND address = $2 AND topic1 = $3
ORDER BY event_index_in_block
"#,
i64::from(block.0),
CONTRACT_DEPLOYER_ADDRESS.as_bytes(),
VmEvent::DEPLOY_EVENT_SIGNATURE.as_bytes()
)
.instrument("get_contract_deployment_logs")
.with_arg("block", &block)
.fetch_all(self.storage)
.await?;

Ok(rows
.into_iter()
.map(|row| ContractDeploymentLog {
transaction_index_in_block: row.transaction_index as u64,
deployer: h256_to_address(&H256::from_slice(&row.deployer)),
deployed_address: h256_to_address(&H256::from_slice(&row.deployed_address)),
})
.collect())
}
}

#[cfg(test)]
Expand Down
32 changes: 18 additions & 14 deletions core/lib/dal/src/models/storage_transaction.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
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},
fee::Fee,
h256_to_address,
l1::{OpProcessingType, PriorityQueueType},
l2::TransactionType,
protocol_upgrade::ProtocolUpgradeTxCommonData,
Expand All @@ -20,7 +18,9 @@ use zksync_types::{
use zksync_vm_interface::Call;

use super::call::{LegacyCall, LegacyMixedCall};
use crate::{models::bigdecimal_to_u256, BigDecimal};
use crate::{
models::bigdecimal_to_u256, transactions_web3_dal::ExtendedTransactionReceipt, BigDecimal,
};

#[derive(Debug, Clone, sqlx::FromRow)]
#[cfg_attr(test, derive(Default))]
Expand Down Expand Up @@ -348,15 +348,16 @@ pub(crate) struct StorageTransactionReceipt {
pub l1_batch_number: Option<i64>,
pub transfer_to: Option<serde_json::Value>,
pub execute_contract_address: Option<serde_json::Value>,
pub calldata: serde_json::Value,
pub refunded_gas: i64,
pub gas_limit: Option<BigDecimal>,
pub effective_gas_price: Option<BigDecimal>,
pub contract_address: Option<Vec<u8>>,
pub initiator_address: Vec<u8>,
pub nonce: Option<i64>,
pub block_timestamp: Option<i64>,
}

impl From<StorageTransactionReceipt> for TransactionReceipt {
impl From<StorageTransactionReceipt> for ExtendedTransactionReceipt {
fn from(storage_receipt: StorageTransactionReceipt) -> Self {
let status = storage_receipt.error.map_or_else(U64::one, |_| U64::zero());

Expand All @@ -367,26 +368,24 @@ impl From<StorageTransactionReceipt> for TransactionReceipt {
.index_in_block
.map_or_else(Default::default, U64::from);

// For better compatibility with various clients, we never return `None` recipient address.
let to = storage_receipt
.transfer_to
.or(storage_receipt.execute_contract_address)
.and_then(|addr| {
serde_json::from_value::<Option<Address>>(addr)
.expect("invalid address value in the database")
})
.unwrap_or_else(Address::zero);
});

let block_hash = H256::from_slice(&storage_receipt.block_hash);
TransactionReceipt {
let inner = TransactionReceipt {
transaction_hash: H256::from_slice(&storage_receipt.tx_hash),
transaction_index,
block_hash,
block_number: storage_receipt.block_number.into(),
l1_batch_tx_index: storage_receipt.l1_batch_tx_index.map(U64::from),
l1_batch_number: storage_receipt.l1_batch_number.map(U64::from),
from: H160::from_slice(&storage_receipt.initiator_address),
to: Some(to),
to,
cumulative_gas_used: Default::default(), // TODO: Should be actually calculated (SMA-1183).
gas_used: {
let refunded_gas: U256 = storage_receipt.refunded_gas.into();
Expand All @@ -401,16 +400,21 @@ impl From<StorageTransactionReceipt> for TransactionReceipt {
.map(bigdecimal_to_u256)
.unwrap_or_default(),
),
contract_address: storage_receipt
.contract_address
.map(|addr| h256_to_address(&H256::from_slice(&addr))),
contract_address: None, // Must be filled in separately
logs: vec![],
l2_to_l1_logs: vec![],
status,
logs_bloom: Default::default(),
// Even though the Rust SDK recommends us to supply "None" for legacy transactions
// we always supply some number anyway to have the same behavior as most popular RPCs
transaction_type: Some(tx_type),
};

Self {
inner,
nonce: (storage_receipt.nonce.unwrap_or(0) as u64).into(),
calldata: serde_json::from_value(storage_receipt.calldata)
.expect("incorrect calldata in Postgres"),
}
}
}
Expand All @@ -419,7 +423,7 @@ impl From<StorageTransactionReceipt> for TransactionReceipt {
#[derive(Debug, Clone, sqlx::FromRow)]
pub struct StorageTransactionExecutionInfo {
/// This is an opaque JSON field, with VM version specific contents.
pub execution_info: Value,
pub execution_info: serde_json::Value,
}

#[derive(Debug, Clone, sqlx::FromRow)]
Expand Down
Loading

0 comments on commit a7a6d83

Please sign in to comment.