@@ -208,6 +208,7 @@ pub struct ReadOnlyNetworkGraph<'a> {
208
208
pub enum NetworkUpdate {
209
209
/// An error indicating a `channel_update` messages should be applied via
210
210
/// [`NetworkGraph::update_channel`].
211
+ #[ cfg( test) ]
211
212
ChannelUpdateMessage {
212
213
/// The update to apply via [`NetworkGraph::update_channel`].
213
214
msg : ChannelUpdate ,
@@ -232,6 +233,7 @@ pub enum NetworkUpdate {
232
233
}
233
234
}
234
235
236
+ #[ cfg( test) ]
235
237
impl_writeable_tlv_based_enum_upgradable ! ( NetworkUpdate ,
236
238
( 0 , ChannelUpdateMessage ) => {
237
239
( 0 , msg, required) ,
@@ -246,6 +248,19 @@ impl_writeable_tlv_based_enum_upgradable!(NetworkUpdate,
246
248
} ,
247
249
) ;
248
250
251
+ #[ cfg( not( test) ) ]
252
+ impl_writeable_tlv_based_enum_upgradable ! ( NetworkUpdate ,
253
+ // 0 used to be ChannelUpdateMessage in LDK versions prior to 0.0.118
254
+ ( 2 , ChannelFailure ) => {
255
+ ( 0 , short_channel_id, required) ,
256
+ ( 2 , is_permanent, required) ,
257
+ } ,
258
+ ( 4 , NodeFailure ) => {
259
+ ( 0 , node_id, required) ,
260
+ ( 2 , is_permanent, required) ,
261
+ } ,
262
+ ) ;
263
+
249
264
/// Receives and validates network updates from peers,
250
265
/// stores authentic and relevant data as a network graph.
251
266
/// This network graph is then used for routing payments.
@@ -345,12 +360,15 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
345
360
/// [`Event`]: crate::events::Event
346
361
pub fn handle_network_update ( & self , network_update : & NetworkUpdate ) {
347
362
match * network_update {
363
+ #[ cfg( test) ]
348
364
NetworkUpdate :: ChannelUpdateMessage { ref msg } => {
349
365
let short_channel_id = msg. contents . short_channel_id ;
350
366
let is_enabled = msg. contents . flags & ( 1 << 1 ) != ( 1 << 1 ) ;
351
367
let status = if is_enabled { "enabled" } else { "disabled" } ;
352
- log_debug ! ( self . logger, "Updating channel with channel_update from a payment failure. Channel {} is {}." , short_channel_id, status) ;
353
- let _ = self . update_channel ( msg) ;
368
+ log_debug ! ( self . logger, "Skipping application of a channel update from a payment failure. Channel {} is {}." , short_channel_id, status) ;
369
+ // While the `ChannelUpdateMessage` variant is available in tests we don't apply
370
+ // them to the network graph to avoid having our test behavior diverge too much
371
+ // from the production case.
354
372
} ,
355
373
NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent } => {
356
374
if is_permanent {
@@ -2531,7 +2549,8 @@ pub(crate) mod tests {
2531
2549
2532
2550
let short_channel_id;
2533
2551
{
2534
- // Announce a channel we will update
2552
+ // Check we won't apply an update via `handle_network_update` for privacy reasons, but
2553
+ // can continue fine if we manually apply it.
2535
2554
let valid_channel_announcement = get_signed_channel_announcement ( |_| { } , node_1_privkey, node_2_privkey, & secp_ctx) ;
2536
2555
short_channel_id = valid_channel_announcement. contents . short_channel_id ;
2537
2556
let chain_source: Option < & test_utils:: TestChainSource > = None ;
@@ -2542,10 +2561,11 @@ pub(crate) mod tests {
2542
2561
assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . one_to_two. is_none( ) ) ;
2543
2562
2544
2563
network_graph. handle_network_update ( & NetworkUpdate :: ChannelUpdateMessage {
2545
- msg : valid_channel_update,
2564
+ msg : valid_channel_update. clone ( ) ,
2546
2565
} ) ;
2547
2566
2548
- assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . one_to_two. is_some( ) ) ;
2567
+ assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . one_to_two. is_none( ) ) ;
2568
+ network_graph. update_channel ( & valid_channel_update) . unwrap ( ) ;
2549
2569
}
2550
2570
2551
2571
// Non-permanent failure doesn't touch the channel at all
0 commit comments