Skip to content

Commit a21aeaa

Browse files
committed
Prune channels if *either* not updated
1 parent e7051af commit a21aeaa

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lightning/src/routing/gossip.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
16901690
if info.two_to_one.is_some() && info.two_to_one.as_ref().unwrap().last_update < min_time_unix {
16911691
info.two_to_one = None;
16921692
}
1693-
if info.one_to_two.is_none() && info.two_to_one.is_none() {
1693+
if info.one_to_two.is_none() || info.two_to_one.is_none() {
16941694
// We check the announcement_received_time here to ensure we don't drop
16951695
// announcements that we just received and are just waiting for our peer to send a
16961696
// channel_update for.
@@ -2587,14 +2587,21 @@ mod tests {
25872587
network_graph.remove_stale_channels_and_tracking_with_time(100 + 1 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS);
25882588
// In std mode, a further check is performed before fully removing the channel -
25892589
// the channel_announcement must have been received at least two weeks ago. We
2590-
// fudge that here by indicating the time has jumped two weeks. Note that the
2591-
// directional channel information will have been removed already..
2590+
// fudge that here by indicating the time has jumped two weeks.
25922591
assert_eq!(network_graph.read_only().channels().len(), 1);
25932592
assert_eq!(network_graph.read_only().nodes().len(), 2);
2594-
assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_none());
25952593

2594+
// Note that the directional channel information will have been removed already..
2595+
// We want to check that this will work even if *one* of the channel updates is recent,
2596+
// so we should add it with a recent timestamp.
2597+
assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_none());
25962598
use std::time::{SystemTime, UNIX_EPOCH};
25972599
let announcement_time = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time must be > 1970").as_secs();
2600+
let valid_channel_update = get_signed_channel_update(|unsigned_channel_update| {
2601+
unsigned_channel_update.timestamp = (announcement_time + 1 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS) as u32;
2602+
}, node_1_privkey, &secp_ctx);
2603+
assert!(gossip_sync.handle_channel_update(&valid_channel_update).is_ok());
2604+
assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_some());
25982605
network_graph.remove_stale_channels_and_tracking_with_time(announcement_time + 1 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS);
25992606
}
26002607

0 commit comments

Comments
 (0)