@@ -31,7 +31,7 @@ use crate::routing::utxo::{self, UtxoLookup, UtxoResolver};
31
31
use crate :: util:: indexed_map:: { Entry as IndexedMapEntry , IndexedMap } ;
32
32
use crate :: util:: logger:: { Level , Logger } ;
33
33
use crate :: util:: scid_utils:: { block_from_scid, scid_from_parts, MAX_SCID_BLOCK } ;
34
- use crate :: util:: ser:: { MaybeReadable , Readable , ReadableArgs , Writeable , Writer } ;
34
+ use crate :: util:: ser:: { MaybeReadable , Readable , ReadableArgs , RequiredWrapper , Writeable , Writer } ;
35
35
use crate :: util:: string:: PrintableString ;
36
36
37
37
use crate :: io;
@@ -218,12 +218,6 @@ pub struct ReadOnlyNetworkGraph<'a> {
218
218
/// [BOLT #4]: https://github.com/lightning/bolts/blob/master/04-onion-routing.md
219
219
#[ derive( Clone , Debug , PartialEq , Eq ) ]
220
220
pub enum NetworkUpdate {
221
- /// An error indicating a `channel_update` messages should be applied via
222
- /// [`NetworkGraph::update_channel`].
223
- ChannelUpdateMessage {
224
- /// The update to apply via [`NetworkGraph::update_channel`].
225
- msg : ChannelUpdate ,
226
- } ,
227
221
/// An error indicating that a channel failed to route a payment, which should be applied via
228
222
/// [`NetworkGraph::channel_failed_permanent`] if permanent.
229
223
ChannelFailure {
@@ -244,19 +238,69 @@ pub enum NetworkUpdate {
244
238
}
245
239
}
246
240
247
- impl_writeable_tlv_based_enum_upgradable ! ( NetworkUpdate ,
248
- ( 0 , ChannelUpdateMessage ) => {
249
- ( 0 , msg, required) ,
250
- } ,
251
- ( 2 , ChannelFailure ) => {
252
- ( 0 , short_channel_id, required) ,
253
- ( 2 , is_permanent, required) ,
254
- } ,
255
- ( 4 , NodeFailure ) => {
256
- ( 0 , node_id, required) ,
257
- ( 2 , is_permanent, required) ,
258
- } ,
259
- ) ;
241
+ impl Writeable for NetworkUpdate {
242
+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
243
+ match self {
244
+ Self :: ChannelFailure { short_channel_id, is_permanent } => {
245
+ 2u8 . write ( writer) ?;
246
+ write_tlv_fields ! ( writer, {
247
+ ( 0 , short_channel_id, required) ,
248
+ ( 2 , is_permanent, required) ,
249
+ } ) ;
250
+ } ,
251
+ Self :: NodeFailure { node_id, is_permanent } => {
252
+ 4u8 . write ( writer) ?;
253
+ write_tlv_fields ! ( writer, {
254
+ ( 0 , node_id, required) ,
255
+ ( 2 , is_permanent, required) ,
256
+ } ) ;
257
+ }
258
+ }
259
+ Ok ( ( ) )
260
+ }
261
+ }
262
+
263
+ impl MaybeReadable for NetworkUpdate {
264
+ fn read < R : io:: Read > ( reader : & mut R ) -> Result < Option < Self > , DecodeError > {
265
+ let id: u8 = Readable :: read ( reader) ?;
266
+ match id {
267
+ 0 => {
268
+ // 0 was previously used for network updates containing a channel update, subsequently
269
+ // removed in LDK version 0.0.124.
270
+ let mut msg: RequiredWrapper < ChannelUpdate > = RequiredWrapper ( None ) ;
271
+ read_tlv_fields ! ( reader, {
272
+ ( 0 , msg, required) ,
273
+ } ) ;
274
+ Ok ( Some ( Self :: ChannelFailure {
275
+ short_channel_id : msg. 0 . unwrap ( ) . contents . short_channel_id ,
276
+ is_permanent : false
277
+ } ) )
278
+ } ,
279
+ 2 => {
280
+ _init_and_read_len_prefixed_tlv_fields ! ( reader, {
281
+ ( 0 , short_channel_id, required) ,
282
+ ( 2 , is_permanent, required) ,
283
+ } ) ;
284
+ Ok ( Some ( Self :: ChannelFailure {
285
+ short_channel_id : short_channel_id. 0 . unwrap ( ) ,
286
+ is_permanent : is_permanent. 0 . unwrap ( ) ,
287
+ } ) )
288
+ } ,
289
+ 4 => {
290
+ _init_and_read_len_prefixed_tlv_fields ! ( reader, {
291
+ ( 0 , node_id, required) ,
292
+ ( 2 , is_permanent, required) ,
293
+ } ) ;
294
+ Ok ( Some ( Self :: NodeFailure {
295
+ node_id : node_id. 0 . unwrap ( ) ,
296
+ is_permanent : is_permanent. 0 . unwrap ( ) ,
297
+ } ) )
298
+ }
299
+ t if t % 2 == 0 => Err ( DecodeError :: UnknownRequiredFeature ) ,
300
+ _ => Ok ( None ) ,
301
+ }
302
+ }
303
+ }
260
304
261
305
/// Receives and validates network updates from peers,
262
306
/// stores authentic and relevant data as a network graph.
@@ -353,19 +397,10 @@ where U::Target: UtxoLookup, L::Target: Logger
353
397
354
398
impl < L : Deref > NetworkGraph < L > where L :: Target : Logger {
355
399
/// Handles any network updates originating from [`Event`]s.
356
- //
357
- /// Note that this will skip applying any [`NetworkUpdate::ChannelUpdateMessage`] to avoid
358
- /// leaking possibly identifying information of the sender to the public network.
359
400
///
360
401
/// [`Event`]: crate::events::Event
361
402
pub fn handle_network_update ( & self , network_update : & NetworkUpdate ) {
362
403
match * network_update {
363
- NetworkUpdate :: ChannelUpdateMessage { ref msg } => {
364
- let short_channel_id = msg. contents . short_channel_id ;
365
- let is_enabled = msg. contents . flags & ( 1 << 1 ) != ( 1 << 1 ) ;
366
- let status = if is_enabled { "enabled" } else { "disabled" } ;
367
- log_debug ! ( self . logger, "Skipping application of a channel update from a payment failure. Channel {} is {}." , short_channel_id, status) ;
368
- } ,
369
404
NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent } => {
370
405
if is_permanent {
371
406
log_debug ! ( self . logger, "Removing channel graph entry for {} due to a payment failure." , short_channel_id) ;
@@ -2575,23 +2610,18 @@ pub(crate) mod tests {
2575
2610
2576
2611
let short_channel_id;
2577
2612
{
2578
- // Check we won't apply an update via `handle_network_update` for privacy reasons, but
2579
- // can continue fine if we manually apply it.
2613
+ // Check that we can manually apply a channel update.
2580
2614
let valid_channel_announcement = get_signed_channel_announcement ( |_| { } , node_1_privkey, node_2_privkey, & secp_ctx) ;
2581
2615
short_channel_id = valid_channel_announcement. contents . short_channel_id ;
2582
2616
let chain_source: Option < & test_utils:: TestChainSource > = None ;
2583
2617
assert ! ( network_graph. update_channel_from_announcement( & valid_channel_announcement, & chain_source) . is_ok( ) ) ;
2584
2618
assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . is_some( ) ) ;
2585
2619
2586
2620
let valid_channel_update = get_signed_channel_update ( |_| { } , node_1_privkey, & secp_ctx) ;
2587
- assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . one_to_two. is_none( ) ) ;
2588
-
2589
- network_graph. handle_network_update ( & NetworkUpdate :: ChannelUpdateMessage {
2590
- msg : valid_channel_update. clone ( ) ,
2591
- } ) ;
2592
2621
2593
2622
assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . one_to_two. is_none( ) ) ;
2594
2623
network_graph. update_channel ( & valid_channel_update) . unwrap ( ) ;
2624
+ assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . one_to_two. is_some( ) ) ;
2595
2625
}
2596
2626
2597
2627
// Non-permanent failure doesn't touch the channel at all
0 commit comments