Merge pull request #1709 from tnull/2022-09-make-access-error-debug
[rust-lightning] / lightning / src / util / events.rs
index 4277e7496abeb8ad8b8de812fc52740e75184095..8ddd762e97036bac77fee08c2be7819ec707388e 100644 (file)
@@ -376,7 +376,7 @@ pub enum Event {
                /// Indicates the payment was rejected for some reason by the recipient. This implies that
                /// the payment has failed, not just the route in question. If this is not set, you may
                /// retry the payment via a different route.
-               rejected_by_dest: bool,
+               payment_failed_permanently: bool,
                /// Any failure information conveyed via the Onion return packet by a node along the failed
                /// payment route.
                ///
@@ -643,7 +643,7 @@ impl Writeable for Event {
                                });
                        },
                        &Event::PaymentPathFailed {
-                               ref payment_id, ref payment_hash, ref rejected_by_dest, ref network_update,
+                               ref payment_id, ref payment_hash, ref payment_failed_permanently, ref network_update,
                                ref all_paths_failed, ref path, ref short_channel_id, ref retry,
                                #[cfg(test)]
                                ref error_code,
@@ -658,7 +658,7 @@ impl Writeable for Event {
                                write_tlv_fields!(writer, {
                                        (0, payment_hash, required),
                                        (1, network_update, option),
-                                       (2, rejected_by_dest, required),
+                                       (2, payment_failed_permanently, required),
                                        (3, all_paths_failed, required),
                                        (5, path, vec_type),
                                        (7, short_channel_id, option),
@@ -827,7 +827,7 @@ impl MaybeReadable for Event {
                                        #[cfg(test)]
                                        let error_data = Readable::read(reader)?;
                                        let mut payment_hash = PaymentHash([0; 32]);
-                                       let mut rejected_by_dest = false;
+                                       let mut payment_failed_permanently = false;
                                        let mut network_update = None;
                                        let mut all_paths_failed = Some(true);
                                        let mut path: Option<Vec<RouteHop>> = Some(vec![]);
@@ -837,7 +837,7 @@ impl MaybeReadable for Event {
                                        read_tlv_fields!(reader, {
                                                (0, payment_hash, required),
                                                (1, network_update, ignorable),
-                                               (2, rejected_by_dest, required),
+                                               (2, payment_failed_permanently, required),
                                                (3, all_paths_failed, option),
                                                (5, path, vec_type),
                                                (7, short_channel_id, option),
@@ -847,7 +847,7 @@ impl MaybeReadable for Event {
                                        Ok(Some(Event::PaymentPathFailed {
                                                payment_id,
                                                payment_hash,
-                                               rejected_by_dest,
+                                               payment_failed_permanently,
                                                network_update,
                                                all_paths_failed: all_paths_failed.unwrap(),
                                                path: path.unwrap(),
@@ -1002,7 +1002,7 @@ impl MaybeReadable for Event {
                                                (4, path, vec_type),
                                                (6, short_channel_id, option),
                                        });
-                                       Ok(Some(Event::ProbeFailed{
+                                       Ok(Some(Event::ProbeFailed {
                                                payment_id,
                                                payment_hash,
                                                path: path.unwrap(),
@@ -1011,6 +1011,28 @@ impl MaybeReadable for Event {
                                };
                                f()
                        },
+                       25u8 => {
+                               let f = || {
+                                       let mut prev_channel_id = [0; 32];
+                                       let mut failed_next_destination_opt = None;
+                                       read_tlv_fields!(reader, {
+                                               (0, prev_channel_id, required),
+                                               (2, failed_next_destination_opt, ignorable),
+                                       });
+                                       if let Some(failed_next_destination) = failed_next_destination_opt {
+                                               Ok(Some(Event::HTLCHandlingFailed {
+                                                       prev_channel_id,
+                                                       failed_next_destination,
+                                               }))
+                                       } else {
+                                               // If we fail to read a `failed_next_destination` assume it's because
+                                               // `MaybeReadable::read` returned `Ok(None)`, though it's also possible we
+                                               // were simply missing the field.
+                                               Ok(None)
+                                       }
+                               };
+                               f()
+                       },
                        // Versions prior to 0.0.100 did not ignore odd types, instead returning InvalidValue.
                        // Version 0.0.100 failed to properly ignore odd types, possibly resulting in corrupt
                        // reads.
@@ -1115,25 +1137,32 @@ pub enum MessageSendEvent {
                /// The message which should be sent.
                msg: msgs::ChannelReestablish,
        },
+       /// Used to send a channel_announcement and channel_update to a specific peer, likely on
+       /// initial connection to ensure our peers know about our channels.
+       SendChannelAnnouncement {
+               /// The node_id of the node which should receive this message
+               node_id: PublicKey,
+               /// The channel_announcement which should be sent.
+               msg: msgs::ChannelAnnouncement,
+               /// The followup channel_update which should be sent.
+               update_msg: msgs::ChannelUpdate,
+       },
        /// Used to indicate that a channel_announcement and channel_update should be broadcast to all
        /// peers (except the peer with node_id either msg.contents.node_id_1 or msg.contents.node_id_2).
        ///
-       /// Note that after doing so, you very likely (unless you did so very recently) want to call
-       /// ChannelManager::broadcast_node_announcement to trigger a BroadcastNodeAnnouncement event.
-       /// This ensures that any nodes which see our channel_announcement also have a relevant
+       /// Note that after doing so, you very likely (unless you did so very recently) want to
+       /// broadcast a node_announcement (e.g. via [`PeerManager::broadcast_node_announcement`]). This
+       /// ensures that any nodes which see our channel_announcement also have a relevant
        /// node_announcement, including relevant feature flags which may be important for routing
        /// through or to us.
+       ///
+       /// [`PeerManager::broadcast_node_announcement`]: crate::ln::peer_handler::PeerManager::broadcast_node_announcement
        BroadcastChannelAnnouncement {
                /// The channel_announcement which should be sent.
                msg: msgs::ChannelAnnouncement,
                /// The followup channel_update which should be sent.
                update_msg: msgs::ChannelUpdate,
        },
-       /// Used to indicate that a node_announcement should be broadcast to all peers.
-       BroadcastNodeAnnouncement {
-               /// The node_announcement which should be sent.
-               msg: msgs::NodeAnnouncement,
-       },
        /// Used to indicate that a channel_update should be broadcast to all peers.
        BroadcastChannelUpdate {
                /// The channel_update which should be sent.