]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Only include channel_update in failure if needed by error code
authorWilmer Paulino <wilmer@wilmerpaulino.com>
Fri, 8 Mar 2024 07:31:14 +0000 (23:31 -0800)
committerWilmer Paulino <wilmer@wilmerpaulino.com>
Wed, 27 Mar 2024 21:28:03 +0000 (14:28 -0700)
This simplifies the failure path by allowing us to return the general
error code for a failure, which we can then amend based on whether it
was for a phantom forward.

lightning/src/ln/channelmanager.rs

index 8c4c68eea50f9ca167f9bd6c6872c030cf6fef1e..683b570dae0d2c0b79849843296f518d36fe635e 100644 (file)
@@ -3189,13 +3189,6 @@ where
                        let chan_update_opt = self.do_funded_channel_callback(next_packet_details.outgoing_scid, |chan: &mut Channel<SP>| {
                                self.get_channel_update_for_onion(next_packet_details.outgoing_scid, chan).ok()
                        }).flatten();
-                       if err_code & 0x1000 != 0 && chan_update_opt.is_none() {
-                               // We really should set `incorrect_cltv_expiry` here but as we're not
-                               // forwarding over a real channel we can't generate a channel_update
-                               // for it. Instead we just return a generic temporary_node_failure.
-                               return Err((err_msg, 0x2000 | 2, None));
-                       }
-                       let chan_update_opt = if err_code & 0x1000 != 0 { chan_update_opt } else { None };
                        return Err((err_msg, err_code, chan_update_opt));
                }
 
@@ -3208,7 +3201,8 @@ where
                shared_secret: &[u8; 32]
        ) -> HTLCFailureMsg {
                let mut res = VecWriter(Vec::with_capacity(chan_update.serialized_length() + 2 + 8 + 2));
-               if let Some(chan_update) = chan_update {
+               if chan_update.is_some() && err_code & 0x1000 == 0x1000 {
+                       let chan_update = chan_update.unwrap();
                        if err_code == 0x1000 | 11 || err_code == 0x1000 | 12 {
                                msg.amount_msat.write(&mut res).expect("Writes cannot fail");
                        }