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 0825217
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -816,14 +816,11 @@ jobs:
rm -rf /home/runner/.local/share/safe/test_faucet
rm -rf /home/runner/.local/share/safe/test_genesis
rm -rf /home/runner/.local/share/safe/client
GENESIS_PK=a9925296499299fdbf4412509d342a92e015f5b996e9acd1d2ab7f2326e3ad05934326efdc345345a95e973ac1bb6637 GENESIS_SK=40f6bbc870355c68138ac70b450b6425af02b49874df3f141b7018378ceaac66 ~/faucet --log-output-dest=data-dir send 100000000 $(~/safe --log-output-dest=data-dir wallet address | tail -n 1) | tail -n 1 1>different.txt
echo "----------"
cat different.txt
if grep "wallet balance: 0.000000000" different.txt; then
echo "Faucet with different genesis key rejected"
else
if GENESIS_PK=a9925296499299fdbf4412509d342a92e015f5b996e9acd1d2ab7f2326e3ad05934326efdc345345a95e973ac1bb6637 GENESIS_SK=40f6bbc870355c68138ac70b450b6425af02b49874df3f141b7018378ceaac66 nohup ~/faucet --log-output-dest=data-dir send 100000000 $(~/safe --log-output-dest=data-dir wallet address | tail -n 1); then
echo "Faucet with different genesis key not rejected!"
exit 1
else
echo "Faucet with different genesis key rejected"
fi
env:
SN_LOG: "all"
Expand Down
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 0825217

Please sign in to comment.