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

fix: fix NodeIdentityHasNoAddress when creating new node identity #4002

Merged
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
2 changes: 1 addition & 1 deletion applications/launchpad/backend/src/docker/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl TariWorkspace {
) -> Result<Option<NodeIdentity>, 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))
Expand Down
22 changes: 10 additions & 12 deletions applications/tari_app_utilities/src/identity_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P: AsRef<Path>>(
identity_file: P,
public_address: &Option<Multiaddr>,
public_address: Option<&Multiaddr>,
create_id: bool,
peer_features: PeerFeatures,
) -> Result<Arc<NodeIdentity>, ExitError> {
Expand Down Expand Up @@ -94,7 +94,11 @@ pub fn setup_node_identity<P: AsRef<Path>>(

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,
Expand All @@ -106,10 +110,10 @@ pub fn setup_node_identity<P: AsRef<Path>>(
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),
))
},
}
Expand Down Expand Up @@ -153,14 +157,10 @@ fn load_node_identity<P: AsRef<Path>>(path: P) -> Result<NodeIdentity, IdentityE
/// Result containing the node identity, string will indicate reason on error
fn create_new_node_identity<P: AsRef<Path>>(
path: P,
public_addr: Option<Multiaddr>,
public_addr: Multiaddr,
features: PeerFeatures,
) -> Result<NodeIdentity, IdentityError> {
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)
}
Expand Down Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_base_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?;
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_validator_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?;
Expand Down