22
22
/* 365.25 * 24 * 60 / 10 */
23
23
#define BLOCKS_PER_YEAR 52596
24
24
25
+ struct pending_spam_node_announce {
26
+ u8 * node_announcement ;
27
+ u32 index ;
28
+ };
29
+
25
30
struct pending_node_announce {
26
31
struct routing_state * rstate ;
27
32
struct node_id nodeid ;
@@ -31,6 +36,8 @@ struct pending_node_announce {
31
36
u32 index ;
32
37
/* If non-NULL this is peer to credit it with */
33
38
struct node_id * source_peer ;
39
+ /* required for loading gossip store */
40
+ struct pending_spam_node_announce spam ;
34
41
};
35
42
36
43
/* 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,
776
783
pna -> index = 0 ;
777
784
pna -> refcount = 0 ;
778
785
pna -> source_peer = NULL ;
786
+ pna -> spam .node_announcement = NULL ;
787
+ pna -> spam .index = 0 ;
779
788
pending_node_map_add (rstate -> pending_node_map , pna );
780
789
}
781
790
pna -> refcount ++ ;
@@ -805,6 +814,22 @@ static void process_pending_node_announcement(struct routing_state *rstate,
805
814
/* Never send this again. */
806
815
pna -> node_announcement = tal_free (pna -> node_announcement );
807
816
}
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
+ }
808
833
809
834
/* We don't need to catch any more node_announcements, since we've
810
835
* accepted the public channel now. But other pending announcements
@@ -1821,12 +1846,20 @@ bool routing_add_node_announcement(struct routing_state *rstate,
1821
1846
1822
1847
SUPERVERBOSE ("Deferring node_announcement for node %s" ,
1823
1848
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
+ }
1830
1863
return true;
1831
1864
}
1832
1865
0 commit comments