Skip to content

Commit 99c91bd

Browse files
committed
Replace build_first_hop_failure_packet with HTLCFailReason
This ensures we always hit our new debug assertions while building failure packets in the immediately-fail pipeline while processing an inbound HTLC.
1 parent c45669a commit 99c91bd

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lightning/src/ln/channelmanager.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2156,7 +2156,8 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
21562156
return PendingHTLCStatus::Fail(HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
21572157
channel_id: msg.channel_id,
21582158
htlc_id: msg.htlc_id,
2159-
reason: onion_utils::build_first_hop_failure_packet(&shared_secret, $err_code, $data),
2159+
reason: HTLCFailReason::reason($err_code, $data.to_vec())
2160+
.get_encrypted_failure_packet(&shared_secret, &None),
21602161
}));
21612162
}
21622163
}
@@ -5013,10 +5014,10 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
50135014
PendingHTLCStatus::Forward(PendingHTLCInfo { ref incoming_shared_secret, .. }) => {
50145015
let reason = if (error_code & 0x1000) != 0 {
50155016
let (real_code, error_data) = self.get_htlc_inbound_temp_fail_err_and_data(error_code, chan);
5016-
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, real_code, &error_data)
5017+
HTLCFailReason::reason(real_code, error_data)
50175018
} else {
5018-
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, error_code, &[])
5019-
};
5019+
HTLCFailReason::from_failure_code(error_code)
5020+
}.get_encrypted_failure_packet(incoming_shared_secret, &None);
50205021
let msg = msgs::UpdateFailHTLC {
50215022
channel_id: msg.channel_id,
50225023
htlc_id: msg.htlc_id,

lightning/src/ln/onion_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ pub(super) fn build_failure_packet(shared_secret: &[u8], failure_type: u16, fail
382382
packet
383383
}
384384

385-
#[inline]
385+
#[cfg(test)]
386386
pub(super) fn build_first_hop_failure_packet(shared_secret: &[u8], failure_type: u16, failure_data: &[u8]) -> msgs::OnionErrorPacket {
387387
let failure_packet = build_failure_packet(shared_secret, failure_type, failure_data);
388388
encrypt_failure_packet(shared_secret, &failure_packet.encode()[..])

0 commit comments

Comments
 (0)