diff --git a/core/bin/snapshots_creator/src/creator.rs b/core/bin/snapshots_creator/src/creator.rs index da2ac930dbd4..51a14ce2ccae 100644 --- a/core/bin/snapshots_creator/src/creator.rs +++ b/core/bin/snapshots_creator/src/creator.rs @@ -1,5 +1,7 @@ //! [`SnapshotCreator`] and tightly related types. +use std::sync::Arc; + use anyhow::Context as _; use tokio::sync::Semaphore; use zksync_config::SnapshotsCreatorConfig; @@ -61,7 +63,7 @@ impl SnapshotProgress { /// Creator of a single storage snapshot. #[derive(Debug)] pub(crate) struct SnapshotCreator { - pub blob_store: Box, + pub blob_store: Arc, pub master_pool: ConnectionPool, pub replica_pool: ConnectionPool, #[cfg(test)] diff --git a/core/bin/snapshots_creator/src/tests.rs b/core/bin/snapshots_creator/src/tests.rs index c0e8dd0cbc28..db8501c7d796 100644 --- a/core/bin/snapshots_creator/src/tests.rs +++ b/core/bin/snapshots_creator/src/tests.rs @@ -3,7 +3,10 @@ use std::{ collections::{HashMap, HashSet}, fmt, - sync::atomic::{AtomicUsize, Ordering}, + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, }; use rand::{thread_rng, Rng}; @@ -58,7 +61,7 @@ impl HandleEvent for TestEventListener { } impl SnapshotCreator { - fn for_tests(blob_store: Box, pool: ConnectionPool) -> Self { + fn for_tests(blob_store: Arc, pool: ConnectionPool) -> Self { Self { blob_store, master_pool: pool.clone(), diff --git a/core/lib/object_store/src/raw.rs b/core/lib/object_store/src/raw.rs index 72e582deeb2b..764809764dac 100644 --- a/core/lib/object_store/src/raw.rs +++ b/core/lib/object_store/src/raw.rs @@ -88,7 +88,7 @@ impl error::Error for ObjectStoreError { /// /// [`StoredObject`]: crate::StoredObject #[async_trait] -pub trait ObjectStore: fmt::Debug + Send + Sync { +pub trait ObjectStore: 'static + fmt::Debug + Send + Sync { /// Fetches the value for the given key from the given bucket if it exists. /// /// # Errors @@ -178,14 +178,14 @@ impl ObjectStoreFactory { } /// Creates an [`ObjectStore`]. - pub async fn create_store(&self) -> Box { + pub async fn create_store(&self) -> Arc { match &self.origin { ObjectStoreOrigin::Config(config) => Self::create_from_config(config).await, - ObjectStoreOrigin::Mock(store) => Box::new(Arc::clone(store)), + ObjectStoreOrigin::Mock(store) => Arc::new(Arc::clone(store)), } } - async fn create_from_config(config: &ObjectStoreConfig) -> Box { + async fn create_from_config(config: &ObjectStoreConfig) -> Arc { let gcs_credential_file_path = match config.mode { ObjectStoreMode::GCSWithCredentialFile => Some(config.gcs_credential_file_path.clone()), _ => None, @@ -201,7 +201,7 @@ impl ObjectStoreFactory { config.max_retries, ) .await; - Box::new(store) + Arc::new(store) } ObjectStoreMode::GCSWithCredentialFile => { tracing::trace!("Initialized GoogleCloudStorage Object store with credential file"); @@ -211,12 +211,12 @@ impl ObjectStoreFactory { config.max_retries, ) .await; - Box::new(store) + Arc::new(store) } ObjectStoreMode::FileBacked => { tracing::trace!("Initialized FileBacked Object store"); let store = FileBackedObjectStore::new(config.file_backed_base_path.clone()).await; - Box::new(store) + Arc::new(store) } } } diff --git a/core/lib/zksync_core/src/basic_witness_input_producer/mod.rs b/core/lib/zksync_core/src/basic_witness_input_producer/mod.rs index 0367830f9c6f..e91ccc4864eb 100644 --- a/core/lib/zksync_core/src/basic_witness_input_producer/mod.rs +++ b/core/lib/zksync_core/src/basic_witness_input_producer/mod.rs @@ -37,7 +37,7 @@ impl BasicWitnessInputProducer { ) -> anyhow::Result { Ok(BasicWitnessInputProducer { connection_pool, - object_store: store_factory.create_store().await.into(), + object_store: store_factory.create_store().await, l2_chain_id, }) } diff --git a/core/lib/zksync_core/src/eth_sender/aggregator.rs b/core/lib/zksync_core/src/eth_sender/aggregator.rs index ebb11752894f..a043b871b1e8 100644 --- a/core/lib/zksync_core/src/eth_sender/aggregator.rs +++ b/core/lib/zksync_core/src/eth_sender/aggregator.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use zksync_config::configs::eth_sender::{ProofLoadingMode, ProofSendingMode, SenderConfig}; use zksync_contracts::BaseSystemContractsHashes; use zksync_dal::StorageProcessor; @@ -24,11 +26,11 @@ pub struct Aggregator { proof_criteria: Vec>, execute_criteria: Vec>, config: SenderConfig, - blob_store: Box, + blob_store: Arc, } impl Aggregator { - pub fn new(config: SenderConfig, blob_store: Box) -> Self { + pub fn new(config: SenderConfig, blob_store: Arc) -> Self { Self { commit_criteria: vec![ Box::from(NumberCriterion { diff --git a/core/lib/zksync_core/src/lib.rs b/core/lib/zksync_core/src/lib.rs index 1964651be3ff..fb3b8bd51955 100644 --- a/core/lib/zksync_core/src/lib.rs +++ b/core/lib/zksync_core/src/lib.rs @@ -674,7 +674,7 @@ async fn add_state_keeper_to_task_futures, - object_store: Box, + object_store: Arc, stop_receiver: watch::Receiver, ) -> anyhow::Result<()> { let fair_l2_gas_price = state_keeper_config.fair_l2_gas_price; @@ -793,7 +793,7 @@ async fn run_tree( merkle_tree_config: &MerkleTreeConfig, api_config: Option<&MerkleTreeApiConfig>, operation_manager: &OperationsManagerConfig, - object_store: Option>, + object_store: Option>, stop_receiver: watch::Receiver, ) -> anyhow::Result<()> { let started_at = Instant::now(); diff --git a/core/lib/zksync_core/src/metadata_calculator/mod.rs b/core/lib/zksync_core/src/metadata_calculator/mod.rs index 0244094be665..c510eb68fb1d 100644 --- a/core/lib/zksync_core/src/metadata_calculator/mod.rs +++ b/core/lib/zksync_core/src/metadata_calculator/mod.rs @@ -3,6 +3,7 @@ use std::{ future::{self, Future}, + sync::Arc, time::Duration, }; @@ -81,7 +82,7 @@ impl MetadataCalculatorConfig { pub struct MetadataCalculator { tree: GenericAsyncTree, tree_reader: watch::Sender>, - object_store: Option>, + object_store: Option>, delayer: Delayer, health_updater: HealthUpdater, max_l1_batches_per_iter: usize, @@ -91,7 +92,7 @@ impl MetadataCalculator { /// Creates a calculator with the specified `config`. pub async fn new( config: MetadataCalculatorConfig, - object_store: Option>, + object_store: Option>, ) -> Self { assert!( config.max_l1_batches_per_iter > 0, diff --git a/core/lib/zksync_core/src/metadata_calculator/tests.rs b/core/lib/zksync_core/src/metadata_calculator/tests.rs index ba8c18daf297..eb9a5693a4a4 100644 --- a/core/lib/zksync_core/src/metadata_calculator/tests.rs +++ b/core/lib/zksync_core/src/metadata_calculator/tests.rs @@ -1,6 +1,6 @@ //! Tests for the metadata calculator component life cycle. -use std::{future::Future, ops, panic, path::Path, time::Duration}; +use std::{future::Future, ops, panic, path::Path, sync::Arc, time::Duration}; use assert_matches::assert_matches; use itertools::Itertools; @@ -360,7 +360,7 @@ async fn postgres_backup_recovery_with_excluded_metadata() { pub(crate) async fn setup_calculator( db_path: &Path, pool: &ConnectionPool, -) -> (MetadataCalculator, Box) { +) -> (MetadataCalculator, Arc) { let store_factory = ObjectStoreFactory::mock(); let store = store_factory.create_store().await; let (merkle_tree_config, operation_manager) = create_config(db_path, MerkleTreeMode::Full); @@ -395,7 +395,7 @@ async fn setup_calculator_with_options( merkle_tree_config: &MerkleTreeConfig, operation_config: &OperationsManagerConfig, pool: &ConnectionPool, - object_store: Option>, + object_store: Option>, ) -> MetadataCalculator { let calculator_config = MetadataCalculatorConfig::for_main_node(merkle_tree_config, operation_config); diff --git a/core/lib/zksync_core/src/metadata_calculator/updater.rs b/core/lib/zksync_core/src/metadata_calculator/updater.rs index 1bed4cbbf080..f3540f25fe94 100644 --- a/core/lib/zksync_core/src/metadata_calculator/updater.rs +++ b/core/lib/zksync_core/src/metadata_calculator/updater.rs @@ -1,6 +1,6 @@ //! Tree updater trait and its implementations. -use std::{ops, time::Instant}; +use std::{ops, sync::Arc, time::Instant}; use anyhow::Context as _; use futures::{future, FutureExt}; @@ -24,14 +24,14 @@ use crate::utils::wait_for_l1_batch; pub(super) struct TreeUpdater { tree: AsyncTree, max_l1_batches_per_iter: usize, - object_store: Option>, + object_store: Option>, } impl TreeUpdater { pub fn new( tree: AsyncTree, max_l1_batches_per_iter: usize, - object_store: Option>, + object_store: Option>, ) -> Self { Self { tree, diff --git a/core/lib/zksync_core/src/proof_data_handler/mod.rs b/core/lib/zksync_core/src/proof_data_handler/mod.rs index f1227d8298c9..7a5b8bc69b32 100644 --- a/core/lib/zksync_core/src/proof_data_handler/mod.rs +++ b/core/lib/zksync_core/src/proof_data_handler/mod.rs @@ -1,4 +1,4 @@ -use std::net::SocketAddr; +use std::{net::SocketAddr, sync::Arc}; use anyhow::Context as _; use axum::{extract::Path, routing::post, Json, Router}; @@ -34,7 +34,7 @@ fn fri_l1_verifier_config(contracts_config: &ContractsConfig) -> L1VerifierConfi pub(crate) async fn run_server( config: ProofDataHandlerConfig, contracts_config: ContractsConfig, - blob_store: Box, + blob_store: Arc, pool: ConnectionPool, mut stop_receiver: watch::Receiver, ) -> anyhow::Result<()> { diff --git a/core/lib/zksync_core/src/proof_data_handler/request_processor.rs b/core/lib/zksync_core/src/proof_data_handler/request_processor.rs index 5a3302ee926d..bc9873d99ed5 100644 --- a/core/lib/zksync_core/src/proof_data_handler/request_processor.rs +++ b/core/lib/zksync_core/src/proof_data_handler/request_processor.rs @@ -65,13 +65,13 @@ impl IntoResponse for RequestProcessorError { impl RequestProcessor { pub(crate) fn new( - blob_store: Box, + blob_store: Arc, pool: ConnectionPool, config: ProofDataHandlerConfig, l1_verifier_config: Option, ) -> Self { Self { - blob_store: Arc::from(blob_store), + blob_store, pool, config, l1_verifier_config, diff --git a/core/lib/zksync_core/src/state_keeper/io/mempool.rs b/core/lib/zksync_core/src/state_keeper/io/mempool.rs index 78a71a6a7130..45484f645b5e 100644 --- a/core/lib/zksync_core/src/state_keeper/io/mempool.rs +++ b/core/lib/zksync_core/src/state_keeper/io/mempool.rs @@ -46,7 +46,7 @@ use crate::{ pub(crate) struct MempoolIO { mempool: MempoolGuard, pool: ConnectionPool, - object_store: Box, + object_store: Arc, timeout_sealer: TimeoutSealer, filter: L2TxFilter, current_miniblock_number: MiniblockNumber, @@ -404,7 +404,7 @@ impl MempoolIO { #[allow(clippy::too_many_arguments)] pub(in crate::state_keeper) async fn new( mempool: MempoolGuard, - object_store: Box, + object_store: Arc, miniblock_sealer_handle: MiniblockSealerHandle, l1_gas_price_provider: Arc, pool: ConnectionPool, diff --git a/core/lib/zksync_core/src/state_keeper/mod.rs b/core/lib/zksync_core/src/state_keeper/mod.rs index 0a146c51a5e3..a17d169bc6ea 100644 --- a/core/lib/zksync_core/src/state_keeper/mod.rs +++ b/core/lib/zksync_core/src/state_keeper/mod.rs @@ -42,7 +42,7 @@ pub(crate) async fn create_state_keeper( mempool: MempoolGuard, l1_gas_price_provider: Arc, miniblock_sealer_handle: MiniblockSealerHandle, - object_store: Box, + object_store: Arc, stop_receiver: watch::Receiver, ) -> ZkSyncStateKeeper { let batch_executor_base = MainBatchExecutorBuilder::new( diff --git a/prover/proof_fri_compressor/src/compressor.rs b/prover/proof_fri_compressor/src/compressor.rs index b4346305b9f9..3b21ef697bca 100644 --- a/prover/proof_fri_compressor/src/compressor.rs +++ b/prover/proof_fri_compressor/src/compressor.rs @@ -1,4 +1,4 @@ -use std::time::Instant; +use std::{sync::Arc, time::Instant}; use anyhow::Context as _; use async_trait::async_trait; @@ -33,7 +33,7 @@ use zksync_vk_setup_data_server_fri::{get_recursive_layer_vk_for_circuit_type, g use crate::metrics::METRICS; pub struct ProofCompressor { - blob_store: Box, + blob_store: Arc, pool: ConnectionPool, compression_mode: u8, verify_wrapper_proof: bool, @@ -42,7 +42,7 @@ pub struct ProofCompressor { impl ProofCompressor { pub fn new( - blob_store: Box, + blob_store: Arc, pool: ConnectionPool, compression_mode: u8, verify_wrapper_proof: bool, diff --git a/prover/prover_fri/src/gpu_prover_job_processor.rs b/prover/prover_fri/src/gpu_prover_job_processor.rs index 5e576bc114bd..f880a296af5e 100644 --- a/prover/prover_fri/src/gpu_prover_job_processor.rs +++ b/prover/prover_fri/src/gpu_prover_job_processor.rs @@ -49,8 +49,8 @@ pub mod gpu_prover { #[allow(dead_code)] pub struct Prover { - blob_store: Box, - public_blob_store: Option>, + blob_store: Arc, + public_blob_store: Option>, config: Arc, prover_connection_pool: ConnectionPool, setup_load_mode: SetupLoadMode, @@ -66,8 +66,8 @@ pub mod gpu_prover { impl Prover { #[allow(dead_code)] pub fn new( - blob_store: Box, - public_blob_store: Option>, + blob_store: Arc, + public_blob_store: Option>, config: FriProverConfig, prover_connection_pool: ConnectionPool, setup_load_mode: SetupLoadMode, diff --git a/prover/prover_fri/src/main.rs b/prover/prover_fri/src/main.rs index 06a71266a3da..ab2dfa30a9a0 100644 --- a/prover/prover_fri/src/main.rs +++ b/prover/prover_fri/src/main.rs @@ -1,5 +1,5 @@ #![feature(generic_const_exprs)] -use std::future::Future; +use std::{future::Future, sync::Arc}; use anyhow::Context as _; use local_ip_address::local_ip; @@ -170,7 +170,7 @@ async fn get_prover_tasks( prover_config: FriProverConfig, stop_receiver: Receiver, store_factory: ObjectStoreFactory, - public_blob_store: Option>, + public_blob_store: Option>, pool: ConnectionPool, circuit_ids_for_round_to_be_proven: Vec, ) -> anyhow::Result>>> { @@ -204,7 +204,7 @@ async fn get_prover_tasks( prover_config: FriProverConfig, stop_receiver: Receiver, store_factory: ObjectStoreFactory, - public_blob_store: Option>, + public_blob_store: Option>, pool: ConnectionPool, circuit_ids_for_round_to_be_proven: Vec, ) -> anyhow::Result>>> { diff --git a/prover/prover_fri/src/prover_job_processor.rs b/prover/prover_fri/src/prover_job_processor.rs index dbe4bee0c86e..40275b681b70 100644 --- a/prover/prover_fri/src/prover_job_processor.rs +++ b/prover/prover_fri/src/prover_job_processor.rs @@ -43,8 +43,8 @@ pub enum SetupLoadMode { } pub struct Prover { - blob_store: Box, - public_blob_store: Option>, + blob_store: Arc, + public_blob_store: Option>, config: Arc, prover_connection_pool: ConnectionPool, setup_load_mode: SetupLoadMode, @@ -57,8 +57,8 @@ pub struct Prover { impl Prover { #[allow(dead_code)] pub fn new( - blob_store: Box, - public_blob_store: Option>, + blob_store: Arc, + public_blob_store: Option>, config: FriProverConfig, prover_connection_pool: ConnectionPool, setup_load_mode: SetupLoadMode, diff --git a/prover/prover_fri_gateway/src/api_data_fetcher.rs b/prover/prover_fri_gateway/src/api_data_fetcher.rs index f56a9af4cc8f..9e0277d1ea89 100644 --- a/prover/prover_fri_gateway/src/api_data_fetcher.rs +++ b/prover/prover_fri_gateway/src/api_data_fetcher.rs @@ -1,4 +1,4 @@ -use std::time::Duration; +use std::{sync::Arc, time::Duration}; use async_trait::async_trait; use reqwest::Client; @@ -16,7 +16,7 @@ pub(crate) const PROOF_GENERATION_DATA_PATH: &str = "/proof_generation_data"; pub(crate) const SUBMIT_PROOF_PATH: &str = "/submit_proof"; pub(crate) struct PeriodicApiStruct { - pub(crate) blob_store: Box, + pub(crate) blob_store: Arc, pub(crate) pool: ConnectionPool, pub(crate) api_url: String, pub(crate) poll_duration: Duration, diff --git a/prover/witness_generator/src/basic_circuits.rs b/prover/witness_generator/src/basic_circuits.rs index b883c4bb35aa..d0909d79dbff 100644 --- a/prover/witness_generator/src/basic_circuits.rs +++ b/prover/witness_generator/src/basic_circuits.rs @@ -88,7 +88,7 @@ pub struct BasicWitnessGeneratorJob { pub struct BasicWitnessGenerator { config: Arc, object_store: Arc, - public_blob_store: Option>, + public_blob_store: Option>, connection_pool: ConnectionPool, prover_connection_pool: ConnectionPool, protocol_versions: Vec, @@ -98,14 +98,14 @@ impl BasicWitnessGenerator { pub async fn new( config: FriWitnessGeneratorConfig, store_factory: &ObjectStoreFactory, - public_blob_store: Option>, + public_blob_store: Option>, connection_pool: ConnectionPool, prover_connection_pool: ConnectionPool, protocol_versions: Vec, ) -> Self { Self { config: Arc::new(config), - object_store: store_factory.create_store().await.into(), + object_store: store_factory.create_store().await, public_blob_store, connection_pool, prover_connection_pool, diff --git a/prover/witness_generator/src/leaf_aggregation.rs b/prover/witness_generator/src/leaf_aggregation.rs index f190aeb21645..eb28936085fc 100644 --- a/prover/witness_generator/src/leaf_aggregation.rs +++ b/prover/witness_generator/src/leaf_aggregation.rs @@ -1,4 +1,4 @@ -use std::time::Instant; +use std::{sync::Arc, time::Instant}; use anyhow::Context as _; use async_trait::async_trait; @@ -72,7 +72,7 @@ pub struct LeafAggregationWitnessGeneratorJob { #[derive(Debug)] pub struct LeafAggregationWitnessGenerator { config: FriWitnessGeneratorConfig, - object_store: Box, + object_store: Arc, prover_connection_pool: ConnectionPool, protocol_versions: Vec, } diff --git a/prover/witness_generator/src/node_aggregation.rs b/prover/witness_generator/src/node_aggregation.rs index be9e5d0d6225..5f817dd88865 100644 --- a/prover/witness_generator/src/node_aggregation.rs +++ b/prover/witness_generator/src/node_aggregation.rs @@ -1,4 +1,4 @@ -use std::time::Instant; +use std::{sync::Arc, time::Instant}; use anyhow::Context as _; use async_trait::async_trait; @@ -74,7 +74,7 @@ pub struct NodeAggregationWitnessGeneratorJob { #[derive(Debug)] pub struct NodeAggregationWitnessGenerator { config: FriWitnessGeneratorConfig, - object_store: Box, + object_store: Arc, prover_connection_pool: ConnectionPool, protocol_versions: Vec, } diff --git a/prover/witness_generator/src/scheduler.rs b/prover/witness_generator/src/scheduler.rs index 921ba68f4024..6571c6e63c4a 100644 --- a/prover/witness_generator/src/scheduler.rs +++ b/prover/witness_generator/src/scheduler.rs @@ -1,4 +1,4 @@ -use std::{convert::TryInto, time::Instant}; +use std::{convert::TryInto, sync::Arc, time::Instant}; use anyhow::Context as _; use async_trait::async_trait; @@ -51,7 +51,7 @@ pub struct SchedulerWitnessGeneratorJob { #[derive(Debug)] pub struct SchedulerWitnessGenerator { config: FriWitnessGeneratorConfig, - object_store: Box, + object_store: Arc, prover_connection_pool: ConnectionPool, protocol_versions: Vec, } diff --git a/prover/witness_vector_generator/src/generator.rs b/prover/witness_vector_generator/src/generator.rs index 5dfb693af8f8..b51e164042a8 100644 --- a/prover/witness_vector_generator/src/generator.rs +++ b/prover/witness_vector_generator/src/generator.rs @@ -1,4 +1,7 @@ -use std::time::{Duration, Instant}; +use std::{ + sync::Arc, + time::{Duration, Instant}, +}; use anyhow::Context as _; use async_trait::async_trait; @@ -24,7 +27,7 @@ use zksync_vk_setup_data_server_fri::get_finalization_hints; use crate::metrics::METRICS; pub struct WitnessVectorGenerator { - blob_store: Box, + blob_store: Arc, pool: ConnectionPool, circuit_ids_for_round_to_be_proven: Vec, zone: String, @@ -35,7 +38,7 @@ pub struct WitnessVectorGenerator { impl WitnessVectorGenerator { pub fn new( - blob_store: Box, + blob_store: Arc, prover_connection_pool: ConnectionPool, circuit_ids_for_round_to_be_proven: Vec, zone: String,