Skip to content

Commit 791fcb5

Browse files
committed
f re-add the payment_ in payment_secret, even where it wasn't
1 parent 8465d8a commit 791fcb5

File tree

1 file changed

+60
-51
lines changed

1 file changed

+60
-51
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 60 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4104,31 +4104,34 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
41044104
send_payment(&nodes[1], &[&nodes[2], &nodes[3], &nodes[5]], 500000);
41054105
assert_eq!(get_local_commitment_txn!(nodes[3], chan_2_3.2)[0].output.len(), 2);
41064106

4107-
let ds_dust_limit = {
4107+
let dust_limit_msat = {
41084108
let per_peer_state_lock;
41094109
let mut peer_state_lock;
41104110
let chan =
41114111
get_channel_ref!(nodes[3], nodes[2], per_peer_state_lock, peer_state_lock, chan_2_3.2);
4112-
chan.context().holder_dust_limit_satoshis
4112+
chan.context().holder_dust_limit_satoshis * 1000
41134113
};
41144114

41154115
// 0th HTLC (not added - smaller than dust limit + HTLC tx fee):
41164116
let path_4: &[_] = &[&nodes[2], &nodes[3], &nodes[4]];
4117-
let (_, hash_1, ..) = route_payment(&nodes[0], path_4, ds_dust_limit*1000);
4117+
let (_, hash_1, ..) = route_payment(&nodes[0], path_4, dust_limit_msat);
41184118

41194119
// 1st HTLC (not added - smaller than dust limit + HTLC tx fee):
4120-
let (_, hash_2, ..) = route_payment(&nodes[0], path_4, ds_dust_limit*1000);
4121-
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[5], ds_dust_limit*1000);
4120+
let (_, hash_2, ..) = route_payment(&nodes[0], path_4, dust_limit_msat);
4121+
let (route_to_5, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[5], dust_limit_msat);
41224122

41234123
// 2nd HTLC (not added - smaller than dust limit + HTLC tx fee):
41244124
let path_5: &[&[_]] = &[&[&nodes[2], &nodes[3], &nodes[5]]];
4125-
let secret = nodes[5].node.create_inbound_payment_for_hash(hash_1, None, 7200, None).unwrap();
4126-
let route_2 = route.clone();
4127-
send_along_route_with_secret(&nodes[1], route_2, path_5, ds_dust_limit*1000, hash_1, secret);
4125+
let payment_secret =
4126+
nodes[5].node.create_inbound_payment_for_hash(hash_1, None, 7200, None).unwrap();
4127+
let route = route_to_5.clone();
4128+
send_along_route_with_secret(&nodes[1], route, path_5, dust_limit_msat, hash_1, payment_secret);
41284129

41294130
// 3rd HTLC (not added - smaller than dust limit + HTLC tx fee):
4130-
let secret = nodes[5].node.create_inbound_payment_for_hash(hash_2, None, 7200, None).unwrap();
4131-
send_along_route_with_secret(&nodes[1], route, path_5, ds_dust_limit*1000, hash_2, secret);
4131+
let payment_secret =
4132+
nodes[5].node.create_inbound_payment_for_hash(hash_2, None, 7200, None).unwrap();
4133+
let route = route_to_5;
4134+
send_along_route_with_secret(&nodes[1], route, path_5, dust_limit_msat, hash_2, payment_secret);
41324135

41334136
// 4th HTLC:
41344137
let (_, hash_3, ..) = route_payment(&nodes[0], &[&nodes[2], &nodes[3], &nodes[4]], 1000000);
@@ -4138,28 +4141,32 @@ fn do_test_fail_backwards_unrevoked_remote_announce(deliver_last_raa: bool, anno
41384141
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[5], 1000000);
41394142

41404143
// 6th HTLC:
4141-
let secret = nodes[5].node.create_inbound_payment_for_hash(hash_3, None, 7200, None).unwrap();
4142-
send_along_route_with_secret(&nodes[1], route.clone(), path_5, 1000000, hash_3, secret);
4144+
let payment_secret =
4145+
nodes[5].node.create_inbound_payment_for_hash(hash_3, None, 7200, None).unwrap();
4146+
send_along_route_with_secret(&nodes[1], route.clone(), path_5, 1000000, hash_3, payment_secret);
41434147

