Skip to content

Commit

Permalink
ol start doesn't need to swtich between validator and fullnode mode w…
Browse files Browse the repository at this point in the history
…ith the new configs!
  • Loading branch information
0o-de-lally committed Jul 23, 2022
1 parent faa81ac commit 4b5d7ad
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 82 deletions.
138 changes: 65 additions & 73 deletions ol/cli/src/check/pilot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#![allow(clippy::never_loop)]
use crate::node::states::*;
use crate::{
mgmt::management::NodeMode::*,
node::node::Node,
};
use std::{thread, time::Duration};
Expand Down Expand Up @@ -53,31 +52,24 @@ pub fn run_once(mut node: &mut Node, verbose: bool) -> &mut Node {
}

// is node started?
if node.vitals.items.node_running {
if verbose {
println!("Node: node is running");
}
node.vitals.host_state.node_state = maybe_switch_mode(&mut node, is_in_val_set, verbose);
} else {
let start_mode = if is_in_val_set { Validator } else { Fullnode };
if !node.vitals.items.node_running {
// if verbose {
// println!("Node: node is running");
// }
// node.vitals.host_state.node_state = maybe_switch_mode(&mut node, is_in_val_set, verbose);
// } else {
// let start_mode = if is_in_val_set { Validator } else { Fullnode };

if verbose {
println!(
"Node: WARN: node is NOT running, starting in {:?} mode",
&start_mode
);
"Node: WARN: node is NOT running, starting node");
}

node.vitals.host_state.node_state = match node.start_node(start_mode.clone(), verbose) {
Ok(_) => match &start_mode {
Validator => NodeState::ValidatorMode,
Fullnode => NodeState::FullnodeMode,
},
node.vitals.host_state.node_state = match node.start_node(verbose) {
Ok(_) => NodeState::ValidatorOutOfSet,
Err(_) => {
if verbose {
println!(".. Node: WARN: could not start node in: {:?}", &start_mode);
}
NodeState::Stopped
println!(".. Node: WARN: could not start node");
NodeState::Stopped
}
}
}
Expand Down Expand Up @@ -131,56 +123,56 @@ pub fn run_once(mut node: &mut Node, verbose: bool) -> &mut Node {
node
}

fn maybe_switch_mode(node: &mut Node, is_in_val_set: bool, verbose: bool) -> NodeState {
let running_mode = match Node::what_node_mode() {
Ok(t) => t,
Err(_) => return NodeState::Stopped,
};

if verbose {
println!(".. Mode: node running in mode: {:?}", running_mode);
}

let running_in_val_mode = running_mode == Validator;
// Running correctly as a FULLNODE
if !running_in_val_mode && !is_in_val_set {
if verbose {
println!(".... Mode: running the correct mode",);
}
return NodeState::FullnodeMode;
}
// Running correctly as a VALIDATOR
// Do nothing, the account is in validator set, and we are running as a validator
if running_in_val_mode && is_in_val_set {
if verbose {
println!(".... Mode: running the correct mode");
}
return NodeState::ValidatorMode;
}

// INCORRECT CASE 1: Need to change mode from Fullnode to Validator mode
if !running_in_val_mode && is_in_val_set {
if verbose {
println!(".... Mode: WARN: running the INCORRECT mode, switching to VALIDATOR mode");
}
node.stop_node();
node.start_node(Validator, verbose)
.expect("could not start node");

return NodeState::ValidatorMode;
}

// INCORRECT CASE 2: Need to change mode from Validator to Fullnode mode
if running_in_val_mode && !is_in_val_set {
if verbose {
println!(".... Mode: WARN: running the INCORRECT mode, switching to FULLNODE mode");
}
node.stop_node();
node.start_node(Validator, verbose)
.expect("could not start node");

return NodeState::FullnodeMode;
}

NodeState::Stopped
}
// fn maybe_switch_mode(node: &mut Node, is_in_val_set: bool, verbose: bool) -> NodeState {
// let running_mode = match Node::what_node_mode() {
// Ok(t) => t,
// Err(_) => return NodeState::Stopped,
// };

// if verbose {
// println!(".. Mode: node running in mode: {:?}", running_mode);
// }

// let running_in_val_mode = running_mode == Validator;
// // Running correctly as a FULLNODE
// if !running_in_val_mode && !is_in_val_set {
// if verbose {
// println!(".... Mode: running the correct mode",);
// }
// return NodeState::FullnodeMode;
// }
// // Running correctly as a VALIDATOR
// // Do nothing, the account is in validator set, and we are running as a validator
// if running_in_val_mode && is_in_val_set {
// if verbose {
// println!(".... Mode: running the correct mode");
// }
// return NodeState::ValidatorMode;
// }

// // INCORRECT CASE 1: Need to change mode from Fullnode to Validator mode
// if !running_in_val_mode && is_in_val_set {
// if verbose {
// println!(".... Mode: WARN: running the INCORRECT mode, switching to VALIDATOR mode");
// }
// node.stop_node();
// node.start_node(verbose)
// .expect("could not start node");

// return NodeState::ValidatorMode;
// }

// // INCORRECT CASE 2: Need to change mode from Validator to Fullnode mode
// if running_in_val_mode && !is_in_val_set {
// if verbose {
// println!(".... Mode: WARN: running the INCORRECT mode, switching to FULLNODE mode");
// }
// node.stop_node();
// node.start_node(Validator, verbose)
// .expect("could not start node");

// return NodeState::FullnodeMode;
// }

// NodeState::Stopped
// }
4 changes: 2 additions & 2 deletions ol/cli/src/commands/mgmt_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! `mgmt` subcommand

use crate::{application::app_config, entrypoint, mgmt::management::NodeMode, node::{client, node::Node}};
use crate::{application::app_config, entrypoint, node::{client, node::Node}};
use abscissa_core::{Command, Options, Runnable};

/// management subcommands
Expand Down Expand Up @@ -31,7 +31,7 @@ impl Runnable for MgmtCmd {
let mut node = Node::new(client, &cfg, is_swarm);

if self.start_node {
node.start_node(NodeMode::Fullnode, true).expect("could not start fullnode");
node.start_node(true).expect("could not start fullnode");
} else if self.stop_node {
node.stop_node();
} else if self.start_miner {
Expand Down
2 changes: 1 addition & 1 deletion ol/cli/src/commands/start_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Runnable for StartCmd {
let client = match client::pick_client(args.swarm_path, &mut cfg) {
Ok(c) => c,
Err(e) => {
println!("ERROR: Could not create a client to connect to network, exiting. Message: {:?}", e );
println!("ERROR: Could not create a client to connect to network. Will not be able to send txs. Exiting. Message: {:?}", e );
exit(1);
},
};
Expand Down
7 changes: 2 additions & 5 deletions ol/cli/src/mgmt/management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn spawn_process(

impl Node {
/// Start Node, as fullnode
pub fn start_node(&mut self, config_type: NodeMode, verbose: bool) -> Result<(), Error> {
pub fn start_node(&mut self, verbose: bool) -> Result<(), Error> {
use BINARY_NODE as NODE;
// if is running do nothing
// TODO: Get another check of node running
Expand All @@ -72,10 +72,7 @@ impl Node {
// Start as validator or fullnode
let conf = app_config();
let node_home = conf.workspace.node_home.to_str().unwrap();
let config_file_name = match config_type {
NodeMode::Validator => format!("{}validator.node.yaml", node_home),
NodeMode::Fullnode => format!("{}fullnode.node.yaml", node_home),
};
let config_file_name = format!("{}validator.node.yaml", node_home);

let child = if *IS_PROD {
let args = vec!["--config", &config_file_name];
Expand Down
10 changes: 9 additions & 1 deletion ol/cli/src/node/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,15 @@ pub fn pick_client(swarm_path: Option<PathBuf>, config: &mut AppCfg) -> Result<D
// check if is in sync
let local_client = default_local_rpc(waypoint.clone())?;

let remote_client = find_a_remote_jsonrpc(config, waypoint.clone())?;

let remote_client = match find_a_remote_jsonrpc(config, waypoint.clone()) {
Ok(r) => r,
// If we can't connect to any remotes, return the local client.
Err(e) => {
println!("{:?}", e);
return Ok(local_client)
},
};
// compares to an upstream random remote client. If it is synced, use the local client as the default
let mut node = Node::new(local_client, config, is_swarm);
match node.check_sync()?.is_synced {
Expand Down

0 comments on commit 4b5d7ad

Please sign in to comment.