Skip to content

Commit

Permalink
Use main database connection in forced exit api (#2259)
Browse files Browse the repository at this point in the history
Signed-off-by: deniallugo <[email protected]>
  • Loading branch information
Deniallugo committed Jul 29, 2022
1 parent b838853 commit 0366dc1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions core/bin/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ async fn run_server(components: &ComponentsToRun) {
let private_config = PrivateApiConfig::from_env();
tasks.push(zksync_api::api_server::rest::start_server_thread_detached(
read_only_connection_pool.clone(),
connection_pool.clone(),
RestApiConfig::from_env().bind_addr(),
contracts_config.contract_addr,
ticker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ pub async fn submit_request(
valid_until,
})
.await
.map_err(|_| ApiError::internal(""))?;
.map_err(|err| {
vlog::error!("Store forced exit error {:?}", err);
ApiError::internal("Database error")
})?;

check_address_space_overflow(saved_fe_request.id, data.digits_in_id);

Expand Down
16 changes: 11 additions & 5 deletions core/bin/zksync_api/src/api_server/rest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ async fn start_server(
) {
HttpServer::new(move || {
let api_v01 = api_v01.clone();

// This api stores forced exit requests, it's necessary to use main database connection
let forced_exit_requests_api_scope = forced_exit_requests::api_scope(
api_v01.connection_pool.clone(),
api_v01.main_database_connection_pool.clone(),
api_v01
.config
.api
Expand Down Expand Up @@ -87,7 +87,8 @@ async fn start_server(
#[allow(clippy::too_many_arguments)]
#[must_use]
pub fn start_server_thread_detached(
connection_pool: ConnectionPool,
read_only_connection_pool: ConnectionPool,
main_database_connection_pool: ConnectionPool,
listen_addr: SocketAddr,
contract_address: H160,
fee_ticker: FeeTicker,
Expand All @@ -106,8 +107,13 @@ pub fn start_server_thread_detached(
let config = ZkSyncConfig::from_env();

let network_status = SharedNetworkStatus::new(core_address);
let api_v01 =
ApiV01::new(connection_pool, contract_address, config, network_status);
let api_v01 = ApiV01::new(
read_only_connection_pool,
main_database_connection_pool,
contract_address,
config,
network_status,
);
api_v01.spawn_network_status_updater(panic_sender);

start_server(
Expand Down
3 changes: 3 additions & 0 deletions core/bin/zksync_api/src/api_server/rest/v01/api_decl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use zksync_types::{block::ExecutedOperations, BlockNumber, PriorityOp, H160, H25
pub struct ApiV01 {
pub(crate) caches: Caches,
pub(crate) connection_pool: ConnectionPool,
pub(crate) main_database_connection_pool: ConnectionPool,
pub(crate) network_status: SharedNetworkStatus,
pub(crate) contract_address: String,
pub(crate) config: ZkSyncConfig,
Expand All @@ -33,13 +34,15 @@ pub struct ApiV01 {
impl ApiV01 {
pub fn new(
connection_pool: ConnectionPool,
main_database_connection_pool: ConnectionPool,
contract_address: H160,
config: ZkSyncConfig,
network_status: SharedNetworkStatus,
) -> Self {
Self {
caches: Caches::new(config.api.common.caches_size),
connection_pool,
main_database_connection_pool,
network_status,
contract_address: format!("{:?}", contract_address),
config,
Expand Down

0 comments on commit 0366dc1

Please sign in to comment.