Skip to content

Commit 8c47354

Browse files
Correctly fail back blinded HTLCs on onion decode and Channel error
TODO: finish tests
1 parent d593d6f commit 8c47354

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,10 +3001,18 @@ where
30013001
{
30023002
Ok(res) => res,
30033003
Err(onion_utils::OnionDecodeErr::Malformed { err_msg, err_code }) => {
3004-
return_malformed_err!(err_msg, err_code);
3004+
if msg.blinding_point.is_some() {
3005+
return_blinded_htlc_err!(err_msg);
3006+
} else {
3007+
return_malformed_err!(err_msg, err_code);
3008+
}
30053009
},
30063010
Err(onion_utils::OnionDecodeErr::Relay { err_msg, err_code }) => {
3007-
return_err!(err_msg, err_code, &[0; 0]);
3011+
if msg.blinding_point.is_some() {
3012+
return_blinded_htlc_err!(err_msg);
3013+
} else {
3014+
return_err!(err_msg, err_code, &[0; 0]);
3015+
}
30083016
},
30093017
};
30103018
let (outgoing_scid, outgoing_amt_msat, outgoing_cltv_value, next_packet_pk_opt, blinded)
@@ -3210,10 +3218,18 @@ where
32103218
($msg: expr, $err_code: expr, $data: expr) => {
32113219
{
32123220
log_info!(self.logger, "Failed to accept/forward incoming HTLC: {}", $msg);
3221+
let (err_code, err_data) = if msg.blinding_point.is_some() {
3222+
return PendingHTLCStatus::Fail(HTLCFailureMsg::Malformed(msgs::UpdateFailMalformedHTLC {
3223+
channel_id: msg.channel_id,
3224+
htlc_id: msg.htlc_id,
3225+
sha256_of_onion: [0; 32],
3226+
failure_code: INVALID_ONION_BLINDING,
3227+
}))
3228+
} else { ($err_code, $data) };
32133229
return PendingHTLCStatus::Fail(HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
32143230
channel_id: msg.channel_id,
32153231
htlc_id: msg.htlc_id,
3216-
reason: HTLCFailReason::reason($err_code, $data.to_vec())
3232+
reason: HTLCFailReason::reason(err_code, err_data.to_vec())
32173233
.get_encrypted_failure_packet(&shared_secret, &None),
32183234
}));
32193235
}
@@ -6109,8 +6125,21 @@ where
61096125
// but if we've sent a shutdown and they haven't acknowledged it yet, we just
61106126
// want to reject the new HTLC and fail it backwards instead of forwarding.
61116127
match pending_forward_info {
6112-
PendingHTLCStatus::Forward(PendingHTLCInfo { ref incoming_shared_secret, .. }) => {
6113-
let reason = if (error_code & 0x1000) != 0 {
6128+
PendingHTLCStatus::Forward(PendingHTLCInfo {
6129+
ref incoming_shared_secret, ref routing, ..
6130+
}) => {
6131+
if msg.blinding_point.is_some() {
6132+
let fail_malformed = msgs::UpdateFailMalformedHTLC {
6133+
channel_id: msg.channel_id,
6134+
htlc_id: msg.htlc_id,
6135+
sha256_of_onion: [0; 32],
6136+
failure_code: INVALID_ONION_BLINDING,
6137+
};
6138+
return PendingHTLCStatus::Fail(HTLCFailureMsg::Malformed(fail_malformed))
6139+
}
6140+
let reason = if routing.blinded().is_some() {
6141+
HTLCFailReason::reason(INVALID_ONION_BLINDING, vec![0; 32])
6142+
} else if (error_code & 0x1000) != 0 {
61146143
let (real_code, error_data) = self.get_htlc_inbound_temp_fail_err_and_data(error_code, chan);
61156144
HTLCFailReason::reason(real_code, error_data)
61166145
} else {

0 commit comments

Comments
 (0)