From 08252173f587de0cad0642ab70ca7f981234ca3f Mon Sep 17 00:00:00 2001 From: qima Date: Wed, 5 Jun 2024 17:45:19 +0800 Subject: [PATCH] feat(network)!: include PKs in the version str BREAKING CHANGE: this will make new launched network incompatible with old client or node. --- .github/workflows/merge.yml | 9 +++----- sn_networking/src/version.rs | 41 +++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index c09a2d3dce..aacffa870f 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -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" diff --git a/sn_networking/src/version.rs b/sn_networking/src/version.rs index 0f1b9a7e40..b507c2d725 100644 --- a/sn_networking/src/version.rs +++ b/sn_networking/src/version.rs @@ -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. @@ -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}") +}