@@ -309,7 +309,6 @@ where U::Target: UtxoLookup, L::Target: Logger
309
309
{
310
310
network_graph : G ,
311
311
utxo_lookup : RwLock < Option < U > > ,
312
- #[ cfg( feature = "std" ) ]
313
312
full_syncs_requested : AtomicUsize ,
314
313
pending_events : Mutex < Vec < MessageSendEvent > > ,
315
314
logger : L ,
@@ -325,7 +324,6 @@ where U::Target: UtxoLookup, L::Target: Logger
325
324
pub fn new ( network_graph : G , utxo_lookup : Option < U > , logger : L ) -> Self {
326
325
P2PGossipSync {
327
326
network_graph,
328
- #[ cfg( feature = "std" ) ]
329
327
full_syncs_requested : AtomicUsize :: new ( 0 ) ,
330
328
utxo_lookup : RwLock :: new ( utxo_lookup) ,
331
329
pending_events : Mutex :: new ( vec ! [ ] ) ,
@@ -348,10 +346,8 @@ where U::Target: UtxoLookup, L::Target: Logger
348
346
& self . network_graph
349
347
}
350
348
351
- #[ cfg( feature = "std" ) ]
352
349
/// 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 {
355
351
const FULL_SYNCS_TO_REQUEST : usize = 5 ;
356
352
if self . full_syncs_requested . load ( Ordering :: Acquire ) < FULL_SYNCS_TO_REQUEST {
357
353
self . full_syncs_requested . fetch_add ( 1 , Ordering :: AcqRel ) ;
@@ -619,10 +615,12 @@ where U::Target: UtxoLookup, L::Target: Logger
619
615
// For no-std builds, we bury our head in the sand and do a full sync on each connection.
620
616
#[ allow( unused_mut, unused_assignments) ]
621
617
let mut gossip_start_time = 0 ;
618
+ #[ allow( unused) ]
619
+ let should_sync = self . should_request_full_sync ( ) ;
622
620
#[ cfg( feature = "std" ) ]
623
621
{
624
622
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 {
626
624
gossip_start_time -= 60 * 60 * 24 * 7 * 2 ; // 2 weeks ago
627
625
} else {
628
626
gossip_start_time -= 60 * 60 ; // an hour ago
@@ -2452,18 +2450,16 @@ pub(crate) mod tests {
2452
2450
}
2453
2451
2454
2452
#[ test]
2455
- #[ cfg( feature = "std" ) ]
2456
2453
fn request_full_sync_finite_times ( ) {
2457
2454
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( ) ) ;
2467
2463
}
2468
2464
2469
2465
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