Skip to content

Commit

Permalink
Merge branch 'main' into kl-factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Deniallugo committed Apr 4, 2024
2 parents 2d5d584 + 9fcb87e commit bb287d6
Show file tree
Hide file tree
Showing 179 changed files with 2,552 additions and 1,361 deletions.
5 changes: 3 additions & 2 deletions 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 checks-config/era.dic
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ sorted_timestamps
known_bytecodes
returndata
namespaces
natively
StateDiffRecord
BYTES_PER_ENUMERATION_INDEX
derived_key
Expand Down Expand Up @@ -927,3 +928,4 @@ StorageMarker
SIGINT
opentelemetry
PubdataSendingMode
FriGpuProverArchiver
3 changes: 3 additions & 0 deletions checks-config/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
},
{
"pattern": "^https://github\\.com/matter-labs/zksync-era/commit/"
},
{
"pattern": "^https://github\\.com/matter-labs//era-compiler-llvm"
}
],
"aliveStatusCodes": [0, 200, 206, 304]
Expand Down
2 changes: 2 additions & 0 deletions core/bin/external_node/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,8 @@ impl From<ExternalNodeConfig> for TxSenderConfig {
.optional
.l1_to_l2_transactions_compatibility_mode,
max_pubdata_per_batch: config.remote.max_pubdata_per_batch,
// Does not matter for EN.
whitelisted_tokens_for_aa: Default::default(),
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions core/bin/external_node/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ pub(crate) async fn ensure_storage_initialized(
let genesis_l1_batch = storage
.blocks_dal()
.get_l1_batch_header(L1BatchNumber(0))
.await
.context("failed getting genesis batch info")?;
.await?;
let snapshot_recovery = storage
.snapshot_recovery_dal()
.get_applied_snapshot_status()
.await
.context("failed getting snapshot recovery info")?;
.await?;
drop(storage);

let decision = match (genesis_l1_batch, snapshot_recovery) {
Expand Down
43 changes: 37 additions & 6 deletions core/bin/external_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use clap::Parser;
use metrics::EN_METRICS;
use prometheus_exporter::PrometheusExporterConfig;
use tokio::{
sync::watch,
sync::{watch, RwLock},
task::{self, JoinHandle},
};
use zksync_concurrency::{ctx, scope};
Expand Down Expand Up @@ -51,7 +51,7 @@ use zksync_state::PostgresStorageCaches;
use zksync_storage::RocksDB;
use zksync_types::L2ChainId;
use zksync_utils::wait_for_tasks::ManagedTasks;
use zksync_web3_decl::client::L2Client;
use zksync_web3_decl::{client::L2Client, namespaces::EnNamespaceClient};

use crate::{
config::{observability::observability_config_from_env, ExternalNodeConfig},
Expand Down Expand Up @@ -387,8 +387,14 @@ async fn run_api(
}
};

let (tx_sender, vm_barrier, cache_update_handle, proxy_cache_updater_handle) = {
let tx_proxy = TxProxy::new(main_node_client);
let (
tx_sender,
vm_barrier,
cache_update_handle,
proxy_cache_updater_handle,
whitelisted_tokens_update_handle,
) = {
let tx_proxy = TxProxy::new(main_node_client.clone());
let proxy_cache_updater_pool = singleton_pool_builder
.build()
.await
Expand Down Expand Up @@ -426,7 +432,31 @@ async fn run_api(
)
});

let whitelisted_tokens_for_aa_cache = Arc::new(RwLock::new(Vec::new()));
let whitelisted_tokens_for_aa_cache_clone = whitelisted_tokens_for_aa_cache.clone();
let mut stop_receiver_for_task = stop_receiver.clone();
let whitelisted_tokens_update_task = task::spawn(async move {
loop {
match main_node_client.whitelisted_tokens_for_aa().await {
Ok(tokens) => {
*whitelisted_tokens_for_aa_cache_clone.write().await = tokens;
}
Err(err) => {
tracing::error!(
"Failed to query `whitelisted_tokens_for_aa`, error: {err:?}"
);
}
}

// Error here corresponds to a timeout w/o `stop_receiver` changed; we're OK with this.
tokio::time::timeout(Duration::from_secs(60), stop_receiver_for_task.changed())
.await
.ok();
}
});

let tx_sender = tx_sender_builder
.with_whitelisted_tokens_for_aa(whitelisted_tokens_for_aa_cache)
.build(
fee_params_fetcher,
Arc::new(vm_concurrency_limiter),
Expand All @@ -439,6 +469,7 @@ async fn run_api(
vm_barrier,
cache_update_handle,
proxy_cache_updater_handle,
whitelisted_tokens_update_task,
)
};

Expand Down Expand Up @@ -490,6 +521,7 @@ async fn run_api(

task_futures.extend(cache_update_handle);
task_futures.push(proxy_cache_updater_handle);
task_futures.push(whitelisted_tokens_update_handle);

Ok(())
}
Expand Down Expand Up @@ -874,8 +906,7 @@ async fn main() -> anyhow::Result<()> {
let sealed_l1_batch_number = connection
.blocks_dal()
.get_sealed_l1_batch_number()
.await
.context("Failed getting sealed L1 batch number")?
.await?
.context(
"Cannot roll back pending L1 batch since there are no L1 batches in Postgres",
)?;
Expand Down
9 changes: 3 additions & 6 deletions core/bin/external_node/src/version_sync_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ pub async fn sync_versions(
let (mid_miniblock, _) = connection
.blocks_dal()
.get_miniblock_range_of_l1_batch(mid_batch)
.await
.with_context(|| format!("Failed to get miniblock range for L1 batch #{mid_batch}"))?
.await?
.with_context(|| {
format!("Postgres is inconsistent: missing miniblocks for L1 batch #{mid_batch}")
})?;
Expand All @@ -88,8 +87,7 @@ pub async fn sync_versions(
let (remote_first_v22_miniblock, _) = connection
.blocks_dal()
.get_miniblock_range_of_l1_batch(remote_first_v22_l1_batch)
.await
.with_context(|| format!("Failed to get miniblock range for L1 batch #{remote_first_v22_l1_batch}"))?
.await?
.with_context(|| {
format!("Postgres is inconsistent: missing miniblocks for L1 batch #{remote_first_v22_l1_batch}")
})?;
Expand All @@ -110,8 +108,7 @@ pub async fn sync_versions(
let (local_first_v22_miniblock, _) = transaction
.blocks_dal()
.get_miniblock_range_of_l1_batch(local_first_v22_l1_batch)
.await
.with_context(|| format!("Failed to get miniblock range for L1 batch #{local_first_v22_l1_batch}"))?
.await?
.with_context(|| {
format!("Postgres is inconsistent: missing miniblocks for L1 batch #{local_first_v22_l1_batch}")
})?;
Expand Down
4 changes: 2 additions & 2 deletions core/bin/snapshots_creator/src/creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Arc;
use anyhow::Context as _;
use tokio::sync::Semaphore;
use zksync_config::SnapshotsCreatorConfig;
use zksync_dal::{Connection, ConnectionPool, Core, CoreDal};
use zksync_dal::{Connection, ConnectionPool, Core, CoreDal, DalResult};
use zksync_object_store::ObjectStore;
use zksync_types::{
snapshots::{
Expand Down Expand Up @@ -67,7 +67,7 @@ pub(crate) struct SnapshotCreator {
}

impl SnapshotCreator {
async fn connect_to_replica(&self) -> anyhow::Result<Connection<'_, Core>> {
async fn connect_to_replica(&self) -> DalResult<Connection<'_, Core>> {
self.replica_pool
.connection_tagged("snapshots_creator")
.await
Expand Down
5 changes: 3 additions & 2 deletions core/bin/system-constants-generator/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,9 @@ pub(super) fn execute_user_txs_in_test_gas_vm(
let metrics = result.get_execution_metrics(None);

VmSpentResourcesResult {
gas_consumed: result.statistics.gas_used,
total_gas_paid: total_gas_paid_upfront.as_u32() - total_gas_refunded,
// It is assumed that the entire `gas_used` was spent on computation and so it safe to convert to u32
gas_consumed: result.statistics.gas_used as u32,
total_gas_paid: total_gas_paid_upfront.as_u32() - total_gas_refunded as u32,
pubdata_published: metrics.size() as u32,
total_pubdata_paid: 0,
}
Expand Down
6 changes: 6 additions & 0 deletions core/lib/basic_types/src/protocol_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ impl ProtocolVersionId {
pub fn is_pre_1_4_2(&self) -> bool {
self < &ProtocolVersionId::Version21
}

pub fn is_pre_1_5_0(&self) -> bool {
// In the current codebase all the protocol versions are pre-1.5.0.
// This method will be updated once the v1.5.0 is added to the server
true
}
}

impl Default for ProtocolVersionId {
Expand Down
18 changes: 16 additions & 2 deletions core/lib/basic_types/src/prover_dal.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Types exposed by the prover DAL for general-purpose use.
use std::{net::IpAddr, ops::Add};
use std::{net::IpAddr, ops::Add, str::FromStr};

use chrono::{DateTime, Duration, Utc};

Expand Down Expand Up @@ -204,7 +204,7 @@ pub struct JobExtendedStatistics {
pub active_area: Vec<ProverJobInfo>,
}

#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum GpuProverInstanceStatus {
// The instance is available for processing.
Available,
Expand All @@ -215,3 +215,17 @@ pub enum GpuProverInstanceStatus {
// The instance is not alive anymore.
Dead,
}

impl FromStr for GpuProverInstanceStatus {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"available" => Ok(Self::Available),
"full" => Ok(Self::Full),
"reserved" => Ok(Self::Reserved),
"dead" => Ok(Self::Dead),
_ => Err(()),
}
}
}
6 changes: 6 additions & 0 deletions core/lib/circuit_breaker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ pub enum CircuitBreakerError {
Internal(#[from] anyhow::Error),
}

impl From<zksync_dal::DalError> for CircuitBreakerError {
fn from(err: zksync_dal::DalError) -> Self {
Self::Internal(err.generalize())
}
}

/// Checks circuit breakers
#[derive(Debug)]
pub struct CircuitBreakerChecker {
Expand Down
7 changes: 6 additions & 1 deletion core/lib/config/src/configs/api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{net::SocketAddr, num::NonZeroU32, time::Duration};

use serde::Deserialize;
use zksync_basic_types::H256;
use zksync_basic_types::{Address, H256};

pub use crate::configs::PrometheusConfig;

Expand Down Expand Up @@ -100,6 +100,10 @@ pub struct Web3JsonRpcConfig {
pub mempool_cache_update_interval: Option<u64>,
/// Maximum number of transactions to be stored in the mempool cache. Default is 10000.
pub mempool_cache_size: Option<usize>,
/// List of L2 token addresses that are white-listed to use by paymasters
/// (additionally to natively bridged tokens).
#[serde(default)]
pub whitelisted_tokens_for_aa: Vec<Address>,
}

impl Web3JsonRpcConfig {
Expand Down Expand Up @@ -137,6 +141,7 @@ impl Web3JsonRpcConfig {
mempool_cache_update_interval: Default::default(),
mempool_cache_size: Default::default(),
tree_api_url: None,
whitelisted_tokens_for_aa: Default::default(),
}
}

Expand Down
6 changes: 6 additions & 0 deletions core/lib/config/src/configs/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ pub struct StateKeeperConfig {
/// Number of keys that is processed by enum_index migration in State Keeper each L1 batch.
pub enum_index_migration_chunk_size: Option<usize>,

/// The maximal number of circuits that a batch can support.
/// Note, that this number corresponds to the "base layer" circuits, i.e. it does not include
/// the recursion layers' circuits.
pub max_circuits_per_batch: usize,

// Base system contract hashes, required only for generating genesis config.
// #PLA-811
#[deprecated(note = "Use GenesisConfig::bootloader_hash instead")]
Expand Down Expand Up @@ -199,6 +204,7 @@ impl StateKeeperConfig {
virtual_blocks_interval: 1,
virtual_blocks_per_miniblock: 1,
enum_index_migration_chunk_size: None,
max_circuits_per_batch: 24100,
bootloader_hash: None,
default_aa_hash: None,
l1_batch_commit_data_generator_mode: L1BatchCommitDataGeneratorMode::Rollup,
Expand Down
2 changes: 2 additions & 0 deletions core/lib/config/src/configs/fri_prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct FriProverConfig {
pub queue_capacity: usize,
pub witness_vector_receiver_port: u16,
pub zone_read_url: String,
pub availability_check_interval_in_secs: u32,

// whether to write to public GCS bucket for https://github.com/matter-labs/era-boojum-validator-cli
pub shall_save_to_public_bucket: bool,
pub object_store: Option<ObjectStoreConfig>,
Expand Down
17 changes: 12 additions & 5 deletions core/lib/config/src/configs/house_keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ pub struct HouseKeeperConfig {
pub prover_db_pool_size: u32,
pub proof_compressor_job_retrying_interval_ms: u64,
pub proof_compressor_stats_reporting_interval_ms: u64,
pub prover_job_archiver_reporting_interval_ms: Option<u64>,
pub prover_job_archiver_archiving_interval_secs: Option<u64>,
pub prover_job_archiver_archiving_interval_ms: Option<u64>,
pub prover_job_archiver_archive_after_secs: Option<u64>,
pub fri_gpu_prover_archiver_archiving_interval_ms: Option<u64>,
pub fri_gpu_prover_archiver_archive_after_secs: Option<u64>,
}

impl HouseKeeperConfig {
pub fn prover_job_archiver_enabled(&self) -> bool {
self.prover_job_archiver_reporting_interval_ms.is_some()
&& self.prover_job_archiver_archiving_interval_secs.is_some()
pub fn prover_job_archiver_params(&self) -> Option<(u64, u64)> {
self.prover_job_archiver_archiving_interval_ms
.zip(self.prover_job_archiver_archive_after_secs)
}

pub fn fri_gpu_prover_archiver_params(&self) -> Option<(u64, u64)> {
self.fri_gpu_prover_archiver_archiving_interval_ms
.zip(self.fri_gpu_prover_archiver_archive_after_secs)
}
}
Loading

0 comments on commit bb287d6

Please sign in to comment.