@@ -309,7 +309,6 @@ where U::Target: UtxoLookup, L::Target: Logger
309309{
310310 network_graph : G ,
311311 utxo_lookup : RwLock < Option < U > > ,
312- #[ cfg( feature = "std" ) ]
313312 full_syncs_requested : AtomicUsize ,
314313 pending_events : Mutex < Vec < MessageSendEvent > > ,
315314 logger : L ,
@@ -325,7 +324,6 @@ where U::Target: UtxoLookup, L::Target: Logger
325324 pub fn new ( network_graph : G , utxo_lookup : Option < U > , logger : L ) -> Self {
326325 P2PGossipSync {
327326 network_graph,
328- #[ cfg( feature = "std" ) ]
329327 full_syncs_requested : AtomicUsize :: new ( 0 ) ,
330328 utxo_lookup : RwLock :: new ( utxo_lookup) ,
331329 pending_events : Mutex :: new ( vec ! [ ] ) ,
@@ -348,10 +346,8 @@ where U::Target: UtxoLookup, L::Target: Logger
348346 & self . network_graph
349347 }
350348
351- #[ cfg( feature = "std" ) ]
352349 /// Returns true when a full routing table sync should be performed with a peer.
353- fn should_request_full_sync ( & self , _node_id : & PublicKey ) -> bool {
354- //TODO: Determine whether to request a full sync based on the network map.
350+ fn should_request_full_sync ( & self ) -> bool {
355351 const FULL_SYNCS_TO_REQUEST : usize = 5 ;
356352 if self . full_syncs_requested . load ( Ordering :: Acquire ) < FULL_SYNCS_TO_REQUEST {
357353 self . full_syncs_requested . fetch_add ( 1 , Ordering :: AcqRel ) ;
@@ -619,10 +615,12 @@ where U::Target: UtxoLookup, L::Target: Logger
619615 // For no-std builds, we bury our head in the sand and do a full sync on each connection.
620616 #[ allow( unused_mut, unused_assignments) ]
621617 let mut gossip_start_time = 0 ;
618+ #[ allow( unused) ]
619+ let should_sync = self . should_request_full_sync ( ) ;
622620 #[ cfg( feature = "std" ) ]
623621 {
624622 gossip_start_time = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . expect ( "Time must be > 1970" ) . as_secs ( ) ;
625- if self . should_request_full_sync ( & their_node_id ) {
623+ if should_sync {
626624 gossip_start_time -= 60 * 60 * 24 * 7 * 2 ; // 2 weeks ago
627625 } else {
628626 gossip_start_time -= 60 * 60 ; // an hour ago
@@ -2452,18 +2450,16 @@ pub(crate) mod tests {
24522450 }
24532451
24542452 #[ test]
2455- #[ cfg( feature = "std" ) ]
24562453 fn request_full_sync_finite_times ( ) {
24572454 let network_graph = create_network_graph ( ) ;
2458- let ( secp_ctx, gossip_sync) = create_gossip_sync ( & network_graph) ;
2459- let node_id = PublicKey :: from_secret_key ( & secp_ctx, & SecretKey :: from_slice ( & <Vec < u8 > >:: from_hex ( "0202020202020202020202020202020202020202020202020202020202020202" ) . unwrap ( ) [ ..] ) . unwrap ( ) ) ;
2460-
2461- assert ! ( gossip_sync. should_request_full_sync( & node_id) ) ;
2462- assert ! ( gossip_sync. should_request_full_sync( & node_id) ) ;
2463- assert ! ( gossip_sync. should_request_full_sync( & node_id) ) ;
2464- assert ! ( gossip_sync. should_request_full_sync( & node_id) ) ;
2465- assert ! ( gossip_sync. should_request_full_sync( & node_id) ) ;
2466- assert ! ( !gossip_sync. should_request_full_sync( & node_id) ) ;
2455+ let ( _, gossip_sync) = create_gossip_sync ( & network_graph) ;
2456+
2457+ assert ! ( gossip_sync. should_request_full_sync( ) ) ;
2458+ assert ! ( gossip_sync. should_request_full_sync( ) ) ;
2459+ assert ! ( gossip_sync. should_request_full_sync( ) ) ;
2460+ assert ! ( gossip_sync. should_request_full_sync( ) ) ;
2461+ assert ! ( gossip_sync. should_request_full_sync( ) ) ;
2462+ assert ! ( !gossip_sync. should_request_full_sync( ) ) ;
24672463 }
24682464
24692465 pub ( crate ) fn get_signed_node_announcement < F : Fn ( & mut UnsignedNodeAnnouncement ) > ( f : F , node_key : & SecretKey , secp_ctx : & Secp256k1 < secp256k1:: All > ) -> NodeAnnouncement {
0 commit comments