Skip to content

Commit 79a0771

Browse files
WIP use public api in trampoline test
1 parent b838480 commit 79a0771

2 files changed

Lines changed: 47 additions & 51 deletions

File tree

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,24 +2597,27 @@ fn do_test_trampoline_relay(blinded: bool, test_case: TrampolineTestCase) {
25972597
// Create a blinded tail where Carol is receiving. In our unblinded test cases, we'll
25982598
// override this anyway (with a tail sending to an unblinded receive, which LDK doesn't
25992599
// allow).
2600-
blinded_tail: Some(create_trampoline_forward_blinded_tail(
2601-
&secp_ctx,
2602-
&nodes[2].keys_manager,
2603-
&[],
2604-
carol_node_id,
2605-
nodes[2].keys_manager.get_receive_auth_key(),
2606-
ReceiveTlvs {
2607-
payment_secret,
2608-
payment_constraints: PaymentConstraints {
2609-
max_cltv_expiry: u32::max_value(),
2610-
htlc_minimum_msat: original_amt_msat,
2600+
blinded_tail: Some(
2601+
create_trampoline_forward_blinded_tail(
2602+
&secp_ctx,
2603+
&nodes[2].keys_manager,
2604+
&[],
2605+
carol_node_id,
2606+
nodes[2].keys_manager.get_receive_auth_key(),
2607+
ReceiveTlvs {
2608+
payment_secret,
2609+
payment_constraints: PaymentConstraints {
2610+
max_cltv_expiry: u32::max_value(),
2611+
htlc_minimum_msat: original_amt_msat,
2612+
},
2613+
payment_context: PaymentContext::Bolt12Refund(Bolt12RefundContext {}),
26112614
},
2612-
payment_context: PaymentContext::Bolt12Refund(Bolt12RefundContext {}),
2613-
},
2614-
original_trampoline_cltv,
2615-
excess_final_cltv,
2616-
original_amt_msat,
2617-
)),
2615+
original_trampoline_cltv,
2616+
excess_final_cltv,
2617+
original_amt_msat,
2618+
)
2619+
.0,
2620+
),
26182621
}],
26192622
route_params: None,
26202623
};
@@ -2822,54 +2825,41 @@ fn send_trampoline_mpp_payment<'a, 'b, 'c>(
28222825
cltv_expiry_delta,
28232826
maybe_announced_channel: true,
28242827
};
2828+
let last_hop_cltv_delta =
2829+
carol_relay.cltv_expiry_delta as u32 + trampoline_cltv + excess_final_cltv;
28252830
let build_path_hops = |first_hop_node_id, first_hop_scid, second_hop_scid| {
28262831
vec![
28272832
hop(first_hop_node_id, first_hop_scid, 1000, 48),
2828-
hop(carol_node_id, second_hop_scid, 0, trampoline_cltv + excess_final_cltv),
2833+
hop(carol_node_id, second_hop_scid, 0, last_hop_cltv_delta),
28292834
]
28302835
};
28312836

