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