Skip to content

Commit cc953a1

Browse files
Correctly fail back blinded inbound fwd HTLCs when adding to a Channel
As the intro node.
1 parent 066ae39 commit cc953a1

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

lightning/src/ln/channelmanager.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -6658,8 +6658,12 @@ where
66586658
// but if we've sent a shutdown and they haven't acknowledged it yet, we just
66596659
// want to reject the new HTLC and fail it backwards instead of forwarding.
66606660
match pending_forward_info {
6661-
PendingHTLCStatus::Forward(PendingHTLCInfo { ref incoming_shared_secret, .. }) => {
6662-
let reason = if (error_code & 0x1000) != 0 {
6661+
PendingHTLCStatus::Forward(PendingHTLCInfo {
6662+
ref incoming_shared_secret, ref routing, ..
6663+
}) => {
6664+
let reason = if routing.blinded().is_some() {
6665+
HTLCFailReason::reason(INVALID_ONION_BLINDING, vec![0; 32])
6666+
} else if (error_code & 0x1000) != 0 {
66636667
let (real_code, error_data) = self.get_htlc_inbound_temp_fail_err_and_data(error_code, chan);
66646668
HTLCFailReason::reason(real_code, error_data)
66656669
} else {

lightning/src/ln/shutdown_tests.rs

+27-5
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
use crate::sign::{EntropySource, SignerProvider};
1313
use crate::chain::transaction::OutPoint;
1414
use crate::events::{MessageSendEvent, MessageSendEventsProvider, ClosureReason};
15-
use crate::ln::channelmanager::{self, PaymentSendFailure, PaymentId, RecipientOnionFields, ChannelShutdownState, ChannelDetails};
15+
use crate::ln::channelmanager::{self, PaymentSendFailure, PaymentId, RecipientOnionFields, Retry, ChannelShutdownState, ChannelDetails};
1616
use crate::routing::router::{PaymentParameters, get_route, RouteParameters};
1717
use crate::ln::msgs;
1818
use crate::ln::msgs::{ChannelMessageHandler, ErrorAction};
19+
use crate::ln::onion_utils::INVALID_ONION_BLINDING;
1920
use crate::ln::script::ShutdownScript;
2021
use crate::util::test_utils;
2122
use crate::util::test_utils::OnGetShutdownScriptpubkey;
@@ -400,6 +401,11 @@ fn updates_shutdown_wait() {
400401

401402
#[test]
402403
fn htlc_fail_async_shutdown() {
404+
do_htlc_fail_async_shutdown(true);
405+
do_htlc_fail_async_shutdown(false);
406+
}
407+
408+
fn do_htlc_fail_async_shutdown(blinded_recipient: bool) {
403409
// Test HTLCs fail if shutdown starts even if messages are delivered out-of-order
404410
let chanmon_cfgs = create_chanmon_cfgs(3);
405411
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
@@ -408,9 +414,20 @@ fn htlc_fail_async_shutdown() {
408414
let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
409415
let chan_2 = create_announced_chan_between_nodes(&nodes, 1, 2);
410416

411-
let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], 100000);
412-
nodes[0].node.send_payment_with_route(&route, our_payment_hash,
413-
RecipientOnionFields::secret_only(our_payment_secret), PaymentId(our_payment_hash.0)).unwrap();
417+
let amt_msat = 100000;
418+
let (_, our_payment_hash, our_payment_secret) = get_payment_preimage_hash(&nodes[2], Some(amt_msat), None);
419+
let route_params = if blinded_recipient {
420+
crate::ln::blinded_payment_tests::get_blinded_route_parameters(
421+
amt_msat, our_payment_secret,
422+
nodes.iter().skip(1).map(|n| n.node.get_our_node_id()).collect(), &[&chan_2.0.contents],
423+
&chanmon_cfgs[2].keys_manager)
424+
} else {
425+
RouteParameters::from_payment_params_and_value(
426+
PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV), amt_msat)
427+
};
428+
nodes[0].node.send_payment(our_payment_hash,
429+
RecipientOnionFields::secret_only(our_payment_secret),
430+
PaymentId(our_payment_hash.0), route_params, Retry::Attempts(0)).unwrap();
414431
check_added_monitors!(nodes[0], 1);
415432
let updates = get_htlc_update_msgs!(nodes[0], nodes[1].node.get_our_node_id());
416433
assert_eq!(updates.update_add_htlcs.len(), 1);
@@ -440,7 +457,12 @@ fn htlc_fail_async_shutdown() {
440457
nodes[0].node.handle_update_fail_htlc(&nodes[1].node.get_our_node_id(), &updates_2.update_fail_htlcs[0]);
441458
commitment_signed_dance!(nodes[0], nodes[1], updates_2.commitment_signed, false, true);
442459

443-
expect_payment_failed_with_update!(nodes[0], our_payment_hash, false, chan_2.0.contents.short_channel_id, true);
460+
if blinded_recipient {
461+
expect_payment_failed_conditions(&nodes[0], our_payment_hash, false,
462+
PaymentFailedConditions::new().expected_htlc_error_data(INVALID_ONION_BLINDING, &[0; 32]));
463+
} else {
464+
expect_payment_failed_with_update!(nodes[0], our_payment_hash, false, chan_2.0.contents.short_channel_id, true);
465+
}
444466

445467
let msg_events = nodes[0].node.get_and_clear_pending_msg_events();
446468
assert_eq!(msg_events.len(), 1);

0 commit comments

Comments
 (0)