@@ -20,7 +20,8 @@ use bitcoin::secp256k1::PublicKey;
20
20
21
21
use crate :: ln:: chan_utils:: make_funding_redeemscript;
22
22
use crate :: ln:: msgs:: { self , LightningError , ErrorAction } ;
23
- use crate :: routing:: gossip:: { NetworkGraph , NodeId } ;
23
+ use crate :: routing:: gossip:: { NetworkGraph , NodeId , P2PGossipSync } ;
24
+ use crate :: util:: events:: MessageSendEvent ;
24
25
use crate :: util:: logger:: Logger ;
25
26
use crate :: util:: ser:: Writeable ;
26
27
@@ -142,8 +143,26 @@ impl AccessFuture {
142
143
}
143
144
144
145
/// Resolves this future against the given `graph` and with the given `result`.
145
- pub fn resolve < L : Deref > ( & self , graph : & NetworkGraph < L > , result : Result < TxOut , ChainAccessError > )
146
+ ///
147
+ /// This is identical to calling [`AccessFuture::resolve`] with a `None` for the `gossip`
148
+ /// field, disabling forwarding the validated gossip message onwards to peers. It avoids
149
+ /// needing to specify a full concrete type for the generic parameters on the gossip parameter.
150
+ pub fn resolve_without_forwarding < L : Deref > ( & self ,
151
+ graph : & NetworkGraph < L > , result : Result < TxOut , ChainAccessError > )
146
152
where L :: Target : Logger {
153
+ // Sadly there's no great way to guess the types the user uses for their P2PGossipSync
154
+ // here, so we have to just make something up, nearly guaranteeing we end up with two
155
+ // copies of every P2PGossipSync method in the build.
156
+ self . resolve ( graph, None :: < & P2PGossipSync < & NetworkGraph < L > , & dyn ChainAccess , L > > , result) ;
157
+ }
158
+
159
+ /// Resolves this future against the given `graph` and with the given `result`.
160
+ ///
161
+ /// If provided, the given `gossip` is used to broadcast any validated messages onwards to all
162
+ /// peers which have available buffer space.
163
+ pub fn resolve < L : Deref , G : Deref < Target =NetworkGraph < L > > , C : Deref , GS : Deref < Target = P2PGossipSync < G , C , L > > > ( & self ,
164
+ graph : & NetworkGraph < L > , gossip : Option < GS > , result : Result < TxOut , ChainAccessError > )
165
+ where L :: Target : Logger , C :: Target : ChainAccess {
147
166
let ( announcement, node_a, node_b, update_a, update_b) = {
148
167
let mut pending_checks = graph. pending_checks . internal . lock ( ) . unwrap ( ) ;
149
168
let mut async_messages = self . state . lock ( ) . unwrap ( ) ;
@@ -197,7 +216,13 @@ impl AccessFuture {
197
216
let resolver = AccessResolver ( result) ;
198
217
match announcement {
199
218
ChannelAnnouncement :: Full ( signed_msg) => {
200
- let _ = graph. update_channel_from_announcement ( & signed_msg, & Some ( & resolver) ) ;
219
+ if graph. update_channel_from_announcement ( & signed_msg, & Some ( & resolver) ) . is_ok ( ) {
220
+ if let Some ( broadcaster) = & gossip {
221
+ broadcaster. forward_gossip_msg ( MessageSendEvent :: BroadcastChannelAnnouncement {
222
+ msg : signed_msg, update_msg : None ,
223
+ } ) ;
224
+ }
225
+ }
201
226
} ,
202
227
ChannelAnnouncement :: Unsigned ( msg) => {
203
228
let _ = graph. update_channel_from_unsigned_announcement ( & msg, & Some ( & resolver) ) ;
@@ -207,7 +232,13 @@ impl AccessFuture {
207
232
for announce in core:: iter:: once ( node_a) . chain ( core:: iter:: once ( node_b) ) {
208
233
match announce {
209
234
Some ( NodeAnnouncement :: Full ( signed_msg) ) => {
210
- let _ = graph. update_node_from_announcement ( & signed_msg) ;
235
+ if graph. update_node_from_announcement ( & signed_msg) . is_ok ( ) {
236
+ if let Some ( broadcaster) = & gossip {
237
+ broadcaster. forward_gossip_msg ( MessageSendEvent :: BroadcastNodeAnnouncement {
238
+ msg : signed_msg,
239
+ } ) ;
240
+ }
241
+ }
211
242
} ,
212
243
Some ( NodeAnnouncement :: Unsigned ( msg) ) => {
213
244
let _ = graph. update_node_from_unsigned_announcement ( & msg) ;
@@ -219,7 +250,13 @@ impl AccessFuture {
219
250
for update in core:: iter:: once ( update_a) . chain ( core:: iter:: once ( update_b) ) {
220
251
match update {
221
252
Some ( ChannelUpdate :: Full ( signed_msg) ) => {
222
- let _ = graph. update_channel ( & signed_msg) ;
253
+ if graph. update_channel ( & signed_msg) . is_ok ( ) {
254
+ if let Some ( broadcaster) = & gossip {
255
+ broadcaster. forward_gossip_msg ( MessageSendEvent :: BroadcastChannelUpdate {
256
+ msg : signed_msg,
257
+ } ) ;
258
+ }
259
+ }
223
260
} ,
224
261
Some ( ChannelUpdate :: Unsigned ( msg) ) => {
225
262
let _ = graph. update_channel_unsigned ( & msg) ;
0 commit comments