@@ -159,8 +159,7 @@ pub(super) fn compute_payinfo(
159
159
let mut curr_base_fee: u64 = 0 ;
160
160
let mut curr_prop_mil: u64 = 0 ;
161
161
let mut cltv_expiry_delta: u16 = 0 ;
162
- let mut htlc_minimum_msat = payee_tlvs. payment_constraints . htlc_minimum_msat as u128 ;
163
- for ( idx, ( _, tlvs) ) in intermediate_nodes. iter ( ) . enumerate ( ) . rev ( ) {
162
+ for ( _, tlvs) in intermediate_nodes. iter ( ) . rev ( ) {
164
163
// In the future, we'll want to take the intersection of all supported features for the
165
164
// `BlindedPayInfo`, but there are no features in that context right now.
166
165
if tlvs. features . requires_unknown_bits_from ( & BlindedHopFeatures :: empty ( ) ) { return Err ( ( ) ) }
@@ -184,23 +183,24 @@ pub(super) fn compute_payinfo(
184
183
. ok_or ( ( ) ) ?;
185
184
186
185
cltv_expiry_delta = cltv_expiry_delta. checked_add ( tlvs. payment_relay . cltv_expiry_delta ) . ok_or ( ( ) ) ?;
186
+ }
187
187
188
- let mut htlc_min_candidate = tlvs. payment_constraints . htlc_minimum_msat as u128 ;
189
- for ( _, node) in intermediate_nodes. iter ( ) . skip ( idx + 1 ) {
190
- // The min htlc for a hop is that hop's htlc_minimum_msat minus the following hops' fees
191
- // because the sender will automatically include that following fee in the amount that this
192
- // hop forwards.
193
- let prop_fee = node. payment_relay . fee_proportional_millionths as u128 ;
194
- let base_fee = node. payment_relay . fee_base_msat as u128 ;
195
- let hop_fee = htlc_min_candidate
196
- . checked_mul ( prop_fee)
197
- . and_then ( |prop_fee| ( prop_fee / 1_000_000 ) . checked_add ( base_fee) )
198
- . ok_or ( ( ) ) ?;
199
- htlc_min_candidate = htlc_min_candidate. saturating_sub ( hop_fee) ;
200
- if htlc_min_candidate == 0 { break }
201
- }
202
- htlc_minimum_msat = core:: cmp:: max ( htlc_min_candidate, htlc_minimum_msat) ;
188
+ let mut htlc_minimum_msat = intermediate_nodes. first ( )
189
+ . map_or ( 0 , |( _, tlvs) | tlvs. payment_constraints . htlc_minimum_msat ) as u128 ;
190
+ for ( _, tlvs) in intermediate_nodes. iter ( ) . skip ( 1 ) {
191
+ let prop_fee = tlvs. payment_relay . fee_proportional_millionths as u128 ;
192
+ let base_fee = tlvs. payment_relay . fee_base_msat as u128 ;
193
+ let hop_fee = htlc_minimum_msat
194
+ . checked_mul ( prop_fee)
195
+ . and_then ( |prop_fee| ( prop_fee / 1_000_000 ) . checked_add ( base_fee) )
196
+ . ok_or ( ( ) ) ?;
197
+ htlc_minimum_msat = core:: cmp:: max (
198
+ htlc_minimum_msat. saturating_sub ( hop_fee) , tlvs. payment_constraints . htlc_minimum_msat as u128
199
+ ) ;
203
200
}
201
+ htlc_minimum_msat = core:: cmp:: max (
202
+ payee_tlvs. payment_constraints . htlc_minimum_msat as u128 , htlc_minimum_msat
203
+ ) ;
204
204
205
205
Ok ( BlindedPayInfo {
206
206
fee_base_msat : u32:: try_from ( curr_base_fee) . map_err ( |_| ( ) ) ?,
0 commit comments