Merge pull request #155 from blockworks-foundation/no_restart

no restart
This commit is contained in:
Aniket Prajapati 2023-06-27 02:06:27 +05:30 committed by GitHub
commit f27a3a6c88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 53 deletions

1
Cargo.lock generated
View File

@ -430,6 +430,7 @@ dependencies = [
"dashmap",
"dirs",
"futures",
"lazy_static",
"log",
"rand 0.8.5",
"rand_chacha 0.3.1",

View File

@ -1,5 +1,4 @@
use std::sync::Arc;
use std::time::Duration;
use std::{sync::Arc, time::Duration};
use anyhow::Context;
use chrono::{DateTime, Utc};
@ -7,13 +6,15 @@ use dashmap::DashMap;
use log::info;
use serde_json::json;
use solana_client::rpc_request::RpcRequest;
use solana_client::rpc_response::{Response, RpcBlockhash};
use solana_client::{nonblocking::rpc_client::RpcClient, rpc_config::RpcBlockConfig};
use solana_client::{
nonblocking::rpc_client::RpcClient,
rpc_config::RpcBlockConfig,
rpc_request::RpcRequest,
rpc_response::{Response, RpcBlockhash},
};
use solana_sdk::commitment_config::CommitmentConfig;
use solana_transaction_status::TransactionDetails;
use tokio::sync::RwLock;
use tokio::time::Instant;
use tokio::{sync::RwLock, time::Instant};
#[derive(Clone, Copy, Debug)]
pub struct BlockInformation {

View File

@ -58,18 +58,6 @@ lazy_static::lazy_static! {
register_int_counter!(opts!("literpc_rpc_airdrop", "RPC call to request airdrop")).unwrap();
static ref RPC_SIGNATURE_SUBSCRIBE: IntCounter =
register_int_counter!(opts!("literpc_rpc_signature_subscribe", "RPC call to subscribe to signature")).unwrap();
static ref WS_SERVER_FAIL: IntCounter =
register_int_counter!(opts!("literpc_rpc_ws_server_fail", "WebSocket server failed")).unwrap();
static ref METRICS_SERVICE_FAIL: IntCounter =
register_int_counter!(opts!("literpc_rpc_metrics_service_fail", "Metrics service failed")).unwrap();
static ref HTTP_SERVER_FAIL: IntCounter =
register_int_counter!(opts!("literpc_rpc_http_server_fail", "Http server failed")).unwrap();
static ref PROMETHEUS_SERVER_FAIL: IntCounter =
register_int_counter!(opts!("literpc_rpc_prometheus_server_fail", "Prometheus server failed")).unwrap();
static ref POSTGRES_SERVICE_FAIL: IntCounter =
register_int_counter!(opts!("literpc_rpc_postgres_service_fail", "Postgres service failed")).unwrap();
static ref TX_SERVICE_FAIL: IntCounter =
register_int_counter!(opts!("literpc_rpc_tx_service_fail", "Tx service failed")).unwrap();
}
/// A bridge between clients and tpu
@ -235,27 +223,21 @@ impl LiteBridge {
tokio::select! {
res = ws_server => {
WS_SERVER_FAIL.inc();
bail!("WebSocket server {res:?}");
},
res = http_server => {
HTTP_SERVER_FAIL.inc();
bail!("HTTP server {res:?}");
},
res = metrics_capture => {
METRICS_SERVICE_FAIL.inc();
bail!("Metrics Capture {res:?}");
},
res = prometheus_sync => {
PROMETHEUS_SERVER_FAIL.inc();
bail!("Prometheus Service {res:?}");
},
res = postgres => {
POSTGRES_SERVICE_FAIL.inc();
bail!("Postgres service {res:?}");
},
res = jh_transaction_services => {
TX_SERVICE_FAIL.inc();
bail!("Transaction service {res:?}");
}
}

View File

@ -2,18 +2,16 @@ pub mod rpc_tester;
use std::time::Duration;
use anyhow::Context;
use anyhow::{bail, Context};
use clap::Parser;
use dotenv::dotenv;
use lite_rpc::{bridge::LiteBridge, cli::Args};
use prometheus::{opts, register_int_counter, IntCounter};
use solana_sdk::signature::Keypair;
use std::env;
use crate::rpc_tester::RpcTester;
const RESTART_DURATION: Duration = Duration::from_secs(20);
async fn get_identity_keypair(identity_from_cli: &str) -> Keypair {
if let Ok(identity_env_var) = env::var("IDENTITY") {
if let Ok(identity_bytes) = serde_json::from_str::<Vec<u8>>(identity_env_var.as_str()) {
@ -37,11 +35,6 @@ async fn get_identity_keypair(identity_from_cli: &str) -> Keypair {
}
}
lazy_static::lazy_static! {
static ref RESTARTS: IntCounter =
register_int_counter!(opts!("literpc_rpc_restarts", "Number of times lite rpc restarted")).unwrap();
}
pub async fn start_lite_rpc(args: Args) -> anyhow::Result<()> {
let Args {
rpc_addr,
@ -103,34 +96,20 @@ pub async fn main() -> anyhow::Result<()> {
let args = get_args();
let ctrl_c_signal = tokio::signal::ctrl_c();
let rpc_tester = RpcTester::from(&args).start();
let main = tokio::spawn(async move {
loop {
let Err(err) = start_lite_rpc(args.clone()).await else {
return anyhow::Error::msg("LiteBridge services returned without error");
};
// log and restart
log::error!("Services quit unexpectedly {err:?} restarting in {RESTART_DURATION:?}");
tokio::time::sleep(RESTART_DURATION).await;
// increment restart
log::error!("Restarting services");
RESTARTS.inc();
}
});
let ctrl_c_signal = tokio::signal::ctrl_c();
let main = start_lite_rpc(args.clone());
tokio::select! {
err = rpc_tester => {
// This should never happen
unreachable!("{err:?}")
}
err = main => {
res = main => {
// This should never happen
unreachable!("{err:?}")
log::error!("Services quit unexpectedly {res:?}");
bail!("")
}
_ = ctrl_c_signal => {
log::info!("Received ctrl+c signal");