1 //! Utilities to decode payment onions and do contextless validation of incoming payments.
3 //! Primarily features [`peel_payment_onion`], which allows the decoding of an onion statelessly
4 //! and can be used to predict whether we'd accept a payment.
6 use bitcoin::hashes::Hash;
7 use bitcoin::hashes::sha256::Hash as Sha256;
8 use bitcoin::secp256k1::{self, Secp256k1, PublicKey};
10 use crate::blinded_path;
11 use crate::blinded_path::payment::{PaymentConstraints, PaymentRelay};
12 use crate::chain::channelmonitor::{HTLC_FAIL_BACK_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS};
13 use crate::ln::PaymentHash;
14 use crate::ln::channelmanager::{BlindedForward, CLTV_FAR_FAR_AWAY, HTLCFailureMsg, MIN_CLTV_EXPIRY_DELTA, PendingHTLCInfo, PendingHTLCRouting};
15 use crate::ln::features::BlindedHopFeatures;
17 use crate::ln::onion_utils;
18 use crate::ln::onion_utils::{HTLCFailReason, INVALID_ONION_BLINDING};
19 use crate::sign::{NodeSigner, Recipient};
20 use crate::util::logger::Logger;
22 use crate::prelude::*;
25 /// Invalid inbound onion payment.
27 pub struct InboundOnionErr {
28 /// BOLT 4 error code.
30 /// Data attached to this error.
31 pub err_data: Vec<u8>,
32 /// Error message text.
33 pub msg: &'static str,
36 fn check_blinded_forward(
37 inbound_amt_msat: u64, inbound_cltv_expiry: u32, payment_relay: &PaymentRelay,
38 payment_constraints: &PaymentConstraints, features: &BlindedHopFeatures
39 ) -> Result<(u64, u32), ()> {
40 let amt_to_forward = blinded_path::payment::amt_to_forward_msat(
41 inbound_amt_msat, payment_relay
43 let outgoing_cltv_value = inbound_cltv_expiry.checked_sub(
44 payment_relay.cltv_expiry_delta as u32
46 if inbound_amt_msat < payment_constraints.htlc_minimum_msat ||
47 outgoing_cltv_value > payment_constraints.max_cltv_expiry
49 if features.requires_unknown_bits_from(&BlindedHopFeatures::empty()) { return Err(()) }
50 Ok((amt_to_forward, outgoing_cltv_value))
53 pub(super) fn create_fwd_pending_htlc_info(
54 msg: &msgs::UpdateAddHTLC, hop_data: msgs::InboundOnionPayload, hop_hmac: [u8; 32],
55 new_packet_bytes: [u8; onion_utils::ONION_DATA_LEN], shared_secret: [u8; 32],
56 next_packet_pubkey_opt: Option<Result<PublicKey, secp256k1::Error>>
57 ) -> Result<PendingHTLCInfo, InboundOnionErr> {
58 debug_assert!(next_packet_pubkey_opt.is_some());
59 let outgoing_packet = msgs::OnionPacket {
61 public_key: next_packet_pubkey_opt.unwrap_or(Err(secp256k1::Error::InvalidPublicKey)),
62 hop_data: new_packet_bytes,
67 short_channel_id, amt_to_forward, outgoing_cltv_value, inbound_blinding_point
69 msgs::InboundOnionPayload::Forward { short_channel_id, amt_to_forward, outgoing_cltv_value } =>
70 (short_channel_id, amt_to_forward, outgoing_cltv_value, None),
71 msgs::InboundOnionPayload::BlindedForward {
72 short_channel_id, payment_relay, payment_constraints, intro_node_blinding_point, features,
74 let (amt_to_forward, outgoing_cltv_value) = check_blinded_forward(
75 msg.amount_msat, msg.cltv_expiry, &payment_relay, &payment_constraints, &features
77 // We should be returning malformed here if `msg.blinding_point` is set, but this is
78 // unreachable right now since we checked it in `decode_update_add_htlc_onion`.
80 msg: "Underflow calculating outbound amount or cltv value for blinded forward",
81 err_code: INVALID_ONION_BLINDING,
82 err_data: vec![0; 32],
85 (short_channel_id, amt_to_forward, outgoing_cltv_value, Some(intro_node_blinding_point))
87 msgs::InboundOnionPayload::Receive { .. } | msgs::InboundOnionPayload::BlindedReceive { .. } =>
88 return Err(InboundOnionErr {
89 msg: "Final Node OnionHopData provided for us as an intermediary node",
90 err_code: 0x4000 | 22,
96 routing: PendingHTLCRouting::Forward {
97 onion_packet: outgoing_packet,
99 blinded: inbound_blinding_point.map(|bp| BlindedForward { inbound_blinding_point: bp }),
101 payment_hash: msg.payment_hash,
102 incoming_shared_secret: shared_secret,
103 incoming_amt_msat: Some(msg.amount_msat),
104 outgoing_amt_msat: amt_to_forward,
106 skimmed_fee_msat: None,
110 pub(super) fn create_recv_pending_htlc_info(
111 hop_data: msgs::InboundOnionPayload, shared_secret: [u8; 32], payment_hash: PaymentHash,
112 amt_msat: u64, cltv_expiry: u32, phantom_shared_secret: Option<[u8; 32]>, allow_underpay: bool,
113 counterparty_skimmed_fee_msat: Option<u64>, current_height: u32, accept_mpp_keysend: bool,
114 ) -> Result<PendingHTLCInfo, InboundOnionErr> {
115 let (payment_data, keysend_preimage, custom_tlvs, onion_amt_msat, outgoing_cltv_value, payment_metadata) = match hop_data {
116 msgs::InboundOnionPayload::Receive {
117 payment_data, keysend_preimage, custom_tlvs, amt_msat, outgoing_cltv_value, payment_metadata, ..
119 (payment_data, keysend_preimage, custom_tlvs, amt_msat, outgoing_cltv_value, payment_metadata),
120 msgs::InboundOnionPayload::BlindedReceive {
121 amt_msat, total_msat, outgoing_cltv_value, payment_secret, ..
123 let payment_data = msgs::FinalOnionHopData { payment_secret, total_msat };
124 (Some(payment_data), None, Vec::new(), amt_msat, outgoing_cltv_value, None)
126 msgs::InboundOnionPayload::Forward { .. } => {
127 return Err(InboundOnionErr {
129 err_data: Vec::new(),
130 msg: "Got non final data with an HMAC of 0",
133 msgs::InboundOnionPayload::BlindedForward { .. } => {
134 return Err(InboundOnionErr {
135 err_code: INVALID_ONION_BLINDING,
136 err_data: vec![0; 32],
137 msg: "Got blinded non final data with an HMAC of 0",
141 // final_incorrect_cltv_expiry
142 if outgoing_cltv_value > cltv_expiry {
143 return Err(InboundOnionErr {
144 msg: "Upstream node set CLTV to less than the CLTV set by the sender",
146 err_data: cltv_expiry.to_be_bytes().to_vec()
149 // final_expiry_too_soon
150 // We have to have some headroom to broadcast on chain if we have the preimage, so make sure
151 // we have at least HTLC_FAIL_BACK_BUFFER blocks to go.
153 // Also, ensure that, in the case of an unknown preimage for the received payment hash, our
154 // payment logic has enough time to fail the HTLC backward before our onchain logic triggers a
155 // channel closure (see HTLC_FAIL_BACK_BUFFER rationale).
156 if cltv_expiry <= current_height + HTLC_FAIL_BACK_BUFFER + 1 {
157 let mut err_data = Vec::with_capacity(12);
158 err_data.extend_from_slice(&amt_msat.to_be_bytes());
159 err_data.extend_from_slice(¤t_height.to_be_bytes());
160 return Err(InboundOnionErr {
161 err_code: 0x4000 | 15, err_data,
162 msg: "The final CLTV expiry is too soon to handle",
165 if (!allow_underpay && onion_amt_msat > amt_msat) ||
166 (allow_underpay && onion_amt_msat >
167 amt_msat.saturating_add(counterparty_skimmed_fee_msat.unwrap_or(0)))
169 return Err(InboundOnionErr {
171 err_data: amt_msat.to_be_bytes().to_vec(),
172 msg: "Upstream node sent less than we were supposed to receive in payment",
176 let routing = if let Some(payment_preimage) = keysend_preimage {
177 // We need to check that the sender knows the keysend preimage before processing this
178 // payment further. Otherwise, an intermediary routing hop forwarding non-keysend-HTLC X
179 // could discover the final destination of X, by probing the adjacent nodes on the route
180 // with a keysend payment of identical payment hash to X and observing the processing
181 // time discrepancies due to a hash collision with X.
182 let hashed_preimage = PaymentHash(Sha256::hash(&payment_preimage.0).to_byte_array());
183 if hashed_preimage != payment_hash {
184 return Err(InboundOnionErr {
186 err_data: Vec::new(),
187 msg: "Payment preimage didn't match payment hash",
190 if !accept_mpp_keysend && payment_data.is_some() {
191 return Err(InboundOnionErr {
193 err_data: Vec::new(),
194 msg: "We don't support MPP keysend payments",
197 PendingHTLCRouting::ReceiveKeysend {
201 incoming_cltv_expiry: outgoing_cltv_value,
204 } else if let Some(data) = payment_data {
205 PendingHTLCRouting::Receive {
208 incoming_cltv_expiry: outgoing_cltv_value,
209 phantom_shared_secret,
213 return Err(InboundOnionErr {
214 err_code: 0x4000|0x2000|3,
215 err_data: Vec::new(),
216 msg: "We require payment_secrets",
222 incoming_shared_secret: shared_secret,
223 incoming_amt_msat: Some(amt_msat),
224 outgoing_amt_msat: onion_amt_msat,
226 skimmed_fee_msat: counterparty_skimmed_fee_msat,
230 /// Peel one layer off an incoming onion, returning a [`PendingHTLCInfo`] that contains information
231 /// about the intended next-hop for the HTLC.
233 /// This does all the relevant context-free checks that LDK requires for payment relay or
234 /// acceptance. If the payment is to be received, and the amount matches the expected amount for
235 /// a given invoice, this indicates the [`msgs::UpdateAddHTLC`], once fully committed in the
236 /// channel, will generate an [`Event::PaymentClaimable`].
238 /// [`Event::PaymentClaimable`]: crate::events::Event::PaymentClaimable
239 pub fn peel_payment_onion<NS: Deref, L: Deref, T: secp256k1::Verification>(
240 msg: &msgs::UpdateAddHTLC, node_signer: &NS, logger: &L, secp_ctx: &Secp256k1<T>,
241 cur_height: u32, accept_mpp_keysend: bool, allow_skimmed_fees: bool,
242 ) -> Result<PendingHTLCInfo, InboundOnionErr>
244 NS::Target: NodeSigner,
247 let (hop, shared_secret, next_packet_details_opt) =
248 decode_incoming_update_add_htlc_onion(msg, node_signer, logger, secp_ctx
250 let (err_code, err_data) = match e {
251 HTLCFailureMsg::Malformed(m) => (m.failure_code, Vec::new()),
252 HTLCFailureMsg::Relay(r) => (0x4000 | 22, r.reason.data),
254 let msg = "Failed to decode update add htlc onion";
255 InboundOnionErr { msg, err_code, err_data }
258 onion_utils::Hop::Forward { next_hop_data, next_hop_hmac, new_packet_bytes } => {
259 let NextPacketDetails {
260 next_packet_pubkey, outgoing_amt_msat: _, outgoing_scid: _, outgoing_cltv_value
261 } = match next_packet_details_opt {
262 Some(next_packet_details) => next_packet_details,
263 // Forward should always include the next hop details
264 None => return Err(InboundOnionErr {
265 msg: "Failed to decode update add htlc onion",
266 err_code: 0x4000 | 22,
267 err_data: Vec::new(),
271 if let Err((err_msg, code)) = check_incoming_htlc_cltv(
272 cur_height, outgoing_cltv_value, msg.cltv_expiry
274 return Err(InboundOnionErr {
277 err_data: Vec::new(),
281 // TODO: If this is potentially a phantom payment we should decode the phantom payment
282 // onion here and check it.
284 create_fwd_pending_htlc_info(
285 msg, next_hop_data, next_hop_hmac, new_packet_bytes, shared_secret,
286 Some(next_packet_pubkey)
289 onion_utils::Hop::Receive(received_data) => {
290 create_recv_pending_htlc_info(
291 received_data, shared_secret, msg.payment_hash, msg.amount_msat, msg.cltv_expiry,
292 None, allow_skimmed_fees, msg.skimmed_fee_msat, cur_height, accept_mpp_keysend,
298 pub(super) struct NextPacketDetails {
299 pub(super) next_packet_pubkey: Result<PublicKey, secp256k1::Error>,
300 pub(super) outgoing_scid: u64,
301 pub(super) outgoing_amt_msat: u64,
302 pub(super) outgoing_cltv_value: u32,
305 pub(super) fn decode_incoming_update_add_htlc_onion<NS: Deref, L: Deref, T: secp256k1::Verification>(
306 msg: &msgs::UpdateAddHTLC, node_signer: &NS, logger: &L, secp_ctx: &Secp256k1<T>,
307 ) -> Result<(onion_utils::Hop, [u8; 32], Option<NextPacketDetails>), HTLCFailureMsg>
309 NS::Target: NodeSigner,
312 macro_rules! return_malformed_err {
313 ($msg: expr, $err_code: expr) => {
315 log_info!(logger, "Failed to accept/forward incoming HTLC: {}", $msg);
316 return Err(HTLCFailureMsg::Malformed(msgs::UpdateFailMalformedHTLC {
317 channel_id: msg.channel_id,
318 htlc_id: msg.htlc_id,
319 sha256_of_onion: Sha256::hash(&msg.onion_routing_packet.hop_data).to_byte_array(),
320 failure_code: $err_code,
326 if let Err(_) = msg.onion_routing_packet.public_key {
327 return_malformed_err!("invalid ephemeral pubkey", 0x8000 | 0x4000 | 6);
330 let shared_secret = node_signer.ecdh(
331 Recipient::Node, &msg.onion_routing_packet.public_key.unwrap(), None
332 ).unwrap().secret_bytes();
334 if msg.onion_routing_packet.version != 0 {
335 //TODO: Spec doesn't indicate if we should only hash hop_data here (and in other
336 //sha256_of_onion error data packets), or the entire onion_routing_packet. Either way,
337 //the hash doesn't really serve any purpose - in the case of hashing all data, the
338 //receiving node would have to brute force to figure out which version was put in the
339 //packet by the node that send us the message, in the case of hashing the hop_data, the
340 //node knows the HMAC matched, so they already know what is there...
341 return_malformed_err!("Unknown onion packet version", 0x8000 | 0x4000 | 4);
343 macro_rules! return_err {
344 ($msg: expr, $err_code: expr, $data: expr) => {
346 log_info!(logger, "Failed to accept/forward incoming HTLC: {}", $msg);
347 return Err(HTLCFailureMsg::Relay(msgs::UpdateFailHTLC {
348 channel_id: msg.channel_id,
349 htlc_id: msg.htlc_id,
350 reason: HTLCFailReason::reason($err_code, $data.to_vec())
351 .get_encrypted_failure_packet(&shared_secret, &None),
357 let next_hop = match onion_utils::decode_next_payment_hop(
358 shared_secret, &msg.onion_routing_packet.hop_data[..], msg.onion_routing_packet.hmac,
359 msg.payment_hash, node_signer
362 Err(onion_utils::OnionDecodeErr::Malformed { err_msg, err_code }) => {
363 return_malformed_err!(err_msg, err_code);
365 Err(onion_utils::OnionDecodeErr::Relay { err_msg, err_code }) => {
366 return_err!(err_msg, err_code, &[0; 0]);
370 let next_packet_details = match next_hop {
371 onion_utils::Hop::Forward {
372 next_hop_data: msgs::InboundOnionPayload::Forward {
373 short_channel_id, amt_to_forward, outgoing_cltv_value
376 let next_packet_pubkey = onion_utils::next_hop_pubkey(secp_ctx,
377 msg.onion_routing_packet.public_key.unwrap(), &shared_secret);
379 next_packet_pubkey, outgoing_scid: short_channel_id,
380 outgoing_amt_msat: amt_to_forward, outgoing_cltv_value
383 onion_utils::Hop::Forward {
384 next_hop_data: msgs::InboundOnionPayload::BlindedForward {
385 short_channel_id, ref payment_relay, ref payment_constraints, ref features, ..
388 let (amt_to_forward, outgoing_cltv_value) = match check_blinded_forward(
389 msg.amount_msat, msg.cltv_expiry, &payment_relay, &payment_constraints, &features
391 Ok((amt, cltv)) => (amt, cltv),
393 return_err!("Underflow calculating outbound amount or cltv value for blinded forward",
394 INVALID_ONION_BLINDING, &[0; 32]);
397 let next_packet_pubkey = onion_utils::next_hop_pubkey(&secp_ctx,
398 msg.onion_routing_packet.public_key.unwrap(), &shared_secret);
400 next_packet_pubkey, outgoing_scid: short_channel_id, outgoing_amt_msat: amt_to_forward,
404 onion_utils::Hop::Receive { .. } => return Ok((next_hop, shared_secret, None)),
405 onion_utils::Hop::Forward { next_hop_data: msgs::InboundOnionPayload::Receive { .. }, .. } |
406 onion_utils::Hop::Forward { next_hop_data: msgs::InboundOnionPayload::BlindedReceive { .. }, .. } =>
408 return_err!("Final Node OnionHopData provided for us as an intermediary node", 0x4000 | 22, &[0; 0]);
412 Ok((next_hop, shared_secret, Some(next_packet_details)))
415 pub(super) fn check_incoming_htlc_cltv(
416 cur_height: u32, outgoing_cltv_value: u32, cltv_expiry: u32
417 ) -> Result<(), (&'static str, u16)> {
418 if (cltv_expiry as u64) < (outgoing_cltv_value) as u64 + MIN_CLTV_EXPIRY_DELTA as u64 {
420 "Forwarding node has tampered with the intended HTLC values or origin node has an obsolete cltv_expiry_delta",
421 0x1000 | 13, // incorrect_cltv_expiry
424 // Theoretically, channel counterparty shouldn't send us a HTLC expiring now,
425 // but we want to be robust wrt to counterparty packet sanitization (see
426 // HTLC_FAIL_BACK_BUFFER rationale).
427 if cltv_expiry <= cur_height + HTLC_FAIL_BACK_BUFFER as u32 { // expiry_too_soon
428 return Err(("CLTV expiry is too close", 0x1000 | 14));
430 if cltv_expiry > cur_height + CLTV_FAR_FAR_AWAY as u32 { // expiry_too_far
431 return Err(("CLTV expiry is too far in the future", 21));
433 // If the HTLC expires ~now, don't bother trying to forward it to our
434 // counterparty. They should fail it anyway, but we don't want to bother with
435 // the round-trips or risk them deciding they definitely want the HTLC and
436 // force-closing to ensure they get it if we're offline.
437 // We previously had a much more aggressive check here which tried to ensure
438 // our counterparty receives an HTLC which has *our* risk threshold met on it,
439 // but there is no need to do that, and since we're a bit conservative with our
440 // risk threshold it just results in failing to forward payments.
441 if (outgoing_cltv_value) as u64 <= (cur_height + LATENCY_GRACE_PERIOD_BLOCKS) as u64 {
442 return Err(("Outgoing CLTV value is too soon", 0x1000 | 14));
450 use bitcoin::hashes::Hash;
451 use bitcoin::hashes::sha256::Hash as Sha256;
452 use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
453 use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
454 use crate::ln::ChannelId;
455 use crate::ln::channelmanager::RecipientOnionFields;
456 use crate::ln::features::{ChannelFeatures, NodeFeatures};
458 use crate::ln::onion_utils::create_payment_onion;
459 use crate::routing::router::{Path, RouteHop};
460 use crate::util::test_utils;
463 fn fail_construct_onion_on_too_big_payloads() {
464 // Ensure that if we call `construct_onion_packet` and friends where payloads are too large for
465 // the allotted packet length, we'll fail to construct. Previously, senders would happily
466 // construct invalid packets by array-shifting the final node's HMAC out of the packet when
467 // adding an intermediate onion layer, causing the receiver to error with "final payload
468 // provided for us as an intermediate node."
469 let secp_ctx = Secp256k1::new();
470 let bob = crate::sign::KeysManager::new(&[2; 32], 42, 42);
471 let bob_pk = PublicKey::from_secret_key(&secp_ctx, &bob.get_node_secret_key());
472 let charlie = crate::sign::KeysManager::new(&[3; 32], 42, 42);
473 let charlie_pk = PublicKey::from_secret_key(&secp_ctx, &charlie.get_node_secret_key());
476 session_priv, total_amt_msat, cur_height, mut recipient_onion, keysend_preimage, payment_hash,
478 ) = payment_onion_args(bob_pk, charlie_pk);
480 // Ensure the onion will not fit all the payloads by adding a large custom TLV.
481 recipient_onion.custom_tlvs.push((13377331, vec![0; 1156]));
483 let path = Path { hops, blinded_tail: None, };
484 let onion_keys = super::onion_utils::construct_onion_keys(&secp_ctx, &path, &session_priv).unwrap();
485 let (onion_payloads, ..) = super::onion_utils::build_onion_payloads(
486 &path, total_amt_msat, recipient_onion, cur_height + 1, &Some(keysend_preimage)
489 assert!(super::onion_utils::construct_onion_packet(
490 onion_payloads, onion_keys, prng_seed, &payment_hash
495 fn test_peel_payment_onion() {
497 let secp_ctx = Secp256k1::new();
499 let bob = crate::sign::KeysManager::new(&[2; 32], 42, 42);
500 let bob_pk = PublicKey::from_secret_key(&secp_ctx, &bob.get_node_secret_key());
501 let charlie = crate::sign::KeysManager::new(&[3; 32], 42, 42);
502 let charlie_pk = PublicKey::from_secret_key(&secp_ctx, &charlie.get_node_secret_key());
504 let (session_priv, total_amt_msat, cur_height, recipient_onion, preimage, payment_hash,
505 prng_seed, hops, recipient_amount, pay_secret) = payment_onion_args(bob_pk, charlie_pk);
512 let (onion, amount_msat, cltv_expiry) = create_payment_onion(
513 &secp_ctx, &path, &session_priv, total_amt_msat, recipient_onion, cur_height,
514 &payment_hash, &Some(preimage), prng_seed
517 let msg = make_update_add_msg(amount_msat, cltv_expiry, payment_hash, onion);
518 let logger = test_utils::TestLogger::with_id("bob".to_string());
520 let peeled = peel_payment_onion(&msg, &&bob, &&logger, &secp_ctx, cur_height, true, false)
521 .map_err(|e| e.msg).unwrap();
523 let next_onion = match peeled.routing {
524 PendingHTLCRouting::Forward { onion_packet, .. } => {
527 _ => panic!("expected a forwarded onion"),
530 let msg2 = make_update_add_msg(amount_msat, cltv_expiry, payment_hash, next_onion);
531 let peeled2 = peel_payment_onion(&msg2, &&charlie, &&logger, &secp_ctx, cur_height, true, false)
532 .map_err(|e| e.msg).unwrap();
534 match peeled2.routing {
535 PendingHTLCRouting::ReceiveKeysend { payment_preimage, payment_data, incoming_cltv_expiry, .. } => {
536 assert_eq!(payment_preimage, preimage);
537 assert_eq!(peeled2.outgoing_amt_msat, recipient_amount);
538 assert_eq!(incoming_cltv_expiry, peeled2.outgoing_cltv_value);
539 let msgs::FinalOnionHopData{total_msat, payment_secret} = payment_data.unwrap();
540 assert_eq!(total_msat, total_amt_msat);
541 assert_eq!(payment_secret, pay_secret);
543 _ => panic!("expected a received keysend"),
547 fn make_update_add_msg(
548 amount_msat: u64, cltv_expiry: u32, payment_hash: PaymentHash,
549 onion_routing_packet: msgs::OnionPacket
550 ) -> msgs::UpdateAddHTLC {
551 msgs::UpdateAddHTLC {
552 channel_id: ChannelId::from_bytes([0; 32]),
557 onion_routing_packet,
558 skimmed_fee_msat: None,
559 blinding_point: None,
563 fn payment_onion_args(hop_pk: PublicKey, recipient_pk: PublicKey) -> (
564 SecretKey, u64, u32, RecipientOnionFields, PaymentPreimage, PaymentHash, [u8; 32],
565 Vec<RouteHop>, u64, PaymentSecret,
567 let session_priv_bytes = [42; 32];
568 let session_priv = SecretKey::from_slice(&session_priv_bytes).unwrap();
569 let total_amt_msat = 1000;
570 let cur_height = 1000;
571 let pay_secret = PaymentSecret([99; 32]);
572 let recipient_onion = RecipientOnionFields::secret_only(pay_secret);
573 let preimage_bytes = [43; 32];
574 let preimage = PaymentPreimage(preimage_bytes);
575 let rhash_bytes = Sha256::hash(&preimage_bytes).to_byte_array();
576 let payment_hash = PaymentHash(rhash_bytes);
577 let prng_seed = [44; 32];
579 // make a route alice -> bob -> charlie
581 let recipient_amount = total_amt_msat - hop_fee;
586 cltv_expiry_delta: 42,
588 node_features: NodeFeatures::empty(),
589 channel_features: ChannelFeatures::empty(),
590 maybe_announced_channel: false,
593 pubkey: recipient_pk,
594 fee_msat: recipient_amount,
595 cltv_expiry_delta: 42,
597 node_features: NodeFeatures::empty(),
598 channel_features: ChannelFeatures::empty(),
599 maybe_announced_channel: false,
603 (session_priv, total_amt_msat, cur_height, recipient_onion, preimage, payment_hash,
604 prng_seed, hops, recipient_amount, pay_secret)