Skip to content

Commit

Permalink
Checkt the network status earlier
Browse files Browse the repository at this point in the history
Signed-off-by: deniallugo <[email protected]>
  • Loading branch information
Deniallugo committed Sep 2, 2022
1 parent a7785f9 commit ad4b92e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
15 changes: 12 additions & 3 deletions core/bin/zksync_api/src/api_server/rest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use actix_web::{web, App, HttpResponse, HttpServer};
use futures::channel::mpsc;
use std::net::SocketAddr;
use zksync_storage::ConnectionPool;
use zksync_types::H160;
use zksync_types::{SequentialTxId, H160};

use zksync_utils::panic_notify::{spawn_panic_handler, ThreadPanicNotify};

Expand Down Expand Up @@ -108,15 +108,24 @@ pub fn start_server_thread_detached(
// TODO remove this config ZKS-815
let config = ZkSyncConfig::from_env();

let network_status = SharedNetworkStatus::new(core_address);
let mut network_status = SharedNetworkStatus::new(core_address);
// We want to update the network status, as soon as possible, otherwise we can catch the situation,
// when the node is start and receiving the request but the status is null and
// we receive the notification that our node is down, but it's just a default status
let last_tx_id = network_status
.update(&read_only_connection_pool, SequentialTxId(0))
.await
.unwrap();

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);

api_v01.spawn_network_status_updater(panic_sender, last_tx_id);

start_server(
api_v01,
Expand Down
2 changes: 1 addition & 1 deletion core/bin/zksync_api/src/api_server/rest/network_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ impl SharedNetworkStatus {
mut self,
panic_notify: mpsc::Sender<bool>,
connection_pool: ConnectionPool,
mut last_tx_id: SequentialTxId,
) {
std::thread::Builder::new()
.name("rest-state-updater".to_string())
Expand All @@ -133,7 +134,6 @@ impl SharedNetworkStatus {

let state_update_task = async move {
let mut timer = time::interval(Duration::from_millis(30000));
let mut last_tx_id = SequentialTxId(0);
loop {
timer.tick().await;
match self.update(&connection_pool, last_tx_id).await {
Expand Down
18 changes: 13 additions & 5 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 @@ -14,7 +14,9 @@ use zksync_storage::{
},
ConnectionPool, StorageProcessor,
};
use zksync_types::{block::ExecutedOperations, BlockNumber, PriorityOp, H160, H256};
use zksync_types::{
block::ExecutedOperations, BlockNumber, PriorityOp, SequentialTxId, H160, H256,
};

/// `ApiV01` structure contains the implementation of `/api/v0.1` endpoints set.
/// It is considered (somewhat) stable and will be supported for a while.
Expand Down Expand Up @@ -114,10 +116,16 @@ impl ApiV01 {
}

// Spawns future updating SharedNetworkStatus in the current `actix::System`
pub fn spawn_network_status_updater(&self, panic_notify: mpsc::Sender<bool>) {
self.network_status
.clone()
.start_updater_detached(panic_notify, self.connection_pool.clone());
pub fn spawn_network_status_updater(
&self,
panic_notify: mpsc::Sender<bool>,
last_tx_id: SequentialTxId,
) {
self.network_status.clone().start_updater_detached(
panic_notify,
self.connection_pool.clone(),
last_tx_id,
);
}

// cache access functions
Expand Down

0 comments on commit ad4b92e

Please sign in to comment.