converted zebra-network -- all crate tests pass
This commit is contained in:
parent
7e539ae0c1
commit
08ed2f3145
|
@ -138,7 +138,7 @@ impl AddressBook {
|
|||
/// Uses the supplied [`tracing::Span`] for address book operations.
|
||||
pub fn new(
|
||||
local_listener: SocketAddr,
|
||||
network: Network,
|
||||
network: &Network,
|
||||
max_connections_per_ip: usize,
|
||||
span: Span,
|
||||
) -> AddressBook {
|
||||
|
@ -157,7 +157,7 @@ impl AddressBook {
|
|||
let mut new_book = AddressBook {
|
||||
by_addr: OrderedMap::new(|meta_addr| Reverse(*meta_addr)),
|
||||
local_listener: canonical_socket_addr(local_listener),
|
||||
network,
|
||||
network: network.clone(),
|
||||
addr_limit: constants::MAX_ADDRS_IN_ADDRESS_BOOK,
|
||||
span,
|
||||
address_metrics_tx,
|
||||
|
@ -183,7 +183,7 @@ impl AddressBook {
|
|||
#[cfg(any(test, feature = "proptest-impl"))]
|
||||
pub fn new_with_addrs(
|
||||
local_listener: SocketAddr,
|
||||
network: Network,
|
||||
network: &Network,
|
||||
max_connections_per_ip: usize,
|
||||
addr_limit: usize,
|
||||
span: Span,
|
||||
|
@ -293,7 +293,7 @@ impl AddressBook {
|
|||
// Then sanitize and shuffle
|
||||
let mut peers: Vec<MetaAddr> = peers
|
||||
.descending_values()
|
||||
.filter_map(|meta_addr| meta_addr.sanitize(self.network))
|
||||
.filter_map(|meta_addr| meta_addr.sanitize(&self.network))
|
||||
// # Security
|
||||
//
|
||||
// Remove peers that:
|
||||
|
@ -431,7 +431,7 @@ impl AddressBook {
|
|||
if let Some(updated) = updated {
|
||||
// Ignore invalid outbound addresses.
|
||||
// (Inbound connections can be monitored via Zebra's metrics.)
|
||||
if !updated.address_is_valid_for_outbound(self.network) {
|
||||
if !updated.address_is_valid_for_outbound(&self.network) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
@ -440,7 +440,7 @@ impl AddressBook {
|
|||
//
|
||||
// Otherwise, if we got the info directly from the peer,
|
||||
// store it in the address book, so we know not to reconnect.
|
||||
if !updated.last_known_info_is_valid_for_outbound(self.network)
|
||||
if !updated.last_known_info_is_valid_for_outbound(&self.network)
|
||||
&& updated.last_connection_state.is_never_attempted()
|
||||
{
|
||||
return None;
|
||||
|
@ -598,7 +598,7 @@ impl AddressBook {
|
|||
self.by_addr
|
||||
.descending_values()
|
||||
.filter(move |peer| {
|
||||
peer.is_ready_for_connection_attempt(instant_now, chrono_now, self.network)
|
||||
peer.is_ready_for_connection_attempt(instant_now, chrono_now, &self.network)
|
||||
&& self.is_ready_for_connection_attempt_with_ip(&peer.addr.ip(), chrono_now)
|
||||
})
|
||||
.cloned()
|
||||
|
@ -630,7 +630,7 @@ impl AddressBook {
|
|||
self.by_addr
|
||||
.descending_values()
|
||||
.filter(move |peer| {
|
||||
!peer.is_ready_for_connection_attempt(instant_now, chrono_now, self.network)
|
||||
!peer.is_ready_for_connection_attempt(instant_now, chrono_now, &self.network)
|
||||
})
|
||||
.cloned()
|
||||
}
|
||||
|
@ -800,7 +800,7 @@ impl Clone for AddressBook {
|
|||
AddressBook {
|
||||
by_addr: self.by_addr.clone(),
|
||||
local_listener: self.local_listener,
|
||||
network: self.network,
|
||||
network: self.network.clone(),
|
||||
addr_limit: self.addr_limit,
|
||||
span: self.span.clone(),
|
||||
address_metrics_tx,
|
||||
|
|
|
@ -32,7 +32,7 @@ proptest! {
|
|||
|
||||
let address_book = AddressBook::new_with_addrs(
|
||||
local_listener,
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
MAX_ADDRS_IN_ADDRESS_BOOK,
|
||||
Span::none(),
|
||||
|
@ -71,7 +71,7 @@ proptest! {
|
|||
|
||||
let address_book = AddressBook::new_with_addrs(
|
||||
local_listener,
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
MAX_ADDRS_IN_ADDRESS_BOOK,
|
||||
Span::none(),
|
||||
|
@ -110,7 +110,7 @@ proptest! {
|
|||
|
||||
let mut address_book = AddressBook::new_with_addrs(
|
||||
local_listener,
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
addr_limit,
|
||||
Span::none(),
|
||||
|
@ -133,7 +133,7 @@ proptest! {
|
|||
|
||||
let mut address_book = AddressBook::new_with_addrs(
|
||||
local_listener,
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
addr_limit,
|
||||
Span::none(),
|
||||
|
|
|
@ -22,7 +22,7 @@ use crate::{
|
|||
fn address_book_empty() {
|
||||
let address_book = AddressBook::new(
|
||||
"0.0.0.0:0".parse().unwrap(),
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
Span::current(),
|
||||
);
|
||||
|
@ -54,7 +54,7 @@ fn address_book_peer_order() {
|
|||
let addrs = vec![meta_addr1, meta_addr2];
|
||||
let address_book = AddressBook::new_with_addrs(
|
||||
"0.0.0.0:0".parse().unwrap(),
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
MAX_ADDRS_IN_ADDRESS_BOOK,
|
||||
Span::current(),
|
||||
|
@ -71,7 +71,7 @@ fn address_book_peer_order() {
|
|||
let addrs = vec![meta_addr2, meta_addr1];
|
||||
let address_book = AddressBook::new_with_addrs(
|
||||
"0.0.0.0:0".parse().unwrap(),
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
MAX_ADDRS_IN_ADDRESS_BOOK,
|
||||
Span::current(),
|
||||
|
@ -91,7 +91,7 @@ fn address_book_peer_order() {
|
|||
let addrs = vec![meta_addr1, meta_addr2];
|
||||
let address_book = AddressBook::new_with_addrs(
|
||||
"0.0.0.0:0".parse().unwrap(),
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
MAX_ADDRS_IN_ADDRESS_BOOK,
|
||||
Span::current(),
|
||||
|
@ -108,7 +108,7 @@ fn address_book_peer_order() {
|
|||
let addrs = vec![meta_addr2, meta_addr1];
|
||||
let address_book = AddressBook::new_with_addrs(
|
||||
"0.0.0.0:0".parse().unwrap(),
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
MAX_ADDRS_IN_ADDRESS_BOOK,
|
||||
Span::current(),
|
||||
|
@ -163,7 +163,7 @@ fn test_reconnection_peers_skips_recently_updated_ip<
|
|||
let addrs = vec![meta_addr1, meta_addr2];
|
||||
let address_book = AddressBook::new_with_addrs(
|
||||
"0.0.0.0:0".parse().unwrap(),
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
MAX_ADDRS_IN_ADDRESS_BOOK,
|
||||
Span::current(),
|
||||
|
|
|
@ -56,7 +56,7 @@ impl AddressBookUpdater {
|
|||
|
||||
let address_book = AddressBook::new(
|
||||
local_listener,
|
||||
config.network,
|
||||
&config.network,
|
||||
config.max_connections_per_ip,
|
||||
span!(Level::TRACE, "address book"),
|
||||
);
|
||||
|
|
|
@ -381,7 +381,7 @@ impl Config {
|
|||
|
||||
/// Returns the addresses in the peer list cache file, if available.
|
||||
pub async fn load_peer_cache(&self) -> io::Result<HashSet<PeerSocketAddr>> {
|
||||
let Some(peer_cache_file) = self.cache_dir.peer_cache_file_path(self.network) else {
|
||||
let Some(peer_cache_file) = self.cache_dir.peer_cache_file_path(&self.network) else {
|
||||
return Ok(HashSet::new());
|
||||
};
|
||||
|
||||
|
@ -457,7 +457,7 @@ impl Config {
|
|||
/// Atomic writes avoid corrupting the cache if Zebra panics or crashes, or if multiple Zebra
|
||||
/// instances try to read and write the same cache file.
|
||||
pub async fn update_peer_cache(&self, peer_list: HashSet<PeerSocketAddr>) -> io::Result<()> {
|
||||
let Some(peer_cache_file) = self.cache_dir.peer_cache_file_path(self.network) else {
|
||||
let Some(peer_cache_file) = self.cache_dir.peer_cache_file_path(&self.network) else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ impl CacheDir {
|
|||
}
|
||||
|
||||
/// Returns the peer cache file path for `network`, if enabled.
|
||||
pub fn peer_cache_file_path(&self, network: Network) -> Option<PathBuf> {
|
||||
pub fn peer_cache_file_path(&self, network: &Network) -> Option<PathBuf> {
|
||||
Some(
|
||||
self.cache_dir()?
|
||||
.join("network")
|
||||
|
|
|
@ -395,8 +395,8 @@ lazy_static! {
|
|||
pub static ref INITIAL_MIN_NETWORK_PROTOCOL_VERSION: HashMap<Network, Version> = {
|
||||
let mut hash_map = HashMap::new();
|
||||
|
||||
hash_map.insert(Mainnet, Version::min_specified_for_upgrade(Mainnet, Nu5));
|
||||
hash_map.insert(Testnet, Version::min_specified_for_upgrade(Testnet, Nu5));
|
||||
hash_map.insert(Mainnet, Version::min_specified_for_upgrade(&Mainnet, Nu5));
|
||||
hash_map.insert(Testnet, Version::min_specified_for_upgrade(&Testnet, Nu5));
|
||||
|
||||
hash_map
|
||||
};
|
||||
|
|
|
@ -47,7 +47,7 @@ mod tests;
|
|||
///
|
||||
/// - `user_agent`: a valid BIP14 user-agent, e.g., the empty string.
|
||||
pub fn connect_isolated<PeerTransport>(
|
||||
network: Network,
|
||||
network: &Network,
|
||||
data_stream: PeerTransport,
|
||||
user_agent: String,
|
||||
) -> impl Future<Output = Result<Client, BoxError>>
|
||||
|
@ -74,7 +74,7 @@ where
|
|||
/// This function can make the isolated connection send different responses to peers,
|
||||
/// which makes it stand out from other isolated connections from other peers.
|
||||
pub fn connect_isolated_with_inbound<PeerTransport, InboundService>(
|
||||
network: Network,
|
||||
network: &Network,
|
||||
data_stream: PeerTransport,
|
||||
user_agent: String,
|
||||
inbound_service: InboundService,
|
||||
|
@ -86,7 +86,7 @@ where
|
|||
InboundService::Future: Send,
|
||||
{
|
||||
let config = Config {
|
||||
network,
|
||||
network: network.clone(),
|
||||
..Config::default()
|
||||
};
|
||||
|
||||
|
@ -125,7 +125,7 @@ where
|
|||
///
|
||||
/// Prefer `connect_isolated_tor` if available.
|
||||
pub fn connect_isolated_tcp_direct(
|
||||
network: Network,
|
||||
network: &Network,
|
||||
addr: impl Into<PeerSocketAddr>,
|
||||
user_agent: String,
|
||||
) -> impl Future<Output = Result<Client, BoxError>> {
|
||||
|
@ -145,7 +145,7 @@ pub fn connect_isolated_tcp_direct(
|
|||
/// This function can make the isolated connection send different responses to peers,
|
||||
/// which makes it stand out from other isolated connections from other peers.
|
||||
pub fn connect_isolated_tcp_direct_with_inbound<InboundService>(
|
||||
network: Network,
|
||||
network: &Network,
|
||||
addr: impl Into<PeerSocketAddr>,
|
||||
user_agent: String,
|
||||
inbound_service: InboundService,
|
||||
|
@ -156,10 +156,11 @@ where
|
|||
InboundService::Future: Send,
|
||||
{
|
||||
let addr = addr.into();
|
||||
let network = network.clone();
|
||||
|
||||
tokio::net::TcpStream::connect(*addr)
|
||||
.err_into()
|
||||
.and_then(move |tcp_stream| {
|
||||
connect_isolated_with_inbound(network, tcp_stream, user_agent, inbound_service)
|
||||
connect_isolated_with_inbound(&network, tcp_stream, user_agent, inbound_service)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -40,15 +40,17 @@ async fn connect_isolated_sends_anonymised_version_message_tcp_net(network: Netw
|
|||
// Connection errors are detected using the JoinHandle.
|
||||
// (They might also make the test hang.)
|
||||
let mut outbound_join_handle = tokio::spawn(connect_isolated_tcp_direct(
|
||||
network,
|
||||
&network,
|
||||
listen_addr,
|
||||
"".to_string(),
|
||||
));
|
||||
|
||||
let (inbound_conn, _) = listener.accept().await.unwrap();
|
||||
|
||||
let mut inbound_stream =
|
||||
Framed::new(inbound_conn, Codec::builder().for_network(network).finish());
|
||||
let mut inbound_stream = Framed::new(
|
||||
inbound_conn,
|
||||
Codec::builder().for_network(&network).finish(),
|
||||
);
|
||||
|
||||
check_version_message(network, &mut inbound_stream).await;
|
||||
|
||||
|
@ -90,11 +92,11 @@ async fn connect_isolated_sends_anonymised_version_message_mem_net(network: Netw
|
|||
let (inbound_stream, outbound_stream) = tokio::io::duplex(1024);
|
||||
|
||||
let mut outbound_join_handle =
|
||||
tokio::spawn(connect_isolated(network, outbound_stream, "".to_string()));
|
||||
tokio::spawn(connect_isolated(&network, outbound_stream, "".to_string()));
|
||||
|
||||
let mut inbound_stream = Framed::new(
|
||||
inbound_stream,
|
||||
Codec::builder().for_network(network).finish(),
|
||||
Codec::builder().for_network(&network).finish(),
|
||||
);
|
||||
|
||||
check_version_message(network, &mut inbound_stream).await;
|
||||
|
|
|
@ -559,7 +559,7 @@ impl MetaAddr {
|
|||
&self,
|
||||
instant_now: Instant,
|
||||
chrono_now: chrono::DateTime<Utc>,
|
||||
network: Network,
|
||||
network: &Network,
|
||||
) -> bool {
|
||||
self.last_known_info_is_valid_for_outbound(network)
|
||||
&& !self.was_recently_updated(instant_now, chrono_now)
|
||||
|
@ -571,8 +571,8 @@ impl MetaAddr {
|
|||
///
|
||||
/// Since the addresses in the address book are unique, this check can be
|
||||
/// used to permanently reject entire [`MetaAddr`]s.
|
||||
pub fn address_is_valid_for_outbound(&self, network: Network) -> bool {
|
||||
address_is_valid_for_outbound_connections(self.addr, network).is_ok()
|
||||
pub fn address_is_valid_for_outbound(&self, network: &Network) -> bool {
|
||||
address_is_valid_for_outbound_connections(self.addr, network.clone()).is_ok()
|
||||
}
|
||||
|
||||
/// Is the last known information for this peer valid for outbound
|
||||
|
@ -582,7 +582,7 @@ impl MetaAddr {
|
|||
/// only be used to:
|
||||
/// - reject `NeverAttempted...` [`MetaAddrChange`]s, and
|
||||
/// - temporarily stop outbound connections to a [`MetaAddr`].
|
||||
pub fn last_known_info_is_valid_for_outbound(&self, network: Network) -> bool {
|
||||
pub fn last_known_info_is_valid_for_outbound(&self, network: &Network) -> bool {
|
||||
let is_node = match self.services {
|
||||
Some(services) => services.contains(PeerServices::NODE_NETWORK),
|
||||
None => true,
|
||||
|
@ -627,7 +627,7 @@ impl MetaAddr {
|
|||
///
|
||||
/// Returns `None` if this `MetaAddr` should not be sent to remote peers.
|
||||
#[allow(clippy::unwrap_in_result)]
|
||||
pub fn sanitize(&self, network: Network) -> Option<MetaAddr> {
|
||||
pub fn sanitize(&self, network: &Network) -> Option<MetaAddr> {
|
||||
if !self.last_known_info_is_valid_for_outbound(network) {
|
||||
return None;
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ impl MetaAddrChange {
|
|||
|(addr, services, local_now)| {
|
||||
let addr = MetaAddr::new_gossiped_meta_addr(addr, services, local_now);
|
||||
|
||||
if addr.last_known_info_is_valid_for_outbound(Mainnet) {
|
||||
if addr.last_known_info_is_valid_for_outbound(&Mainnet) {
|
||||
Some(addr.addr.port())
|
||||
} else {
|
||||
None
|
||||
|
|
|
@ -42,9 +42,9 @@ proptest! {
|
|||
fn sanitize_avoids_leaks(addr in MetaAddr::arbitrary()) {
|
||||
let _init_guard = zebra_test::init();
|
||||
|
||||
if let Some(sanitized) = addr.sanitize(Mainnet) {
|
||||
if let Some(sanitized) = addr.sanitize(&Mainnet) {
|
||||
// check that all sanitized addresses are valid for outbound
|
||||
prop_assert!(addr.last_known_info_is_valid_for_outbound(Mainnet));
|
||||
prop_assert!(addr.last_known_info_is_valid_for_outbound(&Mainnet));
|
||||
// also check the address, port, and services individually
|
||||
prop_assert!(!addr.addr.ip().is_unspecified());
|
||||
prop_assert_ne!(addr.addr.port(), 0);
|
||||
|
@ -117,7 +117,7 @@ proptest! {
|
|||
let mut attempt_count: usize = 0;
|
||||
|
||||
for change in changes {
|
||||
while addr.is_ready_for_connection_attempt(instant_now, chrono_now, Mainnet) {
|
||||
while addr.is_ready_for_connection_attempt(instant_now, chrono_now, &Mainnet) {
|
||||
// Simulate an attempt
|
||||
addr = if let Some(addr) = MetaAddr::new_reconnect(addr.addr)
|
||||
.apply_to_meta_addr(addr, instant_now, chrono_now) {
|
||||
|
@ -158,7 +158,7 @@ proptest! {
|
|||
|
||||
let address_book = AddressBook::new_with_addrs(
|
||||
local_listener,
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
MAX_ADDRS_IN_ADDRESS_BOOK,
|
||||
Span::none(),
|
||||
|
@ -176,7 +176,7 @@ proptest! {
|
|||
// regardless of where they have come from
|
||||
prop_assert_eq!(
|
||||
book_sanitized_local_listener.cloned(),
|
||||
expected_local_listener.sanitize(Mainnet),
|
||||
expected_local_listener.sanitize(&Mainnet),
|
||||
"address book: {:?}, sanitized_addrs: {:?}, canonical_local_listener: {:?}",
|
||||
address_book,
|
||||
sanitized_addrs,
|
||||
|
@ -217,7 +217,7 @@ proptest! {
|
|||
// Check address book update - return value
|
||||
let mut address_book = AddressBook::new_with_addrs(
|
||||
local_listener,
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
1,
|
||||
Span::none(),
|
||||
|
@ -229,8 +229,8 @@ proptest! {
|
|||
let book_contents: Vec<MetaAddr> = address_book.peers().collect();
|
||||
|
||||
// Ignore the same addresses that the address book ignores
|
||||
let expected_result = if !expected_result.address_is_valid_for_outbound(Mainnet)
|
||||
|| ( !expected_result.last_known_info_is_valid_for_outbound(Mainnet)
|
||||
let expected_result = if !expected_result.address_is_valid_for_outbound(&Mainnet)
|
||||
|| ( !expected_result.last_known_info_is_valid_for_outbound(&Mainnet)
|
||||
&& expected_result.last_connection_state.is_never_attempted())
|
||||
{
|
||||
None
|
||||
|
@ -323,7 +323,7 @@ proptest! {
|
|||
|
||||
// Only put valid addresses in the address book.
|
||||
// This means some tests will start with an empty address book.
|
||||
let addrs = if addr.last_known_info_is_valid_for_outbound(Mainnet) {
|
||||
let addrs = if addr.last_known_info_is_valid_for_outbound(&Mainnet) {
|
||||
Some(addr)
|
||||
} else {
|
||||
None
|
||||
|
@ -331,7 +331,7 @@ proptest! {
|
|||
|
||||
let address_book = Arc::new(std::sync::Mutex::new(AddressBook::new_with_addrs(
|
||||
SocketAddr::from_str("0.0.0.0:0").unwrap(),
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
MAX_ADDRS_IN_ADDRESS_BOOK,
|
||||
Span::none(),
|
||||
|
@ -371,7 +371,7 @@ proptest! {
|
|||
LIVE_PEER_INTERVALS,
|
||||
overall_test_time,
|
||||
peer_change_interval,
|
||||
addr.last_known_info_is_valid_for_outbound(Mainnet),
|
||||
addr.last_known_info_is_valid_for_outbound(&Mainnet),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -438,7 +438,7 @@ proptest! {
|
|||
let addr = addrs.entry(addr.addr).or_insert(*addr);
|
||||
let change = changes.get(change_index);
|
||||
|
||||
while addr.is_ready_for_connection_attempt(instant_now, chrono_now, Mainnet) {
|
||||
while addr.is_ready_for_connection_attempt(instant_now, chrono_now, &Mainnet) {
|
||||
// Simulate an attempt
|
||||
*addr = if let Some(addr) = MetaAddr::new_reconnect(addr.addr)
|
||||
.apply_to_meta_addr(*addr, instant_now, chrono_now) {
|
||||
|
|
|
@ -48,10 +48,10 @@ fn sanitize_extremes() {
|
|||
last_connection_state: Default::default(),
|
||||
};
|
||||
|
||||
if let Some(min_sanitized) = min_time_entry.sanitize(Mainnet) {
|
||||
if let Some(min_sanitized) = min_time_entry.sanitize(&Mainnet) {
|
||||
check::sanitize_avoids_leaks(&min_time_entry, &min_sanitized);
|
||||
}
|
||||
if let Some(max_sanitized) = max_time_entry.sanitize(Mainnet) {
|
||||
if let Some(max_sanitized) = max_time_entry.sanitize(&Mainnet) {
|
||||
check::sanitize_avoids_leaks(&max_time_entry, &max_sanitized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -515,8 +515,8 @@ where
|
|||
let user_agent = self.user_agent.unwrap_or_default();
|
||||
let our_services = self.our_services.unwrap_or_else(PeerServices::empty);
|
||||
let relay = self.relay.unwrap_or(false);
|
||||
let network = config.network;
|
||||
let minimum_peer_version = MinimumPeerVersion::new(self.latest_chain_tip, network);
|
||||
let network = config.network.clone();
|
||||
let minimum_peer_version = MinimumPeerVersion::new(self.latest_chain_tip, &network);
|
||||
|
||||
Ok(Handshake {
|
||||
config,
|
||||
|
@ -898,7 +898,7 @@ where
|
|||
let mut peer_conn = Framed::new(
|
||||
data_stream,
|
||||
Codec::builder()
|
||||
.for_network(config.network)
|
||||
.for_network(&config.network)
|
||||
.with_metrics_addr_label(connected_addr.get_transient_addr_label())
|
||||
.finish(),
|
||||
);
|
||||
|
|
|
@ -35,9 +35,9 @@ where
|
|||
{
|
||||
/// Create a new [`MinimumPeerVersion`] to track the minimum supported peer protocol version
|
||||
/// for the current `chain_tip` on the `network`.
|
||||
pub fn new(chain_tip: C, network: Network) -> Self {
|
||||
pub fn new(chain_tip: C, network: &Network) -> Self {
|
||||
MinimumPeerVersion {
|
||||
network,
|
||||
network: network.clone(),
|
||||
chain_tip,
|
||||
current_minimum: Version::min_remote_for_height(network, None),
|
||||
has_changed: true,
|
||||
|
@ -72,7 +72,7 @@ where
|
|||
/// has changed.
|
||||
fn update(&mut self) {
|
||||
let height = self.chain_tip.best_tip_height();
|
||||
let new_minimum = Version::min_remote_for_height(self.network, height);
|
||||
let new_minimum = Version::min_remote_for_height(&self.network, height);
|
||||
|
||||
if self.current_minimum != new_minimum {
|
||||
self.current_minimum = new_minimum;
|
||||
|
@ -99,7 +99,7 @@ where
|
|||
{
|
||||
fn clone(&self) -> Self {
|
||||
MinimumPeerVersion {
|
||||
network: self.network,
|
||||
network: self.network.clone(),
|
||||
chain_tip: self.chain_tip.clone(),
|
||||
current_minimum: self.current_minimum,
|
||||
has_changed: true,
|
||||
|
|
|
@ -13,7 +13,7 @@ use super::MinimumPeerVersion;
|
|||
mod prop;
|
||||
|
||||
impl MinimumPeerVersion<MockChainTip> {
|
||||
pub fn with_mock_chain_tip(network: Network) -> (Self, MockChainTipSender) {
|
||||
pub fn with_mock_chain_tip(network: &Network) -> (Self, MockChainTipSender) {
|
||||
let (chain_tip, best_tip) = MockChainTip::new();
|
||||
let minimum_peer_version = MinimumPeerVersion::new(chain_tip, network);
|
||||
|
||||
|
|
|
@ -12,11 +12,11 @@ proptest! {
|
|||
block_height in any::<Option<block::Height>>(),
|
||||
) {
|
||||
let (mut minimum_peer_version, best_tip) =
|
||||
MinimumPeerVersion::with_mock_chain_tip(network);
|
||||
MinimumPeerVersion::with_mock_chain_tip(&network);
|
||||
|
||||
best_tip.send_best_tip_height(block_height);
|
||||
|
||||
let expected_minimum_version = Version::min_remote_for_height(network, block_height);
|
||||
let expected_minimum_version = Version::min_remote_for_height(&network, block_height);
|
||||
|
||||
prop_assert_eq!(minimum_peer_version.current(), expected_minimum_version);
|
||||
}
|
||||
|
@ -28,12 +28,12 @@ proptest! {
|
|||
block_heights in any::<Vec<Option<block::Height>>>(),
|
||||
) {
|
||||
let (mut minimum_peer_version, best_tip) =
|
||||
MinimumPeerVersion::with_mock_chain_tip(network);
|
||||
MinimumPeerVersion::with_mock_chain_tip(&network);
|
||||
|
||||
for block_height in block_heights {
|
||||
best_tip.send_best_tip_height(block_height);
|
||||
|
||||
let expected_minimum_version = Version::min_remote_for_height(network, block_height);
|
||||
let expected_minimum_version = Version::min_remote_for_height(&network, block_height);
|
||||
|
||||
prop_assert_eq!(minimum_peer_version.current(), expected_minimum_version);
|
||||
}
|
||||
|
@ -46,9 +46,9 @@ proptest! {
|
|||
block_height_updates in any::<Vec<Option<Option<block::Height>>>>(),
|
||||
) {
|
||||
let (mut minimum_peer_version, best_tip) =
|
||||
MinimumPeerVersion::with_mock_chain_tip(network);
|
||||
MinimumPeerVersion::with_mock_chain_tip(&network);
|
||||
|
||||
let mut current_minimum_version = Version::min_remote_for_height(network, None);
|
||||
let mut current_minimum_version = Version::min_remote_for_height(&network, None);
|
||||
let mut expected_minimum_version = Some(current_minimum_version);
|
||||
|
||||
prop_assert_eq!(minimum_peer_version.changed(), expected_minimum_version);
|
||||
|
@ -57,7 +57,7 @@ proptest! {
|
|||
if let Some(new_block_height) = update {
|
||||
best_tip.send_best_tip_height(new_block_height);
|
||||
|
||||
let new_minimum_version = Version::min_remote_for_height(network, new_block_height);
|
||||
let new_minimum_version = Version::min_remote_for_height(&network, new_block_height);
|
||||
|
||||
expected_minimum_version = if new_minimum_version != current_minimum_version {
|
||||
Some(new_minimum_version)
|
||||
|
|
|
@ -71,7 +71,7 @@ proptest! {
|
|||
});
|
||||
|
||||
// Since the address book is empty, there won't be any available peers
|
||||
let address_book = AddressBook::new(SocketAddr::from_str("0.0.0.0:0").unwrap(), Mainnet, DEFAULT_MAX_CONNS_PER_IP, Span::none());
|
||||
let address_book = AddressBook::new(SocketAddr::from_str("0.0.0.0:0").unwrap(), &Mainnet, DEFAULT_MAX_CONNS_PER_IP, Span::none());
|
||||
|
||||
let mut candidate_set = CandidateSet::new(Arc::new(std::sync::Mutex::new(address_book)), peer_service);
|
||||
|
||||
|
@ -113,7 +113,7 @@ proptest! {
|
|||
unreachable!("Mock peer service is never used");
|
||||
});
|
||||
|
||||
let mut address_book = AddressBook::new(SocketAddr::from_str("0.0.0.0:0").unwrap(), Mainnet, DEFAULT_MAX_CONNS_PER_IP, Span::none());
|
||||
let mut address_book = AddressBook::new(SocketAddr::from_str("0.0.0.0:0").unwrap(), &Mainnet, DEFAULT_MAX_CONNS_PER_IP, Span::none());
|
||||
address_book.extend(peers);
|
||||
|
||||
let mut candidate_set = CandidateSet::new(Arc::new(std::sync::Mutex::new(address_book)), peer_service);
|
||||
|
|
|
@ -140,7 +140,7 @@ fn candidate_set_updates_are_rate_limited() {
|
|||
|
||||
let address_book = AddressBook::new(
|
||||
SocketAddr::from_str("0.0.0.0:0").unwrap(),
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
Span::none(),
|
||||
);
|
||||
|
@ -186,7 +186,7 @@ fn candidate_set_update_after_update_initial_is_rate_limited() {
|
|||
|
||||
let address_book = AddressBook::new(
|
||||
SocketAddr::from_str("0.0.0.0:0").unwrap(),
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
Span::none(),
|
||||
);
|
||||
|
|
|
@ -174,7 +174,7 @@ where
|
|||
handle_rx,
|
||||
inv_receiver,
|
||||
address_metrics,
|
||||
MinimumPeerVersion::new(latest_chain_tip, config.network),
|
||||
MinimumPeerVersion::new(latest_chain_tip, &config.network),
|
||||
None,
|
||||
);
|
||||
let peer_set = Buffer::new(BoxService::new(peer_set), constants::PEERSET_BUFFER_SIZE);
|
||||
|
@ -436,7 +436,7 @@ async fn limit_initial_peers(
|
|||
// Filter out invalid initial peers, and prioritise valid peers for initial connections.
|
||||
// (This treats initial peers the same way we treat gossiped peers.)
|
||||
for peer_addr in all_peers {
|
||||
let preference = PeerPreference::new(peer_addr, config.network);
|
||||
let preference = PeerPreference::new(peer_addr, config.network.clone());
|
||||
|
||||
match preference {
|
||||
Ok(preference) => preferred_peers
|
||||
|
@ -499,7 +499,7 @@ async fn limit_initial_peers(
|
|||
pub(crate) async fn open_listener(config: &Config) -> (TcpListener, SocketAddr) {
|
||||
// Warn if we're configured using the wrong network port.
|
||||
if let Err(wrong_addr) =
|
||||
address_is_valid_for_inbound_listeners(config.listen_addr, config.network)
|
||||
address_is_valid_for_inbound_listeners(config.listen_addr, config.network.clone())
|
||||
{
|
||||
warn!(
|
||||
"We are configured with address {} on {:?}, but it could cause network issues. \
|
||||
|
|
|
@ -325,7 +325,7 @@ async fn written_peer_cache_can_be_read_manually() {
|
|||
assert!(
|
||||
!cached_peers.is_empty(),
|
||||
"unexpected empty peer cache from manual load: {:?}",
|
||||
config.cache_dir.peer_cache_file_path(config.network)
|
||||
config.cache_dir.peer_cache_file_path(&config.network)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -371,7 +371,7 @@ async fn written_peer_cache_is_automatically_read_on_startup() {
|
|||
assert!(
|
||||
approximate_cached_peer_count > 0,
|
||||
"unexpected empty address book using cache from previous instance: {:?}",
|
||||
config.cache_dir.peer_cache_file_path(config.network)
|
||||
config.cache_dir.peer_cache_file_path(&config.network)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -336,7 +336,7 @@ impl PeerSetGuard {
|
|||
.expect("Invalid local listener address");
|
||||
let address_book = AddressBook::new(
|
||||
local_listener,
|
||||
Network::Mainnet,
|
||||
&Network::Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
Span::none(),
|
||||
);
|
||||
|
@ -347,7 +347,7 @@ impl PeerSetGuard {
|
|||
|
||||
/// A pair of block height values, where one is before and the other is at or after an arbitrary
|
||||
/// network upgrade's activation height.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BlockHeightPairAcrossNetworkUpgrades {
|
||||
/// The network for which the block height values represent heights before and after an
|
||||
/// upgrade.
|
||||
|
|
|
@ -31,7 +31,7 @@ proptest! {
|
|||
let (runtime, _init_guard) = zebra_test::init_async();
|
||||
|
||||
let (mut minimum_peer_version, best_tip_height) =
|
||||
MinimumPeerVersion::with_mock_chain_tip(network);
|
||||
MinimumPeerVersion::with_mock_chain_tip(&network);
|
||||
|
||||
best_tip_height.send_best_tip_height(block_height);
|
||||
|
||||
|
@ -64,7 +64,7 @@ proptest! {
|
|||
let (runtime, _init_guard) = zebra_test::init_async();
|
||||
|
||||
let (mut minimum_peer_version, best_tip_height) =
|
||||
MinimumPeerVersion::with_mock_chain_tip(block_heights.network);
|
||||
MinimumPeerVersion::with_mock_chain_tip(&block_heights.network);
|
||||
|
||||
best_tip_height.send_best_tip_height(block_heights.before_upgrade);
|
||||
|
||||
|
@ -117,7 +117,7 @@ proptest! {
|
|||
// Get peers and handles
|
||||
let (discovered_peers, mut handles) = peer_versions.mock_peer_discovery();
|
||||
let (minimum_peer_version, _best_tip_height) =
|
||||
MinimumPeerVersion::with_mock_chain_tip(Network::Mainnet);
|
||||
MinimumPeerVersion::with_mock_chain_tip(&Network::Mainnet);
|
||||
|
||||
// Build a peerset
|
||||
runtime.block_on(async move {
|
||||
|
@ -193,7 +193,7 @@ proptest! {
|
|||
// Get peers and handles
|
||||
let (discovered_peers, mut handles) = peer_versions.mock_peer_discovery();
|
||||
let (minimum_peer_version, _best_tip_height) =
|
||||
MinimumPeerVersion::with_mock_chain_tip(Network::Mainnet);
|
||||
MinimumPeerVersion::with_mock_chain_tip(&Network::Mainnet);
|
||||
|
||||
runtime.block_on(async move {
|
||||
// Build a peerset
|
||||
|
@ -264,7 +264,7 @@ proptest! {
|
|||
// Get peers and handles
|
||||
let (discovered_peers, mut handles) = peer_versions.mock_peer_discovery();
|
||||
let (minimum_peer_version, _best_tip_height) =
|
||||
MinimumPeerVersion::with_mock_chain_tip(Network::Mainnet);
|
||||
MinimumPeerVersion::with_mock_chain_tip(&Network::Mainnet);
|
||||
|
||||
runtime.block_on(async move {
|
||||
// Build a peerset
|
||||
|
|
|
@ -25,7 +25,7 @@ fn peer_set_ready_single_connection() {
|
|||
// We are going to use just one peer version in this test
|
||||
let peer_versions = PeerVersions {
|
||||
peer_versions: vec![Version::min_specified_for_upgrade(
|
||||
Network::Mainnet,
|
||||
&Network::Mainnet,
|
||||
NetworkUpgrade::Nu5,
|
||||
)],
|
||||
};
|
||||
|
@ -37,7 +37,7 @@ fn peer_set_ready_single_connection() {
|
|||
// Get peers and client handles of them
|
||||
let (discovered_peers, handles) = peer_versions.mock_peer_discovery();
|
||||
let (minimum_peer_version, _best_tip_height) =
|
||||
MinimumPeerVersion::with_mock_chain_tip(Network::Mainnet);
|
||||
MinimumPeerVersion::with_mock_chain_tip(&Network::Mainnet);
|
||||
|
||||
// We will just use the first peer handle
|
||||
let mut client_handle = handles
|
||||
|
@ -118,7 +118,7 @@ fn peer_set_ready_single_connection() {
|
|||
#[test]
|
||||
fn peer_set_ready_multiple_connections() {
|
||||
// Use three peers with the same version
|
||||
let peer_version = Version::min_specified_for_upgrade(Network::Mainnet, NetworkUpgrade::Nu5);
|
||||
let peer_version = Version::min_specified_for_upgrade(&Network::Mainnet, NetworkUpgrade::Nu5);
|
||||
let peer_versions = PeerVersions {
|
||||
peer_versions: vec![peer_version, peer_version, peer_version],
|
||||
};
|
||||
|
@ -136,7 +136,7 @@ fn peer_set_ready_multiple_connections() {
|
|||
// Get peers and client handles of them
|
||||
let (discovered_peers, handles) = peer_versions.mock_peer_discovery();
|
||||
let (minimum_peer_version, _best_tip_height) =
|
||||
MinimumPeerVersion::with_mock_chain_tip(Network::Mainnet);
|
||||
MinimumPeerVersion::with_mock_chain_tip(&Network::Mainnet);
|
||||
|
||||
// Make sure we have the right number of peers
|
||||
assert_eq!(handles.len(), 3);
|
||||
|
@ -182,7 +182,7 @@ fn peer_set_rejects_connections_past_per_ip_limit() {
|
|||
const NUM_PEER_VERSIONS: usize = crate::constants::DEFAULT_MAX_CONNS_PER_IP + 1;
|
||||
|
||||
// Use three peers with the same version
|
||||
let peer_version = Version::min_specified_for_upgrade(Network::Mainnet, NetworkUpgrade::Nu5);
|
||||
let peer_version = Version::min_specified_for_upgrade(&Network::Mainnet, NetworkUpgrade::Nu5);
|
||||
let peer_versions = PeerVersions {
|
||||
peer_versions: [peer_version; NUM_PEER_VERSIONS].into_iter().collect(),
|
||||
};
|
||||
|
@ -200,7 +200,7 @@ fn peer_set_rejects_connections_past_per_ip_limit() {
|
|||
// Get peers and client handles of them
|
||||
let (discovered_peers, handles) = peer_versions.mock_peer_discovery();
|
||||
let (minimum_peer_version, _best_tip_height) =
|
||||
MinimumPeerVersion::with_mock_chain_tip(Network::Mainnet);
|
||||
MinimumPeerVersion::with_mock_chain_tip(&Network::Mainnet);
|
||||
|
||||
// Make sure we have the right number of peers
|
||||
assert_eq!(handles.len(), NUM_PEER_VERSIONS);
|
||||
|
@ -232,7 +232,7 @@ fn peer_set_route_inv_empty_registry() {
|
|||
let test_hash = block::Hash([0; 32]);
|
||||
|
||||
// Use two peers with the same version
|
||||
let peer_version = Version::min_specified_for_upgrade(Network::Mainnet, NetworkUpgrade::Nu5);
|
||||
let peer_version = Version::min_specified_for_upgrade(&Network::Mainnet, NetworkUpgrade::Nu5);
|
||||
let peer_versions = PeerVersions {
|
||||
peer_versions: vec![peer_version, peer_version],
|
||||
};
|
||||
|
@ -250,7 +250,7 @@ fn peer_set_route_inv_empty_registry() {
|
|||
// Get peers and client handles of them
|
||||
let (discovered_peers, handles) = peer_versions.mock_peer_discovery();
|
||||
let (minimum_peer_version, _best_tip_height) =
|
||||
MinimumPeerVersion::with_mock_chain_tip(Network::Mainnet);
|
||||
MinimumPeerVersion::with_mock_chain_tip(&Network::Mainnet);
|
||||
|
||||
// Make sure we have the right number of peers
|
||||
assert_eq!(handles.len(), 2);
|
||||
|
@ -315,7 +315,7 @@ fn peer_set_route_inv_advertised_registry_order(advertised_first: bool) {
|
|||
let test_change = InventoryStatus::new_available(test_inv, test_peer);
|
||||
|
||||
// Use two peers with the same version
|
||||
let peer_version = Version::min_specified_for_upgrade(Network::Mainnet, NetworkUpgrade::Nu5);
|
||||
let peer_version = Version::min_specified_for_upgrade(&Network::Mainnet, NetworkUpgrade::Nu5);
|
||||
let peer_versions = PeerVersions {
|
||||
peer_versions: vec![peer_version, peer_version],
|
||||
};
|
||||
|
@ -333,7 +333,7 @@ fn peer_set_route_inv_advertised_registry_order(advertised_first: bool) {
|
|||
// Get peers and client handles of them
|
||||
let (discovered_peers, mut handles) = peer_versions.mock_peer_discovery();
|
||||
let (minimum_peer_version, _best_tip_height) =
|
||||
MinimumPeerVersion::with_mock_chain_tip(Network::Mainnet);
|
||||
MinimumPeerVersion::with_mock_chain_tip(&Network::Mainnet);
|
||||
|
||||
// Make sure we have the right number of peers
|
||||
assert_eq!(handles.len(), 2);
|
||||
|
@ -423,7 +423,7 @@ fn peer_set_route_inv_missing_registry_order(missing_first: bool) {
|
|||
let test_change = InventoryStatus::new_missing(test_inv, test_peer);
|
||||
|
||||
// Use two peers with the same version
|
||||
let peer_version = Version::min_specified_for_upgrade(Network::Mainnet, NetworkUpgrade::Nu5);
|
||||
let peer_version = Version::min_specified_for_upgrade(&Network::Mainnet, NetworkUpgrade::Nu5);
|
||||
let peer_versions = PeerVersions {
|
||||
peer_versions: vec![peer_version, peer_version],
|
||||
};
|
||||
|
@ -441,7 +441,7 @@ fn peer_set_route_inv_missing_registry_order(missing_first: bool) {
|
|||
// Get peers and client handles of them
|
||||
let (discovered_peers, mut handles) = peer_versions.mock_peer_discovery();
|
||||
let (minimum_peer_version, _best_tip_height) =
|
||||
MinimumPeerVersion::with_mock_chain_tip(Network::Mainnet);
|
||||
MinimumPeerVersion::with_mock_chain_tip(&Network::Mainnet);
|
||||
|
||||
// Make sure we have the right number of peers
|
||||
assert_eq!(handles.len(), 2);
|
||||
|
@ -525,7 +525,7 @@ fn peer_set_route_inv_all_missing_fail() {
|
|||
let test_change = InventoryStatus::new_missing(test_inv, test_peer);
|
||||
|
||||
// Use one peer
|
||||
let peer_version = Version::min_specified_for_upgrade(Network::Mainnet, NetworkUpgrade::Nu5);
|
||||
let peer_version = Version::min_specified_for_upgrade(&Network::Mainnet, NetworkUpgrade::Nu5);
|
||||
let peer_versions = PeerVersions {
|
||||
peer_versions: vec![peer_version],
|
||||
};
|
||||
|
@ -543,7 +543,7 @@ fn peer_set_route_inv_all_missing_fail() {
|
|||
// Get the peer and its client handle
|
||||
let (discovered_peers, mut handles) = peer_versions.mock_peer_discovery();
|
||||
let (minimum_peer_version, _best_tip_height) =
|
||||
MinimumPeerVersion::with_mock_chain_tip(Network::Mainnet);
|
||||
MinimumPeerVersion::with_mock_chain_tip(&Network::Mainnet);
|
||||
|
||||
// Make sure we have the right number of peers
|
||||
assert_eq!(handles.len(), 1);
|
||||
|
|
|
@ -84,8 +84,8 @@ impl Builder {
|
|||
}
|
||||
|
||||
/// Configure the codec for the given [`Network`].
|
||||
pub fn for_network(mut self, network: Network) -> Self {
|
||||
self.network = network;
|
||||
pub fn for_network(mut self, network: &Network) -> Self {
|
||||
self.network = network.clone();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ proptest! {
|
|||
let _init_guard = zebra_test::init();
|
||||
|
||||
// We require sanitization before serialization
|
||||
let addr = addr.sanitize(Mainnet);
|
||||
let addr = addr.sanitize(&Mainnet);
|
||||
prop_assume!(addr.is_some());
|
||||
|
||||
let addr: AddrV1 = addr.unwrap().into();
|
||||
|
@ -115,7 +115,7 @@ proptest! {
|
|||
let _init_guard = zebra_test::init();
|
||||
|
||||
// We require sanitization before serialization
|
||||
let addr = addr.sanitize(Mainnet);
|
||||
let addr = addr.sanitize(&Mainnet);
|
||||
prop_assume!(addr.is_some());
|
||||
|
||||
let addr: AddrV1 = addr.unwrap().into();
|
||||
|
@ -153,7 +153,7 @@ proptest! {
|
|||
let _init_guard = zebra_test::init();
|
||||
|
||||
// We require sanitization before serialization
|
||||
let addr = addr.sanitize(Mainnet);
|
||||
let addr = addr.sanitize(&Mainnet);
|
||||
prop_assume!(addr.is_some());
|
||||
|
||||
let addr: AddrV2 = addr.unwrap().into();
|
||||
|
@ -172,7 +172,7 @@ proptest! {
|
|||
let _init_guard = zebra_test::init();
|
||||
|
||||
// We require sanitization before serialization
|
||||
let addr = addr.sanitize(Mainnet);
|
||||
let addr = addr.sanitize(&Mainnet);
|
||||
prop_assume!(addr.is_some());
|
||||
|
||||
let addr: AddrV2 = addr.unwrap().into();
|
||||
|
|
|
@ -111,7 +111,7 @@ proptest! {
|
|||
|
||||
// We require sanitization before serialization,
|
||||
// but we also need the original address for this test
|
||||
let sanitized_addr = addr.sanitize(Mainnet);
|
||||
let sanitized_addr = addr.sanitize(&Mainnet);
|
||||
prop_assume!(sanitized_addr.is_some());
|
||||
let sanitized_addr = sanitized_addr.unwrap();
|
||||
|
||||
|
@ -184,7 +184,7 @@ proptest! {
|
|||
|
||||
// We require sanitization before serialization,
|
||||
// but we also need the original address for this test
|
||||
let sanitized_addr = addr.sanitize(Mainnet);
|
||||
let sanitized_addr = addr.sanitize(&Mainnet);
|
||||
prop_assume!(sanitized_addr.is_some());
|
||||
let sanitized_addr = sanitized_addr.unwrap();
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ impl Version {
|
|||
///
|
||||
/// If we are incompatible with our own minimum remote protocol version.
|
||||
pub fn min_remote_for_height(
|
||||
network: Network,
|
||||
network: &Network,
|
||||
height: impl Into<Option<block::Height>>,
|
||||
) -> Version {
|
||||
let height = height.into().unwrap_or(block::Height(0));
|
||||
|
@ -78,7 +78,7 @@ impl Version {
|
|||
/// - during the initial block download,
|
||||
/// - after Zebra restarts, and
|
||||
/// - after Zebra's local network is slow or shut down.
|
||||
fn initial_min_for_network(network: Network) -> Version {
|
||||
fn initial_min_for_network(network: &Network) -> Version {
|
||||
*constants::INITIAL_MIN_NETWORK_PROTOCOL_VERSION
|
||||
.get(&network)
|
||||
.expect("We always have a value for testnet or mainnet")
|
||||
|
@ -88,7 +88,7 @@ impl Version {
|
|||
/// `height`.
|
||||
///
|
||||
/// This is the minimum peer version when Zebra is close to the current tip.
|
||||
fn min_specified_for_height(network: Network, height: block::Height) -> Version {
|
||||
fn min_specified_for_height(network: &Network, height: block::Height) -> Version {
|
||||
let network_upgrade = NetworkUpgrade::current(&network, height);
|
||||
Version::min_specified_for_upgrade(network, network_upgrade)
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ impl Version {
|
|||
/// Returns the minimum specified network protocol version for `network` and
|
||||
/// `network_upgrade`.
|
||||
pub(crate) fn min_specified_for_upgrade(
|
||||
network: Network,
|
||||
network: &Network,
|
||||
network_upgrade: NetworkUpgrade,
|
||||
) -> Version {
|
||||
// TODO: Should we reject earlier protocol versions during our initial
|
||||
|
@ -196,17 +196,17 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn version_extremes_mainnet() {
|
||||
version_extremes(Mainnet)
|
||||
version_extremes(&Mainnet)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_extremes_testnet() {
|
||||
version_extremes(Testnet)
|
||||
version_extremes(&Testnet)
|
||||
}
|
||||
|
||||
/// Test the min_specified_for_upgrade and min_specified_for_height functions for `network` with
|
||||
/// extreme values.
|
||||
fn version_extremes(network: Network) {
|
||||
fn version_extremes(network: &Network) {
|
||||
let _init_guard = zebra_test::init();
|
||||
|
||||
assert_eq!(
|
||||
|
@ -224,17 +224,17 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn version_consistent_mainnet() {
|
||||
version_consistent(Mainnet)
|
||||
version_consistent(&Mainnet)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_consistent_testnet() {
|
||||
version_consistent(Testnet)
|
||||
version_consistent(&Testnet)
|
||||
}
|
||||
|
||||
/// Check that the min_specified_for_upgrade and min_specified_for_height functions
|
||||
/// are consistent for `network`.
|
||||
fn version_consistent(network: Network) {
|
||||
fn version_consistent(network: &Network) {
|
||||
let _init_guard = zebra_test::init();
|
||||
|
||||
let highest_network_upgrade = NetworkUpgrade::current(&network, block::Height::MAX);
|
||||
|
|
|
@ -771,7 +771,7 @@ async fn caches_getaddr_response() {
|
|||
let state_config = StateConfig::ephemeral();
|
||||
let address_book = AddressBook::new_with_addrs(
|
||||
SocketAddr::from_str("0.0.0.0:0").unwrap(),
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
MAX_ADDRS_IN_ADDRESS_BOOK,
|
||||
Span::none(),
|
||||
|
@ -782,7 +782,7 @@ async fn caches_getaddr_response() {
|
|||
|
||||
// UTXO verification doesn't matter for these tests.
|
||||
let (state, _read_only_state_service, latest_chain_tip, _chain_tip_change) =
|
||||
zebra_state::init(state_config.clone(), network, Height::MAX, 0);
|
||||
zebra_state::init(state_config.clone(), &network, Height::MAX, 0);
|
||||
|
||||
let state_service = ServiceBuilder::new().buffer(1).service(state);
|
||||
|
||||
|
@ -882,7 +882,7 @@ async fn setup(
|
|||
let state_config = StateConfig::ephemeral();
|
||||
let address_book = AddressBook::new(
|
||||
SocketAddr::from_str("0.0.0.0:0").unwrap(),
|
||||
Mainnet,
|
||||
&Mainnet,
|
||||
DEFAULT_MAX_CONNS_PER_IP,
|
||||
Span::none(),
|
||||
);
|
||||
|
@ -891,7 +891,7 @@ async fn setup(
|
|||
|
||||
// UTXO verification doesn't matter for these tests.
|
||||
let (state, _read_only_state_service, latest_chain_tip, mut chain_tip_change) =
|
||||
zebra_state::init(state_config.clone(), network, Height::MAX, 0);
|
||||
zebra_state::init(state_config.clone(), &network, Height::MAX, 0);
|
||||
|
||||
let mut state_service = ServiceBuilder::new().buffer(1).service(state);
|
||||
|
||||
|
|
|
@ -641,7 +641,7 @@ async fn setup(
|
|||
// UTXO verification doesn't matter for these tests.
|
||||
let state_config = StateConfig::ephemeral();
|
||||
let (state_service, _read_only_state_service, latest_chain_tip, chain_tip_change) =
|
||||
zebra_state::init(state_config, network, Height::MAX, 0);
|
||||
zebra_state::init(state_config, &network, Height::MAX, 0);
|
||||
let state_service = ServiceBuilder::new().buffer(10).service(state_service);
|
||||
|
||||
// Network
|
||||
|
@ -746,7 +746,7 @@ async fn setup(
|
|||
|
||||
// Open a fake peer connection to the inbound listener, using the isolated connection API
|
||||
let connected_peer_service = connect_isolated_tcp_direct_with_inbound(
|
||||
network,
|
||||
&network,
|
||||
listen_addr,
|
||||
user_agent,
|
||||
response_inbound_service,
|
||||
|
|
Loading…
Reference in New Issue