From 4b5d7ad20a886a70754d8ddc4f5ef6f633f462a3 Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Sat, 23 Jul 2022 22:27:05 +0000 Subject: [PATCH] ol start doesn't need to swtich between validator and fullnode mode with the new configs! --- ol/cli/src/check/pilot.rs | 138 +++++++++++++++---------------- ol/cli/src/commands/mgmt_cmd.rs | 4 +- ol/cli/src/commands/start_cmd.rs | 2 +- ol/cli/src/mgmt/management.rs | 7 +- ol/cli/src/node/client.rs | 10 ++- 5 files changed, 79 insertions(+), 82 deletions(-) diff --git a/ol/cli/src/check/pilot.rs b/ol/cli/src/check/pilot.rs index 49c88d6403..ce1410b33a 100644 --- a/ol/cli/src/check/pilot.rs +++ b/ol/cli/src/check/pilot.rs @@ -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}; @@ -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 } } } @@ -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 +// } diff --git a/ol/cli/src/commands/mgmt_cmd.rs b/ol/cli/src/commands/mgmt_cmd.rs index 1246f87dfa..52293076fa 100644 --- a/ol/cli/src/commands/mgmt_cmd.rs +++ b/ol/cli/src/commands/mgmt_cmd.rs @@ -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 @@ -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 { diff --git a/ol/cli/src/commands/start_cmd.rs b/ol/cli/src/commands/start_cmd.rs index 290aa5f688..610c98ace6 100644 --- a/ol/cli/src/commands/start_cmd.rs +++ b/ol/cli/src/commands/start_cmd.rs @@ -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); }, }; diff --git a/ol/cli/src/mgmt/management.rs b/ol/cli/src/mgmt/management.rs index f446f1e115..f6479d6312 100644 --- a/ol/cli/src/mgmt/management.rs +++ b/ol/cli/src/mgmt/management.rs @@ -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 @@ -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]; diff --git a/ol/cli/src/node/client.rs b/ol/cli/src/node/client.rs index bb3ab6fdaf..456fc35745 100644 --- a/ol/cli/src/node/client.rs +++ b/ol/cli/src/node/client.rs @@ -116,7 +116,15 @@ pub fn pick_client(swarm_path: Option, config: &mut AppCfg) -> Result 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 {