Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[config] fixdevnet config load muilti time #3622

Merged
merged 2 commits into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions cmd/starcoin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use scmd::CmdContext;
use starcoin_account_provider::ProviderFactory;
use starcoin_cmd::*;
use starcoin_cmd::{CliState, StarcoinOpt};
use starcoin_config::{Connect, NodeConfig, G_APP_VERSION, G_CRATE_VERSION};
use starcoin_config::{Connect, G_APP_VERSION, G_CRATE_VERSION};
use starcoin_logger::prelude::*;
use starcoin_node_api::errors::NodeStartError;
use starcoin_rpc_client::RpcClient;
use std::fs;
use std::sync::Arc;
use std::time::Duration;

Expand All @@ -34,21 +33,6 @@ fn run() -> Result<()> {
(client, None)
} else {
info!("Start starcoin node...");
// check and do some clean work
let config = NodeConfig::load_with_opt(opt)
.expect("load config with opt should success.");
let ipc_file = config.rpc.get_ipc_file();
if ipc_file.exists() {
// check if ipc is connectable
info!(
"ipc_file: {:?} already exists, try to check if it's connectable",
ipc_file
);
if RpcClient::connect_ipc(&ipc_file).is_err() {
info!("ipc_file: {:?} is not usable, just to remove it.", ipc_file);
_ = fs::remove_file(ipc_file);
}
}
let (node_handle, config) = starcoin_node::run_node_by_opt(opt)?;
match node_handle {
//first cli use local connect.
Expand Down
13 changes: 12 additions & 1 deletion node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,22 @@ pub fn run_node_by_opt(
.map_err(NodeStartError::LoadConfigError)?,
);
let ipc_file = config.rpc.get_ipc_file();
if ipc_file.exists() {
// check if ipc is connectable
info!(
"ipc_file: {:?} already exists, try to check if it's connectable",
ipc_file
);
if starcoin_rpc_client::RpcClient::connect_ipc(&ipc_file).is_err() {
info!("ipc_file: {:?} is not usable, just to remove it.", ipc_file);
_ = std::fs::remove_file(ipc_file.clone());
}
}

let node_handle = if !ipc_file.exists() {
let node_handle = run_node(config.clone())?;
Some(node_handle)
} else {
//TODO check ipc file is available.
info!("Node has started at {:?}", ipc_file);
None
};
Expand Down