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