@@ -1653,7 +1653,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1653
1653
if info. two_to_one . is_some ( ) && info. two_to_one . as_ref ( ) . unwrap ( ) . last_update < min_time_unix {
1654
1654
info. two_to_one = None ;
1655
1655
}
1656
- if info. one_to_two . is_none ( ) && info. two_to_one . is_none ( ) {
1656
+ if info. one_to_two . is_none ( ) || info. two_to_one . is_none ( ) {
1657
1657
// We check the announcement_received_time here to ensure we don't drop
1658
1658
// announcements that we just received and are just waiting for our peer to send a
1659
1659
// channel_update for.
@@ -1667,6 +1667,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1667
1667
for scid in scids_to_remove {
1668
1668
let info = channels. remove ( & scid) . expect ( "We just accessed this scid, it should be present" ) ;
1669
1669
Self :: remove_channel_in_nodes ( & mut nodes, & info, scid) ;
1670
+ self . removed_channels . lock ( ) . unwrap ( ) . insert ( scid, Some ( current_time_unix) ) ;
1670
1671
}
1671
1672
}
1672
1673
@@ -2532,32 +2533,57 @@ mod tests {
2532
2533
assert ! ( network_graph. update_channel_from_announcement( & valid_channel_announcement, & chain_source) . is_ok( ) ) ;
2533
2534
assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . is_some( ) ) ;
2534
2535
2536
+ // Submit two channel updates for each channel direction (update.flags bit).
2535
2537
let valid_channel_update = get_signed_channel_update ( |_| { } , node_1_privkey, & secp_ctx) ;
2536
2538
assert ! ( gossip_sync. handle_channel_update( & valid_channel_update) . is_ok( ) ) ;
2537
2539
assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . one_to_two. is_some( ) ) ;
2538
2540
2541
+ let valid_channel_update_2 = get_signed_channel_update ( |update| { update. flags |=1 ; } , node_2_privkey, & secp_ctx) ;
2542
+ gossip_sync. handle_channel_update ( & valid_channel_update_2) . unwrap ( ) ;
2543
+ assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . two_to_one. is_some( ) ) ;
2544
+
2539
2545
network_graph. remove_stale_channels_and_tracking_with_time ( 100 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS ) ;
2540
2546
assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 1 ) ;
2541
2547
assert_eq ! ( network_graph. read_only( ) . nodes( ) . len( ) , 2 ) ;
2542
2548
2543
2549
network_graph. remove_stale_channels_and_tracking_with_time ( 101 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS ) ;
2550
+ #[ cfg( not( feature = "std" ) ) ] {
2551
+ // Make sure removed channels are tracked.
2552
+ assert_eq ! ( network_graph. removed_channels. lock( ) . unwrap( ) . len( ) , 1 ) ;
2553
+ }
2554
+ network_graph. remove_stale_channels_and_tracking_with_time ( 101 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS +
2555
+ REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS ) ;
2556
+
2544
2557
#[ cfg( feature = "std" ) ]
2545
2558
{
2546
2559
// In std mode, a further check is performed before fully removing the channel -
2547
2560
// the channel_announcement must have been received at least two weeks ago. We
2548
- // fudge that here by indicating the time has jumped two weeks. Note that the
2549
- // directional channel information will have been removed already..
2561
+ // fudge that here by indicating the time has jumped two weeks.
2550
2562
assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 1 ) ;
2551
2563
assert_eq ! ( network_graph. read_only( ) . nodes( ) . len( ) , 2 ) ;
2552
- assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . one_to_two. is_none( ) ) ;
2553
2564
2565
+ // Note that the directional channel information will have been removed already..
2566
+ // We want to check that this will work even if *one* of the channel updates is recent,
2567
+ // so we should add it with a recent timestamp.
2568
+ assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . one_to_two. is_none( ) ) ;
2554
2569
use std:: time:: { SystemTime , UNIX_EPOCH } ;
2555
2570
let announcement_time = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . expect ( "Time must be > 1970" ) . as_secs ( ) ;
2571
+ let valid_channel_update = get_signed_channel_update ( |unsigned_channel_update| {
2572
+ unsigned_channel_update. timestamp = ( announcement_time + 1 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS ) as u32 ;
2573
+ } , node_1_privkey, & secp_ctx) ;
2574
+ assert ! ( gossip_sync. handle_channel_update( & valid_channel_update) . is_ok( ) ) ;
2575
+ assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . one_to_two. is_some( ) ) ;
2556
2576
network_graph. remove_stale_channels_and_tracking_with_time ( announcement_time + 1 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS ) ;
2577
+ // Make sure removed channels are tracked.
2578
+ assert_eq ! ( network_graph. removed_channels. lock( ) . unwrap( ) . len( ) , 1 ) ;
2579
+ // Provide a later time so that sufficient time has passed
2580
+ network_graph. remove_stale_channels_and_tracking_with_time ( announcement_time + 1 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS +
2581
+ REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS ) ;
2557
2582
}
2558
2583
2559
2584
assert_eq ! ( network_graph. read_only( ) . channels( ) . len( ) , 0 ) ;
2560
2585
assert_eq ! ( network_graph. read_only( ) . nodes( ) . len( ) , 0 ) ;
2586
+ assert ! ( network_graph. removed_channels. lock( ) . unwrap( ) . is_empty( ) ) ;
2561
2587
2562
2588
#[ cfg( feature = "std" ) ]
2563
2589
{
0 commit comments