@@ -31,7 +31,7 @@ use crate::routing::utxo::{self, UtxoLookup, UtxoResolver};
3131use crate :: util:: indexed_map:: { Entry as IndexedMapEntry , IndexedMap } ;
3232use crate :: util:: logger:: { Level , Logger } ;
3333use 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 } ;
3535use crate :: util:: string:: PrintableString ;
3636
3737use crate :: io;
@@ -218,12 +218,6 @@ pub struct ReadOnlyNetworkGraph<'a> {
218218/// [BOLT #4]: https://github.com/lightning/bolts/blob/master/04-onion-routing.md
219219#[ derive( Clone , Debug , PartialEq , Eq ) ]
220220pub 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- } ,
227221 /// An error indicating that a channel failed to route a payment, which should be applied via
228222 /// [`NetworkGraph::channel_failed_permanent`] if permanent.
229223 ChannelFailure {
@@ -244,19 +238,69 @@ pub enum NetworkUpdate {
244238 }
245239}
246240
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+ }
260304
261305/// Receives and validates network updates from peers,
262306/// stores authentic and relevant data as a network graph.
@@ -353,19 +397,10 @@ where U::Target: UtxoLookup, L::Target: Logger
353397
354398impl < L : Deref > NetworkGraph < L > where L :: Target : Logger {
355399 /// 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.
359400 ///
360401 /// [`Event`]: crate::events::Event
361402 pub fn handle_network_update ( & self , network_update : & NetworkUpdate ) {
362403 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- } ,
369404 NetworkUpdate :: ChannelFailure { short_channel_id, is_permanent } => {
370405 if is_permanent {
371406 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 {
25752610
25762611 let short_channel_id;
25772612 {
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.
25802614 let valid_channel_announcement = get_signed_channel_announcement ( |_| { } , node_1_privkey, node_2_privkey, & secp_ctx) ;
25812615 short_channel_id = valid_channel_announcement. contents . short_channel_id ;
25822616 let chain_source: Option < & test_utils:: TestChainSource > = None ;
25832617 assert ! ( network_graph. update_channel_from_announcement( & valid_channel_announcement, & chain_source) . is_ok( ) ) ;
25842618 assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . is_some( ) ) ;
25852619
25862620 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- } ) ;
25922621
25932622 assert ! ( network_graph. read_only( ) . channels( ) . get( & short_channel_id) . unwrap( ) . one_to_two. is_none( ) ) ;
25942623 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( ) ) ;
25952625 }
25962626
25972627 // Non-permanent failure doesn't touch the channel at all
0 commit comments