@@ -12,7 +12,7 @@ use crate::ln::channelmanager::{HTLCSource, RecipientOnionFields};
12
12
use crate :: ln:: msgs;
13
13
use crate :: ln:: wire:: Encode ;
14
14
use crate :: routing:: gossip:: NetworkUpdate ;
15
- use crate :: routing:: router:: { Path , RouteHop } ;
15
+ use crate :: routing:: router:: { BlindedTail , Path , RouteHop } ;
16
16
use crate :: util:: chacha20:: { ChaCha20 , ChaChaReader } ;
17
17
use crate :: util:: errors:: { self , APIError } ;
18
18
use crate :: util:: ser:: { Readable , ReadableArgs , Writeable , Writer , LengthCalculatingWriter } ;
@@ -177,27 +177,51 @@ pub(super) fn build_onion_payloads(path: &Path, total_msat: u64, mut recipient_o
177
177
// the intended recipient).
178
178
let value_msat = if cur_value_msat == 0 { hop. fee_msat } else { cur_value_msat } ;
179
179
let cltv = if cur_cltv == starting_htlc_offset { hop. cltv_expiry_delta + starting_htlc_offset } else { cur_cltv } ;
180
- res. insert ( 0 , if idx == 0 {
181
- msgs:: OutboundOnionPayload :: Receive {
182
- payment_data : if let Some ( secret) = recipient_onion. payment_secret . take ( ) {
183
- Some ( msgs:: FinalOnionHopData {
184
- payment_secret : secret,
185
- total_msat,
186
- } )
187
- } else { None } ,
188
- payment_metadata : recipient_onion. payment_metadata . take ( ) ,
189
- keysend_preimage : * keysend_preimage,
190
- custom_tlvs : recipient_onion. custom_tlvs . clone ( ) ,
191
- amt_msat : value_msat,
192
- outgoing_cltv_value : cltv,
180
+ if idx == 0 {
181
+ if let Some ( BlindedTail {
182
+ blinding_point, hops, final_value_msat, excess_final_cltv_expiry_delta, ..
183
+ } ) = & path. blinded_tail {
184
+ let mut blinding_point = Some ( * blinding_point) ;
185
+ for ( i, blinded_hop) in hops. iter ( ) . enumerate ( ) {
186
+ if i == hops. len ( ) - 1 {
187
+ cur_value_msat += final_value_msat;
188
+ cur_cltv += excess_final_cltv_expiry_delta;
189
+ res. push ( msgs:: OutboundOnionPayload :: BlindedReceive {
190
+ amt_msat : * final_value_msat,
191
+ total_msat,
192
+ outgoing_cltv_value : cltv,
193
+ encrypted_tlvs : blinded_hop. encrypted_payload . clone ( ) ,
194
+ intro_node_blinding_point : blinding_point. take ( ) ,
195
+ } ) ;
196
+ } else {
197
+ res. push ( msgs:: OutboundOnionPayload :: BlindedForward {
198
+ encrypted_tlvs : blinded_hop. encrypted_payload . clone ( ) ,
199
+ intro_node_blinding_point : blinding_point. take ( ) ,
200
+ } ) ;
201
+ }
202
+ }
203
+ } else {
204
+ res. push ( msgs:: OutboundOnionPayload :: Receive {
205
+ payment_data : if let Some ( secret) = recipient_onion. payment_secret . take ( ) {
206
+ Some ( msgs:: FinalOnionHopData {
207
+ payment_secret : secret,
208
+ total_msat,
209
+ } )
210
+ } else { None } ,
211
+ payment_metadata : recipient_onion. payment_metadata . take ( ) ,
212
+ keysend_preimage : * keysend_preimage,
213
+ custom_tlvs : recipient_onion. custom_tlvs . clone ( ) ,
214
+ amt_msat : value_msat,
215
+ outgoing_cltv_value : cltv,
216
+ } ) ;
193
217
}
194
218
} else {
195
- msgs:: OutboundOnionPayload :: Forward {
219
+ res . insert ( 0 , msgs:: OutboundOnionPayload :: Forward {
196
220
short_channel_id : last_short_channel_id,
197
221
amt_to_forward : value_msat,
198
222
outgoing_cltv_value : cltv,
199
- }
200
- } ) ;
223
+ } ) ;
224
+ }
201
225
cur_value_msat += hop. fee_msat ;
202
226
if cur_value_msat >= 21000000 * 100000000 * 1000 {
203
227
return Err ( APIError :: InvalidRoute { err : "Channel fees overflowed?" . to_owned ( ) } ) ;
0 commit comments