Skip to content

Commit 09cf484

Browse files
Correctly fail back blinded inbound fwd HTLCs when adding to a Channel
As the intro node.
1 parent 8c0c3a3 commit 09cf484

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6441,8 +6441,12 @@ where
64416441
// but if we've sent a shutdown and they haven't acknowledged it yet, we just
64426442
// want to reject the new HTLC and fail it backwards instead of forwarding.
64436443
match pending_forward_info {
6444-
PendingHTLCStatus::Forward(PendingHTLCInfo { ref incoming_shared_secret, .. }) => {
6445-
let reason = if (error_code & 0x1000) != 0 {
6444+
PendingHTLCStatus::Forward(PendingHTLCInfo {
6445+
ref incoming_shared_secret, ref routing, ..
6446+
}) => {
6447+
let reason = if routing.blinded_failure().is_some() {
6448+
HTLCFailReason::reason(INVALID_ONION_BLINDING, vec![0; 32])
6449+
} else if (error_code & 0x1000) != 0 {
64466450
let (real_code, error_data) = self.get_htlc_inbound_temp_fail_err_and_data(error_code, chan);
64476451
HTLCFailReason::reason(real_code, error_data)
64486452
} else {

lightning/src/ln/shutdown_tests.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ use crate::sign::{EntropySource, SignerProvider};
1313
use crate::chain::ChannelMonitorUpdateStatus;
1414
use crate::chain::transaction::OutPoint;
1515
use crate::events::{MessageSendEvent, HTLCDestination, MessageSendEventsProvider, ClosureReason};
16-
use crate::ln::channelmanager::{self, PaymentSendFailure, PaymentId, RecipientOnionFields, ChannelShutdownState, ChannelDetails};
16+
use crate::ln::channelmanager::{self, PaymentSendFailure, PaymentId, RecipientOnionFields, Retry, ChannelShutdownState, ChannelDetails};
1717
use crate::routing::router::{PaymentParameters, get_route, RouteParameters};
1818
use crate::ln::msgs;
1919
use crate::ln::msgs::{ChannelMessageHandler, ErrorAction};
20+
use crate::ln::onion_utils::INVALID_ONION_BLINDING;
2021
use crate::ln::script::ShutdownScript;
2122
use crate::util::test_utils;
2223
use crate::util::test_utils::OnGetShutdownScriptpubkey;
@@ -401,6 +402,11 @@ fn updates_shutdown_wait() {
401402

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

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

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

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

0 commit comments

Comments
 (0)