Skip to content

Commit a1fd1d8

Browse files
Fix PaymentPathFailed::payment_failed_permanently on blinded path fail
Previously this value would be incorrectly set to true because we wouldn't account for blinded hops when determining if we were processing the last hop's failure packet.
1 parent c9d7f16 commit a1fd1d8

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

lightning/src/ln/onion_utils.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,24 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
481481
},
482482
};
483483

484+
// The failing hop includes either the inbound channel to the recipient or the outbound channel
485+
// from the current hop (i.e., the next hop's inbound channel).
486+
let num_blinded_hops = path.blinded_tail.as_ref().map_or(0, |bt| bt.hops.len());
487+
is_from_final_node = route_hop_idx + 1 == path.hops.len() && num_blinded_hops <= 1;
488+
let failing_route_hop = if is_from_final_node { route_hop } else {
489+
match path.hops.get(route_hop_idx + 1) {
490+
Some(hop) => hop,
491+
None => {
492+
error_code_ret = Some(BADONION | PERM | 24); // invalid_onion_blinding
493+
error_packet_ret = Some(vec![0; 32]);
494+
res = Some(FailureLearnings {
495+
network_update: None, short_channel_id: None, recipient_rejected: false
496+
});
497+
return
498+
}
499+
}
500+
};
501+
484502
let amt_to_forward = htlc_msat - route_hop.fee_msat;
485503
htlc_msat = amt_to_forward;
486504

@@ -492,11 +510,6 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(
492510
chacha.process(&packet_decrypted, &mut decryption_tmp[..]);
493511
packet_decrypted = decryption_tmp;
494512

495-
// The failing hop includes either the inbound channel to the recipient or the outbound channel
496-
// from the current hop (i.e., the next hop's inbound channel).
497-
is_from_final_node = route_hop_idx + 1 == path.hops.len();
498-
let failing_route_hop = if is_from_final_node { route_hop } else { &path.hops[route_hop_idx + 1] };
499-
500513
let err_packet = match msgs::DecodedOnionErrorPacket::read(&mut Cursor::new(&packet_decrypted)) {
501514
Ok(p) => p,
502515
Err(_) => return

0 commit comments

Comments
 (0)