2222/* 365.25 * 24 * 60 / 10 */
2323#define BLOCKS_PER_YEAR 52596
2424
25+ struct pending_spam_node_announce {
26+ u8 * node_announcement ;
27+ u32 index ;
28+ };
29+
2530struct pending_node_announce {
2631 struct routing_state * rstate ;
2732 struct node_id nodeid ;
@@ -31,6 +36,8 @@ struct pending_node_announce {
3136 u32 index ;
3237 /* If non-NULL this is peer to credit it with */
3338 struct node_id * source_peer ;
39+ /* required for loading gossip store */
40+ struct pending_spam_node_announce spam ;
3441};
3542
3643/* As per the below BOLT #7 quote, we delay forgetting a channel until 12
@@ -776,6 +783,8 @@ static void catch_node_announcement(const tal_t *ctx,
776783 pna -> index = 0 ;
777784 pna -> refcount = 0 ;
778785 pna -> source_peer = NULL ;
786+ pna -> spam .node_announcement = NULL ;
787+ pna -> spam .index = 0 ;
779788 pending_node_map_add (rstate -> pending_node_map , pna );
780789 }
781790 pna -> refcount ++ ;
@@ -805,6 +814,22 @@ static void process_pending_node_announcement(struct routing_state *rstate,
805814 /* Never send this again. */
806815 pna -> node_announcement = tal_free (pna -> node_announcement );
807816 }
817+ if (pna -> spam .node_announcement ) {
818+ SUPERVERBOSE (
819+ "Processing deferred node_announcement for node %s" ,
820+ type_to_string (pna , struct node_id , nodeid ));
821+
822+ /* Can fail it timestamp is now too old */
823+ if (!routing_add_node_announcement (rstate ,
824+ pna -> spam .node_announcement ,
825+ pna -> spam .index ,
826+ NULL , NULL ,
827+ true))
828+ status_unusual ("pending node_announcement %s too old?" ,
829+ tal_hex (tmpctx , pna -> spam .node_announcement ));
830+ /* Never send this again. */
831+ pna -> spam .node_announcement = tal_free (pna -> spam .node_announcement );
832+ }
808833
809834 /* We don't need to catch any more node_announcements, since we've
810835 * accepted the public channel now. But other pending announcements
@@ -1821,12 +1846,20 @@ bool routing_add_node_announcement(struct routing_state *rstate,
18211846
18221847 SUPERVERBOSE ("Deferring node_announcement for node %s" ,
18231848 type_to_string (tmpctx , struct node_id , & node_id ));
1824- pna -> timestamp = timestamp ;
1825- pna -> index = index ;
1826- tal_free (pna -> node_announcement );
1827- tal_free (pna -> source_peer );
1828- pna -> node_announcement = tal_dup_talarr (pna , u8 , msg );
1829- pna -> source_peer = tal_dup_or_null (pna , struct node_id , source_peer );
1849+ /* a pending spam node announcement is possible when loading
1850+ * from the store */
1851+ if (index && force_spam_flag ) {
1852+ tal_free (pna -> spam .node_announcement );
1853+ pna -> spam .node_announcement = tal_dup_talarr (pna , u8 , msg );
1854+ pna -> spam .index = index ;
1855+ } else {
1856+ tal_free (pna -> node_announcement );
1857+ tal_free (pna -> source_peer );
1858+ pna -> node_announcement = tal_dup_talarr (pna , u8 , msg );
1859+ pna -> source_peer = tal_dup_or_null (pna , struct node_id , source_peer );
1860+ pna -> timestamp = timestamp ;
1861+ pna -> index = index ;
1862+ }
18301863 return true;
18311864 }
18321865
0 commit comments