@@ -46,6 +46,8 @@ use bitcoin::hashes::hex::ToHex;
46
46
#[ cfg( feature = "std" ) ]
47
47
use std:: time:: { SystemTime , UNIX_EPOCH } ;
48
48
49
+ /// We remove stale channel directional info two weeks after the last update, per BOLT 7's
50
+ /// suggestion.
49
51
const STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS : u64 = 60 * 60 * 24 * 14 ;
50
52
51
53
/// The maximum number of extra bytes which we do not understand in a gossip message before we will
@@ -1065,7 +1067,7 @@ impl NetworkGraph {
1065
1067
///
1066
1068
/// While there is no formal requirement that nodes regularly re-broadcast their channel
1067
1069
/// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
1068
- /// pruning occurs for updates which are at least two weeks old, which we implement here.
1070
+ /// pruning occur for updates which are at least two weeks old, which we implement here.
1069
1071
///
1070
1072
///
1071
1073
/// This method is only available with the `std` feature. See
@@ -1081,13 +1083,14 @@ impl NetworkGraph {
1081
1083
///
1082
1084
/// While there is no formal requirement that nodes regularly re-broadcast their channel
1083
1085
/// updates every two weeks, the non-normative section of BOLT 7 currently suggests that
1084
- /// pruning occurs for updates which are at least two weeks old, which we implement here.
1086
+ /// pruning occur for updates which are at least two weeks old, which we implement here.
1085
1087
///
1086
1088
/// This function takes the current unix time as an argument. For users with the `std` feature
1087
1089
/// enabled, [`NetworkGraph::remove_stale_channels`] may be preferable.
1088
1090
pub fn remove_stale_channels_with_time ( & self , current_time_unix : u64 ) {
1089
1091
let mut channels = self . channels . write ( ) . unwrap ( ) ;
1090
1092
// Time out if we haven't received an update in at least 14 days.
1093
+ if current_time_unix > u32:: max_value ( ) { return ; } // Remove by 2106
1091
1094
let min_time_unix: u32 = ( current_time_unix - STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS ) as u32 ;
1092
1095
// Sadly BTreeMap::retain was only stabilized in 1.53 so we can't switch to it for some
1093
1096
// time.
0 commit comments