snarkos_node_network/
lib.rs1#![forbid(unsafe_code)]
17
18pub mod node_type;
19pub use node_type::*;
20
21pub mod peer;
22pub use peer::*;
23
24pub mod peering;
25pub use peering::*;
26
27pub mod resolver;
28pub use resolver::*;
29
30use snarkvm::prelude::Network;
31
32use std::{net::SocketAddr, str::FromStr};
33use tracing::*;
34
35pub mod built_info {
37 include!(concat!(env!("OUT_DIR"), "/built.rs"));
38}
39
40#[allow(clippy::if_same_then_else)]
42pub fn bootstrap_peers<N: Network>(is_dev: bool) -> Vec<SocketAddr> {
43 if cfg!(feature = "test") || is_dev {
44 match std::env::var("TEST_BOOTSTRAP_PEERS") {
46 Ok(peers) => peers.split(',').map(|peer| SocketAddr::from_str(peer).unwrap()).collect(),
47 Err(err) => {
48 warn!("Failed to load bootstrap peers from environment: {err}");
49 vec![]
50 }
51 }
52 } else if N::ID == snarkvm::console::network::MainnetV0::ID {
53 vec![
55 SocketAddr::from_str("35.231.67.219:4130").unwrap(),
56 SocketAddr::from_str("34.73.195.196:4130").unwrap(),
57 SocketAddr::from_str("34.23.225.202:4130").unwrap(),
58 SocketAddr::from_str("34.148.16.111:4130").unwrap(),
59 ]
60 } else if N::ID == snarkvm::console::network::TestnetV0::ID {
61 vec![
63 SocketAddr::from_str("34.138.104.159:4130").unwrap(),
64 SocketAddr::from_str("35.231.46.237:4130").unwrap(),
65 SocketAddr::from_str("34.148.251.155:4130").unwrap(),
66 SocketAddr::from_str("35.190.141.234:4130").unwrap(),
67 ]
68 } else if N::ID == snarkvm::console::network::CanaryV0::ID {
69 vec![
71 SocketAddr::from_str("34.139.88.58:4130").unwrap(),
72 SocketAddr::from_str("34.139.252.207:4130").unwrap(),
73 SocketAddr::from_str("35.185.98.12:4130").unwrap(),
74 SocketAddr::from_str("35.231.106.26:4130").unwrap(),
75 ]
76 } else {
77 vec![]
79 }
80}
81
82pub fn log_repo_sha_comparison(peer_addr: SocketAddr, peer_sha: Option<&String>, ctx: &str) {
84 let our_sha = built_info::GIT_COMMIT_HASH.unwrap_or_default();
85 let unknown_sha = "unknown".to_owned();
86 let peer_sha = peer_sha.unwrap_or(&unknown_sha);
87 let sha_cmp = if peer_sha == &unknown_sha {
88 " with an unknown repo SHA".to_owned()
89 } else if peer_sha == our_sha {
90 format!("@{peer_sha} (same as us)")
91 } else if our_sha.is_empty() {
92 format!("@{peer_sha} (potentially different than us)")
93 } else {
94 format!("@{peer_sha} (different than us)")
95 };
96
97 debug!("{ctx} Peer '{peer_addr}' uses snarkOS{sha_cmp}");
98}