Skip to content

Commit 72d7ae3

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 8c7346d commit 72d7ae3

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3180,13 +3180,6 @@ where
31803180
if let Err((err_msg, err_code)) = check_incoming_htlc_cltv(
31813181
cur_height, next_packet_details.outgoing_cltv_value, msg.cltv_expiry
31823182
) {
3183-
if err_code & 0x1000 != 0 && chan_update_opt.is_none() {
3184-
// We really should set `incorrect_cltv_expiry` here but as we're not
3185-
// forwarding over a real channel we can't generate a channel_update
3186-
// for it. Instead we just return a generic temporary_node_failure.
3187-
return Err((err_msg, 0x2000 | 2, None));
3188-
}
3189-
let chan_update_opt = if err_code & 0x1000 != 0 { chan_update_opt } else { None };
31903183
return Err((err_msg, err_code, chan_update_opt));
31913184
}
31923185

@@ -3199,7 +3192,8 @@ where
31993192
shared_secret: &[u8; 32]
32003193
) -> HTLCFailureMsg {
32013194
let mut res = VecWriter(Vec::with_capacity(chan_update.serialized_length() + 2 + 8 + 2));
3202-
if let Some(chan_update) = chan_update {
3195+
if chan_update.is_some() && err_code & 0x1000 == 0x1000 {
3196+
let chan_update = chan_update.unwrap();
32033197
if err_code == 0x1000 | 11 || err_code == 0x1000 | 12 {
32043198
msg.amount_msat.write(&mut res).expect("Writes cannot fail");
32053199
}

0 commit comments

Comments
 (0)