Skip to content

Commit

Permalink
change initial_mainnet_peers and initial_testnet_peers type to `I…
Browse files Browse the repository at this point in the history
…ndexSet`
  • Loading branch information
oxarbitrage committed Jun 22, 2022
1 parent 257f017 commit 7adada8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions zebra-network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bytes = "1.1.0"
chrono = "0.4.19"
hex = "0.4.3"
humantime-serde = "1.1.1"
indexmap = "1.8.2"
lazy_static = "1.4.0"
ordered-map = "0.4.2"
pin-project = "1.0.10"
Expand Down
13 changes: 7 additions & 6 deletions zebra-network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::{
time::Duration,
};

use indexmap::IndexSet;
use serde::{de, Deserialize, Deserializer};

use zebra_chain::parameters::Network;
Expand Down Expand Up @@ -55,11 +56,11 @@ pub struct Config {

/// A list of initial peers for the peerset when operating on
/// mainnet.
pub initial_mainnet_peers: HashSet<String>,
pub initial_mainnet_peers: IndexSet<String>,

/// A list of initial peers for the peerset when operating on
/// testnet.
pub initial_testnet_peers: HashSet<String>,
pub initial_testnet_peers: IndexSet<String>,

/// The initial target size for the peer set.
///
Expand Down Expand Up @@ -127,7 +128,7 @@ impl Config {
}

/// Returns the initial seed peer hostnames for the configured network.
pub fn initial_peer_hostnames(&self) -> &HashSet<String> {
pub fn initial_peer_hostnames(&self) -> &IndexSet<String> {
match self.network {
Network::Mainnet => &self.initial_mainnet_peers,
Network::Testnet => &self.initial_testnet_peers,
Expand All @@ -136,7 +137,7 @@ impl Config {

/// Resolve initial seed peer IP addresses, based on the configured network.
pub async fn initial_peers(&self) -> HashSet<SocketAddr> {
Config::resolve_peers(self.initial_peer_hostnames()).await
Config::resolve_peers(&self.initial_peer_hostnames().iter().cloned().collect()).await
}

/// Concurrently resolves `peers` into zero or more IP addresses, with a
Expand Down Expand Up @@ -296,8 +297,8 @@ impl<'de> Deserialize<'de> for Config {
struct DConfig {
listen_addr: String,
network: Network,
initial_mainnet_peers: HashSet<String>,
initial_testnet_peers: HashSet<String>,
initial_mainnet_peers: IndexSet<String>,
initial_testnet_peers: IndexSet<String>,
peerset_initial_target_size: usize,
#[serde(alias = "new_peer_interval", with = "humantime_serde")]
crawl_new_peer_interval: Duration,
Expand Down
10 changes: 5 additions & 5 deletions zebra-network/src/peer_set/initialize/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
//! skip all the network tests by setting the `ZEBRA_SKIP_NETWORK_TESTS` environmental variable.
use std::{
collections::HashSet,
net::{Ipv4Addr, SocketAddr},
sync::Arc,
time::{Duration, Instant},
};

use chrono::Utc;
use futures::{channel::mpsc, FutureExt, StreamExt};
use indexmap::IndexSet;
use tokio::{net::TcpStream, task::JoinHandle};
use tower::{service_fn, Service};
use tracing::Span;
Expand Down Expand Up @@ -1137,7 +1137,7 @@ async fn add_initial_peers_deadlock() {
// Create a list of dummy IPs, and initialize a config using them as the
// initial peers. The amount of these peers will overflow
// `PEERSET_INITIAL_TARGET_SIZE`.
let mut peers = HashSet::new();
let mut peers = IndexSet::new();
for address_number in 0..PEER_COUNT {
peers.insert(
SocketAddr::new(Ipv4Addr::new(127, 1, 1, address_number as _).into(), 1).to_string(),
Expand Down Expand Up @@ -1173,8 +1173,8 @@ async fn local_listener_port_with(listen_addr: SocketAddr, network: Network) {
network,

// Stop Zebra making outbound connections
initial_mainnet_peers: HashSet::new(),
initial_testnet_peers: HashSet::new(),
initial_mainnet_peers: IndexSet::new(),
initial_testnet_peers: IndexSet::new(),

..Config::default()
};
Expand Down Expand Up @@ -1468,7 +1468,7 @@ where
{
// Create a list of dummy IPs and initialize a config using them as the
// initial peers.
let mut peers = HashSet::new();
let mut peers = IndexSet::new();
for address_number in 0..peer_count {
peers.insert(
SocketAddr::new(Ipv4Addr::new(127, 1, 1, address_number as _).into(), 1).to_string(),
Expand Down
7 changes: 4 additions & 3 deletions zebrad/src/components/inbound/tests/real_peer_set.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Inbound service tests with a real peer set.
use std::{collections::HashSet, iter, net::SocketAddr, sync::Arc};
use std::{iter, net::SocketAddr, sync::Arc};

use futures::FutureExt;
use indexmap::IndexSet;
use tokio::{sync::oneshot, task::JoinHandle};
use tower::{
buffer::Buffer,
Expand Down Expand Up @@ -655,8 +656,8 @@ async fn setup(
listen_addr: config_listen_addr,

// Stop Zebra making outbound connections
initial_mainnet_peers: HashSet::new(),
initial_testnet_peers: HashSet::new(),
initial_mainnet_peers: IndexSet::new(),
initial_testnet_peers: IndexSet::new(),

..NetworkConfig::default()
};
Expand Down
6 changes: 3 additions & 3 deletions zebrad/tests/common/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
//! This file is only for test library code.
use std::{
collections::HashSet,
env,
net::SocketAddr,
path::{Path, PathBuf},
time::Duration,
};

use color_eyre::eyre::Result;
use indexmap::IndexSet;

use zebra_chain::parameters::Network;
use zebra_test::{
Expand Down Expand Up @@ -201,8 +201,8 @@ pub fn spawn_zebrad_for_rpc_without_initial_peers<P: ZebradTestDirExt>(
.expect("Failed to create a config file with a known RPC listener port");

config.state.ephemeral = false;
config.network.initial_mainnet_peers = HashSet::new();
config.network.initial_testnet_peers = HashSet::new();
config.network.initial_mainnet_peers = IndexSet::new();
config.network.initial_testnet_peers = IndexSet::new();
config.network.network = network;
config.mempool.debug_enable_at_height = Some(0);

Expand Down

0 comments on commit 7adada8

Please sign in to comment.