41444148
// 7th HTLC:
4145-
let secret = nodes[5].node.create_inbound_payment_for_hash(hash_4, None, 7200, None).unwrap();
4146-
send_along_route_with_secret(&nodes[1], route, path_5, 1000000, hash_4, secret);
4149+
let payment_secret =
4150+
nodes[5].node.create_inbound_payment_for_hash(hash_4, None, 7200, None).unwrap();
4151+
send_along_route_with_secret(&nodes[1], route, path_5, 1000000, hash_4, payment_secret);
41474152

41484153
// 8th HTLC:
41494154
let (_, hash_5, ..) = route_payment(&nodes[0], path_4, 1000000);
41504155

41514156
// 9th HTLC (not added - smaller than dust limit + HTLC tx fee):
4152-
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[5], ds_dust_limit*1000);
4153-
let secret = nodes[5].node.create_inbound_payment_for_hash(hash_5, None, 7200, None).unwrap();
4154-
send_along_route_with_secret(&nodes[1], route, path_5, ds_dust_limit*1000, hash_5, secret);
4157+
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[5], dust_limit_msat);
4158+
let payment_secret =
4159+
nodes[5].node.create_inbound_payment_for_hash(hash_5, None, 7200, None).unwrap();
4160+
send_along_route_with_secret(&nodes[1], route, path_5, dust_limit_msat, hash_5, payment_secret);
41554161

41564162
// 10th HTLC (not added - smaller than dust limit + HTLC tx fee):
4157-
let (_, hash_6, ..) = route_payment(&nodes[0], path_4, ds_dust_limit*1000);
4163+
let (_, hash_6, ..) = route_payment(&nodes[0], path_4, dust_limit_msat);
41584164

41594165
// 11th HTLC:
41604166
let (route, _, _, _) = get_route_and_payment_hash!(nodes[1], nodes[5], 1000000);
4161-
let secret = nodes[5].node.create_inbound_payment_for_hash(hash_6, None, 7200, None).unwrap();
4162-
send_along_route_with_secret(&nodes[1], route, path_5, 1000000, hash_6, secret);
4167+
let payment_secret =
4168+
nodes[5].node.create_inbound_payment_for_hash(hash_6, None, 7200, None).unwrap();
4169+
send_along_route_with_secret(&nodes[1], route, path_5, 1000000, hash_6, payment_secret);
41634170

41644171
// Double-check that six of the new HTLC were added
41654172
// We now have six HTLCs pending over the dust limit and six HTLCs under the dust limit (ie,
@@ -6683,7 +6690,8 @@ pub fn test_onion_value_mpp_set_calculation() {
66836690

66846691
let total_msat = 100_000;
66856692
let expected_paths: &[&[&Node]] = &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]];
6686-
let (mut route, hash, preimage, secret) = get_route_and_payment_hash!(&nodes[0], nodes[3], total_msat);
6693+
let (mut route, hash, preimage, payment_secret) =
6694+
get_route_and_payment_hash!(&nodes[0], nodes[3], total_msat);
66876695
let sample_path = route.paths.pop().unwrap();
66886696

