@@ -11,7 +11,8 @@ use bitcoin::secp256k1::PublicKey;
11
11
12
12
use crate :: ln:: chan_utils:: make_funding_redeemscript;
13
13
use crate :: ln:: msgs:: { self , LightningError , ErrorAction } ;
14
- use crate :: routing:: gossip:: { NetworkGraph , NodeId } ;
14
+ use crate :: routing:: gossip:: { NetworkGraph , NodeId , P2PGossipSync } ;
15
+ use crate :: util:: events:: MessageSendEvent ;
15
16
use crate :: util:: logger:: Logger ;
16
17
use crate :: util:: ser:: Writeable ;
17
18
@@ -131,8 +132,26 @@ impl AccessFuture {
131
132
}
132
133
133
134
/// Resolves this future against the given `graph` and with the given `result`.
134
- pub fn resolve < L : Deref > ( & self , graph : & NetworkGraph < L > , result : Result < TxOut , ChainAccessError > )
135
+ ///
136
+ /// This is identical to calling [`AccessFuture::resolve`] with a `None` for the `gossip`
137
+ /// field, disabling forwarding the validated gossip message onwards to peers. It avoids
138
+ /// needing to specify a full concrete type for the generic parameters on the gossip parameter.
139
+ pub fn resolve_without_forwarding < L : Deref > ( & self ,
140
+ graph : & NetworkGraph < L > , result : Result < TxOut , ChainAccessError > )
135
141
where L :: Target : Logger {
142
+ // Sadly there's no great way to guess the types the user uses for their P2PGossipSync
143
+ // here, so we have to just make something up, nearly guaranteeing we end up with two
144
+ // copies of every P2PGossipSync method in the build.
145
+ self . resolve ( graph, None :: < & P2PGossipSync < & NetworkGraph < L > , & dyn ChainAccess , L > > , result) ;
146
+ }
147
+
148
+ /// Resolves this future against the given `graph` and with the given `result`.
149
+ ///
150
+ /// If provided, the given `gossip` is used to broadcast any validated messages onwards to all
151
+ /// peers which have available buffer space.
152
+ pub fn resolve < L : Deref , G : Deref < Target =NetworkGraph < L > > , C : Deref , GS : Deref < Target = P2PGossipSync < G , C , L > > > ( & self ,
153
+ graph : & NetworkGraph < L > , gossip : Option < GS > , result : Result < TxOut , ChainAccessError > )
154
+ where L :: Target : Logger , C :: Target : ChainAccess {
136
155
let ( announcement, node_a, node_b, update_a, update_b) = {
137
156
let mut pending_checks = graph. pending_checks . internal . lock ( ) . unwrap ( ) ;
138
157
let mut async_messages = self . state . lock ( ) . unwrap ( ) ;
@@ -186,7 +205,13 @@ impl AccessFuture {
186
205
let resolver = AccessResolver ( result) ;
187
206
match announcement {
188
207
ChannelAnnouncement :: Full ( signed_msg) => {
189
- let _ = graph. update_channel_from_announcement ( & signed_msg, & Some ( & resolver) ) ;
208
+ if graph. update_channel_from_announcement ( & signed_msg, & Some ( & resolver) ) . is_ok ( ) {
209
+ if let Some ( broadcaster) = & gossip {
210
+ broadcaster. forward_gossip_msg ( MessageSendEvent :: BroadcastChannelAnnouncement {
211
+ msg : signed_msg, update_msg : None ,
212
+ } ) ;
213
+ }
214
+ }
190
215
} ,
191
216
ChannelAnnouncement :: Unsigned ( msg) => {
192
217
let _ = graph. update_channel_from_unsigned_announcement ( & msg, & Some ( & resolver) ) ;
@@ -196,7 +221,13 @@ impl AccessFuture {
196
221
for announce in [ node_a, node_b] {
197
222
match announce {
198
223
Some ( NodeAnnouncement :: Full ( signed_msg) ) => {
199
- let _ = graph. update_node_from_announcement ( & signed_msg) ;
224
+ if graph. update_node_from_announcement ( & signed_msg) . is_ok ( ) {
225
+ if let Some ( broadcaster) = & gossip {
226
+ broadcaster. forward_gossip_msg ( MessageSendEvent :: BroadcastNodeAnnouncement {
227
+ msg : signed_msg,
228
+ } ) ;
229
+ }
230
+ }
200
231
} ,
201
232
Some ( NodeAnnouncement :: Unsigned ( msg) ) => {
202
233
let _ = graph. update_node_from_unsigned_announcement ( & msg) ;
@@ -208,7 +239,13 @@ impl AccessFuture {
208
239
for update in [ update_a, update_b] {
209
240
match update {
210
241
Some ( ChannelUpdate :: Full ( signed_msg) ) => {
211
- let _ = graph. update_channel ( & signed_msg) ;
242
+ if graph. update_channel ( & signed_msg) . is_ok ( ) {
243
+ if let Some ( broadcaster) = & gossip {
244
+ broadcaster. forward_gossip_msg ( MessageSendEvent :: BroadcastChannelUpdate {
245
+ msg : signed_msg,
246
+ } ) ;
247
+ }
248
+ }
212
249
} ,
213
250
Some ( ChannelUpdate :: Unsigned ( msg) ) => {
214
251
let _ = graph. update_channel_unsigned ( & msg) ;
0 commit comments