From b8b1eafcdf94e9cb04fcda9791418a8b546de979 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Tue, 8 Oct 2024 15:12:15 +1100 Subject: [PATCH 01/19] More lenient ipv6 auto-update --- src/service.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/service.rs b/src/service.rs index c28eaa20..02a3b45f 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1345,6 +1345,28 @@ impl Service { } InsertResult::ValueUpdated | InsertResult::UpdatedPending => {} InsertResult::Failed(reason) => { + // On large networks with limited IPv6 nodes, it is hard to get enough + // PONG votes in order to estimate our external IP address. Often the + // routing table can be full, and so we reject useful IPv6 here. + // + // If we are low on votes and we initiated this connection (i.e it was not + // forced on us) then lets get a PONG from this node. + + if direction == ConnectionDirection::Outgoing { + if let Some(ip_votes) = self.ip_votes.as_mut() { + match (ip_votes.majority(), enr.udp4_socket(), enr.udp6_socket()) { + // We don't have enough ipv4 votes, but this is an IPv4 node. + ((None, Some(_)), Some(_), _) | + // We don't have enough ipv6 votes, but this is an IPv6 node + ((Some(_), None), _, Some(_)) | + // We don't have enough ipv6 or ipv4 nodes, ping this peer + ((None, None), _, _) => self.send_ping(enr, None), + // We have enough votes do nothing + ((_, _), _, _) => {} + } + } + } + self.peers_to_ping.remove(&node_id); trace!(%node_id, ?reason, "Could not insert node"); } From a5b7ccfff9308067360984c2dbb9c8cd71bdec1f Mon Sep 17 00:00:00 2001 From: Age Manning Date: Tue, 8 Oct 2024 15:26:16 +1100 Subject: [PATCH 02/19] fmt --- src/service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service.rs b/src/service.rs index 02a3b45f..32dedbc3 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1356,7 +1356,7 @@ impl Service { if let Some(ip_votes) = self.ip_votes.as_mut() { match (ip_votes.majority(), enr.udp4_socket(), enr.udp6_socket()) { // We don't have enough ipv4 votes, but this is an IPv4 node. - ((None, Some(_)), Some(_), _) | + ((None, Some(_)), Some(_), _) | // We don't have enough ipv6 votes, but this is an IPv6 node ((Some(_), None), _, Some(_)) | // We don't have enough ipv6 or ipv4 nodes, ping this peer From 30f9e8e9181f9593b105052af3449a943261f4c3 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Tue, 8 Oct 2024 16:33:42 +1100 Subject: [PATCH 03/19] Add unit test --- src/service/test.rs | 159 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 158 insertions(+), 1 deletion(-) diff --git a/src/service/test.rs b/src/service/test.rs index c85f6a97..c82e04f8 100644 --- a/src/service/test.rs +++ b/src/service/test.rs @@ -17,7 +17,9 @@ use crate::{ }; use enr::CombinedKey; use parking_lot::RwLock; -use std::{collections::HashMap, net::Ipv4Addr, sync::Arc, time::Duration}; +use rand; +use std::{collections::HashMap, net::Ipv4Addr, net::Ipv6Addr, sync::Arc, time::Duration}; +use tokio::sync::mpsc::{Sender, UnboundedReceiver}; use tokio::sync::{mpsc, oneshot}; /// Default UDP port number to use for tests requiring UDP exposure @@ -102,6 +104,65 @@ async fn build_service( } } +fn build_non_handler_service( + local_enr: Arc>, + enr_key: Arc>, + filters: bool, +) -> (Service, UnboundedReceiver, Sender) { + let listen_config = ListenConfig::Ipv4 { + ip: local_enr.read().ip4().unwrap(), + port: local_enr.read().udp4().unwrap(), + }; + let config = ConfigBuilder::new(listen_config).build(); + + // Fake's the handler with empty channels + let (handler_send, handler_recv_fake) = mpsc::unbounded_channel(); + let (handler_send_fake, handler_recv) = mpsc::channel(1000); + + let (table_filter, bucket_filter) = if filters { + ( + Some(Box::new(kbucket::IpTableFilter) as Box>), + Some(Box::new(kbucket::IpBucketFilter) as Box>), + ) + } else { + (None, None) + }; + + let kbuckets = Arc::new(RwLock::new(KBucketsTable::new( + local_enr.read().node_id().into(), + Duration::from_secs(60), + config.incoming_bucket_limit, + table_filter, + bucket_filter, + ))); + + let ip_vote = IpVote::new(10, Duration::from_secs(10000)); + + // create the required channels + let (_discv5_send, discv5_recv) = mpsc::channel(30); + let (_exit_send, exit) = oneshot::channel(); + + let service = Service { + local_enr, + enr_key, + kbuckets, + queries: QueryPool::new(config.query_timeout), + active_requests: Default::default(), + active_nodes_responses: HashMap::new(), + ip_votes: Some(ip_vote), + handler_send, + handler_recv, + handler_exit: None, + peers_to_ping: HashSetDelay::new(config.ping_interval), + discv5_recv, + event_stream: None, + exit, + config, + ip_mode: IpMode::DualStack, + }; + (service, handler_recv_fake, handler_send_fake) +} + #[tokio::test] async fn test_updating_connection_on_ping() { init(); @@ -341,3 +402,99 @@ async fn test_handling_concurrent_responses() { assert!(service.active_requests.is_empty()); assert!(service.active_nodes_responses.is_empty()); } + +fn generate_rand_ipv4() -> Ipv4Addr { + let a: u8 = rand::random(); + let b: u8 = rand::random(); + let c: u8 = rand::random(); + let d: u8 = rand::random(); + Ipv4Addr::new(a, b, c, d) +} + +fn generate_rand_ipv6() -> Ipv6Addr { + let a: u16 = rand::random(); + let b: u16 = rand::random(); + let c: u16 = rand::random(); + let d: u16 = rand::random(); + let e: u16 = rand::random(); + let f: u16 = rand::random(); + let g: u16 = rand::random(); + let h: u16 = rand::random(); + Ipv6Addr::new(a, b, c, d, e, f, g, h) +} + +fn random_connection_direction() -> ConnectionDirection { + let outgoing: bool = rand::random(); + if outgoing { + ConnectionDirection::Outgoing + } else { + ConnectionDirection::Incoming + } +} + +#[tokio::test] +async fn test_ipv6_update_amongst_ipv4_dominated_network() { + init(); + + let enr_key = CombinedKey::generate_secp256k1(); + let ip = std::net::Ipv4Addr::LOCALHOST; + let local_enr = Enr::builder() + .ip4(ip) + .udp4(DEFAULT_UDP_PORT) + .build(&enr_key) + .unwrap(); + + let (mut service, mut handler_recv, _handler_send) = + build_non_handler_service::( + Arc::new(RwLock::new(local_enr)), + Arc::new(RwLock::new(enr_key)), + false, + ); + + // Load up the routing table with 100 random ENRs + + for _ in 0..100 { + let key = CombinedKey::generate_secp256k1(); + let ip = generate_rand_ipv4(); + let enr = Enr::builder() + .ip4(ip) + .udp4(DEFAULT_UDP_PORT) + .build(&key) + .unwrap(); + + let direction = random_connection_direction(); + service.inject_session_established(enr.clone(), direction); + } + + // Attempt to add 10 IPv6 nodes and expect that we attempt to send 10 PING's to IPv6 nodes. + for _ in 0..10 { + let key = CombinedKey::generate_secp256k1(); + let ip = generate_rand_ipv6(); + let enr = Enr::builder() + .ip6(ip) + .udp6(DEFAULT_UDP_PORT) + .build(&key) + .unwrap(); + + let direction = ConnectionDirection::Outgoing; + service.inject_session_established(enr.clone(), direction); + } + + // Collect all the messages to the handler and count the PING requests for ENR v6 addresses + let mut v6_pings = 0; + while let Ok(event) = handler_recv.try_recv() { + match event { + HandlerIn::Request(contact, request) => { + if contact.node_address().socket_addr.is_ipv6() + && matches!(request.body, RequestBody::Ping { .. }) + { + v6_pings += 1 + } + } + _ => {} + } + } + + // Should be 10 ipv6 pings + assert_eq!(v6_pings, 10) +} From df656b79f476391bb2c761ea30ce52cd9d99377e Mon Sep 17 00:00:00 2001 From: Age Manning Date: Tue, 8 Oct 2024 16:34:59 +1100 Subject: [PATCH 04/19] fmt --- src/service/test.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/service/test.rs b/src/service/test.rs index c82e04f8..294ebb45 100644 --- a/src/service/test.rs +++ b/src/service/test.rs @@ -18,9 +18,17 @@ use crate::{ use enr::CombinedKey; use parking_lot::RwLock; use rand; -use std::{collections::HashMap, net::Ipv4Addr, net::Ipv6Addr, sync::Arc, time::Duration}; -use tokio::sync::mpsc::{Sender, UnboundedReceiver}; -use tokio::sync::{mpsc, oneshot}; +use std::{ + collections::HashMap, + net::{Ipv4Addr, Ipv6Addr}, + sync::Arc, + time::Duration, +}; +use tokio::sync::{ + mpsc, + mpsc::{Sender, UnboundedReceiver}, + oneshot, +}; /// Default UDP port number to use for tests requiring UDP exposure pub const DEFAULT_UDP_PORT: u16 = 0; From 493bb12ce0b0f41ef8360ce22f01a9018d66f89c Mon Sep 17 00:00:00 2001 From: Age Manning Date: Tue, 8 Oct 2024 16:37:16 +1100 Subject: [PATCH 05/19] Clippy --- src/service/test.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/service/test.rs b/src/service/test.rs index 294ebb45..ea1b0244 100644 --- a/src/service/test.rs +++ b/src/service/test.rs @@ -491,15 +491,12 @@ async fn test_ipv6_update_amongst_ipv4_dominated_network() { // Collect all the messages to the handler and count the PING requests for ENR v6 addresses let mut v6_pings = 0; while let Ok(event) = handler_recv.try_recv() { - match event { - HandlerIn::Request(contact, request) => { - if contact.node_address().socket_addr.is_ipv6() - && matches!(request.body, RequestBody::Ping { .. }) - { - v6_pings += 1 - } + if let HandlerIn::Request(contact, request) = event { + if contact.node_address().socket_addr.is_ipv6() + && matches!(request.body, RequestBody::Ping { .. }) + { + v6_pings += 1 } - _ => {} } } From 765abacf4daae3d41317af3eb9d1f76d826d25be Mon Sep 17 00:00:00 2001 From: Age Manning Date: Tue, 8 Oct 2024 16:41:18 +1100 Subject: [PATCH 06/19] Correct match conditions --- src/service.rs | 4 ++-- src/service/test.rs | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/service.rs b/src/service.rs index 32dedbc3..4b852db7 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1356,9 +1356,9 @@ impl Service { if let Some(ip_votes) = self.ip_votes.as_mut() { match (ip_votes.majority(), enr.udp4_socket(), enr.udp6_socket()) { // We don't have enough ipv4 votes, but this is an IPv4 node. - ((None, Some(_)), Some(_), _) | + ((Some(_), None), Some(_), _) | // We don't have enough ipv6 votes, but this is an IPv6 node - ((Some(_), None), _, Some(_)) | + ((None, Some(_)), _, Some(_)) | // We don't have enough ipv6 or ipv4 nodes, ping this peer ((None, None), _, _) => self.send_ping(enr, None), // We have enough votes do nothing diff --git a/src/service/test.rs b/src/service/test.rs index ea1b0244..49de94d0 100644 --- a/src/service/test.rs +++ b/src/service/test.rs @@ -112,7 +112,7 @@ async fn build_service( } } -fn build_non_handler_service( +fn build_non_handler_service( local_enr: Arc>, enr_key: Arc>, filters: bool, @@ -452,12 +452,11 @@ async fn test_ipv6_update_amongst_ipv4_dominated_network() { .build(&enr_key) .unwrap(); - let (mut service, mut handler_recv, _handler_send) = - build_non_handler_service::( - Arc::new(RwLock::new(local_enr)), - Arc::new(RwLock::new(enr_key)), - false, - ); + let (mut service, mut handler_recv, _handler_send) = build_non_handler_service( + Arc::new(RwLock::new(local_enr)), + Arc::new(RwLock::new(enr_key)), + false, + ); // Load up the routing table with 100 random ENRs From 4af0dfe74ed0d12994cc96fca773512a02120413 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Wed, 9 Oct 2024 15:26:44 +1100 Subject: [PATCH 07/19] Count ip votes if we need them --- src/service.rs | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/src/service.rs b/src/service.rs index 4b852db7..288d6002 100644 --- a/src/service.rs +++ b/src/service.rs @@ -817,7 +817,7 @@ impl Service { kbucket::Entry::Present(_, status) if status.is_connected() && !status.is_incoming()); - if should_count { + if should_count | self.require_more_ip_votes(socket.is_ipv6()) { // get the advertised local addresses let (local_ip4_socket, local_ip6_socket) = { let local_enr = self.local_enr.read(); @@ -1352,19 +1352,10 @@ impl Service { // If we are low on votes and we initiated this connection (i.e it was not // forced on us) then lets get a PONG from this node. - if direction == ConnectionDirection::Outgoing { - if let Some(ip_votes) = self.ip_votes.as_mut() { - match (ip_votes.majority(), enr.udp4_socket(), enr.udp6_socket()) { - // We don't have enough ipv4 votes, but this is an IPv4 node. - ((Some(_), None), Some(_), _) | - // We don't have enough ipv6 votes, but this is an IPv6 node - ((None, Some(_)), _, Some(_)) | - // We don't have enough ipv6 or ipv4 nodes, ping this peer - ((None, None), _, _) => self.send_ping(enr, None), - // We have enough votes do nothing - ((_, _), _, _) => {} - } - } + if direction == ConnectionDirection::Outgoing + && self.require_more_ip_votes(enr.udp6_socket().is_some()) + { + self.send_ping(enr, None); } self.peers_to_ping.remove(&node_id); @@ -1557,6 +1548,32 @@ impl Service { } } + /// This is a helper function that determines if we need more votes for a specific IP + /// class. + /// + /// If we are in dual-stack made and don't have enough votes for either ipv4 or ipv6 and the + /// requesting node/vote is what we need, then this will return true + fn require_more_ip_votes(&mut self, is_ipv6: bool) -> bool { + if !matches!(self.ip_mode, IpMode::DualStack) { + return false; + } + + if let Some(ip_votes) = self.ip_votes.as_mut() { + match (ip_votes.majority(), is_ipv6) { + // We don't have enough ipv4 votes, but this is an IPv4-only node. + ((None, Some(_)), false) | + // We don't have enough ipv6 votes, but this is an IPv6 node + ((Some(_), None), true) | + // We don't have enough ipv6 or ipv4 nodes, ping this peer + ((None, None), _,) => true, + // We have enough votes do nothing + ((_, _), _,) => false, + } + } else { + false + } + } + /// A future that maintains the routing table and inserts nodes when required. This returns the /// [`Event::NodeInserted`] variant if a new node has been inserted into the routing table. async fn bucket_maintenance_poll(kbuckets: &Arc>>) -> Event { From 0e83d17f2f8edd7a674b69b8b43c45bdc6921f9f Mon Sep 17 00:00:00 2001 From: Age Manning Date: Mon, 14 Oct 2024 13:05:19 +1100 Subject: [PATCH 08/19] Update src/service.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- src/service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service.rs b/src/service.rs index 288d6002..6045b195 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1548,7 +1548,7 @@ impl Service { } } - /// This is a helper function that determines if we need more votes for a specific IP + /// Helper function that determines if we need more votes for a specific IP /// class. /// /// If we are in dual-stack made and don't have enough votes for either ipv4 or ipv6 and the From 03c11cc1bae0c52ff55686bed5e78d2439fd1860 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Mon, 14 Oct 2024 13:05:26 +1100 Subject: [PATCH 09/19] Update src/service.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- src/service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service.rs b/src/service.rs index 6045b195..8df43070 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1551,7 +1551,7 @@ impl Service { /// Helper function that determines if we need more votes for a specific IP /// class. /// - /// If we are in dual-stack made and don't have enough votes for either ipv4 or ipv6 and the + /// If we are in dual-stack mode and don't have enough votes for either ipv4 or ipv6 and the /// requesting node/vote is what we need, then this will return true fn require_more_ip_votes(&mut self, is_ipv6: bool) -> bool { if !matches!(self.ip_mode, IpMode::DualStack) { From 1c89cf1519c5567de708c544814066bddeac671a Mon Sep 17 00:00:00 2001 From: Age Manning Date: Mon, 14 Oct 2024 13:05:34 +1100 Subject: [PATCH 10/19] Update src/service.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- src/service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service.rs b/src/service.rs index 8df43070..dd1e97a0 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1552,7 +1552,7 @@ impl Service { /// class. /// /// If we are in dual-stack mode and don't have enough votes for either ipv4 or ipv6 and the - /// requesting node/vote is what we need, then this will return true + /// requesting node/vote is what we need, then this will return true. fn require_more_ip_votes(&mut self, is_ipv6: bool) -> bool { if !matches!(self.ip_mode, IpMode::DualStack) { return false; From 37daff1d451808c07f45874ba8d1af81d84bc1e2 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Mon, 14 Oct 2024 13:06:44 +1100 Subject: [PATCH 11/19] Update src/service.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- src/service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service.rs b/src/service.rs index dd1e97a0..bb400010 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1562,7 +1562,7 @@ impl Service { match (ip_votes.majority(), is_ipv6) { // We don't have enough ipv4 votes, but this is an IPv4-only node. ((None, Some(_)), false) | - // We don't have enough ipv6 votes, but this is an IPv6 node + // We don't have enough ipv6 votes, but this is an IPv6 node. ((Some(_), None), true) | // We don't have enough ipv6 or ipv4 nodes, ping this peer ((None, None), _,) => true, From 860b0a2770958a6d82cd35789b6542181cb067d2 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Mon, 14 Oct 2024 13:06:57 +1100 Subject: [PATCH 12/19] Update src/service.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- src/service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service.rs b/src/service.rs index bb400010..67dbf8e6 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1566,7 +1566,7 @@ impl Service { ((Some(_), None), true) | // We don't have enough ipv6 or ipv4 nodes, ping this peer ((None, None), _,) => true, - // We have enough votes do nothing + // We have enough votes do nothing. ((_, _), _,) => false, } } else { From cccf3f9c49ee9042b4680e29387b1b19f6a25a82 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Mon, 14 Oct 2024 13:09:40 +1100 Subject: [PATCH 13/19] Update src/service.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- src/service.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/service.rs b/src/service.rs index 67dbf8e6..48326f2e 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1558,7 +1558,9 @@ impl Service { return false; } - if let Some(ip_votes) = self.ip_votes.as_mut() { + let Some(ip_votes) = self.ip_votes.as_mut() else { + return false; + } match (ip_votes.majority(), is_ipv6) { // We don't have enough ipv4 votes, but this is an IPv4-only node. ((None, Some(_)), false) | From 5afc7dcc01bde51bca831e7b38bbeff2883648cb Mon Sep 17 00:00:00 2001 From: Age Manning Date: Mon, 14 Oct 2024 13:09:51 +1100 Subject: [PATCH 14/19] Update src/service.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- src/service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service.rs b/src/service.rs index 48326f2e..e3f16ba1 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1566,7 +1566,7 @@ impl Service { ((None, Some(_)), false) | // We don't have enough ipv6 votes, but this is an IPv6 node. ((Some(_), None), true) | - // We don't have enough ipv6 or ipv4 nodes, ping this peer + // We don't have enough ipv6 or ipv4 nodes, ping this peer. ((None, None), _,) => true, // We have enough votes do nothing. ((_, _), _,) => false, From 7b3b146120aaf5767e34b88603dd958ce08011bb Mon Sep 17 00:00:00 2001 From: Age Manning Date: Mon, 14 Oct 2024 13:10:04 +1100 Subject: [PATCH 15/19] Update src/service/test.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- src/service/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/test.rs b/src/service/test.rs index 49de94d0..ce1c772e 100644 --- a/src/service/test.rs +++ b/src/service/test.rs @@ -123,7 +123,7 @@ fn build_non_handler_service( }; let config = ConfigBuilder::new(listen_config).build(); - // Fake's the handler with empty channels + // Fake's the handler with empty channels. let (handler_send, handler_recv_fake) = mpsc::unbounded_channel(); let (handler_send_fake, handler_recv) = mpsc::channel(1000); From 71017cfaf035bcb6dd925d46dfac8d569e3c8c81 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Mon, 14 Oct 2024 13:10:13 +1100 Subject: [PATCH 16/19] Update src/service/test.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- src/service/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/test.rs b/src/service/test.rs index ce1c772e..d1da1d59 100644 --- a/src/service/test.rs +++ b/src/service/test.rs @@ -146,7 +146,7 @@ fn build_non_handler_service( let ip_vote = IpVote::new(10, Duration::from_secs(10000)); - // create the required channels + // create the required channels. let (_discv5_send, discv5_recv) = mpsc::channel(30); let (_exit_send, exit) = oneshot::channel(); From b4e11e318d486c514231faea74e2c3ee06bf40ba Mon Sep 17 00:00:00 2001 From: Age Manning Date: Mon, 14 Oct 2024 13:10:21 +1100 Subject: [PATCH 17/19] Update src/service/test.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- src/service/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/test.rs b/src/service/test.rs index d1da1d59..16731ea9 100644 --- a/src/service/test.rs +++ b/src/service/test.rs @@ -458,7 +458,7 @@ async fn test_ipv6_update_amongst_ipv4_dominated_network() { false, ); - // Load up the routing table with 100 random ENRs + // Load up the routing table with 100 random ENRs. for _ in 0..100 { let key = CombinedKey::generate_secp256k1(); From 73b842d18db5c9f11a20beaf1705bab5c542fc36 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Mon, 14 Oct 2024 13:10:29 +1100 Subject: [PATCH 18/19] Update src/service/test.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Oliveira --- src/service/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/service/test.rs b/src/service/test.rs index 16731ea9..128ad9e0 100644 --- a/src/service/test.rs +++ b/src/service/test.rs @@ -487,7 +487,7 @@ async fn test_ipv6_update_amongst_ipv4_dominated_network() { service.inject_session_established(enr.clone(), direction); } - // Collect all the messages to the handler and count the PING requests for ENR v6 addresses + // Collect all the messages to the handler and count the PING requests for ENR v6 addresses. let mut v6_pings = 0; while let Ok(event) = handler_recv.try_recv() { if let HandlerIn::Request(contact, request) = event { From f84ba02bcfb91ca0c2947c91aa9de1d29573c63f Mon Sep 17 00:00:00 2001 From: Age Manning Date: Mon, 14 Oct 2024 13:21:28 +1100 Subject: [PATCH 19/19] Correct commits --- src/service.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/service.rs b/src/service.rs index e3f16ba1..8b409398 100644 --- a/src/service.rs +++ b/src/service.rs @@ -1558,10 +1558,10 @@ impl Service { return false; } - let Some(ip_votes) = self.ip_votes.as_mut() else { - return false; - } - match (ip_votes.majority(), is_ipv6) { + let Some(ip_votes) = self.ip_votes.as_mut() else { + return false; + }; + match (ip_votes.majority(), is_ipv6) { // We don't have enough ipv4 votes, but this is an IPv4-only node. ((None, Some(_)), false) | // We don't have enough ipv6 votes, but this is an IPv6 node. @@ -1570,10 +1570,7 @@ impl Service { ((None, None), _,) => true, // We have enough votes do nothing. ((_, _), _,) => false, - } - } else { - false - } + } } /// A future that maintains the routing table and inserts nodes when required. This returns the