@@ -195,6 +195,21 @@ static void destroy_routing_state(struct routing_state *rstate)
195
195
local_chan_map_clear (& rstate -> local_chan_map );
196
196
}
197
197
198
+ /* We don't check this when loading from the gossip_store: that would break
199
+ * our canned tests, and usually old gossip is better than no gossip */
200
+ static bool timestamp_reasonable (struct routing_state * rstate , u32 timestamp )
201
+ {
202
+ u64 now = gossip_time_now (rstate ).ts .tv_sec ;
203
+
204
+ /* More than one day ahead? */
205
+ if (timestamp > now + 24 * 60 * 60 )
206
+ return false;
207
+ /* More than 2 weeks behind? */
208
+ if (timestamp < now - rstate -> prune_timeout )
209
+ return false;
210
+ return true;
211
+ }
212
+
198
213
#if DEVELOPER
199
214
static void memleak_help_routing_tables (struct htable * memtable ,
200
215
struct routing_state * rstate )
@@ -1949,6 +1964,17 @@ bool routing_add_channel_update(struct routing_state *rstate,
1949
1964
}
1950
1965
}
1951
1966
1967
+ /* Check timestamp is sane (unless from store). */
1968
+ if (!index && !timestamp_reasonable (rstate , timestamp )) {
1969
+ status_debug ("Ignoring update timestamp %u for %s/%u" ,
1970
+ timestamp ,
1971
+ type_to_string (tmpctx ,
1972
+ struct short_channel_id ,
1973
+ & short_channel_id ),
1974
+ direction );
1975
+ return false;
1976
+ }
1977
+
1952
1978
/* OK, we're going to accept this, so create chan if doesn't exist */
1953
1979
if (uc ) {
1954
1980
assert (!chan );
@@ -2267,6 +2293,14 @@ bool routing_add_node_announcement(struct routing_state *rstate,
2267
2293
status_debug ("Received node_announcement for node %s" ,
2268
2294
type_to_string (tmpctx , struct node_id , & node_id ));
2269
2295
2296
+ /* Check timestamp is sane (unless from gossip_store). */
2297
+ if (!index && !timestamp_reasonable (rstate , timestamp )) {
2298
+ status_debug ("Ignoring node_announcement timestamp %u for %s" ,
2299
+ timestamp ,
2300
+ type_to_string (tmpctx , struct node_id , & node_id ));
2301
+ return false;
2302
+ }
2303
+
2270
2304
node = get_node (rstate , & node_id );
2271
2305
2272
2306
if (node == NULL || !node_has_broadcastable_channels (node )) {
0 commit comments