diff --git a/applications/launchpad/backend/src/docker/workspace.rs b/applications/launchpad/backend/src/docker/workspace.rs index 7cf5bf77b9..f57ed48e11 100644 --- a/applications/launchpad/backend/src/docker/workspace.rs +++ b/applications/launchpad/backend/src/docker/workspace.rs @@ -256,7 +256,7 @@ impl TariWorkspace { ) -> Result, DockerWrapperError> { if let Some(id_file_path) = self.config.id_path(root_path, image) { debug!("Loading or creating identity file {}", id_file_path.to_string_lossy()); - let id = setup_node_identity(id_file_path, &None, true, PeerFeatures::COMMUNICATION_NODE)? + let id = setup_node_identity(id_file_path, None, true, PeerFeatures::COMMUNICATION_NODE)? .as_ref() .clone(); Ok(Some(id)) diff --git a/applications/tari_app_utilities/src/identity_management.rs b/applications/tari_app_utilities/src/identity_management.rs index 9c6951c53e..1dffc900cb 100644 --- a/applications/tari_app_utilities/src/identity_management.rs +++ b/applications/tari_app_utilities/src/identity_management.rs @@ -48,7 +48,7 @@ const REQUIRED_IDENTITY_PERMS: u32 = 0o100600; /// A NodeIdentity wrapped in an atomic reference counter on success, the exit code indicating the reason on failure pub fn setup_node_identity>( identity_file: P, - public_address: &Option, + public_address: Option<&Multiaddr>, create_id: bool, peer_features: PeerFeatures, ) -> Result, ExitError> { @@ -94,7 +94,11 @@ pub fn setup_node_identity>( debug!(target: LOG_TARGET, "Existing node id not found. {}. Creating new ID", e); - match create_new_node_identity(&identity_file, public_address.clone(), peer_features) { + match create_new_node_identity( + &identity_file, + public_address.cloned().unwrap_or_else(Multiaddr::empty), + peer_features, + ) { Ok(id) => { info!( target: LOG_TARGET, @@ -106,10 +110,10 @@ pub fn setup_node_identity>( Ok(Arc::new(id)) }, Err(e) => { - error!(target: LOG_TARGET, "Could not create new node id. {:?}.", e); + error!(target: LOG_TARGET, "Could not create new node id. {}.", e); Err(ExitError::new( ExitCode::ConfigError, - &format!("Could not create new node id. {:?}.", e), + &format!("Could not create new node id. {}.", e), )) }, } @@ -153,14 +157,10 @@ fn load_node_identity>(path: P) -> Result>( path: P, - public_addr: Option, + public_addr: Multiaddr, features: PeerFeatures, ) -> Result { - let node_identity = NodeIdentity::random( - &mut OsRng, - public_addr.ok_or(IdentityError::NodeIdentityHasNoAddress)?, - features, - ); + let node_identity = NodeIdentity::random(&mut OsRng, public_addr, features); save_as_json(&path, &node_identity)?; Ok(node_identity) } @@ -268,8 +268,6 @@ pub enum IdentityError { NotFound, #[error("Path is not a file")] NotFile, - #[error("NodeIdentity has no public address")] - NodeIdentityHasNoAddress, #[error("Malformed identity file: {0}")] JsonError(#[from] json5::Error), #[error(transparent)] diff --git a/applications/tari_base_node/src/main.rs b/applications/tari_base_node/src/main.rs index 6d886db31c..9e380e60f1 100644 --- a/applications/tari_base_node/src/main.rs +++ b/applications/tari_base_node/src/main.rs @@ -140,7 +140,7 @@ fn main_inner() -> Result<(), ExitError> { // Load or create the Node identity let node_identity = setup_node_identity( &config.base_node_identity_file, - &config.comms_public_address, + config.comms_public_address.as_ref(), bootstrap.create_id, PeerFeatures::COMMUNICATION_NODE, )?; diff --git a/applications/tari_validator_node/src/main.rs b/applications/tari_validator_node/src/main.rs index 9e3b673821..0f2e8392a8 100644 --- a/applications/tari_validator_node/src/main.rs +++ b/applications/tari_validator_node/src/main.rs @@ -104,7 +104,7 @@ async fn run_node(config: GlobalConfig, create_id: bool) -> Result<(), ExitError fs::create_dir_all(&config.comms_peer_db_path).map_err(|err| ExitError::new(ExitCode::ConfigError, &err))?; let node_identity = setup_node_identity( &config.base_node_identity_file, - &config.comms_public_address, + config.comms_public_address.as_ref(), create_id, PeerFeatures::NONE, )?;