Skip to content

Commit

Permalink
chore: refactor main initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-aranha-cw committed Aug 12, 2024
1 parent 2c8febf commit f2d7c50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use tokio::runtime::Runtime;
use tokio_util::sync::CancellationToken;

use crate::config;
use crate::config::StratusConfig;
use crate::config::WithCommonConfig;
use crate::ext::spawn_signal_handler;
use crate::infra::tracing::warn_task_cancellation;
Expand Down Expand Up @@ -187,6 +188,12 @@ impl GlobalState {
// Node Mode
// -------------------------------------------------------------------------

/// Initializes the node mode based on the StratusConfig.
pub fn initialize_node_mode(config: &StratusConfig) {
let mode = if config.follower { NodeMode::Follower } else { NodeMode::Leader };
Self::set_node_mode(mode);
}

/// Sets the current node mode.
pub fn set_node_mode(mode: NodeMode) {
IS_LEADER.store(matches!(mode, NodeMode::Leader), Ordering::Relaxed);
Expand Down
7 changes: 1 addition & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@ use stratus::config::StratusConfig;
use stratus::eth::rpc::serve_rpc;
use stratus::GlobalServices;
use stratus::GlobalState;
use stratus::NodeMode;

fn main() -> anyhow::Result<()> {
let global_services = GlobalServices::<StratusConfig>::init();
GlobalState::set_node_mode(if global_services.config.follower {
NodeMode::Follower
} else {
NodeMode::Leader
});
GlobalState::initialize_node_mode(&global_services.config);
global_services.runtime.block_on(run(global_services.config))
}

Expand Down

0 comments on commit f2d7c50

Please sign in to comment.