Skip to content

Commit

Permalink
feat(network)!: include PKs in the version str
Browse files Browse the repository at this point in the history
BREAKING CHANGE: this will make new launched network incompatible with
old client or node.
  • Loading branch information
maqi committed Jun 17, 2024
1 parent cde9e4f commit 4be629a
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions sn_networking/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,44 @@
// permissions and limitations relating to use of the SAFE Network Software.

use lazy_static::lazy_static;
use sn_transfers::{FOUNDATION_PK, GENESIS_PK, NETWORK_ROYALTIES_PK, PAYMENT_FORWARD_PK};

lazy_static! {
/// The node version used during Identify Behaviour.
pub static ref IDENTIFY_NODE_VERSION_STR: String =
format!(
"safe{}/node/{}",
"safe{}/node/{}/{}",
write_network_version_with_slash(),
get_truncate_version_str()
get_truncate_version_str(),
get_key_version_str(),
);

/// The client version used during Identify Behaviour.
pub static ref IDENTIFY_CLIENT_VERSION_STR: String =
format!(
"safe{}/client/{}",
"safe{}/client/{}/{}",
write_network_version_with_slash(),
get_truncate_version_str()
get_truncate_version_str(),
get_key_version_str(),
);

/// / first version for the req/response protocol
/// The req/response protocol version
pub static ref REQ_RESPONSE_VERSION_STR: String =
format!(
"/safe{}/node/{}",
"/safe{}/node/{}/{}",
write_network_version_with_slash(),
get_truncate_version_str()
get_truncate_version_str(),
get_key_version_str(),
);


/// The identify protocol version
pub static ref IDENTIFY_PROTOCOL_STR: String =
format!(
"safe{}/{}",
"safe{}/{}/{}",
write_network_version_with_slash(),
get_truncate_version_str()
get_truncate_version_str(),
get_key_version_str(),
);


}

/// Get the network version string.
Expand Down Expand Up @@ -85,3 +87,18 @@ fn get_truncate_version_str() -> String {
panic!("Cannot obtain truncated version str for {version_str:?}: {parts:?}");
}
}

/// Get the PKs version string.
/// If the public key mis-configed via env variable,
/// it shall result in being rejected to join by the network
fn get_key_version_str() -> String {
let mut f_k_str = FOUNDATION_PK.to_hex();
let _ = f_k_str.split_off(6);
let mut g_k_str = GENESIS_PK.to_hex();
let _ = g_k_str.split_off(6);
let mut n_k_str = NETWORK_ROYALTIES_PK.to_hex();
let _ = n_k_str.split_off(6);
let mut p_k_str = PAYMENT_FORWARD_PK.to_hex();
let _ = p_k_str.split_off(6);
format!("{f_k_str}_{g_k_str}_{n_k_str}_{p_k_str}")
}

0 comments on commit 4be629a

Please sign in to comment.