X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Frouting%2Fgossip.rs;h=d31d08f5ffb9c72466cc8825472109d1f8849b19;hb=1e81287cbcb3cbe83557b6b092fa263016f0d28d;hp=947df9edae0f2b3a166e96ff704c9c5775e7da8e;hpb=49c9f1885dd7a564c0c78ad5f73ea4792c0171a8;p=rust-lightning diff --git a/lightning/src/routing/gossip.rs b/lightning/src/routing/gossip.rs index 947df9ed..d31d08f5 100644 --- a/lightning/src/routing/gossip.rs +++ b/lightning/src/routing/gossip.rs @@ -673,13 +673,13 @@ impl Writeable for ChannelUpdateInfo { impl Readable for ChannelUpdateInfo { fn read(reader: &mut R) -> Result { - init_tlv_field_var!(last_update, required); - init_tlv_field_var!(enabled, required); - init_tlv_field_var!(cltv_expiry_delta, required); - init_tlv_field_var!(htlc_minimum_msat, required); - init_tlv_field_var!(htlc_maximum_msat, option); - init_tlv_field_var!(fees, required); - init_tlv_field_var!(last_update_message, required); + _init_tlv_field_var!(last_update, required); + _init_tlv_field_var!(enabled, required); + _init_tlv_field_var!(cltv_expiry_delta, required); + _init_tlv_field_var!(htlc_minimum_msat, required); + _init_tlv_field_var!(htlc_maximum_msat, option); + _init_tlv_field_var!(fees, required); + _init_tlv_field_var!(last_update_message, required); read_tlv_fields!(reader, { (0, last_update, required), @@ -693,13 +693,13 @@ impl Readable for ChannelUpdateInfo { if let Some(htlc_maximum_msat) = htlc_maximum_msat { Ok(ChannelUpdateInfo { - last_update: init_tlv_based_struct_field!(last_update, required), - enabled: init_tlv_based_struct_field!(enabled, required), - cltv_expiry_delta: init_tlv_based_struct_field!(cltv_expiry_delta, required), - htlc_minimum_msat: init_tlv_based_struct_field!(htlc_minimum_msat, required), + last_update: _init_tlv_based_struct_field!(last_update, required), + enabled: _init_tlv_based_struct_field!(enabled, required), + cltv_expiry_delta: _init_tlv_based_struct_field!(cltv_expiry_delta, required), + htlc_minimum_msat: _init_tlv_based_struct_field!(htlc_minimum_msat, required), htlc_maximum_msat, - fees: init_tlv_based_struct_field!(fees, required), - last_update_message: init_tlv_based_struct_field!(last_update_message, required), + fees: _init_tlv_based_struct_field!(fees, required), + last_update_message: _init_tlv_based_struct_field!(last_update_message, required), }) } else { Err(DecodeError::InvalidValue) @@ -820,14 +820,14 @@ impl MaybeReadable for ChannelUpdateInfoDeserWrapper { impl Readable for ChannelInfo { fn read(reader: &mut R) -> Result { - init_tlv_field_var!(features, required); - init_tlv_field_var!(announcement_received_time, (default_value, 0)); - init_tlv_field_var!(node_one, required); + _init_tlv_field_var!(features, required); + _init_tlv_field_var!(announcement_received_time, (default_value, 0)); + _init_tlv_field_var!(node_one, required); let mut one_to_two_wrap: Option = None; - init_tlv_field_var!(node_two, required); + _init_tlv_field_var!(node_two, required); let mut two_to_one_wrap: Option = None; - init_tlv_field_var!(capacity_sats, required); - init_tlv_field_var!(announcement_message, required); + _init_tlv_field_var!(capacity_sats, required); + _init_tlv_field_var!(announcement_message, required); read_tlv_fields!(reader, { (0, features, required), (1, announcement_received_time, (default_value, 0)), @@ -840,14 +840,14 @@ impl Readable for ChannelInfo { }); Ok(ChannelInfo { - features: init_tlv_based_struct_field!(features, required), - node_one: init_tlv_based_struct_field!(node_one, required), + features: _init_tlv_based_struct_field!(features, required), + node_one: _init_tlv_based_struct_field!(node_one, required), one_to_two: one_to_two_wrap.map(|w| w.0).unwrap_or(None), - node_two: init_tlv_based_struct_field!(node_two, required), + node_two: _init_tlv_based_struct_field!(node_two, required), two_to_one: two_to_one_wrap.map(|w| w.0).unwrap_or(None), - capacity_sats: init_tlv_based_struct_field!(capacity_sats, required), - announcement_message: init_tlv_based_struct_field!(announcement_message, required), - announcement_received_time: init_tlv_based_struct_field!(announcement_received_time, (default_value, 0)), + capacity_sats: _init_tlv_based_struct_field!(capacity_sats, required), + announcement_message: _init_tlv_based_struct_field!(announcement_message, required), + announcement_received_time: _init_tlv_based_struct_field!(announcement_received_time, (default_value, 0)), }) } } @@ -1103,9 +1103,9 @@ impl MaybeReadable for NodeAnnouncementInfoDeserWrapper { impl Readable for NodeInfo { fn read(reader: &mut R) -> Result { - init_tlv_field_var!(lowest_inbound_channel_fees, option); + _init_tlv_field_var!(lowest_inbound_channel_fees, option); let mut announcement_info_wrap: Option = None; - init_tlv_field_var!(channels, vec_type); + _init_tlv_field_var!(channels, vec_type); read_tlv_fields!(reader, { (0, lowest_inbound_channel_fees, option), @@ -1114,9 +1114,9 @@ impl Readable for NodeInfo { }); Ok(NodeInfo { - lowest_inbound_channel_fees: init_tlv_based_struct_field!(lowest_inbound_channel_fees, option), + lowest_inbound_channel_fees: _init_tlv_based_struct_field!(lowest_inbound_channel_fees, option), announcement_info: announcement_info_wrap.map(|w| w.0), - channels: init_tlv_based_struct_field!(channels, vec_type), + channels: _init_tlv_based_struct_field!(channels, vec_type), }) } } @@ -1541,6 +1541,14 @@ impl NetworkGraph where L::Target: Logger { #[cfg(not(feature = "std"))] let current_time_unix = None; + self.channel_failed_with_time(short_channel_id, is_permanent, current_time_unix) + } + + /// Marks a channel in the graph as failed if a corresponding HTLC fail was sent. + /// If permanent, removes a channel from the local storage. + /// May cause the removal of nodes too, if this was their last channel. + /// If not permanent, makes channels unavailable for routing. + fn channel_failed_with_time(&self, short_channel_id: u64, is_permanent: bool, current_time_unix: Option) { let mut channels = self.channels.write().unwrap(); if is_permanent { if let Some(chan) = channels.remove(&short_channel_id) { @@ -2537,18 +2545,18 @@ mod tests { // Mark the channel as permanently failed. This will also remove the two nodes // and all of the entries will be tracked as removed. - network_graph.channel_failed(short_channel_id, true); + network_graph.channel_failed_with_time(short_channel_id, true, Some(tracking_time)); // Should not remove from tracking if insufficient time has passed network_graph.remove_stale_channels_and_tracking_with_time( tracking_time + REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS - 1); - assert_eq!(network_graph.removed_channels.lock().unwrap().len(), 1); + assert_eq!(network_graph.removed_channels.lock().unwrap().len(), 1, "Removed channel count ≠ 1 with tracking_time {}", tracking_time); // Provide a later time so that sufficient time has passed network_graph.remove_stale_channels_and_tracking_with_time( tracking_time + REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS); - assert!(network_graph.removed_channels.lock().unwrap().is_empty()); - assert!(network_graph.removed_nodes.lock().unwrap().is_empty()); + assert!(network_graph.removed_channels.lock().unwrap().is_empty(), "Unexpectedly removed channels with tracking_time {}", tracking_time); + assert!(network_graph.removed_nodes.lock().unwrap().is_empty(), "Unexpectedly removed nodes with tracking_time {}", tracking_time); } #[cfg(not(feature = "std"))]