2832-
let placeholder_tail = fwd_tail();
2833-
let mut route = Route {
2837+
let (tail_bob, blinded_path_bob) = fwd_tail();
2838+
let (tail_barry, blinded_path_barry) = fwd_tail();
2839+
let payment_params = PaymentParameters::blinded(vec![blinded_path_bob, blinded_path_barry]);
2840+
let route_params = RouteParameters {
2841+
payment_params,
2842+
final_value_msat: total_amt,
2843+
max_total_routing_fee_msat: None,
2844+
};
2845+
let route = Route {
28342846
paths: vec![
28352847
Path {
28362848
hops: build_path_hops(bob_node_id, alice_bob_scid, bob_carol_scid),
2837-
blinded_tail: Some(placeholder_tail.clone()),
2849+
blinded_tail: Some(tail_bob),
28382850
},
28392851
Path {
28402852
hops: build_path_hops(barry_node_id, alice_barry_scid, barry_carol_scid),
2841-
blinded_tail: Some(placeholder_tail),
2853+
blinded_tail: Some(tail_barry),
28422854
},
28432855
],
2844-
route_params: None,
2856+
route_params: Some(route_params),
28452857
};
28462858

2847-
let cur_height = nodes[0].best_block_info().1 + 1;
28482859
let payment_id = PaymentId(payment_hash.0);
28492860
let onion = RecipientOnionFields::secret_only(payment_secret, total_amt);
2850-
let session_privs = nodes[0]
2851-
.node
2852-
.test_add_new_pending_payment(payment_hash, onion.clone(), payment_id, &route)
2853-
.unwrap();
2854-
2855-
route.paths[0].blinded_tail = Some(fwd_tail());
2856-
route.paths[1].blinded_tail = Some(fwd_tail());
2857-
2858-
for (i, path) in route.paths.iter().enumerate() {
2859-
nodes[0]
2860-
.node
2861-
.test_send_payment_along_path(
2862-
path,
2863-
&payment_hash,
2864-
onion.clone(),
2865-
cur_height,
2866-
payment_id,
2867-
&None,
2868-
session_privs[i],
2869-
)
2870-
.unwrap();
2871-
check_added_monitors(&nodes[0], 1);
2872-
}
2861+
nodes[0].node.send_payment_with_route(route, payment_hash, onion, payment_id).unwrap();
2862+
check_added_monitors(&nodes[0], 2);
28732863

28742864
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
28752865
assert_eq!(events.len(), 2);
@@ -2921,7 +2911,10 @@ fn do_trampoline_mpp_test(timeout: Option<TrampolineTimeout>) {
29212911
Some(TrampolineTimeout::OnChain) => {
29222912
let current_height = nodes[2].best_block_info().1;
29232913
let send_height = nodes[0].best_block_info().1;
2924-
let htlc_cltv = send_height + 1 + 48 + 42 + 70;
2914+
// Carol's incoming HTLC cltv = send_height + 1 + last_hop_cltv_delta,
2915+
// where last_hop_cltv_delta = carol_relay.cltv_expiry_delta (72) + trampoline_cltv (42)
2916+
// + excess_final_cltv (70) = 184.
2917+
let htlc_cltv = send_height + 1 + 184;
29252918
connect_blocks(&nodes[2], htlc_cltv - HTLC_FAIL_BACK_BUFFER - current_height);
29262919
LocalHTLCFailureReason::CLTVExpiryTooSoon
29272920
},

lightning/src/ln/functional_test_utils.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5776,12 +5776,14 @@ pub fn get_scid_from_channel_id<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, channel_id:
57765776
///
57775777
/// The resulting tail contains blinded hops built from `intermediate_nodes` plus a dummy receive
57785778
/// TLV, with the `TrampolineHop` fee and CLTV derived from the blinded path's aggregated payinfo.
5779+
/// The constructed [`BlindedPaymentPath`] is also returned so callers can register it in
5780+
/// [`PaymentParameters`].
57795781
pub fn create_trampoline_forward_blinded_tail<ES: EntropySource>(
57805782
secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>, entropy_source: ES,
57815783
intermediate_nodes: &[ForwardNode<TrampolineForwardTlvs>], payee_node_id: PublicKey,
57825784
payee_receive_key: ReceiveAuthKey, payee_tlvs: ReceiveTlvs, min_final_cltv_expiry_delta: u32,
57835785
excess_final_cltv_delta: u32, final_value_msat: u64,
5784-
) -> BlindedTail {
5786+
) -> (BlindedTail, BlindedPaymentPath) {
57855787
let blinded_path = BlindedPaymentPath::new_for_trampoline(
57865788
intermediate_nodes,
57875789
payee_node_id,
@@ -5794,7 +5796,7 @@ pub fn create_trampoline_forward_blinded_tail<ES: EntropySource>(
57945796
)
57955797
.unwrap();
57965798

5797-
BlindedTail {
5799+
let tail = BlindedTail {
57985800
trampoline_hops: vec![TrampolineHop {
57995801
pubkey: intermediate_nodes.first().map(|n| n.node_id).unwrap_or(payee_node_id),
58005802
node_features: types::features::Features::empty(),
@@ -5813,5 +5815,6 @@ pub fn create_trampoline_forward_blinded_tail<ES: EntropySource>(
58135815
blinding_point: blinded_path.blinding_point(),
58145816
excess_final_cltv_expiry_delta: excess_final_cltv_delta,
58155817
final_value_msat,
5816-
}
5818+
};
5819+
(tail, blinded_path)
58175820
}

0 commit comments

Comments
 (0)