@@ -18,7 +18,7 @@ use crate::events::{self, PaymentFailureReason};
18
18
use crate :: ln:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
19
19
use crate :: ln:: channelmanager:: { ChannelDetails , HTLCSource , IDEMPOTENCY_TIMEOUT_TICKS , PaymentId } ;
20
20
use crate :: ln:: onion_utils:: HTLCFailReason ;
21
- use crate :: routing:: router:: { InFlightHtlcs , Path , PaymentParameters , Route , RouteParameters , RoutePath , Router } ;
21
+ use crate :: routing:: router:: { InFlightHtlcs , Path , PaymentParameters , Route , RouteParameters , Router } ;
22
22
use crate :: util:: errors:: APIError ;
23
23
use crate :: util:: logger:: Logger ;
24
24
use crate :: util:: time:: Time ;
@@ -171,10 +171,9 @@ impl PendingOutboundPayment {
171
171
if remove_res {
172
172
if let PendingOutboundPayment :: Retryable { ref mut pending_amt_msat, ref mut pending_fee_msat, .. } = self {
173
173
let path = path. expect ( "Fulfilling a payment should always come with a path" ) ;
174
- let path_last_hop = path. hops . last ( ) . expect ( "Outbound payments must have had a valid path" ) ;
175
- * pending_amt_msat -= path_last_hop. fee_msat ;
174
+ * pending_amt_msat -= path. final_value_msat ( ) ;
176
175
if let Some ( fee_msat) = pending_fee_msat. as_mut ( ) {
177
- * fee_msat -= path. hops . get_path_fees ( ) ;
176
+ * fee_msat -= path. fee_msat ( ) ;
178
177
}
179
178
}
180
179
}
@@ -192,10 +191,9 @@ impl PendingOutboundPayment {
192
191
} ;
193
192
if insert_res {
194
193
if let PendingOutboundPayment :: Retryable { ref mut pending_amt_msat, ref mut pending_fee_msat, .. } = self {
195
- let path_last_hop = path. hops . last ( ) . expect ( "Outbound payments must have had a valid path" ) ;
196
- * pending_amt_msat += path_last_hop. fee_msat ;
194
+ * pending_amt_msat += path. final_value_msat ( ) ;
197
195
if let Some ( fee_msat) = pending_fee_msat. as_mut ( ) {
198
- * fee_msat += path. hops . get_path_fees ( ) ;
196
+ * fee_msat += path. fee_msat ( ) ;
199
197
}
200
198
}
201
199
}
@@ -687,7 +685,7 @@ impl OutboundPayments {
687
685
}
688
686
} ;
689
687
for path in route. paths . iter ( ) {
690
- if path. hops . len ( ) == 0 {
688
+ if path. len ( ) == 0 {
691
689
log_error ! ( logger, "length-0 path in route" ) ;
692
690
self . abandon_payment ( payment_id, PaymentFailureReason :: UnexpectedError , pending_events) ;
693
691
return
@@ -723,7 +721,7 @@ impl OutboundPayments {
723
721
PendingOutboundPayment :: Retryable {
724
722
total_msat, keysend_preimage, payment_secret, pending_amt_msat, ..
725
723
} => {
726
- let retry_amt_msat: u64 = route. paths . iter ( ) . map ( |path| path . hops . last ( ) . unwrap ( ) . fee_msat ) . sum ( ) ;
724
+ let retry_amt_msat = route. get_total_amount ( ) ;
727
725
if retry_amt_msat + * pending_amt_msat > * total_msat * ( 100 + RETRY_OVERFLOW_PERCENTAGE ) / 100 {
728
726
log_error ! ( logger, "retry_amt_msat of {} will put pending_amt_msat (currently: {}) more than 10% over total_payment_amt_msat of {}" , retry_amt_msat, pending_amt_msat, total_msat) ;
729
727
abandon_with_entry ! ( payment, PaymentFailureReason :: UnexpectedError ) ;
@@ -829,7 +827,7 @@ impl OutboundPayments {
829
827
log_error ! ( logger, "Failed to send along path due to error: {:?}" , e) ;
830
828
let mut failed_scid = None ;
831
829
if let APIError :: ChannelUnavailable { .. } = e {
832
- let scid = path. hops [ 0 ] . short_channel_id ;
830
+ let scid = path. first_hop_scid ( ) ;
833
831
failed_scid = Some ( scid) ;
834
832
route_params. payment_params . previously_failed_channels . push ( scid) ;
835
833
}
@@ -863,7 +861,7 @@ impl OutboundPayments {
863
861
864
862
let payment_hash = probing_cookie_from_id ( & payment_id, probing_cookie_secret) ;
865
863
866
- if path. hops . len ( ) < 2 {
864
+ if path. len ( ) < 2 {
867
865
return Err ( PaymentSendFailure :: ParameterError ( APIError :: APIMisuseError {
868
866
err : "No need probing a path with less than two hops" . to_string ( )
869
867
} ) )
@@ -951,17 +949,20 @@ impl OutboundPayments {
951
949
let our_node_id = node_signer. get_node_id ( Recipient :: Node ) . unwrap ( ) ; // TODO no unwrap
952
950
let mut path_errs = Vec :: with_capacity ( route. paths . len ( ) ) ;
953
951
' path_check: for path in route. paths . iter ( ) {
954
- if path. hops . len ( ) < 1 || path. hops . len ( ) > 20 {
952
+ if path. len ( ) < 1 || path. len ( ) > 20 {
955
953
path_errs. push ( Err ( APIError :: InvalidRoute { err : "Path didn't go anywhere/had bogus size" . to_owned ( ) } ) ) ;
956
954
continue ' path_check;
957
955
}
958
- for ( idx, hop) in path. hops . iter ( ) . enumerate ( ) {
959
- if idx != path. hops . len ( ) - 1 && hop. pubkey == our_node_id {
960
- path_errs. push ( Err ( APIError :: InvalidRoute { err : "Path went through us but wasn't a simple rebalance loop to us" . to_owned ( ) } ) ) ;
961
- continue ' path_check;
962
- }
956
+ let we_are_intermed_hop = path. blinded_tail . as_ref ( ) . map_or_else (
957
+ || path. hops . split_last ( ) . map_or ( false , |( _, path_prefix) | path_prefix. iter ( ) . any ( |hop| hop. pubkey == our_node_id) ) ,
958
+ |tail|
959
+ ( tail. path . introduction_node_id == our_node_id && tail. path . blinded_hops . len ( ) > 1 )
960
+ || path. hops . iter ( ) . any ( |hop| hop. pubkey == our_node_id) ) ;
961
+ if we_are_intermed_hop {
962
+ path_errs. push ( Err ( APIError :: InvalidRoute { err : "Path went through us but wasn't a simple rebalance loop to us" . to_owned ( ) } ) ) ;
963
+ continue ' path_check;
963
964
}
964
- total_value += path. hops . last ( ) . unwrap ( ) . fee_msat ;
965
+ total_value += path. final_value_msat ( ) ;
965
966
path_errs. push ( Ok ( ( ) ) ) ;
966
967
}
967
968
if path_errs. iter ( ) . any ( |e| e. is_err ( ) ) {
@@ -1009,7 +1010,7 @@ impl OutboundPayments {
1009
1010
has_err = true ;
1010
1011
has_ok = true ;
1011
1012
} else if res. is_err ( ) {
1012
- pending_amt_unsent += path. hops . last ( ) . unwrap ( ) . fee_msat ;
1013
+ pending_amt_unsent += path. final_value_msat ( ) ;
1013
1014
}
1014
1015
}
1015
1016
if has_err && has_ok {
0 commit comments