@@ -14,9 +14,10 @@ use bitcoin::hashes::Hash;
14
14
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
15
15
16
16
use crate :: blinded_path:: { BlindedHop , BlindedPath } ;
17
+ use crate :: blinded_path:: payment:: { ForwardNode , ForwardTlvs , PaymentConstraints , PaymentRelay , ReceiveTlvs } ;
17
18
use crate :: ln:: PaymentHash ;
18
19
use crate :: ln:: channelmanager:: { ChannelDetails , PaymentId } ;
19
- use crate :: ln:: features:: { Bolt11InvoiceFeatures , Bolt12InvoiceFeatures , ChannelFeatures , NodeFeatures } ;
20
+ use crate :: ln:: features:: { BlindedHopFeatures , Bolt11InvoiceFeatures , Bolt12InvoiceFeatures , ChannelFeatures , NodeFeatures } ;
20
21
use crate :: ln:: msgs:: { DecodeError , ErrorAction , LightningError , MAX_VALUE_MSAT } ;
21
22
use crate :: offers:: invoice:: { BlindedPayInfo , Bolt12Invoice } ;
22
23
use crate :: onion_message:: { DefaultMessageRouter , Destination , MessageRouter , OnionMessagePath } ;
@@ -129,6 +130,48 @@ pub trait Router: MessageRouter {
129
130
) -> Result < Route , LightningError > {
130
131
self . find_route ( payer, route_params, first_hops, inflight_htlcs)
131
132
}
133
+
134
+ /// Creates [`BlindedPath`]s for payment to the `recipient` node. The channels in `first_hops`
135
+ /// are assumed to be with the `recipient`'s peers. The payment secret and any constraints are
136
+ /// given in `tlvs`.
137
+ ///
138
+ /// The default implementation returns two-hop payment paths for each channel in `first_hops`
139
+ /// with the `recipient` node (i.e., the channel counterparty is the introduction point).
140
+ fn create_blinded_payment_paths <
141
+ ES : EntropySource + ?Sized , T : secp256k1:: Signing + secp256k1:: Verification
142
+ > (
143
+ & self , recipient : PublicKey , first_hops : Vec < ChannelDetails > , tlvs : ReceiveTlvs ,
144
+ amount_msats : u64 , count : usize , entropy_source : & ES , secp_ctx : & Secp256k1 < T >
145
+ ) -> Result < Vec < ( BlindedPayInfo , BlindedPath ) > , ( ) > {
146
+ first_hops. into_iter ( )
147
+ . filter ( |details| details. counterparty . features . supports_route_blinding ( ) )
148
+ . filter ( |details| amount_msats >= details. inbound_htlc_minimum_msat . unwrap_or ( 0 ) )
149
+ . filter ( |details| amount_msats <= details. inbound_htlc_maximum_msat . unwrap_or ( 0 ) )
150
+ . map ( |details| {
151
+ let short_channel_id = details. get_inbound_payment_scid ( ) . unwrap ( ) ;
152
+ let payment_relay: PaymentRelay = details. counterparty . forwarding_info . unwrap ( ) . into ( ) ;
153
+ let payment_constraints = PaymentConstraints {
154
+ max_cltv_expiry : tlvs. payment_constraints . max_cltv_expiry
155
+ + payment_relay. cltv_expiry_delta as u32 ,
156
+ htlc_minimum_msat : details. inbound_htlc_minimum_msat . unwrap_or ( 0 ) ,
157
+ } ;
158
+ let forward_node = ForwardNode {
159
+ tlvs : ForwardTlvs {
160
+ short_channel_id,
161
+ payment_relay,
162
+ payment_constraints,
163
+ features : BlindedHopFeatures :: empty ( ) ,
164
+ } ,
165
+ node_id : details. counterparty . node_id ,
166
+ htlc_maximum_msat : details. inbound_htlc_maximum_msat . unwrap_or ( 0 ) ,
167
+ } ;
168
+ BlindedPath :: new_for_payment (
169
+ & [ forward_node] , recipient, tlvs. clone ( ) , u64:: MAX , entropy_source, secp_ctx
170
+ )
171
+ } )
172
+ . take ( count)
173
+ . collect ( )
174
+ }
132
175
}
133
176
134
177
/// [`ScoreLookUp`] implementation that factors in in-flight HTLC liquidity.
0 commit comments