Skip to content

Commit 2db51c0

Browse files
Correctly fail back blinded HTLCs on onion decode and Channel error
TODO: finish tests
1 parent 0bc4aa9 commit 2db51c0

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)
@@ -3205,10 +3213,18 @@ where
32053213
($msg: expr, $err_code: expr, $data: expr) => {
32063214
{
32073215
log_info!(self.logger, "Failed to accept/forward incoming HTLC: {}", $msg);
3216+
let (err_code, err_data) = if msg.blinding_point.is_some() {
3217+
return PendingHTLCStatus::Fail(HTLCFailureMsg::Malformed(msgs::UpdateFailMalformedHTLC {
3218+
channel_id: msg.channel_id,
3219+
htlc_id: msg.htlc_id,
3220+
sha256_of_onion: [0; 32],
3221+
failure_code: INVALID_ONION_BLINDING,
3222+
}))
3223+
} else { ($err_code, $data) };
32083224
return PendingHTLCStatus::Fail(HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
32093225
channel_id: msg.channel_id,
32103226
htlc_id: msg.htlc_id,
3211-
reason: HTLCFailReason::reason($err_code, $data.to_vec())
3227+
reason: HTLCFailReason::reason(err_code, err_data.to_vec())
32123228
.get_encrypted_failure_packet(&shared_secret, &None),
32133229
}));
32143230
}
@@ -6104,8 +6120,21 @@ where
61046120
// but if we've sent a shutdown and they haven't acknowledged it yet, we just
61056121
// want to reject the new HTLC and fail it backwards instead of forwarding.
61066122
match pending_forward_info {
6107-
PendingHTLCStatus::Forward(PendingHTLCInfo { ref incoming_shared_secret, .. }) => {
6108-
let reason = if (error_code & 0x1000) != 0 {
6123+
PendingHTLCStatus::Forward(PendingHTLCInfo {
6124+
ref incoming_shared_secret, ref routing, ..
6125+
}) => {
6126+
if msg.blinding_point.is_some() {
6127+
let fail_malformed = msgs::UpdateFailMalformedHTLC {
6128+
channel_id: msg.channel_id,
6129+
htlc_id: msg.htlc_id,
6130+
sha256_of_onion: [0; 32],
6131+
failure_code: INVALID_ONION_BLINDING,
6132+
};
6133+
return PendingHTLCStatus::Fail(HTLCFailureMsg::Malformed(fail_malformed))
6134+
}
6135+
let reason = if routing.blinded().is_some() {
6136+
HTLCFailReason::reason(INVALID_ONION_BLINDING, vec![0; 32])
6137+
} else if (error_code & 0x1000) != 0 {
61096138
let (real_code, error_data) = self.get_htlc_inbound_temp_fail_err_and_data(error_code, chan);
61106139
HTLCFailReason::reason(real_code, error_data)
61116140
} else {

0 commit comments

Comments
 (0)