@@ -18,7 +18,7 @@ use crate::events;
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 ;
@@ -174,10 +174,9 @@ impl PendingOutboundPayment {
174
174
if remove_res {
175
175
if let PendingOutboundPayment :: Retryable { ref mut pending_amt_msat, ref mut pending_fee_msat, .. } = self {
176
176
let path = path. expect ( "Fulfilling a payment should always come with a path" ) ;
177
- let path_last_hop = path. hops . last ( ) . expect ( "Outbound payments must have had a valid path" ) ;
178
- * pending_amt_msat -= path_last_hop. fee_msat ;
177
+ * pending_amt_msat -= path. final_value_msat ( ) ;
179
178
if let Some ( fee_msat) = pending_fee_msat. as_mut ( ) {
180
- * fee_msat -= path. hops . get_path_fees ( ) ;
179
+ * fee_msat -= path. fee_msat ( ) ;
181
180
}
182
181
}
183
182
}
@@ -195,10 +194,9 @@ impl PendingOutboundPayment {
195
194
} ;
196
195
if insert_res {
197
196
if let PendingOutboundPayment :: Retryable { ref mut pending_amt_msat, ref mut pending_fee_msat, .. } = self {
198
- let path_last_hop = path. hops . last ( ) . expect ( "Outbound payments must have had a valid path" ) ;
199
- * pending_amt_msat += path_last_hop. fee_msat ;
197
+ * pending_amt_msat += path. final_value_msat ( ) ;
200
198
if let Some ( fee_msat) = pending_fee_msat. as_mut ( ) {
201
- * fee_msat += path. hops . get_path_fees ( ) ;
199
+ * fee_msat += path. fee_msat ( ) ;
202
200
}
203
201
}
204
202
}
@@ -688,7 +686,7 @@ impl OutboundPayments {
688
686
}
689
687
} ;
690
688
for path in route. paths . iter ( ) {
691
- if path. hops . len ( ) == 0 {
689
+ if path. len ( ) == 0 {
692
690
log_error ! ( logger, "length-0 path in route" ) ;
693
691
self . abandon_payment ( payment_id, pending_events) ;
694
692
return
@@ -720,7 +718,7 @@ impl OutboundPayments {
720
718
PendingOutboundPayment :: Retryable {
721
719
total_msat, keysend_preimage, payment_secret, pending_amt_msat, ..
722
720
} => {
723
- let retry_amt_msat: u64 = route. paths . iter ( ) . map ( |path| path . hops . last ( ) . unwrap ( ) . fee_msat ) . sum ( ) ;
721
+ let retry_amt_msat = route. get_total_amount ( ) ;
724
722
if retry_amt_msat + * pending_amt_msat > * total_msat * ( 100 + RETRY_OVERFLOW_PERCENTAGE ) / 100 {
725
723
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) ;
726
724
abandon_with_entry ! ( payment) ;
@@ -824,7 +822,7 @@ impl OutboundPayments {
824
822
if let APIError :: MonitorUpdateInProgress = e { continue }
825
823
let mut failed_scid = None ;
826
824
if let APIError :: ChannelUnavailable { .. } = e {
827
- let scid = path. hops [ 0 ] . short_channel_id ;
825
+ let scid = path. first_hop_scid ( ) ;
828
826
failed_scid = Some ( scid) ;
829
827
route_params. payment_params . previously_failed_channels . push ( scid) ;
830
828
}
@@ -858,7 +856,7 @@ impl OutboundPayments {
858
856
859
857
let payment_hash = probing_cookie_from_id ( & payment_id, probing_cookie_secret) ;
860
858
861
- if path. hops . len ( ) < 2 {
859
+ if path. len ( ) < 2 {
862
860
return Err ( PaymentSendFailure :: ParameterError ( APIError :: APIMisuseError {
863
861
err : "No need probing a path with less than two hops" . to_string ( )
864
862
} ) )
@@ -946,17 +944,20 @@ impl OutboundPayments {
946
944
let our_node_id = node_signer. get_node_id ( Recipient :: Node ) . unwrap ( ) ; // TODO no unwrap
947
945
let mut path_errs = Vec :: with_capacity ( route. paths . len ( ) ) ;
948
946
' path_check: for path in route. paths . iter ( ) {
949
- if path. hops . len ( ) < 1 || path. hops . len ( ) > 20 {
947
+ if path. len ( ) < 1 || path. len ( ) > 20 {
950
948
path_errs. push ( Err ( APIError :: InvalidRoute { err : "Path didn't go anywhere/had bogus size" . to_owned ( ) } ) ) ;
951
949
continue ' path_check;
952
950
}
953
- for ( idx, hop) in path. hops . iter ( ) . enumerate ( ) {
954
- if idx != path. hops . len ( ) - 1 && hop. pubkey == our_node_id {
955
- path_errs. push ( Err ( APIError :: InvalidRoute { err : "Path went through us but wasn't a simple rebalance loop to us" . to_owned ( ) } ) ) ;
956
- continue ' path_check;
957
- }
951
+ let we_are_intermed_hop = path. blinded_tail . as_ref ( ) . map_or_else (
952
+ || path. hops . split_last ( ) . map_or ( false , |( _, path_prefix) | path_prefix. iter ( ) . any ( |hop| hop. pubkey == our_node_id) ) ,
953
+ |tail|
954
+ ( tail. path . introduction_node_id == our_node_id && tail. path . blinded_hops . len ( ) > 1 )
955
+ || path. hops . iter ( ) . any ( |hop| hop. pubkey == our_node_id) ) ;
956
+ if we_are_intermed_hop {
957
+ path_errs. push ( Err ( APIError :: InvalidRoute { err : "Path went through us but wasn't a simple rebalance loop to us" . to_owned ( ) } ) ) ;
958
+ continue ' path_check;
958
959
}
959
- total_value += path. hops . last ( ) . unwrap ( ) . fee_msat ;
960
+ total_value += path. final_value_msat ( ) ;
960
961
path_errs. push ( Ok ( ( ) ) ) ;
961
962
}
962
963
if path_errs. iter ( ) . any ( |e| e. is_err ( ) ) {
@@ -1004,7 +1005,7 @@ impl OutboundPayments {
1004
1005
has_err = true ;
1005
1006
has_ok = true ;
1006
1007
} else if res. is_err ( ) {
1007
- pending_amt_unsent += path. hops . last ( ) . unwrap ( ) . fee_msat ;
1008
+ pending_amt_unsent += path. final_value_msat ( ) ;
1008
1009
}
1009
1010
}
1010
1011
if has_err && has_ok {
0 commit comments