@@ -1123,13 +1123,19 @@ impl NetworkGraph {
1123
1123
/// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1124
1124
/// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1125
1125
/// routing messages from a source using a protocol other than the lightning P2P protocol.
1126
+ ///
1127
+ /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
1128
+ /// materially in the future will be rejected.
1126
1129
pub fn update_channel < T : secp256k1:: Verification > ( & self , msg : & msgs:: ChannelUpdate , secp_ctx : & Secp256k1 < T > ) -> Result < ( ) , LightningError > {
1127
1130
self . update_channel_intern ( & msg. contents , Some ( & msg) , Some ( ( & msg. signature , secp_ctx) ) )
1128
1131
}
1129
1132
1130
1133
/// For an already known (from announcement) channel, update info about one of the directions
1131
1134
/// of the channel without verifying the associated signatures. Because we aren't given the
1132
1135
/// associated signatures here we cannot relay the channel update to any of our peers.
1136
+ ///
1137
+ /// If built with `no-std`, any updates with a timestamp more than two weeks in the past or
1138
+ /// materially in the future will be rejected.
1133
1139
pub fn update_channel_unsigned ( & self , msg : & msgs:: UnsignedChannelUpdate ) -> Result < ( ) , LightningError > {
1134
1140
self . update_channel_intern ( msg, None , None :: < ( & secp256k1:: Signature , & Secp256k1 < secp256k1:: VerifyOnly > ) > )
1135
1141
}
@@ -1139,6 +1145,19 @@ impl NetworkGraph {
1139
1145
let chan_enabled = msg. flags & ( 1 << 1 ) != ( 1 << 1 ) ;
1140
1146
let chan_was_enabled;
1141
1147
1148
+ #[ cfg( all( feature = "std" , not( test) , not( feature = "_test_utils" ) ) ) ]
1149
+ {
1150
+ // Note that many tests rely on being able to set arbitrarily old timestamps, thus we
1151
+ // disable this check during tests!
1152
+ let time = SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) . expect ( "Time must be > 1970" ) . as_secs ( ) ;
1153
+ if ( msg. timestamp as u64 ) < time - STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS {
1154
+ return Err ( LightningError { err : "channel_update is older than two weeks old" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
1155
+ }
1156
+ if msg. timestamp as u64 > time + 60 * 60 * 24 {
1157
+ return Err ( LightningError { err : "channel_update is older than two weeks old" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ;
1158
+ }
1159
+ }
1160
+
1142
1161
let mut channels = self . channels . write ( ) . unwrap ( ) ;
1143
1162
match channels. get_mut ( & msg. short_channel_id ) {
1144
1163
None => return Err ( LightningError { err : "Couldn't find channel for update" . to_owned ( ) , action : ErrorAction :: IgnoreError } ) ,
0 commit comments