From 99a61f85166dc5cbb6f8c8c6b862b20ef2402cdc Mon Sep 17 00:00:00 2001 From: deniallugo Date: Mon, 6 Dec 2021 18:07:03 +0100 Subject: [PATCH 1/3] Run rpc websocket as thread Signed-off-by: deniallugo --- .../src/api_server/rpc_subscriptions.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/core/bin/zksync_api/src/api_server/rpc_subscriptions.rs b/core/bin/zksync_api/src/api_server/rpc_subscriptions.rs index cee497f667..97877f3ba9 100644 --- a/core/bin/zksync_api/src/api_server/rpc_subscriptions.rs +++ b/core/bin/zksync_api/src/api_server/rpc_subscriptions.rs @@ -2,13 +2,16 @@ // Built-in deps use std::sync::Arc; +use std::time::Duration; // External uses use futures::channel::mpsc; use jsonrpc_core::{MetaIoHandler, Result}; use jsonrpc_derive::rpc; use jsonrpc_pubsub::{typed::Subscriber, PubSubHandler, Session, SubscriptionId}; use jsonrpc_ws_server::RequestContext; +use tokio::task::JoinHandle; // Workspace uses +use zksync_config::configs::api::{CommonApiConfig, JsonRpcConfig}; use zksync_storage::ConnectionPool; use zksync_types::{tx::TxHash, ActionType, Address}; // Local uses @@ -18,10 +21,6 @@ use crate::{ api_server::rpc_server::types::{ETHOpInfoResp, ResponseAccountState, TransactionInfoResp}, signature_checker::VerifySignatureRequest, }; -use std::time::Duration; -use zksync_config::configs::api::{CommonApiConfig, JsonRpcConfig}; - -use tokio::task::JoinHandle; #[rpc] pub trait RpcPubSub { @@ -206,7 +205,10 @@ pub fn start_ws_server( confirmations_for_eth_event, ); - tokio::spawn(async move { + let (handler, panic_sender) = spawn_panic_handler(); + + std::thread::spawn(move || { + let _panic_sentinel = ThreadPanicNotify(panic_sender); let mut io = PubSubHandler::new(MetaIoHandler::default()); req_rpc_app.extend(&mut io); @@ -224,5 +226,6 @@ pub fn start_ws_server( .expect("Unable to start RPC ws server"); server.wait().expect("rpc ws server start"); - }) + }); + handler } From 638be067572873605d046bf9a401728fc14ddcae Mon Sep 17 00:00:00 2001 From: deniallugo Date: Mon, 6 Dec 2021 20:36:47 +0100 Subject: [PATCH 2/3] Fix uses Signed-off-by: deniallugo --- core/bin/zksync_api/src/api_server/rpc_server/mod.rs | 9 ++++----- core/bin/zksync_api/src/api_server/rpc_subscriptions.rs | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/bin/zksync_api/src/api_server/rpc_server/mod.rs b/core/bin/zksync_api/src/api_server/rpc_server/mod.rs index 006efbd3fe..257a9e8258 100644 --- a/core/bin/zksync_api/src/api_server/rpc_server/mod.rs +++ b/core/bin/zksync_api/src/api_server/rpc_server/mod.rs @@ -2,15 +2,17 @@ use std::time::Instant; // External uses +use bigdecimal::BigDecimal; use futures::{ channel::{mpsc, oneshot}, SinkExt, }; use jsonrpc_core::{Error, IoHandler, MetaIoHandler, Metadata, Middleware, Result}; use jsonrpc_http_server::ServerBuilder; +use tokio::task::JoinHandle; // Workspace uses - +use zksync_config::configs::api::{CommonApiConfig, JsonRpcConfig}; use zksync_storage::{ chain::{ block::records::StorageBlockDetails, operations::records::StoredExecutedPriorityOperation, @@ -19,6 +21,7 @@ use zksync_storage::{ ConnectionPool, StorageProcessor, }; use zksync_types::{tx::TxHash, Address, BlockNumber, TokenLike, TxFeeTypes}; +use zksync_utils::panic_notify::{spawn_panic_handler, ThreadPanicNotify}; // Local uses use crate::{ @@ -26,8 +29,6 @@ use crate::{ signature_checker::VerifySignatureRequest, utils::shared_lru_cache::AsyncLruCache, }; -use bigdecimal::BigDecimal; -use zksync_utils::panic_notify::{spawn_panic_handler, ThreadPanicNotify}; pub mod error; mod rpc_impl; @@ -37,8 +38,6 @@ pub mod types; pub use self::rpc_trait::Rpc; use self::types::*; use super::tx_sender::TxSender; -use tokio::task::JoinHandle; -use zksync_config::configs::api::{CommonApiConfig, JsonRpcConfig}; #[derive(Clone)] pub struct RpcApp { diff --git a/core/bin/zksync_api/src/api_server/rpc_subscriptions.rs b/core/bin/zksync_api/src/api_server/rpc_subscriptions.rs index 97877f3ba9..17b296ebf3 100644 --- a/core/bin/zksync_api/src/api_server/rpc_subscriptions.rs +++ b/core/bin/zksync_api/src/api_server/rpc_subscriptions.rs @@ -14,6 +14,7 @@ use tokio::task::JoinHandle; use zksync_config::configs::api::{CommonApiConfig, JsonRpcConfig}; use zksync_storage::ConnectionPool; use zksync_types::{tx::TxHash, ActionType, Address}; +use zksync_utils::panic_notify::{spawn_panic_handler, ThreadPanicNotify}; // Local uses use crate::fee_ticker::TickerRequest; use crate::{ From 032735cd58324cb600670830a7d057c54856dd42 Mon Sep 17 00:00:00 2001 From: deniallugo Date: Mon, 6 Dec 2021 21:41:33 +0100 Subject: [PATCH 3/3] Spawn prover server as thread Signed-off-by: deniallugo --- .../src/tests/prover_server.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/core/bin/zksync_witness_generator/src/tests/prover_server.rs b/core/bin/zksync_witness_generator/src/tests/prover_server.rs index 1035673fd5..1632bc1231 100644 --- a/core/bin/zksync_witness_generator/src/tests/prover_server.rs +++ b/core/bin/zksync_witness_generator/src/tests/prover_server.rs @@ -40,13 +40,11 @@ impl Default for MockProverOptions { async fn spawn_server(database: MockDatabase) { let prover_options = MockProverOptions::default(); - tokio::spawn({ - run_prover_server( - database, - prover_options.0.api.prover, - prover_options.0.prover, - ) - }); + run_prover_server( + database, + prover_options.0.api.prover, + prover_options.0.prover, + ); } #[tokio::test]