Skip to content

Commit c0a2f6a

Browse files
committed
Only include channel_update in failure if needed by error code
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.
1 parent f7eb8e6 commit c0a2f6a

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

lightning/src/ln/channelmanager.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -3184,13 +3184,6 @@ where
31843184
let chan_update_opt = self.do_channel_callback(next_packet_details.outgoing_scid, |chan: &mut Channel<SP>| {
31853185
self.get_channel_update_for_onion(next_packet_details.outgoing_scid, chan).ok()
31863186
}).flatten();
3187-
if err_code & 0x1000 != 0 && chan_update_opt.is_none() {
3188-
// We really should set `incorrect_cltv_expiry` here but as we're not
3189-
// forwarding over a real channel we can't generate a channel_update
3190-
// for it. Instead we just return a generic temporary_node_failure.
3191-
return Err((err_msg, 0x2000 | 2, None));
3192-
}
3193-
let chan_update_opt = if err_code & 0x1000 != 0 { chan_update_opt } else { None };
31943187
return Err((err_msg, err_code, chan_update_opt));
31953188
}
31963189

@@ -3203,7 +3196,8 @@ where
32033196
shared_secret: &[u8; 32]
32043197
) -> HTLCFailureMsg {
32053198
let mut res = VecWriter(Vec::with_capacity(chan_update.serialized_length() + 2 + 8 + 2));
3206-
if let Some(chan_update) = chan_update {
3199+
if chan_update.is_some() && err_code & 0x1000 == 0x1000 {
3200+
let chan_update = chan_update.unwrap();
32073201
if err_code == 0x1000 | 11 || err_code == 0x1000 | 12 {
32083202
msg.amount_msat.write(&mut res).expect("Writes cannot fail");
32093203
}

0 commit comments

Comments
 (0)