@@ -18,8 +18,9 @@ use futures::prelude::*;
1818use futures:: stream:: FuturesUnordered ;
1919use libp2p:: core:: PeerId ;
2020use lru:: LruCache ;
21- use slog:: { crit, debug, error, info, warn} ;
21+ use slog:: { crit, debug, error, info, trace , warn} ;
2222use ssz:: Encode ;
23+ use std:: fmt:: Display ;
2324use std:: {
2425 collections:: { HashMap , VecDeque } ,
2526 net:: { IpAddr , SocketAddr } ,
@@ -71,6 +72,19 @@ struct SubnetQuery {
7172 retries : usize ,
7273}
7374
75+ impl Display for SubnetQuery {
76+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
77+ let min_ttl_secs = self
78+ . min_ttl
79+ . map ( |ttl| ttl. saturating_duration_since ( Instant :: now ( ) ) . as_secs ( ) ) ;
80+ write ! (
81+ f,
82+ "Subnet: {:?}, ttl_seconds: {:?}, attempt: {}" ,
83+ self . subnet, min_ttl_secs, self . retries
84+ )
85+ }
86+ }
87+
7488#[ derive( Debug , Clone , PartialEq ) ]
7589enum QueryType {
7690 /// We are searching for subnet peers.
@@ -317,7 +331,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
317331 if !self . started {
318332 return ;
319333 }
320- debug ! (
334+ trace ! (
321335 self . log,
322336 "Making discovery query for subnets" ;
323337 "subnets" => ?subnets_to_discover. iter( ) . map( |s| s. subnet) . collect:: <Vec <_>>( )
@@ -601,7 +615,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
601615 retries,
602616 } ) ;
603617 // update the metrics and insert into the queue.
604- debug ! ( self . log, "Queuing subnet query" ; "subnet" => ?subnet, "retries" => retries) ;
618+ trace ! ( self . log, "Queuing subnet query" ; "subnet" => ?subnet, "retries" => retries) ;
605619 self . queued_queries . push_back ( query) ;
606620 metrics:: set_gauge ( & metrics:: DISCOVERY_QUEUE , self . queued_queries . len ( ) as i64 ) ;
607621 }
@@ -655,11 +669,6 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
655669 // This query is for searching for peers of a particular subnet
656670 // Drain subnet_queries so we can re-use it as we continue to process the queue
657671 let grouped_queries: Vec < SubnetQuery > = subnet_queries. drain ( ..) . collect ( ) ;
658- debug ! (
659- self . log,
660- "Starting grouped subnet query" ;
661- "subnets" => ?grouped_queries. iter( ) . map( |q| q. subnet) . collect:: <Vec <_>>( ) ,
662- ) ;
663672 self . start_subnet_query ( grouped_queries) ;
664673 processed = true ;
665674 }
@@ -704,13 +713,10 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
704713 }
705714
706715 let target_peers = TARGET_SUBNET_PEERS - peers_on_subnet;
707- debug ! ( self . log, "Discovery query started for subnet" ;
708- "subnet_id " => ? subnet_query. subnet ,
716+ trace ! ( self . log, "Discovery query started for subnet" ;
717+ "subnet_query " => % subnet_query,
709718 "connected_peers_on_subnet" => peers_on_subnet,
710- "target_subnet_peers" => TARGET_SUBNET_PEERS ,
711719 "peers_to_find" => target_peers,
712- "attempt" => subnet_query. retries,
713- "min_ttl" => ?subnet_query. min_ttl,
714720 ) ;
715721
716722 filtered_subnets. push ( subnet_query. subnet ) ;
@@ -723,6 +729,11 @@ impl<TSpec: EthSpec> Discovery<TSpec> {
723729 // build the subnet predicate as a combination of the eth2_fork_predicate and the subnet predicate
724730 let subnet_predicate = subnet_predicate :: < TSpec > ( filtered_subnets, & self . log ) ;
725731
732+ debug ! (
733+ self . log,
734+ "Starting grouped subnet query" ;
735+ "subnets" => ?filtered_subnet_queries. iter( ) . map( |q| q. to_string( ) ) . collect:: <Vec <_>>( ) ,
736+ ) ;
726737 self . start_query (
727738 GroupedQueryType :: Subnet ( filtered_subnet_queries) ,
728739 TARGET_PEERS_FOR_GROUPED_QUERY ,
0 commit comments