66896697
let mut path_1 = sample_path.clone();
@@ -6704,7 +6712,7 @@ pub fn test_onion_value_mpp_set_calculation() {
67046712

67056713
// Send payment
67066714
let id = PaymentId(nodes[0].keys_manager.backing.get_secure_random_bytes());
6707-
let onion = RecipientOnionFields::secret_only(secret);
6715+
let onion = RecipientOnionFields::secret_only(payment_secret);
67086716
let onion_session_privs = nodes[0]
67096717
.node
67106718
.test_add_new_pending_payment(hash, onion.clone(), id, &route)
@@ -6732,7 +6740,7 @@ pub fn test_onion_value_mpp_set_calculation() {
67326740
let height = nodes[0].best_block_info().1;
67336741
let session_priv = SecretKey::from_slice(&session_priv).unwrap();
67346742
let mut onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv);
6735-
let recipient_onion_fields = RecipientOnionFields::secret_only(secret);
6743+
let recipient_onion_fields = RecipientOnionFields::secret_only(payment_secret);
67366744
let (mut onion_payloads, _, _) = onion_utils::build_onion_payloads(&route.paths[0], 100_000,
67376745
&recipient_onion_fields, height + 1, &None, None, None).unwrap();
67386746
// Edit amt_to_forward to simulate the sender having set
@@ -6769,7 +6777,8 @@ pub fn test_onion_value_mpp_set_calculation() {
67696777

67706778
// Second path
67716779
let ev = remove_first_msg_event_to_node(&expected_paths[1][0].node.get_our_node_id(), &mut events);
6772-
pass_along_path(&nodes[0], expected_paths[1], 101_000, hash, Some(secret), ev, true, None);
6780+
let payment_secret = Some(payment_secret);
6781+
pass_along_path(&nodes[0], expected_paths[1], 101_000, hash, payment_secret, ev, true, None);
67736782

67746783
claim_payment_along_route(
67756784
ClaimAlongRouteArgs::new(&nodes[0], expected_paths, preimage)
@@ -6808,7 +6817,7 @@ fn do_test_overshoot_mpp(msat_amounts: &[u64], total_msat: u64){
68086817

68096818
// Create a route for each amount
68106819
let example_amount = 100000;
6811-
let (mut route, hash, preimage, secret) = get_route_and_payment_hash!(&nodes[src_idx], nodes[dst_idx], example_amount);
6820+
let (mut route, hash, preimage, payment_secret) = get_route_and_payment_hash!(&nodes[src_idx], nodes[dst_idx], example_amount);
68126821
let sample_path = route.paths.pop().unwrap();
68136822
for i in 0..routing_node_count {
68146823
let routing_node = 2 + i;
@@ -6823,12 +6832,12 @@ fn do_test_overshoot_mpp(msat_amounts: &[u64], total_msat: u64){
68236832

68246833
// Send payment with manually set total_msat
68256834
let id = PaymentId(nodes[src_idx].keys_manager.backing.get_secure_random_bytes());
6826-
let onion = RecipientOnionFields::secret_only(secret);
6835+
let onion = RecipientOnionFields::secret_only(payment_secret);
68276836
let onion_session_privs = nodes[src_idx]
68286837
.node
68296838
.test_add_new_pending_payment(hash, onion, id, &route)
68306839
.unwrap();
6831-
let onion = RecipientOnionFields::secret_only(secret);
6840+
let onion = RecipientOnionFields::secret_only(payment_secret);
68326841
let amt = Some(total_msat);
68336842
nodes[src_idx]
68346843
.node
@@ -6845,7 +6854,7 @@ fn do_test_overshoot_mpp(msat_amounts: &[u64], total_msat: u64){
68456854
let current_path_amount = msat_amounts[path_idx];
68466855
amount_received += current_path_amount;
68476856
let became_claimable_now = amount_received >= total_msat && amount_received - current_path_amount < total_msat;
6848-
pass_along_path(&nodes[src_idx], expected_path, amount_received, hash.clone(), Some(secret), ev, became_claimable_now, None);
6857+
pass_along_path(&nodes[src_idx], expected_path, amount_received, hash.clone(), Some(payment_secret), ev, became_claimable_now, None);
68496858
}
68506859

68516860
claim_payment_along_route(
@@ -8355,7 +8364,7 @@ pub fn test_inconsistent_mpp_params() {
83558364
core::cmp::Ordering::Less } else { core::cmp::Ordering::Greater }
83568365
});
83578366

8358-
let (preimage, hash, secret) = get_payment_preimage_hash!(&nodes[3]);
8367+
let (preimage, hash, payment_secret) = get_payment_preimage_hash!(&nodes[3]);
83598368

83608369
let cur_height = nodes[0].best_block_info().1;
83618370
let id = PaymentId([42; 32]);
@@ -8365,10 +8374,10 @@ pub fn test_inconsistent_mpp_params() {
83658374
// ultimately have, just not right away.
83668375
let mut dup_route = route.clone();
83678376
dup_route.paths.push(route.paths[1].clone());
8368-
let onion = RecipientOnionFields::secret_only(secret);
8377+
let onion = RecipientOnionFields::secret_only(payment_secret);
83698378
nodes[0].node.test_add_new_pending_payment(hash, onion, id, &dup_route).unwrap()
83708379
};
8371-
let onion = RecipientOnionFields::secret_only(secret);
8380+
let onion = RecipientOnionFields::secret_only(payment_secret);
83728381
let path_a = &route.paths[0];
83738382
let real_amt = 15_000_000;
83748383
let priv_a = session_privs[0];
@@ -8382,11 +8391,11 @@ pub fn test_inconsistent_mpp_params() {
83828391
assert_eq!(events.len(), 1);
83838392
let path_a = &[&nodes[1], &nodes[3]];
83848393
let event = events.pop().unwrap();
8385-
pass_along_path(&nodes[0], path_a, real_amt, hash, Some(secret), event, false, None);
8394+
pass_along_path(&nodes[0], path_a, real_amt, hash, Some(payment_secret), event, false, None);
83868395
assert!(nodes[3].node.get_and_clear_pending_events().is_empty());
83878396

83888397
let path_b = &route.paths[1];
8389-
let onion = RecipientOnionFields::secret_only(secret);
8398+
let onion = RecipientOnionFields::secret_only(payment_secret);
83908399
let amt_b = 14_000_000;
83918400
let priv_b = session_privs[1];
83928401
nodes[0]
@@ -8440,7 +8449,7 @@ pub fn test_inconsistent_mpp_params() {
84408449
let conditions = PaymentFailedConditions::new().mpp_parts_remain();
84418450
expect_payment_failed_conditions(&nodes[0], hash, true, conditions);
84428451

8443-
let onion = RecipientOnionFields::secret_only(secret);
8452+
let onion = RecipientOnionFields::secret_only(payment_secret);
84448453
let path_b = &route.paths[1];
84458454
let priv_c = session_privs[2];
84468455
nodes[0]
@@ -8453,7 +8462,7 @@ pub fn test_inconsistent_mpp_params() {
84538462
assert_eq!(events.len(), 1);
84548463
let event = events.pop().unwrap();
84558464
let path_b = &[&nodes[2], &nodes[3]];
8456-
pass_along_path(&nodes[0], path_b, real_amt, hash, Some(secret), event, true, None);
8465+
pass_along_path(&nodes[0], path_b, real_amt, hash, Some(payment_secret), event, true, None);
84578466

84588467
do_claim_payment_along_route(
84598468
ClaimAlongRouteArgs::new(&nodes[0], &[path_a, path_b], preimage)
@@ -8479,7 +8488,7 @@ pub fn test_double_partial_claim() {
84798488
create_announced_chan_between_nodes_with_value(&nodes, 1, 3, 100_000, 0);
84808489
create_announced_chan_between_nodes_with_value(&nodes, 2, 3, 100_000, 0);
84818490

8482-
let (mut route, payment_hash, payment_preimage, secret) = get_route_and_payment_hash!(nodes[0], nodes[3], 15_000_000);
8491+
let (mut route, hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[3], 15_000_000);
84838492
assert_eq!(route.paths.len(), 2);
84848493
route.paths.sort_by(|path_a, _| {
84858494
// Sort the path so that the path through nodes[1] comes first
@@ -8488,7 +8497,7 @@ pub fn test_double_partial_claim() {
84888497
});
84898498

84908499
let paths: &[&[_]] = &[&[&nodes[1], &nodes[3]], &[&nodes[2], &nodes[3]]];
8491-
send_along_route_with_secret(&nodes[0], route.clone(), paths, 15_000_000, payment_hash, secret);
8500+
send_along_route_with_secret(&nodes[0], route.clone(), paths, 15_000_000, hash, payment_secret);
84928501
// nodes[3] has now received a PaymentClaimable event...which it will take some (exorbitant)
84938502
// amount of time to respond to.
84948503

@@ -8497,25 +8506,25 @@ pub fn test_double_partial_claim() {
84978506
connect_blocks(&nodes[0], TEST_FINAL_CLTV); // To get the same height for sending later
84988507

84998508
let failed_destinations = vec![
8500-
HTLCHandlingFailureType::Receive { payment_hash },
8501-
HTLCHandlingFailureType::Receive { payment_hash },
8509+
HTLCHandlingFailureType::Receive { payment_hash: hash },
8510+
HTLCHandlingFailureType::Receive { payment_hash: hash },
85028511
];
85038512
expect_pending_htlcs_forwardable_and_htlc_handling_failed!(nodes[3], failed_destinations);
85048513

85058514
let reason = PaymentFailureReason::RecipientRejected;
8506-
pass_failed_payment_back(&nodes[0], paths, false, payment_hash, reason);
8515+
pass_failed_payment_back(&nodes[0], paths, false, hash, reason);
85078516

85088517
// nodes[1] now retries one of the two paths...
8509-
let onion = RecipientOnionFields::secret_only(secret);
8510-
let id = PaymentId(payment_hash.0);
8511-
nodes[0].node.send_payment_with_route(route, payment_hash, onion, id).unwrap();
8518+
let onion = RecipientOnionFields::secret_only(payment_secret);
8519+
let id = PaymentId(hash.0);
8520+
nodes[0].node.send_payment_with_route(route, hash, onion, id).unwrap();
85128521
check_added_monitors!(nodes[0], 2);
85138522

85148523
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
85158524
assert_eq!(events.len(), 2);
85168525
let msgs = remove_first_msg_event_to_node(&node_b_id, &mut events);
85178526
let path = &[&nodes[1], &nodes[3]];
8518-
pass_along_path(&nodes[0], path, 15_000_000, payment_hash, Some(secret), msgs, false, None);
8527+
pass_along_path(&nodes[0], path, 15_000_000, hash, Some(payment_secret), msgs, false, None);
85198528

85208529
// At this point nodes[3] has received one half of the payment, and the user goes to handle
85218530
// that PaymentClaimable event they got hours ago and never handled...we should refuse to claim.
@@ -9263,20 +9272,20 @@ fn do_payment_with_custom_min_final_cltv_expiry(valid_delta: bool, use_user_hash
92639272

92649273
let payment_parameters =
92659274
PaymentParameters::from_node_id(node_b_id, final_cltv_expiry_delta as u32);
9266-
let (hash, payment_preimage, secret) = if use_user_hash {
9267-
let (payment_preimage, hash, secret) =
9275+
let (hash, payment_preimage, payment_secret) = if use_user_hash {
9276+
let (payment_preimage, hash, payment_secret) =
92689277
get_payment_preimage_hash!(nodes[1], Some(recv_value), Some(min_cltv_expiry_delta));
9269-
(hash, payment_preimage, secret)
9278+
(hash, payment_preimage, payment_secret)
92709279
} else {
9271-
let (hash, secret) =
9280+
let (hash, payment_secret) =
92729281
nodes[1]
92739282
.node
92749283
.create_inbound_payment(Some(recv_value), 7200, Some(min_cltv_expiry_delta))
92759284
.unwrap();
9276-
(hash, nodes[1].node.get_payment_preimage(hash, secret).unwrap(), secret)
9285+
(hash, nodes[1].node.get_payment_preimage(hash, payment_secret).unwrap(), payment_secret)
92779286
};
92789287
let route = get_route!(nodes[0], payment_parameters, recv_value).unwrap();
9279-
let onion = RecipientOnionFields::secret_only(secret);
9288+
let onion = RecipientOnionFields::secret_only(payment_secret);
92809289
nodes[0].node.send_payment_with_route(route, hash, onion, PaymentId(hash.0)).unwrap();
92819290
check_added_monitors!(nodes[0], 1);
92829291
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
@@ -9288,7 +9297,7 @@ fn do_payment_with_custom_min_final_cltv_expiry(valid_delta: bool, use_user_hash
92889297

92899298
if valid_delta {
92909299
let preimage = if use_user_hash { None } else { Some(payment_preimage) };
9291-
expect_payment_claimable!(nodes[1], hash, secret, recv_value, preimage, node_b_id);
9300+
expect_payment_claimable!(nodes[1], hash, payment_secret, recv_value, preimage, node_b_id);
92929301

92939302
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage);
92949303
} else {

0 commit comments

Comments
 (0)