Skip to content

Commit eb01a8e

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 e5479ce commit eb01a8e

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
@@ -3189,13 +3189,6 @@ where
31893189
let chan_update_opt = self.do_channel_callback(next_packet_details.outgoing_scid, |chan: &mut Channel<SP>| {
31903190
self.get_channel_update_for_onion(next_packet_details.outgoing_scid, chan).ok()
31913191
}).flatten();
3192-
if err_code & 0x1000 != 0 && chan_update_opt.is_none() {
3193-
// We really should set `incorrect_cltv_expiry` here but as we're not
3194-
// forwarding over a real channel we can't generate a channel_update
3195-
// for it. Instead we just return a generic temporary_node_failure.
3196-
return Err((err_msg, 0x2000 | 2, None));
3197-
}
3198-
let chan_update_opt = if err_code & 0x1000 != 0 { chan_update_opt } else { None };
31993192
return Err((err_msg, err_code, chan_update_opt));
32003193
}
32013194

@@ -3208,7 +3201,8 @@ where
32083201
shared_secret: &[u8; 32]
32093202
) -> HTLCFailureMsg {
32103203
let mut res = VecWriter(Vec::with_capacity(chan_update.serialized_length() + 2 + 8 + 2));
3211-
if let Some(chan_update) = chan_update {
3204+
if chan_update.is_some() && err_code & 0x1000 == 0x1000 {
3205+
let chan_update = chan_update.unwrap();
32123206
if err_code == 0x1000 | 11 || err_code == 0x1000 | 12 {
32133207
msg.amount_msat.write(&mut res).expect("Writes cannot fail");
32143208
}

0 commit comments

Comments
 (0)