Skip to content

Commit

Permalink
Merge branch 'main' into perf-split-transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhani-cw authored Aug 14, 2024
2 parents f8e3a36 + 5b3a840 commit 2518b86
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/eth/rpc/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ fn stratus_config(_: Params<'_>, ctx: &RpcContext, _: &Extensions) -> Result<Jso
}

fn stratus_state(_: Params<'_>, _: &RpcContext, _: &Extensions) -> Result<JsonValue, StratusError> {
Ok(GlobalState::get_internal_state_as_json())
Ok(GlobalState::get_global_state_as_json())
}

async fn stratus_get_subscriptions(_: Params<'_>, ctx: Arc<RpcContext>, ext: Extensions) -> Result<JsonValue, StratusError> {
Expand Down
31 changes: 21 additions & 10 deletions src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::sync::atomic::Ordering;

use once_cell::sync::Lazy;
use sentry::ClientInitGuard;
use serde::Deserialize;
use serde::Serialize;
use serde_json::json;
use tokio::runtime::Runtime;
use tokio_util::sync::CancellationToken;
Expand Down Expand Up @@ -106,7 +108,14 @@ static UNKNOWN_CLIENT_ENABLED: AtomicBool = AtomicBool::new(true);
/// Current node mode.
static IS_LEADER: AtomicBool = AtomicBool::new(false);

pub struct GlobalState;
#[derive(Serialize, Deserialize, Debug)]
pub struct GlobalState {
pub is_leader: bool,
pub is_shutdown: bool,
pub transactions_enabled: bool,
pub miner_enabled: bool,
pub unknown_client_enabled: bool,
}

impl GlobalState {
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -224,16 +233,18 @@ impl GlobalState {
}

// -------------------------------------------------------------------------
// Internal State
// JSON State
// -------------------------------------------------------------------------

pub fn get_internal_state_as_json() -> JsonValue {
json!({
"is_leader": Self::is_leader(),
"is_shutdown": Self::is_shutdown(),
"transactions_enabled": Self::is_transactions_enabled(),
"miner_enabled": Self::is_miner_enabled(),
"unknown_client_enabled": Self::is_unknown_client_enabled(),
})
pub fn get_global_state_as_json() -> JsonValue {
let state = GlobalState {
is_leader: Self::is_leader(),
is_shutdown: Self::is_shutdown(),
transactions_enabled: Self::is_transactions_enabled(),
miner_enabled: Self::is_miner_enabled(),
unknown_client_enabled: Self::is_unknown_client_enabled(),
};

json!(state)
}
}

0 comments on commit 2518b86

Please sign in to comment.