|
10 | 10 | //! A bunch of useful utilities for building networks of nodes and exchanging messages between |
11 | 11 | //! nodes for functional tests. |
12 | 12 |
|
13 | | -use crate::blinded_path::payment::DummyTlvs; |
| 13 | +use crate::blinded_path::payment::{ |
| 14 | + BlindedPaymentPath, DummyTlvs, ForwardNode, ReceiveTlvs, TrampolineForwardTlvs, |
| 15 | +}; |
14 | 16 | use crate::chain::channelmonitor::{ChannelMonitor, HTLC_FAIL_BACK_BUFFER}; |
15 | 17 | use crate::chain::transaction::OutPoint; |
16 | 18 | use crate::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Listen, Watch}; |
@@ -40,7 +42,8 @@ use crate::ln::types::ChannelId; |
40 | 42 | use crate::onion_message::messenger::OnionMessenger; |
41 | 43 | use crate::routing::gossip::{NetworkGraph, NetworkUpdate, P2PGossipSync}; |
42 | 44 | use crate::routing::router::{self, PaymentParameters, Route, RouteParameters}; |
43 | | -use crate::sign::{EntropySource, RandomBytes}; |
| 45 | +use crate::routing::router::{compute_fees, BlindedTail, TrampolineHop}; |
| 46 | +use crate::sign::{EntropySource, RandomBytes, ReceiveAuthKey}; |
44 | 47 | use crate::types::features::ChannelTypeFeatures; |
45 | 48 | use crate::types::features::InitFeatures; |
46 | 49 | use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret}; |
@@ -5768,3 +5771,47 @@ pub fn get_scid_from_channel_id<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, channel_id: |
5768 | 5771 | .short_channel_id |
5769 | 5772 | .unwrap() |
5770 | 5773 | } |
| 5774 | + |
| 5775 | +/// Creates a [`BlindedTail`] for a trampoline forward through a single intermediate node. |
| 5776 | +/// |
| 5777 | +/// The resulting tail contains blinded hops built from `intermediate_nodes` plus a dummy receive |
| 5778 | +/// TLV, with the `TrampolineHop` fee and CLTV derived from the blinded path's aggregated payinfo. |
| 5779 | +pub fn create_trampoline_forward_blinded_tail<ES: EntropySource>( |
| 5780 | + secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>, entropy_source: ES, |
| 5781 | + intermediate_nodes: &[ForwardNode<TrampolineForwardTlvs>], payee_node_id: PublicKey, |
| 5782 | + payee_receive_key: ReceiveAuthKey, payee_tlvs: ReceiveTlvs, min_final_cltv_expiry_delta: u32, |
| 5783 | + excess_final_cltv_delta: u32, final_value_msat: u64, |
| 5784 | +) -> BlindedTail { |
| 5785 | + let blinded_path = BlindedPaymentPath::new_for_trampoline( |
| 5786 | + intermediate_nodes, |
| 5787 | + payee_node_id, |
| 5788 | + payee_receive_key, |
| 5789 | + payee_tlvs, |
| 5790 | + u64::max_value(), |
| 5791 | + min_final_cltv_expiry_delta as u16, |
| 5792 | + entropy_source, |
| 5793 | + secp_ctx, |
| 5794 | + ) |
| 5795 | + .unwrap(); |
| 5796 | + |
| 5797 | + BlindedTail { |
| 5798 | + trampoline_hops: vec![TrampolineHop { |
| 5799 | + pubkey: intermediate_nodes.first().map(|n| n.node_id).unwrap_or(payee_node_id), |
| 5800 | + node_features: types::features::Features::empty(), |
| 5801 | + fee_msat: compute_fees( |
| 5802 | + final_value_msat, |
| 5803 | + lightning_types::routing::RoutingFees { |
| 5804 | + base_msat: blinded_path.payinfo.fee_base_msat, |
| 5805 | + proportional_millionths: blinded_path.payinfo.fee_proportional_millionths, |
| 5806 | + }, |
| 5807 | + ) |
| 5808 | + .unwrap(), |
| 5809 | + cltv_expiry_delta: blinded_path.payinfo.cltv_expiry_delta as u32 |
| 5810 | + + excess_final_cltv_delta, |
| 5811 | + }], |
| 5812 | + hops: blinded_path.blinded_hops().to_vec(), |
| 5813 | + blinding_point: blinded_path.blinding_point(), |
| 5814 | + excess_final_cltv_expiry_delta: excess_final_cltv_delta, |
| 5815 | + final_value_msat, |
| 5816 | + } |
| 5817 | +} |
0 commit comments