@@ -18,7 +18,8 @@ use bitcoin::hashes::hex::ToHex;
18
18
19
19
use crate :: ln:: chan_utils:: make_funding_redeemscript_from_slices;
20
20
use crate :: ln:: msgs:: { self , LightningError , ErrorAction } ;
21
- use crate :: routing:: gossip:: { NetworkGraph , NodeId } ;
21
+ use crate :: routing:: gossip:: { NetworkGraph , NodeId , P2PGossipSync } ;
22
+ use crate :: util:: events:: MessageSendEvent ;
22
23
use crate :: util:: logger:: { Level , Logger } ;
23
24
use crate :: util:: ser:: Writeable ;
24
25
@@ -144,8 +145,32 @@ impl UtxoFuture {
144
145
}
145
146
146
147
/// Resolves this future against the given `graph` and with the given `result`.
147
- pub fn resolve < L : Deref > ( & self , graph : & NetworkGraph < L > , result : Result < TxOut , UtxoLookupError > )
148
+ ///
149
+ /// This is identical to calling [`UtxoFuture::resolve`] with a dummy `gossip`, disabling
150
+ /// forwarding the validated gossip message onwards to peers.
151
+ pub fn resolve_without_forwarding < L : Deref > ( & self ,
152
+ graph : & NetworkGraph < L > , result : Result < TxOut , UtxoLookupError > )
148
153
where L :: Target : Logger {
154
+ self . do_resolve ( graph, result) ;
155
+ }
156
+
157
+ /// Resolves this future against the given `graph` and with the given `result`.
158
+ ///
159
+ /// The given `gossip` is used to broadcast any validated messages onwards to all peers which
160
+ /// have available buffer space.
161
+ pub fn resolve < L : Deref , G : Deref < Target =NetworkGraph < L > > , U : Deref , GS : Deref < Target = P2PGossipSync < G , U , L > > > ( & self ,
162
+ graph : & NetworkGraph < L > , gossip : GS , result : Result < TxOut , UtxoLookupError >
163
+ ) where L :: Target : Logger , U :: Target : UtxoLookup {
164
+ let mut res = self . do_resolve ( graph, result) ;
165
+ for msg_opt in res. iter_mut ( ) {
166
+ if let Some ( msg) = msg_opt. take ( ) {
167
+ gossip. forward_gossip_msg ( msg) ;
168
+ }
169
+ }
170
+ }
171
+
172
+ fn do_resolve < L : Deref > ( & self , graph : & NetworkGraph < L > , result : Result < TxOut , UtxoLookupError > )
173
+ -> [ Option < MessageSendEvent > ; 5 ] where L :: Target : Logger {
149
174
let ( announcement, node_a, node_b, update_a, update_b) = {
150
175
let mut pending_checks = graph. pending_checks . internal . lock ( ) . unwrap ( ) ;
151
176
let mut async_messages = self . state . lock ( ) . unwrap ( ) ;
@@ -155,7 +180,7 @@ impl UtxoFuture {
155
180
// `channel_announce` yet. That's okay, we can set the `complete` field which it will
156
181
// check once it gets control again.
157
182
async_messages. complete = Some ( result) ;
158
- return ;
183
+ return [ None , None , None , None , None ] ;
159
184
}
160
185
161
186
let announcement_msg = match async_messages. channel_announce . as_ref ( ) . unwrap ( ) {
@@ -172,14 +197,22 @@ impl UtxoFuture {
172
197
async_messages. latest_channel_update_b . take ( ) )
173
198
} ;
174
199
200
+ let mut res = [ None , None , None , None , None ] ;
201
+ let mut res_idx = 0 ;
202
+
175
203
// Now that we've updated our internal state, pass the pending messages back through the
176
204
// network graph with a different `UtxoLookup` which will resolve immediately.
177
205
// Note that we ignore errors as we don't disconnect peers anyway, so there's nothing to do
178
206
// with them.
179
207
let resolver = UtxoResolver ( result) ;
180
208
match announcement {
181
209
ChannelAnnouncement :: Full ( signed_msg) => {
182
- let _ = graph. update_channel_from_announcement ( & signed_msg, & Some ( & resolver) ) ;
210
+ if graph. update_channel_from_announcement ( & signed_msg, & Some ( & resolver) ) . is_ok ( ) {
211
+ res[ res_idx] = Some ( MessageSendEvent :: BroadcastChannelAnnouncement {
212
+ msg : signed_msg, update_msg : None ,
213
+ } ) ;
214
+ res_idx += 1 ;
215
+ }
183
216
} ,
184
217
ChannelAnnouncement :: Unsigned ( msg) => {
185
218
let _ = graph. update_channel_from_unsigned_announcement ( & msg, & Some ( & resolver) ) ;
@@ -189,7 +222,12 @@ impl UtxoFuture {
189
222
for announce in core:: iter:: once ( node_a) . chain ( core:: iter:: once ( node_b) ) {
190
223
match announce {
191
224
Some ( NodeAnnouncement :: Full ( signed_msg) ) => {
192
- let _ = graph. update_node_from_announcement ( & signed_msg) ;
225
+ if graph. update_node_from_announcement ( & signed_msg) . is_ok ( ) {
226
+ res[ res_idx] = Some ( MessageSendEvent :: BroadcastNodeAnnouncement {
227
+ msg : signed_msg,
228
+ } ) ;
229
+ res_idx += 1 ;
230
+ }
193
231
} ,
194
232
Some ( NodeAnnouncement :: Unsigned ( msg) ) => {
195
233
let _ = graph. update_node_from_unsigned_announcement ( & msg) ;
@@ -201,14 +239,21 @@ impl UtxoFuture {
201
239
for update in core:: iter:: once ( update_a) . chain ( core:: iter:: once ( update_b) ) {
202
240
match update {
203
241
Some ( ChannelUpdate :: Full ( signed_msg) ) => {
204
- let _ = graph. update_channel ( & signed_msg) ;
242
+ if graph. update_channel ( & signed_msg) . is_ok ( ) {
243
+ res[ res_idx] = Some ( MessageSendEvent :: BroadcastChannelUpdate {
244
+ msg : signed_msg,
245
+ } ) ;
246
+ res_idx += 1 ;
247
+ }
205
248
} ,
206
249
Some ( ChannelUpdate :: Unsigned ( msg) ) => {
207
250
let _ = graph. update_channel_unsigned ( & msg) ;
208
251
} ,
209
252
None => { } ,
210
253
}
211
254
}
255
+
256
+ res
212
257
}
213
258
}
214
259
0 commit comments