From ef403fc45bcfa9169b502c6326fc4cdcc6bf7c29 Mon Sep 17 00:00:00 2001 From: Hansie Odendaal Date: Thu, 22 Aug 2024 17:15:07 +0200 Subject: [PATCH 1/7] Add custom noise prologue Added a custom noise prologue to the noise protocol to be hashed in to the handshake hash value. This enables an application to specify a unique identifier like the genesis block hash as the noise prologue, effectively stopping any communication handshake to succeed with nodes that is not on the same genesis block. --- Cargo.lock | 1 + applications/minotari_node/src/bootstrap.rs | 10 ++++- .../contacts/src/chat_client/Cargo.toml | 1 + .../contacts/src/chat_client/src/error.rs | 9 +++++ .../src/chat_client/src/networking.rs | 7 ++++ base_layer/contacts/tests/contacts_service.rs | 1 + base_layer/core/src/blocks/genesis_block.rs | 38 +++++++++++++++++++ base_layer/p2p/src/initialization.rs | 5 +++ base_layer/wallet/src/error.rs | 8 ++++ base_layer/wallet/src/wallet.rs | 11 +++++- common/src/lib.rs | 17 +++++++++ comms/core/src/builder/comms_node.rs | 2 + comms/core/src/builder/mod.rs | 12 ++++++ comms/core/src/connection_manager/manager.rs | 5 ++- .../tests/listener_dialer.rs | 12 +++--- .../src/connection_manager/tests/manager.rs | 1 + .../core/src/connection_manager/wire_mode.rs | 2 +- comms/core/src/noise/config.rs | 15 ++++---- comms/core/src/test_utils/test_node.rs | 1 + comms/dht/examples/propagation/node.rs | 1 + 20 files changed, 141 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a54088324..68779ae287 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5972,6 +5972,7 @@ dependencies = [ "tari_service_framework", "tari_shutdown", "tari_storage", + "tari_utilities", "thiserror", ] diff --git a/applications/minotari_node/src/bootstrap.rs b/applications/minotari_node/src/bootstrap.rs index f06ddb37e9..d0d525c26b 100644 --- a/applications/minotari_node/src/bootstrap.rs +++ b/applications/minotari_node/src/bootstrap.rs @@ -25,9 +25,11 @@ use std::{cmp, str::FromStr, sync::Arc}; use log::*; use minotari_app_utilities::{consts, identity_management, identity_management::load_from_json}; use tari_common::{ - configuration::bootstrap::ApplicationType, + configuration::{bootstrap::ApplicationType, Network}, exit_codes::{ExitCode, ExitError}, + get_static_genesis_block_hash, }; +use tari_common_types::types::FixedHash; use tari_comms::{ multiaddr::{Error as MultiaddrError, Multiaddr}, peer_manager::Peer, @@ -65,6 +67,7 @@ use tari_p2p::{ }; use tari_service_framework::{ServiceHandles, StackBuilder}; use tari_shutdown::ShutdownSignal; +use tari_utilities::{hex::Hex, ByteArray}; use crate::ApplicationConfig; @@ -125,6 +128,11 @@ where B: BlockchainBackend + 'static base_node_config.network, self.node_identity.clone(), publisher, + FixedHash::from_hex(get_static_genesis_block_hash( + Network::get_current_or_user_setting_or_default(), + )) + .map_err(|e| ExitError::new(ExitCode::ConfigError, e))? + .to_vec(), )) .add_initializer(SoftwareUpdaterService::new( ApplicationType::BaseNode, diff --git a/base_layer/contacts/src/chat_client/Cargo.toml b/base_layer/contacts/src/chat_client/Cargo.toml index d5c9e08e80..92fc46ba51 100644 --- a/base_layer/contacts/src/chat_client/Cargo.toml +++ b/base_layer/contacts/src/chat_client/Cargo.toml @@ -19,6 +19,7 @@ tari_p2p = { path = "../../../p2p" } tari_service_framework= { path = "../../../service_framework" } tari_shutdown = { path = "../../../../infrastructure/shutdown" } tari_storage = { path = "../../../../infrastructure/storage" } +tari_utilities = { version = "0.7" } anyhow = "1.0.41" async-trait = "0.1.52" diff --git a/base_layer/contacts/src/chat_client/src/error.rs b/base_layer/contacts/src/chat_client/src/error.rs index c5eda9635a..0dcfaf1718 100644 --- a/base_layer/contacts/src/chat_client/src/error.rs +++ b/base_layer/contacts/src/chat_client/src/error.rs @@ -30,6 +30,7 @@ use tari_comms::peer_manager::PeerManagerError; use tari_contacts::contacts_service::error::ContactsServiceError; use tari_p2p::initialization::CommsInitializationError; use tari_storage::lmdb_store::LMDBError; +use tari_utilities::hex::HexError; #[derive(Debug, thiserror::Error)] pub enum Error { @@ -73,4 +74,12 @@ pub enum NetworkingError { ServiceInitializerError(#[from] anyhow::Error), #[error("Comms failed to spawn")] CommsSpawnError, + #[error("Hex error: `{0}`")] + HexError(String), +} + +impl From for NetworkingError { + fn from(err: HexError) -> Self { + NetworkingError::HexError(err.to_string()) + } } diff --git a/base_layer/contacts/src/chat_client/src/networking.rs b/base_layer/contacts/src/chat_client/src/networking.rs index fcedb1fdc8..200afc88c5 100644 --- a/base_layer/contacts/src/chat_client/src/networking.rs +++ b/base_layer/contacts/src/chat_client/src/networking.rs @@ -24,6 +24,8 @@ use std::{str::FromStr, sync::Arc, time::Duration}; use log::{error, trace}; use minotari_app_utilities::{identity_management, identity_management::load_from_json}; +use tari_common::{configuration::Network, get_static_genesis_block_hash}; +use tari_common_types::types::FixedHash; // Re-exports pub use tari_comms::{ multiaddr::{Error as MultiaddrError, Multiaddr}, @@ -40,6 +42,7 @@ use tari_p2p::{ }; use tari_service_framework::StackBuilder; use tari_shutdown::ShutdownSignal; +use tari_utilities::hex::Hex; use crate::{ config::ApplicationConfig, @@ -75,6 +78,10 @@ pub async fn start( config.chat_client.network, node_identity, publisher, + FixedHash::from_hex(get_static_genesis_block_hash( + Network::get_current_or_user_setting_or_default(), + ))? + .to_vec(), )) .add_initializer(LivenessInitializer::new( LivenessConfig { diff --git a/base_layer/contacts/tests/contacts_service.rs b/base_layer/contacts/tests/contacts_service.rs index 73acc051ae..2a5d6a8765 100644 --- a/base_layer/contacts/tests/contacts_service.rs +++ b/base_layer/contacts/tests/contacts_service.rs @@ -108,6 +108,7 @@ pub fn setup_contacts_service( Network::LocalNet, node_identity.clone(), publisher, + b"tari.contats_service.testing.prologue".to_vec(), )) .add_initializer(LivenessInitializer::new( LivenessConfig { diff --git a/base_layer/core/src/blocks/genesis_block.rs b/base_layer/core/src/blocks/genesis_block.rs index 50172aab99..6a73204677 100644 --- a/base_layer/core/src/blocks/genesis_block.rs +++ b/base_layer/core/src/blocks/genesis_block.rs @@ -49,6 +49,11 @@ pub fn get_genesis_block(network: Network) -> ChainBlock { } } +/// Returns the genesis block hash for the selected network. +pub fn get_genesis_block_hash(network: Network) -> FixedHash { + *get_genesis_block(network).hash() +} + fn add_pre_mine_utxos_to_genesis_block(file: &str, block: &mut Block) { let mut utxos = Vec::new(); let mut counter = 1; @@ -473,6 +478,7 @@ fn get_raw_block(genesis_timestamp: &DateTime, not_before_proof: &P mod test { use std::convert::TryFrom; + use tari_common::get_static_genesis_block_hash; use tari_common_types::{epoch::VnEpoch, types::Commitment}; use super::*; @@ -624,4 +630,36 @@ mod test { .validate(&*lock, 0, &utxo_sum, &kernel_sum, &Commitment::default()) .unwrap(); } + + // Update `tari_common::get_static_genesis_block_hash` with the correct values if the genesis block change + #[test] + fn test_get_static_genesis_block_hash() { + for network in [ + Network::MainNet, + Network::StageNet, + Network::NextNet, + Network::Igor, + Network::Esmeralda, + Network::LocalNet, + ] { + match network { + Network::MainNet => assert_genesis_block_hash(network), + Network::StageNet => assert_genesis_block_hash(network), + Network::NextNet => assert_genesis_block_hash(network), + Network::Igor => assert_genesis_block_hash(network), + Network::Esmeralda => assert_genesis_block_hash(network), + Network::LocalNet => assert_genesis_block_hash(network), + } + } + } + + fn assert_genesis_block_hash(network: Network) { + assert_eq!( + get_genesis_block_hash(network), + FixedHash::from_hex(get_static_genesis_block_hash(network)).unwrap(), + "network: {}, expected hash: {} (update `tari_common::get_static_genesis_block_hash`)", + network, + get_genesis_block_hash(network) + ); + } } diff --git a/base_layer/p2p/src/initialization.rs b/base_layer/p2p/src/initialization.rs index 75465d69d6..afe0471dc9 100644 --- a/base_layer/p2p/src/initialization.rs +++ b/base_layer/p2p/src/initialization.rs @@ -174,6 +174,7 @@ pub async fn initialize_local_test_comms>( .with_dial_backoff(ConstantBackoff::new(Duration::from_millis(500))) .with_min_connectivity(1) .with_network_byte(Network::LocalNet.as_byte()) + .with_noise_prologue(b"let us test the network".to_vec()) .with_shutdown_signal(shutdown_signal) .build()?; @@ -450,6 +451,7 @@ pub struct P2pInitializer { network: Network, node_identity: Arc, connector: Option, + noise_prologue: Vec, } impl P2pInitializer { @@ -460,6 +462,7 @@ impl P2pInitializer { network: Network, node_identity: Arc, connector: PubsubDomainConnector, + noise_prologue: Vec, ) -> Self { Self { config, @@ -468,6 +471,7 @@ impl P2pInitializer { network, node_identity, connector: Some(connector), + noise_prologue, } } @@ -555,6 +559,7 @@ impl ServiceInitializer for P2pInitializer { let mut builder = CommsBuilder::new() .with_shutdown_signal(context.get_shutdown_signal()) + .with_noise_prologue(self.noise_prologue.clone()) .with_node_identity(self.node_identity.clone()) .with_node_info(NodeNetworkInfo { major_version: MAJOR_NETWORK_VERSION, diff --git a/base_layer/wallet/src/error.rs b/base_layer/wallet/src/error.rs index 1ce1cbed13..0ab63c5626 100644 --- a/base_layer/wallet/src/error.rs +++ b/base_layer/wallet/src/error.rs @@ -103,6 +103,8 @@ pub enum WalletError { UnexpectedApiResponse { method: String, api: String }, #[error("Public address not set for this wallet")] PublicAddressNotSet, + #[error("Hex error: `{0}`")] + HexError(String), } pub const LOG_TARGET: &str = "minotari::application"; @@ -119,6 +121,12 @@ impl From for ExitError { } } +impl From for WalletError { + fn from(err: HexError) -> Self { + WalletError::HexError(err.to_string()) + } +} + #[derive(Debug, Error)] pub enum WalletStorageError { #[error("Tried to insert an output that already exists in the database")] diff --git a/base_layer/wallet/src/wallet.rs b/base_layer/wallet/src/wallet.rs index 2022b97de9..168e4b0458 100644 --- a/base_layer/wallet/src/wallet.rs +++ b/base_layer/wallet/src/wallet.rs @@ -27,11 +27,14 @@ use digest::consts::U32; use futures::executor::block_on; use log::*; use rand::rngs::OsRng; -use tari_common::configuration::bootstrap::ApplicationType; +use tari_common::{ + configuration::{bootstrap::ApplicationType, Network}, + get_static_genesis_block_hash, +}; use tari_common_types::{ tari_address::{TariAddress, TariAddressFeatures}, transaction::{ImportStatus, TxId}, - types::{ComAndPubSignature, Commitment, PrivateKey, PublicKey, RangeProof, SignatureWithDomain}, + types::{ComAndPubSignature, Commitment, FixedHash, PrivateKey, PublicKey, RangeProof, SignatureWithDomain}, wallet_types::WalletType, }; use tari_comms::{ @@ -196,6 +199,10 @@ where config.network, node_identity.clone(), publisher, + FixedHash::from_hex(get_static_genesis_block_hash( + Network::get_current_or_user_setting_or_default(), + ))? + .to_vec(), )) .add_initializer(OutputManagerServiceInitializer::::new( config.output_manager_service_config, diff --git a/common/src/lib.rs b/common/src/lib.rs index ba6a6ba96d..7b31cebc81 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -68,6 +68,8 @@ pub mod dir_utils; pub use logging::initialize_logging; +use crate::configuration::Network; + pub const DEFAULT_CONFIG: &str = "config/config.toml"; pub const DEFAULT_BASE_NODE_LOG_CONFIG: &str = "config/log4rs_base_node.yml"; pub const DEFAULT_WALLET_LOG_CONFIG: &str = "config/log4rs_console_wallet.yml"; @@ -77,3 +79,18 @@ pub const DEFAULT_MINER_LOG_CONFIG: &str = "config/log4rs_miner.yml"; pub const DEFAULT_COLLECTIBLES_LOG_CONFIG: &str = "config/log4rs_collectibles.yml"; pub(crate) const LOG_TARGET: &str = "common::config"; + +/// This is a static function that returns the genesis block hash for the specified network. This is useful for +/// applications that need to know the genesis block hash for a specific network, but do not have access to the +/// genesis block in tari_core. Test `fn test_get_static_genesis_block_hash()` in tari_core will fail if these values +/// are wrong. +pub fn get_static_genesis_block_hash<'a>(network: Network) -> &'a str { + match network { + Network::MainNet => "54537be28b5d91b58d27fc52b7dc0cc8cea1977f199eb509d8b4978b0d6630c9", + Network::StageNet => "40afb45c7f10a2dd7bcdd3802273518aba20ac468a75cdfd0c85342a82096557", + Network::NextNet => "fed55ccea50122f9bc7ca913e4bbc0fcbd6913c10cb77bf08f98486ec88d5f02", + Network::Igor => "6cf2950380c69c991612f4ba0afb80281a41bb016239adc642c78817c2e1dbd4", + Network::Esmeralda => "6598d13c5dcb398f5cad294473421bc2fed69071b56fada4387a6ad03a44df08", + Network::LocalNet => "7a32e20ebaf29f7cd67f59a7894050488c350f9d97fcea0765b7a4723e2d0bf7", + } +} diff --git a/comms/core/src/builder/comms_node.rs b/comms/core/src/builder/comms_node.rs index 39252642d5..1fca1d02da 100644 --- a/comms/core/src/builder/comms_node.rs +++ b/comms/core/src/builder/comms_node.rs @@ -132,6 +132,7 @@ impl UnspawnedCommsNode { TTransport: Transport + Unpin + Send + Sync + Clone + 'static, TTransport::Output: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static, { + let noise_prologue = self.builder.get_noise_prologue(); let UnspawnedCommsNode { builder, connection_manager_request_rx, @@ -187,6 +188,7 @@ impl UnspawnedCommsNode { peer_manager.clone(), connection_manager_requester.get_event_publisher(), shutdown_signal.clone(), + &noise_prologue, ); ext_context.register_complete_signal(connection_manager.complete_signal()); diff --git a/comms/core/src/builder/mod.rs b/comms/core/src/builder/mod.rs index 43b78874b0..aadd0a3058 100644 --- a/comms/core/src/builder/mod.rs +++ b/comms/core/src/builder/mod.rs @@ -128,6 +128,7 @@ pub struct CommsBuilder { connectivity_config: ConnectivityConfig, shutdown_signal: Option, maintain_n_closest_connections_only: Option, + noise_prologue: Vec, } impl Default for CommsBuilder { @@ -142,6 +143,7 @@ impl Default for CommsBuilder { connectivity_config: ConnectivityConfig::default(), shutdown_signal: None, maintain_n_closest_connections_only: None, + noise_prologue: b"com.tari.comms.noise.prologue".to_vec(), } } } @@ -178,6 +180,16 @@ impl CommsBuilder { self } + /// Set the noise prologue for this comms instance. + pub fn with_noise_prologue(mut self, prologue: Vec) -> Self { + self.noise_prologue = prologue; + self + } + + pub fn get_noise_prologue(&self) -> Vec { + self.noise_prologue.clone() + } + /// Set a network info (versions etc) as per [RFC-173 Versioning](https://rfc.tari.com/RFC-0173_Versioning.html) pub fn with_node_info(mut self, node_info: NodeNetworkInfo) -> Self { self.connection_manager_config.network_info = node_info; diff --git a/comms/core/src/connection_manager/manager.rs b/comms/core/src/connection_manager/manager.rs index ff88f17501..f850499698 100644 --- a/comms/core/src/connection_manager/manager.rs +++ b/comms/core/src/connection_manager/manager.rs @@ -210,12 +210,13 @@ where peer_manager: Arc, connection_manager_events_tx: broadcast::Sender>, shutdown_signal: ShutdownSignal, + noise_prologue: &[u8], ) -> Self { let (internal_event_tx, internal_event_rx) = mpsc::channel(EVENT_CHANNEL_SIZE); let (dialer_tx, dialer_rx) = mpsc::channel(DIALER_REQUEST_CHANNEL_SIZE); - let noise_config = - NoiseConfig::new(node_identity.clone()).with_recv_timeout(config.noise_handshake_recv_timeout); + let noise_config = NoiseConfig::new(node_identity.clone(), noise_prologue) + .with_recv_timeout(config.noise_handshake_recv_timeout); let listener = PeerListener::new( config.clone(), diff --git a/comms/core/src/connection_manager/tests/listener_dialer.rs b/comms/core/src/connection_manager/tests/listener_dialer.rs index 6db482ac33..6a080c4970 100644 --- a/comms/core/src/connection_manager/tests/listener_dialer.rs +++ b/comms/core/src/connection_manager/tests/listener_dialer.rs @@ -55,7 +55,7 @@ async fn listen() -> Result<(), Box> { let mut shutdown = Shutdown::new(); let peer_manager = build_peer_manager(); let node_identity = build_node_identity(PeerFeatures::COMMUNICATION_NODE); - let noise_config = NoiseConfig::new(node_identity.clone()); + let noise_config = NoiseConfig::new(node_identity.clone(), &[1]); let listener = PeerListener::new( Default::default(), "/memory/0".parse()?, @@ -84,9 +84,10 @@ async fn smoke() { // receives and checks the message and then disconnects and shuts down. let (event_tx, mut event_rx) = mpsc::channel(10); let mut shutdown = Shutdown::new(); + let noise_prologue = [1, 2, 3]; let node_identity1 = build_node_identity(PeerFeatures::COMMUNICATION_NODE); - let noise_config1 = NoiseConfig::new(node_identity1.clone()); + let noise_config1 = NoiseConfig::new(node_identity1.clone(), &noise_prologue); let expected_proto = ProtocolId::from_static(b"/tari/test-proto"); let supported_protocols = vec![expected_proto.clone()]; let peer_manager1 = build_peer_manager(); @@ -106,7 +107,7 @@ async fn smoke() { let address = listener.listen().await.unwrap(); let node_identity2 = build_node_identity(PeerFeatures::COMMUNICATION_NODE); - let noise_config2 = NoiseConfig::new(node_identity2.clone()); + let noise_config2 = NoiseConfig::new(node_identity2.clone(), &noise_prologue); let (request_tx, request_rx) = mpsc::channel(1); let peer_manager2 = build_peer_manager(); let mut dialer = Dialer::new( @@ -187,9 +188,10 @@ async fn smoke() { async fn banned() { let (event_tx, mut event_rx) = mpsc::channel(10); let mut shutdown = Shutdown::new(); + let noise_prologue = [1, 2, 3, 4]; let node_identity1 = build_node_identity(PeerFeatures::COMMUNICATION_NODE); - let noise_config1 = NoiseConfig::new(node_identity1.clone()); + let noise_config1 = NoiseConfig::new(node_identity1.clone(), &noise_prologue); let expected_proto = ProtocolId::from_static(b"/tari/test-proto"); let supported_protocols = vec![expected_proto.clone()]; let peer_manager1 = build_peer_manager(); @@ -214,7 +216,7 @@ async fn banned() { peer.ban_for(Duration::from_secs(60 * 60), "".to_string()); peer_manager1.add_peer(peer).await.unwrap(); - let noise_config2 = NoiseConfig::new(node_identity2.clone()); + let noise_config2 = NoiseConfig::new(node_identity2.clone(), &noise_prologue); let (request_tx, request_rx) = mpsc::channel(1); let peer_manager2 = build_peer_manager(); let mut dialer = Dialer::new( diff --git a/comms/core/src/connection_manager/tests/manager.rs b/comms/core/src/connection_manager/tests/manager.rs index 1abde14e21..1750098400 100644 --- a/comms/core/src/connection_manager/tests/manager.rs +++ b/comms/core/src/connection_manager/tests/manager.rs @@ -72,6 +72,7 @@ async fn connect_to_nonexistent_peer() { peer_manager, event_tx, shutdown.to_signal(), + &[0, 0, 0, 0], ); rt_handle.spawn(connection_manager.run()); diff --git a/comms/core/src/connection_manager/wire_mode.rs b/comms/core/src/connection_manager/wire_mode.rs index d3b52d8b9f..e42ff3d9b7 100644 --- a/comms/core/src/connection_manager/wire_mode.rs +++ b/comms/core/src/connection_manager/wire_mode.rs @@ -22,7 +22,7 @@ use std::convert::TryFrom; -pub(crate) const LIVENESS_WIRE_MODE: u8 = 0xa7; +pub(crate) const LIVENESS_WIRE_MODE: u8 = 0xa6; #[derive(Debug, Clone, Copy)] pub enum WireMode { diff --git a/comms/core/src/noise/config.rs b/comms/core/src/noise/config.rs index a18ab1af50..030159a933 100644 --- a/comms/core/src/noise/config.rs +++ b/comms/core/src/noise/config.rs @@ -49,16 +49,18 @@ pub struct NoiseConfig { node_identity: Arc, parameters: NoiseParams, recv_timeout: Duration, + noise_prologue: Vec, } impl NoiseConfig { /// Create a new NoiseConfig with the provided keypair - pub fn new(node_identity: Arc) -> Self { + pub fn new(node_identity: Arc, noise_prologue: &[u8]) -> Self { let parameters: NoiseParams = NOISE_PARAMETERS.parse().expect("Invalid noise parameters"); Self { node_identity, parameters, recv_timeout: Duration::from_secs(3), + noise_prologue: noise_prologue.to_vec(), } } @@ -78,11 +80,9 @@ impl NoiseConfig { where TSocket: AsyncWrite + AsyncRead + Unpin, { - const TARI_PROLOGUE: &[u8] = b"com.tari.comms.noise.prologue"; - let handshake_state = { let builder = snow::Builder::with_resolver(self.parameters.clone(), Box::::default()) - .prologue(TARI_PROLOGUE) + .prologue(&self.noise_prologue) .local_private_key(self.node_identity.secret_key().as_bytes()); match direction { @@ -128,18 +128,19 @@ mod test { #[test] fn new() { let node_identity = build_node_identity(PeerFeatures::COMMUNICATION_NODE); - let config = NoiseConfig::new(node_identity.clone()); + let config = NoiseConfig::new(node_identity.clone(), &[0]); check_noise_params(&config); assert_eq!(config.node_identity.public_key(), node_identity.public_key()); } #[tokio::test] async fn upgrade_socket() { + let noise_prologue = [0, 1]; let node_identity1 = build_node_identity(PeerFeatures::COMMUNICATION_NODE); - let config1 = NoiseConfig::new(node_identity1.clone()); + let config1 = NoiseConfig::new(node_identity1.clone(), &noise_prologue); let node_identity2 = build_node_identity(PeerFeatures::COMMUNICATION_NODE); - let config2 = NoiseConfig::new(node_identity2.clone()); + let config2 = NoiseConfig::new(node_identity2.clone(), &noise_prologue); let (in_socket, out_socket) = MemorySocket::new_pair(); let (mut socket_in, mut socket_out) = future::join( diff --git a/comms/core/src/test_utils/test_node.rs b/comms/core/src/test_utils/test_node.rs index 9e1fd4b584..db2cc33eab 100644 --- a/comms/core/src/test_utils/test_node.rs +++ b/comms/core/src/test_utils/test_node.rs @@ -94,6 +94,7 @@ where peer_manager, event_tx, shutdown, + &[1, 1, 1, 1] ); connection_manager.add_protocols(protocols); diff --git a/comms/dht/examples/propagation/node.rs b/comms/dht/examples/propagation/node.rs index 3e06162a8d..0aba5c4881 100644 --- a/comms/dht/examples/propagation/node.rs +++ b/comms/dht/examples/propagation/node.rs @@ -79,6 +79,7 @@ pub async fn create>( let builder = CommsBuilder::new() .allow_test_addresses() .with_network_byte(0x25) + .with_noise_prologue(b"dht propagation example".to_vec()) .with_shutdown_signal(shutdown_signal) .with_node_info(NodeNetworkInfo { major_version: 0, From bebb9ff8de0f43c49fa90896a0ed63b651f49830 Mon Sep 17 00:00:00 2001 From: Hansie Odendaal Date: Fri, 23 Aug 2024 07:45:15 +0200 Subject: [PATCH 2/7] review comments --- base_layer/p2p/src/initialization.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/base_layer/p2p/src/initialization.rs b/base_layer/p2p/src/initialization.rs index afe0471dc9..dd8e51f15e 100644 --- a/base_layer/p2p/src/initialization.rs +++ b/base_layer/p2p/src/initialization.rs @@ -464,6 +464,11 @@ impl P2pInitializer { connector: PubsubDomainConnector, noise_prologue: Vec, ) -> Self { + const PREFIX: &[u8] = b"com.tari.comms.noise."; + let mut noise_prologue_buf = vec![0u8; PREFIX.len() + noise_prologue.len()]; + noise_prologue_buf[..PREFIX.len()].copy_from_slice(PREFIX); + noise_prologue_buf[PREFIX.len()..].copy_from_slice(&noise_prologue); + Self { config, user_agent, @@ -471,7 +476,7 @@ impl P2pInitializer { network, node_identity, connector: Some(connector), - noise_prologue, + noise_prologue: noise_prologue_buf, } } From c8e98212a0ce093dbe660e0a5bcf446c572b38dc Mon Sep 17 00:00:00 2001 From: Hansie Odendaal Date: Fri, 23 Aug 2024 12:23:51 +0200 Subject: [PATCH 3/7] error handling --- comms/core/src/connection_manager/dialer.rs | 20 +++++++++++--- comms/core/src/connection_manager/error.rs | 7 ++++- comms/core/src/connectivity/manager.rs | 29 ++++++++++++++++++++- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/comms/core/src/connection_manager/dialer.rs b/comms/core/src/connection_manager/dialer.rs index 0451d8b5b4..924a8361cf 100644 --- a/comms/core/src/connection_manager/dialer.rs +++ b/comms/core/src/connection_manager/dialer.rs @@ -524,6 +524,10 @@ where (state, Err(ConnectionManagerError::DialCancelled)) => break (state, Err(ConnectionManagerError::DialCancelled)), (state, Err(err)) => { debug!(target: LOG_TARGET, "Failed to dial peer {} | Attempt {} | Error: {}", state.peer().node_id.short_str(), state.num_attempts(), err); + if let ConnectionManagerError::NoiseHandshakeError(_) = err { + // If the noise handshake failed, we should not retry the dial + break (state, Err(err)); + } if state.num_attempts() >= config.max_dial_attempts { break (state, Err(ConnectionManagerError::ConnectFailedMaximumAttemptsReached)); } @@ -546,6 +550,7 @@ where /// Attempts to dial a peer sequentially on all addresses; if connections are to be minimized only. /// Returns ownership of the given `DialState` and a success or failure result for the dial, /// or None if the dial was cancelled inflight + #[allow(clippy::too_many_lines)] async fn dial_peer( mut dial_state: DialState, noise_config: &NoiseConfig, @@ -596,7 +601,7 @@ where let initial_dial_time = timer.elapsed(); debug!( - "Dialed peer: {} on address: {} on tcp after: {}", + "Dialed peer: {} on address: {} on tcp after: {} ms", node_id.short_str(), moved_address, timer.elapsed().as_millis() @@ -644,13 +649,20 @@ where dial_state.peer().node_id.short_str(), err, ); - dial_state .peer_mut() .addresses .mark_failed_connection_attempt(&address, err.to_string()); - // Try the next address - continue; + + match err { + ConnectionManagerError::NoiseHandshakeError(_) => { + return (dial_state, Err(err)); + }, + _ => { + // Try the next address + continue; + }, + } }, // Canceled Either::Right(_) => { diff --git a/comms/core/src/connection_manager/error.rs b/comms/core/src/connection_manager/error.rs index 7d2bb4af76..25e2443b91 100644 --- a/comms/core/src/connection_manager/error.rs +++ b/comms/core/src/connection_manager/error.rs @@ -68,6 +68,8 @@ pub enum ConnectionManagerError { // send the same response to multiple requesters #[error("Noise error: {0}")] NoiseError(String), + #[error("Noise handshake error: {0}")] + NoiseHandshakeError(String), #[error("Peer is banned, denying connection")] PeerBanned, #[error("Identity protocol failed: {0}")] @@ -94,7 +96,10 @@ impl From for ConnectionManagerError { impl From for ConnectionManagerError { fn from(err: noise::NoiseError) -> Self { - ConnectionManagerError::NoiseError(err.to_string()) + match err { + noise::NoiseError::HandshakeFailed(_) => ConnectionManagerError::NoiseHandshakeError(err.to_string()), + _ => ConnectionManagerError::NoiseError(err.to_string()), + } } } diff --git a/comms/core/src/connectivity/manager.rs b/comms/core/src/connectivity/manager.rs index c6ccb00500..ea0d3be916 100644 --- a/comms/core/src/connectivity/manager.rs +++ b/comms/core/src/connectivity/manager.rs @@ -602,6 +602,29 @@ impl ConnectivityManagerActor { Ok(()) } + async fn on_peer_handshake_failure(&mut self, node_id: &NodeId) -> Result<(), ConnectivityError> { + let num_failed = self.mark_peer_failed(node_id.clone()); + + if (self.peer_manager.find_by_node_id(node_id).await?).is_some() { + debug!( + target: LOG_TARGET, + "Peer `{}` was marked as offline after {} attempts due to incompatible handshake noise prologue. \ + Removing peer from peer list", + node_id, + num_failed, + ); + self.peer_manager.delete_peer(node_id).await?; + self.ban_peer( + node_id, + Duration::from_secs(3 * 24 * 60 * 60), + "Incompatible handshake noise prologue".to_string(), + ) + .await?; + } + + Ok(()) + } + async fn handle_connection_manager_event( &mut self, event: &ConnectionManagerEvent, @@ -684,7 +707,11 @@ impl ConnectivityManagerActor { target: LOG_TARGET, "Connection to peer '{}' failed because '{:?}'", node_id, err ); - self.on_peer_connection_failure(node_id).await?; + if let ConnectionManagerError::NoiseHandshakeError(_) = err { + self.on_peer_handshake_failure(node_id).await?; + } else { + self.on_peer_connection_failure(node_id).await?; + } (node_id, ConnectionStatus::Failed, None) }, _ => return Ok(()), From 99133f049a6daf010117c18dec06e2068e051527 Mon Sep 17 00:00:00 2001 From: Hansie Odendaal Date: Fri, 23 Aug 2024 13:57:49 +0200 Subject: [PATCH 4/7] review comments --- base_layer/contacts/tests/contacts_service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base_layer/contacts/tests/contacts_service.rs b/base_layer/contacts/tests/contacts_service.rs index 2a5d6a8765..c0fca64d94 100644 --- a/base_layer/contacts/tests/contacts_service.rs +++ b/base_layer/contacts/tests/contacts_service.rs @@ -108,7 +108,7 @@ pub fn setup_contacts_service( Network::LocalNet, node_identity.clone(), publisher, - b"tari.contats_service.testing.prologue".to_vec(), + b"tari.contacts_service.testing.prologue".to_vec(), )) .add_initializer(LivenessInitializer::new( LivenessConfig { From 66a05715d7f0409203c796fae01f5f4a5e55cd17 Mon Sep 17 00:00:00 2001 From: Hansie Odendaal Date: Fri, 23 Aug 2024 16:59:02 +0200 Subject: [PATCH 5/7] fix use of network domain separated hashes in genesis block tests --- Cargo.lock | 23 +++ base_layer/core/Cargo.toml | 1 + base_layer/core/src/blocks/genesis_block.rs | 144 ++++++++++++++---- .../consensus/consensus_encoding/hashing.rs | 85 ++++++----- common/src/lib.rs | 10 +- 5 files changed, 196 insertions(+), 67 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 68779ae287..f74500aaca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5450,6 +5450,28 @@ dependencies = [ "unsafe-libyaml", ] +[[package]] +name = "serial_test" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0bccbcf40c8938196944a3da0e133e031a33f4d6b72db3bda3cc556e361905d" +dependencies = [ + "lazy_static", + "parking_lot 0.11.2", + "serial_test_derive", +] + +[[package]] +name = "serial_test_derive" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2acd6defeddb41eb60bb468f8825d0cfd0c2a76bc03bfd235b6a1dc4f6a1ad5" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "servo_arc" version = "0.3.0" @@ -6223,6 +6245,7 @@ dependencies = [ "serde", "serde_json", "serde_repr", + "serial_test", "sha2 0.10.8", "sha3", "strum", diff --git a/base_layer/core/Cargo.toml b/base_layer/core/Cargo.toml index e516dbcc9a..62397a4d48 100644 --- a/base_layer/core/Cargo.toml +++ b/base_layer/core/Cargo.toml @@ -106,6 +106,7 @@ env_logger = "0.7.0" tempfile = "3.1.0" toml = { version = "0.5" } quickcheck = "1.0" +serial_test = "0.5" [build-dependencies] tari_common = { path = "../../common", features = ["build"], version = "1.3.0-pre.0" } diff --git a/base_layer/core/src/blocks/genesis_block.rs b/base_layer/core/src/blocks/genesis_block.rs index 6a73204677..09a614cab9 100644 --- a/base_layer/core/src/blocks/genesis_block.rs +++ b/base_layer/core/src/blocks/genesis_block.rs @@ -49,11 +49,6 @@ pub fn get_genesis_block(network: Network) -> ChainBlock { } } -/// Returns the genesis block hash for the selected network. -pub fn get_genesis_block_hash(network: Network) -> FixedHash { - *get_genesis_block(network).hash() -} - fn add_pre_mine_utxos_to_genesis_block(file: &str, block: &mut Block) { let mut utxos = Vec::new(); let mut counter = 1; @@ -474,10 +469,12 @@ fn get_raw_block(genesis_timestamp: &DateTime, not_before_proof: &P } } +// Note: Tests in this module are serialized to prevent domain separated network hash conflicts #[cfg(test)] mod test { use std::convert::TryFrom; + use serial_test::serial; use tari_common::get_static_genesis_block_hash; use tari_common_types::{epoch::VnEpoch, types::Commitment}; @@ -495,61 +492,103 @@ mod test { }; #[test] - #[cfg(tari_target_network_testnet)] + // #[cfg(tari_target_network_testnet)] + #[serial] fn esmeralda_genesis_sanity_check() { - let _ = Network::set_current(Network::Esmeralda); + let network = Network::Esmeralda; + set_network_by_env_var_or_force_set(network); + if !network_matches(network) { + panic!("Network could not be set ('esmeralda_genesis_sanity_check()')"); + } // Note: Generate new data for `pub fn get_esmeralda_genesis_block()` and `fn get_esmeralda_genesis_block_raw()` // if consensus values change, e.g. new pre_mine or other let block = get_esmeralda_genesis_block(); - check_block(Network::Esmeralda, &block, 164, 1); + check_block(network, &block, 164, 1); + assert_genesis_block_hash(network); + remove_network_env_var() } #[test] - #[cfg(tari_target_network_nextnet)] + #[serial] + // #[cfg(tari_target_network_nextnet)] fn nextnet_genesis_sanity_check() { - let _ = Network::set_current(Network::NextNet); + let network = Network::NextNet; + set_network_by_env_var_or_force_set(network); + if !network_matches(network) { + panic!("Network could not be set ('nextnet_genesis_sanity_check()')"); + } // Note: Generate new data for `pub fn get_nextnet_genesis_block()` and `fn get_stagenet_genesis_block_raw()` // if consensus values change, e.g. new pre_mine or other let block = get_nextnet_genesis_block(); - check_block(Network::NextNet, &block, 0, 0); + check_block(network, &block, 0, 0); + assert_genesis_block_hash(network); + remove_network_env_var() } #[test] - #[cfg(tari_target_network_mainnet)] + #[serial] + // #[cfg(tari_target_network_mainnet)] fn mainnet_genesis_sanity_check() { - let _ = Network::set_current(Network::MainNet); + let network = Network::MainNet; + set_network_by_env_var_or_force_set(network); + if !network_matches(network) { + panic!("Network could not be set ('mainnet_genesis_sanity_check()')"); + } // Note: Generate new data for `pub fn get_nextnet_genesis_block()` and `fn get_stagenet_genesis_block_raw()` // if consensus values change, e.g. new pre_mine or other let block = get_mainnet_genesis_block(); - check_block(Network::MainNet, &block, 164, 1); + check_block(network, &block, 164, 1); + assert_genesis_block_hash(network); + remove_network_env_var() } #[test] - #[cfg(tari_target_network_mainnet)] + #[serial] + // #[cfg(tari_target_network_mainnet)] fn stagenet_genesis_sanity_check() { - let _ = Network::set_current(Network::StageNet); + let network = Network::StageNet; + set_network_by_env_var_or_force_set(network); + if !network_matches(network) { + panic!("Network could not be set ('stagenet_genesis_sanity_check()')"); + } // Note: Generate new data for `pub fn get_stagenet_genesis_block()` and `fn get_stagenet_genesis_block_raw()` // if consensus values change, e.g. new pre_mine or other let block = get_stagenet_genesis_block(); - check_block(Network::StageNet, &block, 0, 0); + check_block(network, &block, 0, 0); + assert_genesis_block_hash(network); + remove_network_env_var() } #[test] - #[cfg(tari_target_network_testnet)] + #[serial] + // #[cfg(tari_target_network_testnet)] fn igor_genesis_sanity_check() { - let _ = Network::set_current(Network::Igor); + let network = Network::Igor; + set_network_by_env_var_or_force_set(network); + if !network_matches(network) { + panic!("Network could not be set ('igor_genesis_sanity_check()')"); + } // Note: If outputs and kernels are added, this test will fail unless you explicitly check that network == Igor let block = get_igor_genesis_block(); - check_block(Network::Igor, &block, 0, 0); + check_block(network, &block, 0, 0); + assert_genesis_block_hash(network); + remove_network_env_var() } #[test] - #[cfg(tari_target_network_testnet)] + #[serial] + // #[cfg(tari_target_network_testnet)] fn localnet_genesis_sanity_check() { - let _ = Network::set_current(Network::LocalNet); + let network = Network::LocalNet; + set_network_by_env_var_or_force_set(network); + if !network_matches(network) { + panic!("Network could not be set ('localnet_genesis_sanity_check()')"); + } // Note: If outputs and kernels are added, this test will fail unless you explicitly check that network == Igor let block = get_localnet_genesis_block(); - check_block(Network::LocalNet, &block, 0, 0); + check_block(network, &block, 0, 0); + assert_genesis_block_hash(network); + remove_network_env_var() } fn check_block(network: Network, block: &ChainBlock, expected_outputs: usize, expected_kernels: usize) { @@ -631,9 +670,21 @@ mod test { .unwrap(); } - // Update `tari_common::get_static_genesis_block_hash` with the correct values if the genesis block change + // This is a convenience test to check all networks are covered and to be able to test all networks at once + // without the need to re-compile or be dependent on the global static network setting. Update + // `tari_common::get_static_genesis_block_hash` with the correct values if the genesis block change. #[test] + #[serial] fn test_get_static_genesis_block_hash() { + if Network::is_set() { + println!("\nNote!! Static network constant is set, cannot run `test_get_static_genesis_block_hash`\n"); + return; + } + if std::env::var("TARI_NETWORK").is_ok() { + println!("\nNote!! env_var 'TARI_NETWORK' in use, cannot run `test_get_static_genesis_block_hash`\n"); + return; + } + for network in [ Network::MainNet, Network::StageNet, @@ -642,6 +693,10 @@ mod test { Network::Esmeralda, Network::LocalNet, ] { + set_network_by_env_var(network); + if !network_matches(network) { + panic!("Network could not be set ('test_get_static_genesis_block_hash()')"); + } match network { Network::MainNet => assert_genesis_block_hash(network), Network::StageNet => assert_genesis_block_hash(network), @@ -650,16 +705,51 @@ mod test { Network::Esmeralda => assert_genesis_block_hash(network), Network::LocalNet => assert_genesis_block_hash(network), } + remove_network_env_var(); } } fn assert_genesis_block_hash(network: Network) { + let expected_hash = *get_genesis_block(network).hash(); assert_eq!( - get_genesis_block_hash(network), - FixedHash::from_hex(get_static_genesis_block_hash(network)).unwrap(), + expected_hash.to_hex(), + get_static_genesis_block_hash(network), "network: {}, expected hash: {} (update `tari_common::get_static_genesis_block_hash`)", network, - get_genesis_block_hash(network) + expected_hash ); } + + fn set_network_by_env_var_or_force_set(network: Network) { + set_network_by_env_var(network); + if Network::get_current_or_user_setting_or_default() != network { + let _ = Network::set_current(network); + } + } + + // Targeted network compilations will override inferred network hashes; this has effect only if + // `Network::set_current()` has not been called. + fn set_network_by_env_var(network: Network) { + // Do not override the env_var if network is already set; another test may fail + if std::env::var("TARI_NETWORK").is_err() { + std::env::set_var("TARI_NETWORK", network.as_key_str()); + } + } + + fn remove_network_env_var() { + std::env::remove_var("TARI_NETWORK"); + } + + fn network_matches(network: Network) -> bool { + let current_network = Network::get_current_or_user_setting_or_default(); + if current_network == network { + true + } else { + println!( + "\nNetwork mismatch!! Required: {:?}, current: {:?}.\n", + network, current_network + ); + false + } + } } diff --git a/base_layer/core/src/consensus/consensus_encoding/hashing.rs b/base_layer/core/src/consensus/consensus_encoding/hashing.rs index 93abebc848..4c611380ca 100644 --- a/base_layer/core/src/consensus/consensus_encoding/hashing.rs +++ b/base_layer/core/src/consensus/consensus_encoding/hashing.rs @@ -145,44 +145,59 @@ mod tests { #[test] fn it_uses_the_network_environment_variable_if_set() { - // This test will not pass if `Network::set_current()` is called before the test - if !Network::is_set() { - let label = "test"; - let input = [1u8; 32]; - - for network in [ - Network::MainNet, - Network::StageNet, - Network::NextNet, - Network::LocalNet, - Network::Igor, - Network::Esmeralda, - ] { - println!("Testing network: {:?}", network); - // Generate a specific network hash - let hash_specify_network = - DomainSeparatedConsensusHasher::>::new_with_network(label, network) - .chain(&input) - .finalize(); - - // Generate an inferred network hash - std::env::set_var("TARI_NETWORK", network.as_key_str()); - println!( - "TARI_NETWORK: {:?}", - std::env::var("TARI_NETWORK").unwrap_or_default() - ); - println!( - "Network: {:?}\n", - Network::get_current_or_user_setting_or_default() - ); - let inferred_network_hash = DomainSeparatedConsensusHasher::>::new(label) + // Targeted network compilations will override inferred network hashes; this only has effect if + // `Network::set_current()` has not been called. The test may also not run if + // `std::env::var("TARI_NETWORK")` has been set by some other test. + if Network::is_set() { + println!( + "\nNote!! Static network constant is set, cannot run \ + `it_uses_the_network_environment_variable_if_set`\n" + ); + return; + } + if std::env::var("TARI_NETWORK").is_ok() { + println!( + "\nNote!! env_var 'TARI_NETWORK' in use, cannot run \ + `it_uses_the_network_environment_variable_if_set`\n" + ); + return; + } + + let label = "test"; + let input = [1u8; 32]; + + for network in [ + Network::MainNet, + Network::StageNet, + Network::NextNet, + Network::LocalNet, + Network::Igor, + Network::Esmeralda, + ] { + println!("Testing network: {:?}", network); + // Generate a specific network hash + let hash_specify_network = + DomainSeparatedConsensusHasher::>::new_with_network(label, network) .chain(&input) .finalize(); - std::env::remove_var("TARI_NETWORK"); - // They should be equal - assert_eq!(hash_specify_network, inferred_network_hash); - } + // Generate an inferred network hash + std::env::set_var("TARI_NETWORK", network.as_key_str()); + println!( + "TARI_NETWORK: {:?}", + std::env::var("TARI_NETWORK").unwrap_or_default() + ); + println!( + "Network: {:?}\n", + Network::get_current_or_user_setting_or_default() + ); + let inferred_network_hash = DomainSeparatedConsensusHasher::>::new(label) + .chain(&input) + .finalize(); + std::env::remove_var("TARI_NETWORK"); + + // They should be equal + assert_eq!(hash_specify_network, inferred_network_hash); } } } diff --git a/common/src/lib.rs b/common/src/lib.rs index 7b31cebc81..860582a922 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -86,11 +86,11 @@ pub(crate) const LOG_TARGET: &str = "common::config"; /// are wrong. pub fn get_static_genesis_block_hash<'a>(network: Network) -> &'a str { match network { - Network::MainNet => "54537be28b5d91b58d27fc52b7dc0cc8cea1977f199eb509d8b4978b0d6630c9", - Network::StageNet => "40afb45c7f10a2dd7bcdd3802273518aba20ac468a75cdfd0c85342a82096557", - Network::NextNet => "fed55ccea50122f9bc7ca913e4bbc0fcbd6913c10cb77bf08f98486ec88d5f02", - Network::Igor => "6cf2950380c69c991612f4ba0afb80281a41bb016239adc642c78817c2e1dbd4", + Network::MainNet => "ba4379a1319a6315d5262f61761d3f609f5b8eb9fa30a05f0d18a80c25d6bae9", + Network::StageNet => "cd073787a0bd8803a2546919523c687ccd88c8f0b39d652783530502e101f351", + Network::NextNet => "5ae9384d705f8df49d7e5b5988297440a53bc8be48b8792f8bc0a2c3d17c3479", + Network::Igor => "50ed5847a5b4b88dfd86fd48597801b72565a0e1ba14701fddbeaca356e8b4c3", Network::Esmeralda => "6598d13c5dcb398f5cad294473421bc2fed69071b56fada4387a6ad03a44df08", - Network::LocalNet => "7a32e20ebaf29f7cd67f59a7894050488c350f9d97fcea0765b7a4723e2d0bf7", + Network::LocalNet => "b693c14804ceaafaee77c2d01310a221960383128de6b0f36c581fb706332bb3", } } From e99876066f10ddc0e0f2de107e7ccfdf4127185b Mon Sep 17 00:00:00 2001 From: Hansie Odendaal Date: Sun, 25 Aug 2024 07:19:30 +0200 Subject: [PATCH 6/7] Remove commented out code --- base_layer/core/src/blocks/genesis_block.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/base_layer/core/src/blocks/genesis_block.rs b/base_layer/core/src/blocks/genesis_block.rs index 09a614cab9..5aedf2069e 100644 --- a/base_layer/core/src/blocks/genesis_block.rs +++ b/base_layer/core/src/blocks/genesis_block.rs @@ -492,7 +492,6 @@ mod test { }; #[test] - // #[cfg(tari_target_network_testnet)] #[serial] fn esmeralda_genesis_sanity_check() { let network = Network::Esmeralda; @@ -510,7 +509,6 @@ mod test { #[test] #[serial] - // #[cfg(tari_target_network_nextnet)] fn nextnet_genesis_sanity_check() { let network = Network::NextNet; set_network_by_env_var_or_force_set(network); @@ -527,7 +525,6 @@ mod test { #[test] #[serial] - // #[cfg(tari_target_network_mainnet)] fn mainnet_genesis_sanity_check() { let network = Network::MainNet; set_network_by_env_var_or_force_set(network); @@ -544,7 +541,6 @@ mod test { #[test] #[serial] - // #[cfg(tari_target_network_mainnet)] fn stagenet_genesis_sanity_check() { let network = Network::StageNet; set_network_by_env_var_or_force_set(network); @@ -561,7 +557,6 @@ mod test { #[test] #[serial] - // #[cfg(tari_target_network_testnet)] fn igor_genesis_sanity_check() { let network = Network::Igor; set_network_by_env_var_or_force_set(network); @@ -577,7 +572,6 @@ mod test { #[test] #[serial] - // #[cfg(tari_target_network_testnet)] fn localnet_genesis_sanity_check() { let network = Network::LocalNet; set_network_by_env_var_or_force_set(network); From 3d7733646fd7839de7247238b441cc6ad250e0fa Mon Sep 17 00:00:00 2001 From: Hansie Odendaal Date: Mon, 26 Aug 2024 09:09:06 +0200 Subject: [PATCH 7/7] review comments --- common/src/lib.rs | 2 +- comms/core/src/connectivity/manager.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/lib.rs b/common/src/lib.rs index 860582a922..e01c37d92a 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -84,7 +84,7 @@ pub(crate) const LOG_TARGET: &str = "common::config"; /// applications that need to know the genesis block hash for a specific network, but do not have access to the /// genesis block in tari_core. Test `fn test_get_static_genesis_block_hash()` in tari_core will fail if these values /// are wrong. -pub fn get_static_genesis_block_hash<'a>(network: Network) -> &'a str { +pub fn get_static_genesis_block_hash(network: Network) -> &'static str { match network { Network::MainNet => "ba4379a1319a6315d5262f61761d3f609f5b8eb9fa30a05f0d18a80c25d6bae9", Network::StageNet => "cd073787a0bd8803a2546919523c687ccd88c8f0b39d652783530502e101f351", diff --git a/comms/core/src/connectivity/manager.rs b/comms/core/src/connectivity/manager.rs index ea0d3be916..6b4f9be9a0 100644 --- a/comms/core/src/connectivity/manager.rs +++ b/comms/core/src/connectivity/manager.rs @@ -605,7 +605,7 @@ impl ConnectivityManagerActor { async fn on_peer_handshake_failure(&mut self, node_id: &NodeId) -> Result<(), ConnectivityError> { let num_failed = self.mark_peer_failed(node_id.clone()); - if (self.peer_manager.find_by_node_id(node_id).await?).is_some() { + if self.peer_manager.exists_node_id(node_id).await { debug!( target: LOG_TARGET, "Peer `{}` was marked as offline after {} attempts due to incompatible handshake noise prologue. \