Skip to content

Commit

Permalink
fix(manager): restart nodes with the same safenode port
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin authored and jacderida committed Feb 13, 2024
1 parent 6e592c8 commit 11ac2ab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
24 changes: 22 additions & 2 deletions sn_node_manager/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.

use crate::{service::ServiceControl, VerbosityLevel};
use crate::{
service::{ServiceConfig, ServiceControl},
VerbosityLevel,
};
use color_eyre::{eyre::eyre, Help, Result};
use colored::Colorize;
use libp2p::multiaddr::Protocol;
use libp2p::{multiaddr::Protocol, Multiaddr};
use semver::Version;
use sn_node_rpc_client::{RpcActions, RpcClient};
use sn_protocol::node_registry::{Node, NodeRegistry, NodeStatus};
Expand Down Expand Up @@ -277,6 +280,7 @@ pub async fn remove(

pub async fn upgrade(
node: &mut Node,
bootstrap_peers: Vec<Multiaddr>,
upgraded_safenode_path: &PathBuf,
latest_version: &Version,
service_control: &dyn ServiceControl,
Expand All @@ -289,6 +293,22 @@ pub async fn upgrade(

stop(node, service_control).await?;
std::fs::copy(upgraded_safenode_path, &node.safenode_path)?;

// Install the service again to make sure we re-use the same node port.
// Initially the node_port is generated on random. We obtain this port from the Node::listen_addr field to be re-used.
service_control.install(ServiceConfig {
local: node.local,
data_dir_path: node.data_dir_path.clone(),
genesis: node.genesis,
name: node.service_name.clone(),
node_port: Some(node.get_safenode_port()?),
bootstrap_peers,
rpc_socket_addr: node.rpc_socket_addr,
log_dir_path: node.log_dir_path.clone(),
safenode_path: node.safenode_path.clone(),
service_user: node.user.clone(),
})?;

start(node, service_control, rpc_client, VerbosityLevel::Normal).await?;
node.version = latest_version.to_string();

Expand Down
3 changes: 3 additions & 0 deletions sn_node_manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ async fn main() -> Result<()> {
let rpc_client = RpcClient::from_socket_addr(node.rpc_socket_addr);
let result = upgrade(
node,
node_registry.bootstrap_peers.clone(),
&safenode_download_path,
&latest_version,
&NodeServiceManager {},
Expand Down Expand Up @@ -879,6 +880,7 @@ async fn main() -> Result<()> {
let rpc_client = RpcClient::from_socket_addr(node.rpc_socket_addr);
let result = upgrade(
node,
node_registry.bootstrap_peers.clone(),
&safenode_download_path,
&latest_version,
&NodeServiceManager {},
Expand All @@ -902,6 +904,7 @@ async fn main() -> Result<()> {
let rpc_client = RpcClient::from_socket_addr(node.rpc_socket_addr);
let result = upgrade(
node,
node_registry.bootstrap_peers.clone(),
&safenode_download_path,
&latest_version,
&NodeServiceManager {},
Expand Down

0 comments on commit 11ac2ab

Please sign in to comment.