Skip to content

Commit a150dbf

Browse files
committed
Prune channels if *either* not updated
1 parent 2e343e7 commit a150dbf

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.
@@ -2582,14 +2582,21 @@ mod tests {
25822582
{
25832583
// In std mode, a further check is performed before fully removing the channel -
25842584
// the channel_announcement must have been received at least two weeks ago. We
2585-
// fudge that here by indicating the time has jumped two weeks. Note that the
2586-
// directional channel information will have been removed already..
2585+
// fudge that here by indicating the time has jumped two weeks.
25872586
assert_eq!(network_graph.read_only().channels().len(), 1);
25882587
assert_eq!(network_graph.read_only().nodes().len(), 2);
2589-
assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_none());
25902588

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

0 commit comments

Comments
 (0)