|
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}; |
@@ -5798,3 +5801,47 @@ pub fn get_scid_from_channel_id<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, channel_id: |
5798 | 5801 | .short_channel_id |
5799 | 5802 | .unwrap() |
5800 | 5803 | } |
| 5804 | + |
| 5805 | +/// Creates a [`BlindedTail`] for a trampoline forward through a single intermediate node. |
| 5806 | +/// |
| 5807 | +/// The resulting tail contains blinded hops built from `intermediate_nodes` plus a dummy receive |
| 5808 | +/// TLV, with the `TrampolineHop` fee and CLTV derived from the blinded path's aggregated payinfo. |
| 5809 | +pub fn create_trampoline_forward_blinded_tail<ES: EntropySource>( |
| 5810 | + secp_ctx: &bitcoin::secp256k1::Secp256k1<bitcoin::secp256k1::All>, entropy_source: ES, |
| 5811 | + intermediate_nodes: &[ForwardNode<TrampolineForwardTlvs>], payee_node_id: PublicKey, |
| 5812 | + payee_receive_key: ReceiveAuthKey, payee_tlvs: ReceiveTlvs, min_final_cltv_expiry_delta: u32, |
| 5813 | + excess_final_cltv_delta: u32, final_value_msat: u64, |
| 5814 | +) -> BlindedTail { |
| 5815 | + let blinded_path = BlindedPaymentPath::new_for_trampoline( |
| 5816 | + intermediate_nodes, |
| 5817 | + payee_node_id, |
| 5818 | + payee_receive_key, |
| 5819 | + payee_tlvs, |
| 5820 | + u64::max_value(), |
| 5821 | + min_final_cltv_expiry_delta as u16, |
| 5822 | + entropy_source, |
| 5823 | + secp_ctx, |
| 5824 | + ) |
| 5825 | + .unwrap(); |
| 5826 | + |
| 5827 | + BlindedTail { |
| 5828 | + trampoline_hops: vec![TrampolineHop { |
| 5829 | + pubkey: intermediate_nodes.first().map(|n| n.node_id).unwrap_or(payee_node_id), |
| 5830 | + node_features: types::features::Features::empty(), |
| 5831 | + fee_msat: compute_fees( |
| 5832 | + final_value_msat, |
| 5833 | + lightning_types::routing::RoutingFees { |
| 5834 | + base_msat: blinded_path.payinfo.fee_base_msat, |
| 5835 | + proportional_millionths: blinded_path.payinfo.fee_proportional_millionths, |
| 5836 | + }, |
| 5837 | + ) |
| 5838 | + .unwrap(), |
| 5839 | + cltv_expiry_delta: blinded_path.payinfo.cltv_expiry_delta as u32 |
| 5840 | + + excess_final_cltv_delta, |
| 5841 | + }], |
| 5842 | + hops: blinded_path.blinded_hops().to_vec(), |
| 5843 | + blinding_point: blinded_path.blinding_point(), |
| 5844 | + excess_final_cltv_expiry_delta: excess_final_cltv_delta, |
| 5845 | + final_value_msat, |
| 5846 | + } |
| 5847 | +} |
0 commit comments