Skip to content

Commit db29939

Browse files
committed
f - reject mpp keysend during receive instead of upon claim
1 parent a7f5e04 commit db29939

File tree

2 files changed

+59
-21
lines changed

2 files changed

+59
-21
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3577,6 +3577,10 @@ where
35773577
purpose: purpose.clone(), htlcs: Vec::new(), onion_fields: None,
35783578
}
35793579
});
3580+
if !self.default_configuration.accept_mpp_keysend && is_keysend && !claimable_payment.htlcs.is_empty() {
3581+
log_trace!(self.logger, "Failing new keysend HTLC with payment_hash {} as we already had an existing keysend HTLC with the same payment hash and our config states we don't accept MPP keysend", log_bytes!(payment_hash.0));
3582+
fail_htlc!(claimable_htlc, payment_hash);
3583+
}
35803584
if purpose != claimable_payment.purpose {
35813585
let log_keysend = |keysend| if keysend { "keysend" } else { "non-keysend" };
35823586
log_trace!(self.logger, "Failing new {} HTLC with payment_hash {} as we already had an existing {} HTLC with the same payment hash", log_keysend(is_keysend), log_bytes!(payment_hash.0), log_keysend(!is_keysend));
@@ -4233,15 +4237,6 @@ where
42334237
break;
42344238
}
42354239
expected_amt_msat = htlc.total_value_received;
4236-
4237-
if let OnionPayload::Spontaneous(_) = &htlc.onion_payload {
4238-
if !self.default_configuration.accept_mpp_keysend && sources.len() != 1 {
4239-
log_info!(self.logger, "Rejecting a received MPP spontaneous payment since our config states we don't accept them.");
4240-
valid_mpp = false;
4241-
break;
4242-
}
4243-
}
4244-
42454240
claimable_amt_msat += htlc.value;
42464241
}
42474242
mem::drop(per_peer_state);

lightning/src/ln/functional_tests.rs

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8201,10 +8201,10 @@ fn do_test_mpp_keysend(accept_mpp_keysend: bool) {
82018201
let node_chanmgrs = create_node_chanmgrs(4, &node_cfgs, &[None, None, None, Some(mpp_keysend_config)]);
82028202
let nodes = create_network(4, &node_cfgs, &node_chanmgrs);
82038203

8204-
create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id;
8205-
create_announced_chan_between_nodes(&nodes, 0, 2).0.contents.short_channel_id;
8206-
create_announced_chan_between_nodes(&nodes, 1, 3).0.contents.short_channel_id;
8207-
create_announced_chan_between_nodes(&nodes, 2, 3).0.contents.short_channel_id;
8204+
create_announced_chan_between_nodes(&nodes, 0, 1);
8205+
create_announced_chan_between_nodes(&nodes, 0, 2);
8206+
create_announced_chan_between_nodes(&nodes, 1, 3);
8207+
let chan_2_3 = create_announced_chan_between_nodes(&nodes, 2, 3);
82088208
let network_graph = nodes[0].network_graph.clone();
82098209

82108210
let payer_pubkey = nodes[0].node.get_our_node_id();
@@ -8228,14 +8228,58 @@ fn do_test_mpp_keysend(accept_mpp_keysend: bool) {
82288228
let expected_route: &[&[&Node]] = &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]];
82298229
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
82308230
assert_eq!(events.len(), 2);
8231-
for (path_idx, expected_path) in expected_route.iter().enumerate() {
8232-
let ev = remove_first_msg_event_to_node(&expected_path[0].node.get_our_node_id(), &mut events);
8233-
let expect_payment = path_idx == expected_route.len() - 1;
8234-
pass_along_path(&nodes[0], *expected_path, recv_value, payment_hash.clone(),
8235-
Some(payment_secret), ev, expect_payment, Some(payment_preimage));
8236-
}
82378231

8238-
claim_payment_along_route(&nodes[0], expected_route, false, payment_preimage);
8232+
let ev = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut events);
8233+
pass_along_path(&nodes[0], expected_route[0], recv_value, payment_hash.clone(),
8234+
Some(payment_secret), ev.clone(), false, Some(payment_preimage));
8235+
8236+
if accept_mpp_keysend {
8237+
let ev = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut events);
8238+
pass_along_path(&nodes[0], expected_route[1], recv_value, payment_hash.clone(),
8239+
Some(payment_secret), ev.clone(), true, Some(payment_preimage));
8240+
claim_payment_along_route(&nodes[0], expected_route, false, payment_preimage);
8241+
} else {
8242+
let ev = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut events);
8243+
let mut payment_event = SendEvent::from_event(ev.clone());
8244+
8245+
assert_eq!(nodes[2].node.get_our_node_id(), payment_event.node_id);
8246+
8247+
nodes[2].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
8248+
commitment_signed_dance!(nodes[2], nodes[0], payment_event.commitment_msg, false);
8249+
8250+
expect_pending_htlcs_forwardable!(nodes[2]);
8251+
check_added_monitors!(nodes[2], 1);
8252+
8253+
let mut events_2 = nodes[2].node.get_and_clear_pending_msg_events();
8254+
assert_eq!(events_2.len(), 1);
8255+
payment_event = SendEvent::from_event(events_2.remove(0));
8256+
8257+
nodes[3].node.handle_update_add_htlc(&nodes[2].node.get_our_node_id(), &payment_event.msgs[0]);
8258+
check_added_monitors!(nodes[3], 0);
8259+
commitment_signed_dance!(nodes[3], nodes[2], payment_event.commitment_msg, false);
8260+
8261+
expect_pending_htlcs_forwardable_ignore!(nodes[3]);
8262+
nodes[3].node.process_pending_htlc_forwards();
8263+
expect_pending_htlcs_forwardable_and_htlc_handling_failed_ignore!(nodes[3],
8264+
vec![HTLCDestination::FailedPayment { payment_hash: payment_hash }]);
8265+
nodes[3].node.process_pending_htlc_forwards();
8266+
8267+
check_added_monitors!(nodes[3], 1);
8268+
8269+
let fail_updates_1 = get_htlc_update_msgs!(nodes[3], nodes[2].node.get_our_node_id());
8270+
nodes[2].node.handle_update_fail_htlc(&nodes[3].node.get_our_node_id(), &fail_updates_1.update_fail_htlcs[0]);
8271+
commitment_signed_dance!(nodes[2], nodes[3], fail_updates_1.commitment_signed, false);
8272+
8273+
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[2],
8274+
vec![HTLCDestination::NextHopChannel { node_id: Some(nodes[3].node.get_our_node_id()), channel_id: chan_2_3.2 }]);
8275+
check_added_monitors!(nodes[2], 1);
8276+
8277+
let fail_updates_2 = get_htlc_update_msgs!(nodes[2], nodes[0].node.get_our_node_id());
8278+
nodes[0].node.handle_update_fail_htlc(&nodes[2].node.get_our_node_id(), &fail_updates_2.update_fail_htlcs[0]);
8279+
commitment_signed_dance!(nodes[0], nodes[2], fail_updates_2.commitment_signed, false);
8280+
8281+
expect_payment_failed_conditions(&nodes[0], payment_hash, true, PaymentFailedConditions::new().mpp_parts_remain());
8282+
}
82398283
}
82408284

82418285
#[test]
@@ -8244,7 +8288,6 @@ fn test_mpp_keysend() {
82448288
}
82458289

82468290
#[test]
8247-
#[should_panic]
82488291
fn test_mpp_keysend_fail() {
82498292
do_test_mpp_keysend(false);
82508293
}

0 commit comments

Comments
 (0)