Skip to content

Commit c997f22

Browse files
valentinewallacea-mpch
authored andcommitted
Simplify test_trampoline_unblinded_receive
No need to construct unused blinded hop data or hardcode session privs/prng seeds.
1 parent 445ca83 commit c997f22

File tree

1 file changed

+18
-40
lines changed

1 file changed

+18
-40
lines changed

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,7 +2217,6 @@ fn test_trampoline_unblinded_receive() {
22172217
connect_blocks(&nodes[i], (TOTAL_NODE_COUNT as u32) * CHAN_CONFIRM_DEPTH + 1 - nodes[i].best_block_info().1);
22182218
}
22192219

2220-
let alice_node_id = nodes[0].node().get_our_node_id();
22212220
let bob_node_id = nodes[1].node().get_our_node_id();
22222221
let carol_node_id = nodes[2].node().get_our_node_id();
22232222

@@ -2226,29 +2225,6 @@ fn test_trampoline_unblinded_receive() {
22262225

22272226
let amt_msat = 1000;
22282227
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[2], Some(amt_msat), None);
2229-
let payee_tlvs = blinded_path::payment::TrampolineForwardTlvs {
2230-
next_trampoline: alice_node_id,
2231-
payment_constraints: PaymentConstraints {
2232-
max_cltv_expiry: u32::max_value(),
2233-
htlc_minimum_msat: amt_msat,
2234-
},
2235-
features: BlindedHopFeatures::empty(),
2236-
payment_relay: PaymentRelay {
2237-
cltv_expiry_delta: 0,
2238-
fee_proportional_millionths: 0,
2239-
fee_base_msat: 0,
2240-
},
2241-
next_blinding_override: None,
2242-
};
2243-
2244-
let carol_unblinded_tlvs = payee_tlvs.encode();
2245-
let path = [((carol_node_id, None), WithoutLength(&carol_unblinded_tlvs))];
2246-
let carol_alice_trampoline_session_priv = secret_from_hex("a0f4b8d7b6c2d0ffdfaf718f76e9decaef4d9fb38a8c4addb95c4007cc3eee03");
2247-
let carol_blinding_point = PublicKey::from_secret_key(&secp_ctx, &carol_alice_trampoline_session_priv);
2248-
let carol_blinded_hops = blinded_path::utils::construct_blinded_hops(
2249-
&secp_ctx, path.into_iter(), &carol_alice_trampoline_session_priv,
2250-
);
2251-
22522228
let route = Route {
22532229
paths: vec![Path {
22542230
hops: vec![
@@ -2284,58 +2260,60 @@ fn test_trampoline_unblinded_receive() {
22842260
cltv_expiry_delta: 24,
22852261
},
22862262
],
2287-
hops: carol_blinded_hops,
2288-
blinding_point: carol_blinding_point,
2263+
// The blinded path data is unused because we replace the onion of the last hop
2264+
hops: vec![BlindedHop {
2265+
blinded_node_id: PublicKey::from_slice(&[2; 33]).unwrap(),
2266+
encrypted_payload: vec![42; 32]
2267+
}],
2268+
blinding_point: PublicKey::from_slice(&[2; 33]).unwrap(),
22892269
excess_final_cltv_expiry_delta: 39,
22902270
final_value_msat: amt_msat,
22912271
})
22922272
}],
22932273
route_params: None,
22942274
};
22952275

2276+
// We need the session priv to construct an invalid onion packet later.
2277+
let override_random_bytes = [42; 32];
2278+
*nodes[0].keys_manager.override_random_bytes.lock().unwrap() = Some(override_random_bytes);
22962279
nodes[0].node.send_payment_with_route(route.clone(), payment_hash, RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0)).unwrap();
22972280

22982281
let replacement_onion = {
22992282
// create a substitute onion where the last Trampoline hop is an unblinded receive, which we
23002283
// (deliberately) do not support out of the box, therefore necessitating this workaround
2301-
let trampoline_secret_key = secret_from_hex("0134928f7b7ca6769080d70f16be84c812c741f545b49a34db47ce338a205799");
2302-
let prng_seed = secret_from_hex("fe02b4b9054302a3ddf4e1e9f7c411d644aebbd295218ab009dca94435f775a9");
2284+
let outer_session_priv = SecretKey::from_slice(&override_random_bytes[..]).unwrap();
2285+
let trampoline_session_priv = onion_utils::compute_trampoline_session_priv(&outer_session_priv);
23032286
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
23042287

23052288
let blinded_tail = route.paths[0].blinded_tail.clone().unwrap();
2306-
let (mut trampoline_payloads, outer_total_msat, outer_starting_htlc_offset) = onion_utils::build_trampoline_onion_payloads(&blinded_tail, amt_msat, &recipient_onion_fields, 32, &None).unwrap();
2307-
2308-
// pop the last dummy hop
2309-
trampoline_payloads.pop();
2310-
2311-
trampoline_payloads.push(msgs::OutboundTrampolinePayload::Receive {
2289+
let (_, _, outer_starting_htlc_offset) = onion_utils::build_trampoline_onion_payloads(&blinded_tail, amt_msat, &recipient_onion_fields, 32, &None).unwrap();
2290+
let trampoline_payloads = vec![msgs::OutboundTrampolinePayload::Receive {
23122291
payment_data: Some(msgs::FinalOnionHopData {
23132292
payment_secret,
23142293
total_msat: amt_msat,
23152294
}),
23162295
sender_intended_htlc_amt_msat: amt_msat,
23172296
cltv_expiry_height: 104,
2318-
});
2297+
}];
23192298

2320-
let trampoline_onion_keys = onion_utils::construct_trampoline_onion_keys(&secp_ctx, &route.paths[0].blinded_tail.as_ref().unwrap(), &trampoline_secret_key);
2299+
let trampoline_onion_keys = onion_utils::construct_trampoline_onion_keys(&secp_ctx, &route.paths[0].blinded_tail.as_ref().unwrap(), &trampoline_session_priv);
23212300
let trampoline_packet = onion_utils::construct_trampoline_onion_packet(
23222301
trampoline_payloads,
23232302
trampoline_onion_keys,
2324-
prng_seed.secret_bytes(),
2303+
override_random_bytes,
23252304
&payment_hash,
23262305
None,
23272306
).unwrap();
23282307

23292308
// Use a different session key to construct the replacement onion packet. Note that the sender isn't aware of
23302309
// this and won't be able to decode the fulfill hold times.
2331-
let outer_session_priv = secret_from_hex("e52c20461ed7acd46c4e7b591a37610519179482887bd73bf3b94617f8f03677");
23322310

2333-
let (outer_payloads, _, _) = onion_utils::build_onion_payloads(&route.paths[0], outer_total_msat, &recipient_onion_fields, outer_starting_htlc_offset, &None, None, Some(trampoline_packet)).unwrap();
2311+
let (outer_payloads, _, _) = onion_utils::build_onion_payloads(&route.paths[0], amt_msat, &recipient_onion_fields, outer_starting_htlc_offset, &None, None, Some(trampoline_packet)).unwrap();
23342312
let outer_onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route.clone().paths[0], &outer_session_priv);
23352313
let outer_packet = onion_utils::construct_onion_packet(
23362314
outer_payloads,
23372315
outer_onion_keys,
2338-
prng_seed.secret_bytes(),
2316+
override_random_bytes,
23392317
&payment_hash,
23402318
).unwrap();
23412319

0 commit comments

Comments
 (0)