From f949029072d6223984fb4ad647efc6318d70f0ab Mon Sep 17 00:00:00 2001 From: Roland Sherwin Date: Wed, 4 Dec 2024 23:33:10 +0530 Subject: [PATCH] feat: remove ant-peers-acquisition and use ant-bootstrap instead - This also removes the `network-contact` feature flag. - The flag was used to indicate if we should connect to the mainnet or the testnet, which can easily be done with PeersArgs::testnet flag --- Cargo.lock | 25 +-- Cargo.toml | 1 - Justfile | 8 +- README.md | 19 +- ant-cli/Cargo.toml | 4 +- ant-cli/src/main.rs | 2 +- ant-logging/src/layers.rs | 1 - ant-node-manager/Cargo.toml | 3 +- ant-node-manager/src/bin/cli/main.rs | 4 +- ant-node-manager/src/cmd/auditor.rs | 2 +- ant-node-manager/src/cmd/faucet.rs | 2 +- ant-node-manager/src/cmd/local.rs | 6 +- ant-node-manager/src/cmd/mod.rs | 3 - ant-node-manager/src/cmd/nat_detection.rs | 8 +- ant-node-manager/src/cmd/node.rs | 8 +- ant-node-rpc-client/Cargo.toml | 1 - ant-node/Cargo.toml | 4 +- ant-node/src/bin/antnode/main.rs | 2 +- ant-peers-acquisition/Cargo.toml | 31 --- ant-peers-acquisition/README.md | 5 - ant-peers-acquisition/src/error.rs | 19 -- ant-peers-acquisition/src/lib.rs | 242 ---------------------- autonomi/Cargo.toml | 2 - node-launchpad/Cargo.toml | 2 +- node-launchpad/src/app.rs | 4 +- node-launchpad/src/bin/tui/main.rs | 2 +- node-launchpad/src/components/status.rs | 2 +- node-launchpad/src/node_mgmt.rs | 2 +- node-launchpad/src/utils.rs | 8 +- test-utils/Cargo.toml | 4 - test-utils/src/lib.rs | 10 +- 31 files changed, 49 insertions(+), 387 deletions(-) delete mode 100644 ant-peers-acquisition/Cargo.toml delete mode 100644 ant-peers-acquisition/README.md delete mode 100644 ant-peers-acquisition/src/error.rs delete mode 100644 ant-peers-acquisition/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 0fa6aa094e..607e15070a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -762,7 +762,6 @@ dependencies = [ "ant-bootstrap", "ant-build-info", "ant-logging", - "ant-peers-acquisition", "autonomi", "clap", "color-eyre", @@ -905,7 +904,6 @@ dependencies = [ "ant-evm", "ant-logging", "ant-networking", - "ant-peers-acquisition", "ant-protocol", "ant-registers", "ant-service-management", @@ -959,10 +957,10 @@ dependencies = [ name = "ant-node-manager" version = "0.11.3" dependencies = [ + "ant-bootstrap", "ant-build-info", "ant-evm", "ant-logging", - "ant-peers-acquisition", "ant-protocol", "ant-releases", "ant-service-management", @@ -1005,7 +1003,6 @@ dependencies = [ "ant-build-info", "ant-logging", "ant-node", - "ant-peers-acquisition", "ant-protocol", "ant-service-management", "async-trait", @@ -1023,22 +1020,6 @@ dependencies = [ "tracing-core", ] -[[package]] -name = "ant-peers-acquisition" -version = "0.5.7" -dependencies = [ - "ant-protocol", - "clap", - "lazy_static", - "libp2p 0.54.1 (git+https://github.com/maqi/rust-libp2p.git?branch=kad_0.46.2)", - "rand 0.8.5", - "reqwest 0.12.9", - "thiserror 1.0.69", - "tokio", - "tracing", - "url", -] - [[package]] name = "ant-protocol" version = "0.17.15" @@ -1556,7 +1537,6 @@ dependencies = [ "ant-evm", "ant-logging", "ant-networking", - "ant-peers-acquisition", "ant-protocol", "ant-registers", "bip39", @@ -6586,10 +6566,10 @@ dependencies = [ name = "node-launchpad" version = "0.4.5" dependencies = [ + "ant-bootstrap", "ant-build-info", "ant-evm", "ant-node-manager", - "ant-peers-acquisition", "ant-protocol", "ant-releases", "ant-service-management", @@ -9594,7 +9574,6 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" name = "test-utils" version = "0.4.11" dependencies = [ - "ant-peers-acquisition", "bytes", "color-eyre", "dirs-next", diff --git a/Cargo.toml b/Cargo.toml index eeafdece63..6840a1e40d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ members = [ "ant-node", "ant-node-manager", "ant-node-rpc-client", - "ant-peers-acquisition", "ant-protocol", "ant-registers", "ant-service-management", diff --git a/Justfile b/Justfile index c80fcf1b1a..2eb3768d03 100644 --- a/Justfile +++ b/Justfile @@ -68,16 +68,16 @@ build-release-artifacts arch nightly="false": cargo binstall --no-confirm cross cross build --release --target $arch --bin nat-detection $nightly_feature cross build --release --target $arch --bin node-launchpad $nightly_feature - cross build --release --features network-contacts,websockets --target $arch --bin ant $nightly_feature - cross build --release --features network-contacts,websockets --target $arch --bin antnode $nightly_feature + cross build --release --features websockets --target $arch --bin ant $nightly_feature + cross build --release --features websockets --target $arch --bin antnode $nightly_feature cross build --release --target $arch --bin antctl $nightly_feature cross build --release --target $arch --bin antctld $nightly_feature cross build --release --target $arch --bin antnode_rpc_client $nightly_feature else cargo build --release --target $arch --bin nat-detection $nightly_feature cargo build --release --target $arch --bin node-launchpad $nightly_feature - cargo build --release --features network-contacts,websockets --target $arch --bin ant $nightly_feature - cargo build --release --features network-contacts,websockets --target $arch --bin antnode $nightly_feature + cargo build --release --features websockets --target $arch --bin ant $nightly_feature + cargo build --release --features websockets --target $arch --bin antnode $nightly_feature cargo build --release --target $arch --bin antctl $nightly_feature cargo build --release --target $arch --bin antctld $nightly_feature cargo build --release --target $arch --bin antnode_rpc_client $nightly_feature diff --git a/README.md b/README.md index 014ea96496..bac5d08181 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ You should build from the `stable` branch, as follows: ``` git checkout stable -cargo build --release --features network-contacts --bin antnode +cargo build --release --bin antnode ``` #### Running the Node @@ -40,23 +40,12 @@ cargo build --release --features network-contacts --bin antnode To run a node and receive rewards, you need to specify your Ethereum address as a parameter. Rewards are paid to the specified address. ``` -cargo run --release --bin antnode --features network-contacts -- --rewards-address +cargo run --release --bin antnode -- --rewards-address ``` More options about EVM Network below. ### For Developers - -#### Build - -You can build `autonomi` and `antnode` with the `network-contacts` feature: - -``` -cargo build --release --features network-contacts --bin autonomi -cargo build --release --features network-contacts --bin antnode -``` - - #### Main Crates - [Autonomi API](https://github.com/maidsafe/autonomi/blob/main/autonomi/README.md) The client APIs @@ -97,8 +86,8 @@ WASM support for the autonomi API is currently under active development. More do used by the autonomi network. - [Registers](https://github.com/maidsafe/autonomi/blob/main/ant-registers/README.md) The registers crate, used for the Register CRDT data type on the network. -- [Peers Acquisition](https://github.com/maidsafe/autonomi/blob/main/ant-peers-acquisition/README.md) - The peers acquisition crate, or: how the network layer discovers bootstrap peers. +- [Bootstrap](https://github.com/maidsafe/autonomi/blob/main/ant-bootstrap/README.md) + The network bootstrap cache or: how the network layer discovers bootstrap peers. - [Build Info](https://github.com/maidsafe/autonomi/blob/main/ant-build-info/README.md) Small helper used to get the build/commit versioning info for debug purposes. diff --git a/ant-cli/Cargo.toml b/ant-cli/Cargo.toml index 05cbd82eac..e7752bde9e 100644 --- a/ant-cli/Cargo.toml +++ b/ant-cli/Cargo.toml @@ -15,9 +15,8 @@ path = "src/main.rs" [features] default = ["metrics"] -local = ["ant-peers-acquisition/local", "autonomi/local"] +local = ["ant-bootstrap/local", "autonomi/local"] metrics = ["ant-logging/process-metrics"] -network-contacts = ["ant-peers-acquisition/network-contacts"] websockets = ["autonomi/websockets"] [[bench]] @@ -28,7 +27,6 @@ harness = false ant-bootstrap = { path = "../ant-bootstrap", version = "0.1.0" } ant-build-info = { path = "../ant-build-info", version = "0.1.19" } ant-logging = { path = "../ant-logging", version = "0.2.40" } -ant-peers-acquisition = { path = "../ant-peers-acquisition", version = "0.5.7" } autonomi = { path = "../autonomi", version = "0.2.4", features = [ "data", "fs", diff --git a/ant-cli/src/main.rs b/ant-cli/src/main.rs index cbab96d8fc..b50092e538 100644 --- a/ant-cli/src/main.rs +++ b/ant-cli/src/main.rs @@ -51,6 +51,7 @@ async fn main() -> Result<()> { fn init_logging_and_metrics(opt: &Opt) -> Result<(ReloadHandle, Option)> { let logging_targets = vec![ + ("ant_bootstrap".to_string(), Level::DEBUG), ("ant_build_info".to_string(), Level::TRACE), ("ant_evm".to_string(), Level::TRACE), ("ant_networking".to_string(), Level::INFO), @@ -59,7 +60,6 @@ fn init_logging_and_metrics(opt: &Opt) -> Result<(ReloadHandle, Option Result> ("ant_logging".to_string(), Level::TRACE), ("ant_node_manager".to_string(), Level::TRACE), ("ant_node_rpc_client".to_string(), Level::TRACE), - ("ant_peers_acquisition".to_string(), Level::TRACE), ("ant_protocol".to_string(), Level::TRACE), ("ant_registers".to_string(), Level::INFO), ("ant_service_management".to_string(), Level::TRACE), diff --git a/ant-node-manager/Cargo.toml b/ant-node-manager/Cargo.toml index 94857697b6..50029846c3 100644 --- a/ant-node-manager/Cargo.toml +++ b/ant-node-manager/Cargo.toml @@ -21,7 +21,6 @@ path = "src/bin/daemon/main.rs" chaos = [] default = ["quic"] local = [] -network-contacts = [] nightly = [] open-metrics = [] otlp = [] @@ -31,10 +30,10 @@ tcp = [] websockets = [] [dependencies] +ant-bootstrap = { path = "../ant-bootstrap", version = "0.1.0" } ant-build-info = { path = "../ant-build-info", version = "0.1.19" } ant-evm = { path = "../ant-evm", version = "0.1.4" } ant-logging = { path = "../ant-logging", version = "0.2.40" } -ant-peers-acquisition = { path = "../ant-peers-acquisition", version = "0.5.7" } ant-protocol = { path = "../ant-protocol", version = "0.17.15" } ant-releases = { git = "https://github.com/jacderida/ant-releases.git", branch = "chore-rename_binaries" } ant-service-management = { path = "../ant-service-management", version = "0.4.3" } diff --git a/ant-node-manager/src/bin/cli/main.rs b/ant-node-manager/src/bin/cli/main.rs index 1e40d20589..eee22641e3 100644 --- a/ant-node-manager/src/bin/cli/main.rs +++ b/ant-node-manager/src/bin/cli/main.rs @@ -9,6 +9,7 @@ mod subcommands; use crate::subcommands::evm_network::EvmNetworkCommand; +use ant_bootstrap::PeersArgs; use ant_evm::RewardsAddress; use ant_logging::{LogBuilder, LogFormat}; use ant_node_manager::{ @@ -16,7 +17,6 @@ use ant_node_manager::{ cmd::{self}, VerbosityLevel, DEFAULT_NODE_STARTUP_CONNECTION_TIMEOUT_S, }; -use ant_peers_acquisition::PeersArgs; use clap::{Parser, Subcommand}; use color_eyre::{eyre::eyre, Result}; use libp2p::Multiaddr; @@ -1381,9 +1381,9 @@ async fn main() -> Result<()> { fn get_log_builder(level: Level) -> Result { let logging_targets = vec![ + ("ant_bootstrap".to_string(), level), ("evmlib".to_string(), level), ("evm-testnet".to_string(), level), - ("ant_peers_acquisition".to_string(), level), ("ant_node_manager".to_string(), level), ("antctl".to_string(), level), ("antctld".to_string(), level), diff --git a/ant-node-manager/src/cmd/auditor.rs b/ant-node-manager/src/cmd/auditor.rs index 92061c1e20..764656d3cc 100644 --- a/ant-node-manager/src/cmd/auditor.rs +++ b/ant-node-manager/src/cmd/auditor.rs @@ -10,7 +10,7 @@ use crate::{ config::{self, is_running_as_root}, print_banner, ServiceManager, VerbosityLevel, }; -use ant_peers_acquisition::PeersArgs; +use ant_bootstrap::PeersArgs; use ant_service_management::{auditor::AuditorService, control::ServiceController, NodeRegistry}; use color_eyre::{eyre::eyre, Result}; use std::path::PathBuf; diff --git a/ant-node-manager/src/cmd/faucet.rs b/ant-node-manager/src/cmd/faucet.rs index d598aed62b..053c3727ac 100644 --- a/ant-node-manager/src/cmd/faucet.rs +++ b/ant-node-manager/src/cmd/faucet.rs @@ -10,7 +10,7 @@ use crate::{ config::{self, is_running_as_root}, print_banner, ServiceManager, VerbosityLevel, }; -use ant_peers_acquisition::PeersArgs; +use ant_bootstrap::PeersArgs; use ant_service_management::{control::ServiceController, FaucetService, NodeRegistry}; use color_eyre::{eyre::eyre, Result}; use std::path::PathBuf; diff --git a/ant-node-manager/src/cmd/local.rs b/ant-node-manager/src/cmd/local.rs index f83c6e3d4c..f28f37d206 100644 --- a/ant-node-manager/src/cmd/local.rs +++ b/ant-node-manager/src/cmd/local.rs @@ -14,9 +14,9 @@ use crate::{ local::{kill_network, run_network, LocalNetworkOptions}, print_banner, status_report, VerbosityLevel, }; +use ant_bootstrap::PeersArgs; use ant_evm::{EvmNetwork, RewardsAddress}; use ant_logging::LogFormat; -use ant_peers_acquisition::PeersArgs; use ant_releases::{AntReleaseRepoActions, ReleaseType}; use ant_service_management::{ control::ServiceController, get_local_node_registry_path, NodeRegistry, @@ -72,10 +72,10 @@ pub async fn join( // If no peers are obtained we will attempt to join the existing local network, if one // is running. - let peers = match peers_args.get_peers().await { + let peers = match peers_args.get_addrs().await { Ok(peers) => Some(peers), Err(err) => match err { - ant_peers_acquisition::error::Error::PeersNotObtained => { + ant_bootstrap::error::Error::NoBootstrapPeersFound => { warn!("PeersNotObtained, peers is set to None"); None } diff --git a/ant-node-manager/src/cmd/mod.rs b/ant-node-manager/src/cmd/mod.rs index 7a77e81678..45138e640d 100644 --- a/ant-node-manager/src/cmd/mod.rs +++ b/ant-node-manager/src/cmd/mod.rs @@ -184,9 +184,6 @@ fn build_binary(bin_type: &ReleaseType) -> Result { if cfg!(feature = "local") { args.extend(["--features", "local"]); } - if cfg!(feature = "network-contacts") { - args.extend(["--features", "network-contacts"]); - } if cfg!(feature = "websockets") { args.extend(["--features", "websockets"]); } diff --git a/ant-node-manager/src/cmd/nat_detection.rs b/ant-node-manager/src/cmd/nat_detection.rs index afe2d442dd..b43238513f 100644 --- a/ant-node-manager/src/cmd/nat_detection.rs +++ b/ant-node-manager/src/cmd/nat_detection.rs @@ -9,7 +9,7 @@ use crate::{ config::get_node_registry_path, helpers::download_and_extract_release, VerbosityLevel, }; -use ant_peers_acquisition::get_peers_from_url; +use ant_bootstrap::ContactsFetcher; use ant_releases::{AntReleaseRepoActions, ReleaseType}; use ant_service_management::{NatDetectionStatus, NodeRegistry}; use color_eyre::eyre::{bail, OptionExt, Result}; @@ -35,7 +35,11 @@ pub async fn run_nat_detection( let servers = match servers { Some(servers) => servers, None => { - let servers = get_peers_from_url(NAT_DETECTION_SERVERS_LIST_URL.parse()?).await?; + let mut contacts_fetcher = ContactsFetcher::new()?; + contacts_fetcher.ignore_peer_id(true); + contacts_fetcher.insert_endpoint(NAT_DETECTION_SERVERS_LIST_URL.parse()?); + + let servers = contacts_fetcher.fetch_addrs().await?; servers .choose_multiple(&mut rand::thread_rng(), 10) diff --git a/ant-node-manager/src/cmd/node.rs b/ant-node-manager/src/cmd/node.rs index 59a04ddc11..f4f6b67a48 100644 --- a/ant-node-manager/src/cmd/node.rs +++ b/ant-node-manager/src/cmd/node.rs @@ -18,9 +18,9 @@ use crate::{ helpers::{download_and_extract_release, get_bin_version}, print_banner, refresh_node_registry, status_report, ServiceManager, VerbosityLevel, }; +use ant_bootstrap::PeersArgs; use ant_evm::{EvmNetwork, RewardsAddress}; use ant_logging::LogFormat; -use ant_peers_acquisition::PeersArgs; use ant_releases::{AntReleaseRepoActions, ReleaseType}; use ant_service_management::{ control::{ServiceControl, ServiceController}, @@ -117,13 +117,13 @@ pub async fn add( // If the `antnode` binary we're using has `network-contacts` enabled (which is the case for released binaries), // it's fine if the service definition doesn't call `antnode` with a `--peer` argument. let is_first = peers_args.first; - let bootstrap_peers = match peers_args.get_peers_exclude_network_contacts().await { + let bootstrap_peers = match peers_args.get_addrs().await { Ok(peers) => { info!("Obtained peers of length {}", peers.len()); - peers + peers.into_iter().take(10).collect::>() } Err(err) => match err { - ant_peers_acquisition::error::Error::PeersNotObtained => { + ant_bootstrap::error::Error::NoBootstrapPeersFound => { info!("No bootstrap peers obtained, setting empty vec."); Vec::new() } diff --git a/ant-node-rpc-client/Cargo.toml b/ant-node-rpc-client/Cargo.toml index 057ed08492..c34db03215 100644 --- a/ant-node-rpc-client/Cargo.toml +++ b/ant-node-rpc-client/Cargo.toml @@ -19,7 +19,6 @@ nightly = [] [dependencies] ant-build-info = { path = "../ant-build-info", version = "0.1.19" } ant-logging = { path = "../ant-logging", version = "0.2.40" } -ant-peers-acquisition = { path = "../ant-peers-acquisition", version = "0.5.7" } ant-protocol = { path = "../ant-protocol", version = "0.17.15", features=["rpc"] } ant-node = { path = "../ant-node", version = "0.112.6" } ant-service-management = { path = "../ant-service-management", version = "0.4.3" } diff --git a/ant-node/Cargo.toml b/ant-node/Cargo.toml index 283dc940a3..8daa19b30e 100644 --- a/ant-node/Cargo.toml +++ b/ant-node/Cargo.toml @@ -17,10 +17,9 @@ path = "src/bin/antnode/main.rs" default = ["metrics", "upnp", "open-metrics", "encrypt-records"] encrypt-records = ["ant-networking/encrypt-records"] extension-module = ["pyo3/extension-module"] -local = ["ant-networking/local", "ant-evm/local"] +local = ["ant-networking/local", "ant-evm/local", "ant-bootstrap/local"] loud = ["ant-networking/loud"] # loud mode: print important messages to console metrics = ["ant-logging/process-metrics"] -network-contacts = ["ant-peers-acquisition/network-contacts"] nightly = [] open-metrics = ["ant-networking/open-metrics", "prometheus-client"] otlp = ["ant-logging/otlp"] @@ -33,7 +32,6 @@ ant-build-info = { path = "../ant-build-info", version = "0.1.19" } ant-evm = { path = "../ant-evm", version = "0.1.4" } ant-logging = { path = "../ant-logging", version = "0.2.40" } ant-networking = { path = "../ant-networking", version = "0.19.5" } -ant-peers-acquisition = { path = "../ant-peers-acquisition", version = "0.5.7" } ant-protocol = { path = "../ant-protocol", version = "0.17.15" } ant-registers = { path = "../ant-registers", version = "0.4.3" } ant-service-management = { path = "../ant-service-management", version = "0.4.3" } diff --git a/ant-node/src/bin/antnode/main.rs b/ant-node/src/bin/antnode/main.rs index caae71685f..bfaa2b8aae 100644 --- a/ant-node/src/bin/antnode/main.rs +++ b/ant-node/src/bin/antnode/main.rs @@ -548,12 +548,12 @@ fn monitor_node_events(mut node_events_rx: NodeEventsReceiver, ctrl_tx: mpsc::Se fn init_logging(opt: &Opt, peer_id: PeerId) -> Result<(String, ReloadHandle, Option)> { let logging_targets = vec![ + ("ant_bootstrap".to_string(), Level::INFO), ("ant_build_info".to_string(), Level::DEBUG), ("ant_evm".to_string(), Level::DEBUG), ("ant_logging".to_string(), Level::DEBUG), ("ant_networking".to_string(), Level::INFO), ("ant_node".to_string(), Level::DEBUG), - ("ant_peers_acquisition".to_string(), Level::DEBUG), ("ant_protocol".to_string(), Level::DEBUG), ("ant_registers".to_string(), Level::DEBUG), ("antnode".to_string(), Level::DEBUG), diff --git a/ant-peers-acquisition/Cargo.toml b/ant-peers-acquisition/Cargo.toml deleted file mode 100644 index 660b55b3e6..0000000000 --- a/ant-peers-acquisition/Cargo.toml +++ /dev/null @@ -1,31 +0,0 @@ -[package] -authors = ["MaidSafe Developers "] -description = "Peer acquisition utilities" -edition = "2021" -homepage = "https://maidsafe.net" -license = "GPL-3.0" -name = "ant-peers-acquisition" -readme = "README.md" -repository = "https://github.com/maidsafe/autonomi" -version = "0.5.7" - -[features] -default = ["network-contacts"] -local = [] -network-contacts = ["ant-protocol"] -websockets = [] - -[dependencies] -ant-protocol = { path = "../ant-protocol", version = "0.17.15", optional = true} -clap = { version = "4.2.1", features = ["derive", "env"] } -lazy_static = "~1.4.0" -libp2p = { git = "https://github.com/maqi/rust-libp2p.git", branch = "kad_0.46.2", features = [] } -rand = "0.8.5" -reqwest = { version="0.12.2", default-features=false, features = ["rustls-tls"] } -thiserror = "1.0.23" -tokio = { version = "1.32.0", default-features = false } -tracing = { version = "~0.1.26" } -url = { version = "2.4.0" } - -[lints] -workspace = true diff --git a/ant-peers-acquisition/README.md b/ant-peers-acquisition/README.md deleted file mode 100644 index 6c409a9103..0000000000 --- a/ant-peers-acquisition/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# ant_peers_acquisition - -Provides utilities for discovering bootstrap peers on a given system. - -It handles `--peer` arguments across all bins, as well as `ANT_PEERS` or indeed picking up an initial set of `network-conacts` from a provided, or hard-coded url. diff --git a/ant-peers-acquisition/src/error.rs b/ant-peers-acquisition/src/error.rs deleted file mode 100644 index d5df7c969b..0000000000 --- a/ant-peers-acquisition/src/error.rs +++ /dev/null @@ -1,19 +0,0 @@ -use thiserror::Error; - -pub type Result = std::result::Result; - -#[derive(Debug, Error)] -pub enum Error { - #[error("Could not parse the supplied multiaddr or socket address")] - InvalidPeerAddr(#[from] libp2p::multiaddr::Error), - #[error("Could not obtain network contacts from {0} after {1} retries")] - FailedToObtainPeersFromUrl(String, usize), - #[error("No valid multaddr was present in the contacts file at {0}")] - NoMultiAddrObtainedFromNetworkContacts(String), - #[error("Could not obtain peers through any available options")] - PeersNotObtained, - #[error(transparent)] - ReqwestError(#[from] reqwest::Error), - #[error(transparent)] - UrlParseError(#[from] url::ParseError), -} diff --git a/ant-peers-acquisition/src/lib.rs b/ant-peers-acquisition/src/lib.rs deleted file mode 100644 index da613e97ad..0000000000 --- a/ant-peers-acquisition/src/lib.rs +++ /dev/null @@ -1,242 +0,0 @@ -// Copyright 2024 MaidSafe.net limited. -// -// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. -// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed -// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. Please review the Licences for the specific language governing -// permissions and limitations relating to use of the SAFE Network Software. - -pub mod error; - -use crate::error::{Error, Result}; -use clap::Args; -#[cfg(feature = "network-contacts")] -use lazy_static::lazy_static; -use libp2p::{multiaddr::Protocol, Multiaddr}; -use rand::{seq::SliceRandom, thread_rng}; -use reqwest::Client; -use std::time::Duration; -use tracing::*; -use url::Url; - -#[cfg(feature = "network-contacts")] -lazy_static! { - // URL containing the multi-addresses of the bootstrap nodes. - pub static ref NETWORK_CONTACTS_URL: String = - "https://sn-testnet.s3.eu-west-2.amazonaws.com/network-contacts".to_string(); -} - -// The maximum number of retries to be performed while trying to get peers from a URL. -const MAX_RETRIES_ON_GET_PEERS_FROM_URL: usize = 7; - -/// The name of the environment variable that can be used to pass peers to the node. -pub const ANT_PEERS_ENV: &str = "ANT_PEERS"; - -#[derive(Args, Debug, Default, Clone)] -pub struct PeersArgs { - /// Set to indicate this is the first node in a new network - /// - /// If this argument is used, any others will be ignored because they do not apply to the first - /// node. - #[clap(long)] - pub first: bool, - /// Peer(s) to use for bootstrap, in a 'multiaddr' format containing the peer ID. - /// - /// A multiaddr looks like - /// '/ip4/1.2.3.4/tcp/1200/tcp/p2p/12D3KooWRi6wF7yxWLuPSNskXc6kQ5cJ6eaymeMbCRdTnMesPgFx' where - /// `1.2.3.4` is the IP, `1200` is the port and the (optional) last part is the peer ID. - /// - /// This argument can be provided multiple times to connect to multiple peers. - /// - /// Alternatively, the `ANT_PEERS` environment variable can provide a comma-separated peer - /// list. - #[clap(long = "peer", env = "ANT_PEERS", value_name = "multiaddr", value_delimiter = ',', value_parser = parse_peer_addr, conflicts_with = "first")] - pub peers: Vec, - - /// Specify the URL to fetch the network contacts from. - /// - /// This argument will be overridden if the "peers" argument is set or if the `local` - /// feature flag is enabled. - #[cfg(feature = "network-contacts")] - #[clap(long, conflicts_with = "first")] - pub network_contacts_url: Option, -} - -impl PeersArgs { - /// Gets the peers based on the arguments provided. - /// - /// If the `--first` flag is used, no peers will be provided. - /// - /// Otherwise, peers are obtained in the following order of precedence: - /// * The `--peer` argument. - /// * The `ANT_PEERS` environment variable. - /// * Using the `local` feature, which will return an empty peer list. - /// * Using the `network-contacts` feature, which will download the peer list from a file on S3. - /// - /// Note: the current behaviour is that `--peer` and `ANT_PEERS` will be combined. Some tests - /// currently rely on this. We will change it soon. - pub async fn get_peers(self) -> Result> { - self.get_peers_inner(false).await - } - - /// Gets the peers based on the arguments provided. - /// - /// If the `--first` flag is used, no peers will be provided. - /// - /// Otherwise, peers are obtained in the following order of precedence: - /// * The `--peer` argument. - /// * The `ANT_PEERS` environment variable. - /// * Using the `local` feature, which will return an empty peer list. - /// - /// This will not fetch the peers from network-contacts even if the `network-contacts` feature is enabled. Use - /// get_peers() instead. - /// - /// Note: the current behaviour is that `--peer` and `ANT_PEERS` will be combined. Some tests - /// currently rely on this. We will change it soon. - pub async fn get_peers_exclude_network_contacts(self) -> Result> { - self.get_peers_inner(true).await - } - - async fn get_peers_inner(self, skip_network_contacts: bool) -> Result> { - if self.first { - info!("First node in a new network"); - return Ok(vec![]); - } - - let mut peers = if !self.peers.is_empty() { - info!("Using peers supplied with the --peer argument(s) or ANT_PEERS"); - self.peers - } else if cfg!(feature = "local") { - info!("No peers given"); - info!("The `local` feature is enabled, so peers will be discovered through mDNS."); - return Ok(vec![]); - } else if skip_network_contacts { - info!("Skipping network contacts"); - return Ok(vec![]); - } else if cfg!(feature = "network-contacts") { - self.get_network_contacts().await? - } else { - vec![] - }; - - if peers.is_empty() { - error!("Peers not obtained through any available options"); - return Err(Error::PeersNotObtained); - }; - - // Randomly sort peers before we return them to avoid overly hitting any one peer - let mut rng = thread_rng(); - peers.shuffle(&mut rng); - - Ok(peers) - } - - // should not be reachable, but needed for the compiler to be happy. - #[expect(clippy::unused_async)] - #[cfg(not(feature = "network-contacts"))] - async fn get_network_contacts(&self) -> Result> { - Ok(vec![]) - } - - #[cfg(feature = "network-contacts")] - async fn get_network_contacts(&self) -> Result> { - let url = self - .network_contacts_url - .clone() - .unwrap_or(Url::parse(NETWORK_CONTACTS_URL.as_str())?); - - info!("Trying to fetch the bootstrap peers from {url}"); - - get_peers_from_url(url).await - } -} - -/// Parse strings like `1.2.3.4:1234` and `/ip4/1.2.3.4/tcp/1234` into a multiaddr. -pub fn parse_peer_addr(addr: &str) -> std::result::Result { - // Parse valid IPv4 socket address, e.g. `1.2.3.4:1234`. - if let Ok(addr) = addr.parse::() { - let start_addr = Multiaddr::from(*addr.ip()); - - // Turn the address into a `/ip4//udp//quic-v1` multiaddr. - #[cfg(not(feature = "websockets"))] - let multiaddr = start_addr - .with(Protocol::Udp(addr.port())) - .with(Protocol::QuicV1); - - // Turn the address into a `/ip4//udp//websocket-websys-v1` multiaddr. - #[cfg(feature = "websockets")] - let multiaddr = start_addr - .with(Protocol::Tcp(addr.port())) - .with(Protocol::Ws("/".into())); - - return Ok(multiaddr); - } - - // Parse any valid multiaddr string - addr.parse::() -} - -/// Get and parse a list of peers from a URL. The URL should contain one multiaddr per line. -pub async fn get_peers_from_url(url: Url) -> Result> { - let mut retries = 0; - - #[cfg(not(target_arch = "wasm32"))] - let request_client = Client::builder().timeout(Duration::from_secs(10)).build()?; - // Wasm does not have the timeout method yet. - #[cfg(target_arch = "wasm32")] - let request_client = Client::builder().build()?; - - loop { - let response = request_client.get(url.clone()).send().await; - - match response { - Ok(response) => { - let mut multi_addresses = Vec::new(); - if response.status().is_success() { - let text = response.text().await?; - trace!("Got peers from url: {url}: {text}"); - // example of contacts file exists in resources/network-contacts-examples - for addr in text.split('\n') { - // ignore empty/last lines - if addr.is_empty() { - continue; - } - - debug!("Attempting to parse {addr}"); - multi_addresses.push(parse_peer_addr(addr)?); - } - if !multi_addresses.is_empty() { - trace!("Successfully got peers from URL {multi_addresses:?}"); - return Ok(multi_addresses); - } else { - return Err(Error::NoMultiAddrObtainedFromNetworkContacts( - url.to_string(), - )); - } - } else { - retries += 1; - if retries >= MAX_RETRIES_ON_GET_PEERS_FROM_URL { - return Err(Error::FailedToObtainPeersFromUrl( - url.to_string(), - MAX_RETRIES_ON_GET_PEERS_FROM_URL, - )); - } - } - } - Err(err) => { - error!("Failed to get peers from URL {url}: {err:?}"); - retries += 1; - if retries >= MAX_RETRIES_ON_GET_PEERS_FROM_URL { - return Err(Error::FailedToObtainPeersFromUrl( - url.to_string(), - MAX_RETRIES_ON_GET_PEERS_FROM_URL, - )); - } - } - } - trace!( - "Failed to get peers from URL, retrying {retries}/{MAX_RETRIES_ON_GET_PEERS_FROM_URL}" - ); - tokio::time::sleep(Duration::from_secs(1)).await; - } -} diff --git a/autonomi/Cargo.toml b/autonomi/Cargo.toml index 88d61c711a..2c2b4a7c79 100644 --- a/autonomi/Cargo.toml +++ b/autonomi/Cargo.toml @@ -29,7 +29,6 @@ websockets = ["ant-networking/websockets"] [dependencies] ant-evm = { path = "../ant-evm", version = "0.1.4" } ant-networking = { path = "../ant-networking", version = "0.19.5" } -ant-peers-acquisition = { path = "../ant-peers-acquisition", version = "0.5.7" } ant-protocol = { version = "0.17.15", path = "../ant-protocol" } ant-registers = { path = "../ant-registers", version = "0.4.3" } bip39 = "2.0.0" @@ -63,7 +62,6 @@ xor_name = "5.0.0" [dev-dependencies] alloy = { version = "0.5.3", default-features = false, features = ["std", "reqwest-rustls-tls", "provider-anvil-node", "sol-types", "json", "signers", "contract", "signer-local", "network"] } ant-logging = { path = "../ant-logging", version = "0.2.40" } -ant-peers-acquisition = { path = "../ant-peers-acquisition", version = "0.5.7" } eyre = "0.6.5" sha2 = "0.10.6" # Do not specify the version field. Release process expects even the local dev deps to be published. diff --git a/node-launchpad/Cargo.toml b/node-launchpad/Cargo.toml index 4e488880a2..23926653e0 100644 --- a/node-launchpad/Cargo.toml +++ b/node-launchpad/Cargo.toml @@ -18,10 +18,10 @@ path = "src/bin/tui/main.rs" nightly = [] [dependencies] +ant-bootstrap = { path = "../ant-bootstrap", version = "0.1.0" } ant-build-info = { path = "../ant-build-info", version = "0.1.19" } ant-evm = { path = "../ant-evm", version = "0.1.4" } ant-node-manager = { version = "0.11.3", path = "../ant-node-manager" } -ant-peers-acquisition = { version = "0.5.7", path = "../ant-peers-acquisition" } ant-protocol = { path = "../ant-protocol", version = "0.17.15" } ant-releases = { git = "https://github.com/jacderida/ant-releases.git", branch = "chore-rename_binaries" } ant-service-management = { version = "0.4.3", path = "../ant-service-management" } diff --git a/node-launchpad/src/app.rs b/node-launchpad/src/app.rs index 40124f4d3f..605c51efd3 100644 --- a/node-launchpad/src/app.rs +++ b/node-launchpad/src/app.rs @@ -29,7 +29,7 @@ use crate::{ system::{get_default_mount_point, get_primary_mount_point, get_primary_mount_point_name}, tui, }; -use ant_peers_acquisition::PeersArgs; +use ant_bootstrap::PeersArgs; use color_eyre::eyre::Result; use crossterm::event::KeyEvent; use ratatui::{prelude::Rect, style::Style, widgets::Block}; @@ -317,7 +317,7 @@ impl App { #[cfg(test)] mod tests { use super::*; - use ant_peers_acquisition::PeersArgs; + use ant_bootstrap::PeersArgs; use color_eyre::eyre::Result; use std::io::Cursor; use std::io::Write; diff --git a/node-launchpad/src/bin/tui/main.rs b/node-launchpad/src/bin/tui/main.rs index f2f28af40b..969e2c811a 100644 --- a/node-launchpad/src/bin/tui/main.rs +++ b/node-launchpad/src/bin/tui/main.rs @@ -11,9 +11,9 @@ mod terminal; #[macro_use] extern crate tracing; +use ant_bootstrap::PeersArgs; #[cfg(target_os = "windows")] use ant_node_manager::config::is_running_as_root; -use ant_peers_acquisition::PeersArgs; use clap::Parser; use color_eyre::eyre::Result; use node_launchpad::{ diff --git a/node-launchpad/src/components/status.rs b/node-launchpad/src/components/status.rs index 02e39a54ad..1899bbd9bc 100644 --- a/node-launchpad/src/components/status.rs +++ b/node-launchpad/src/components/status.rs @@ -31,9 +31,9 @@ use crate::{ clear_area, EUCALYPTUS, GHOST_WHITE, LIGHT_PERIWINKLE, VERY_LIGHT_AZURE, VIVID_SKY_BLUE, }, }; +use ant_bootstrap::PeersArgs; use ant_node_manager::add_services::config::PortRange; use ant_node_manager::config::get_node_registry_path; -use ant_peers_acquisition::PeersArgs; use ant_service_management::{ control::ServiceController, NodeRegistry, NodeServiceData, ServiceStatus, }; diff --git a/node-launchpad/src/node_mgmt.rs b/node-launchpad/src/node_mgmt.rs index 788c2991fa..49fd1c1b32 100644 --- a/node-launchpad/src/node_mgmt.rs +++ b/node-launchpad/src/node_mgmt.rs @@ -1,10 +1,10 @@ use crate::action::{Action, StatusActions}; use crate::connection_mode::ConnectionMode; +use ant_bootstrap::PeersArgs; use ant_evm::{EvmNetwork, RewardsAddress}; use ant_node_manager::{ add_services::config::PortRange, config::get_node_registry_path, VerbosityLevel, }; -use ant_peers_acquisition::PeersArgs; use ant_releases::{self, AntReleaseRepoActions, ReleaseType}; use ant_service_management::NodeRegistry; use color_eyre::eyre::{eyre, Error}; diff --git a/node-launchpad/src/utils.rs b/node-launchpad/src/utils.rs index 15dc6b085e..9defb101e5 100644 --- a/node-launchpad/src/utils.rs +++ b/node-launchpad/src/utils.rs @@ -81,8 +81,12 @@ pub fn initialize_logging() -> Result<()> { .context(format!("Failed to create file {log_path:?}"))?; std::env::set_var( "RUST_LOG", - std::env::var("RUST_LOG") - .unwrap_or_else(|_| format!("{}=trace,ant_node_manager=trace,ant_service_management=trace,ant_peers_acquisition=trace", env!("CARGO_CRATE_NAME"))), + std::env::var("RUST_LOG").unwrap_or_else(|_| { + format!( + "{}=trace,ant_node_manager=trace,ant_service_management=trace,ant_bootstrap=debug", + env!("CARGO_CRATE_NAME") + ) + }), ); let file_subscriber = tracing_subscriber::fmt::layer() .with_file(true) diff --git a/test-utils/Cargo.toml b/test-utils/Cargo.toml index 4d05fbfbb3..4124d37c3e 100644 --- a/test-utils/Cargo.toml +++ b/test-utils/Cargo.toml @@ -9,11 +9,7 @@ readme = "README.md" repository = "https://github.com/maidsafe/safe_network" version = "0.4.11" -[features] -local = ["ant-peers-acquisition/local"] - [dependencies] -ant-peers-acquisition = { path = "../ant-peers-acquisition", version = "0.5.7" } bytes = { version = "1.0.1", features = ["serde"] } color-eyre = "~0.6.2" dirs-next = "~2.0.0" diff --git a/test-utils/src/lib.rs b/test-utils/src/lib.rs index 5d3c57960a..68798d7864 100644 --- a/test-utils/src/lib.rs +++ b/test-utils/src/lib.rs @@ -9,7 +9,6 @@ pub mod evm; pub mod testnet; -use ant_peers_acquisition::parse_peer_addr; use bytes::Bytes; use color_eyre::eyre::Result; use libp2p::Multiaddr; @@ -39,10 +38,11 @@ pub fn gen_random_data(len: usize) -> Bytes { /// /// An empty `Vec` will be returned if the env var is not set or if local discovery is enabled. pub fn peers_from_env() -> Result> { - let bootstrap_peers = if cfg!(feature = "local") { - Ok(vec![]) - } else if let Some(peers_str) = env_from_runtime_or_compiletime!("ANT_PEERS") { - peers_str.split(',').map(parse_peer_addr).collect() + let bootstrap_peers = if let Some(peers_str) = env_from_runtime_or_compiletime!("ANT_PEERS") { + peers_str + .split(',') + .map(|str| str.parse::()) + .collect() } else { Ok(vec![]) }?;