@@ -200,6 +200,7 @@ struct PathBuildingHop {
200
200
/// hop_use_fee_msat pays for the following hops, but is deducted on this one.
201
201
/// Should not be updated manually and generally should not be accessed.
202
202
effective_htlc_minimum_msat : u64 ,
203
+ overpaid_fee_msat : u64 ,
203
204
}
204
205
205
206
impl PathBuildingHop {
@@ -518,8 +519,13 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
518
519
// If HTLC minimum is larger than the amount we're going to transfer, we shouldn
519
520
// transfer that value instead, thus overpaying fees.
520
521
let effective_htlc_minimum_msat = cmp:: max( $directional_info. htlc_minimum_msat, $incl_fee_next_hops_htlc_minimum_msat) ;
521
- amount_to_transfer_over_msat = cmp:: max( amount_to_transfer_over_msat, effective_htlc_minimum_msat) ;
522
- if contributes_sufficient_value {
522
+ println!( "{} transfer over {} {}" , $chan_id, amount_to_transfer_over_msat, effective_htlc_minimum_msat) ;
523
+ let overpaid_fee_msat = match effective_htlc_minimum_msat. checked_sub( amount_to_transfer_over_msat) {
524
+ Some ( fee_msat) => fee_msat,
525
+ None => 0 ,
526
+ } ;
527
+ amount_to_transfer_over_msat += overpaid_fee_msat;
528
+ if contributes_sufficient_value {
523
529
let hm_entry = dist. entry( & $src_node_id) ;
524
530
let old_entry = hm_entry. or_insert_with( || {
525
531
// If there was previously no known way to access
@@ -552,6 +558,7 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
552
558
total_fee_msat: u64 :: max_value( ) ,
553
559
htlc_minimum_msat: $directional_info. htlc_minimum_msat,
554
560
effective_htlc_minimum_msat,
561
+ overpaid_fee_msat
555
562
}
556
563
} ) ;
557
564
@@ -613,14 +620,15 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
613
620
node_features: NodeFeatures :: empty( ) ,
614
621
short_channel_id: $chan_id. clone( ) ,
615
622
channel_features: $chan_features. clone( ) ,
616
- fee_msat: 0 , // This value will be later filled with hop_use_fee_msat of the following channel
623
+ fee_msat: 0 ,
617
624
cltv_expiry_delta: $directional_info. cltv_expiry_delta as u32 ,
618
625
} ;
619
626
old_entry. channel_fees = $directional_info. fees;
620
627
// It's probably fine to replace the old entry, because the new one
621
628
// passed the htlc_minimum-related checks above.
622
629
old_entry. htlc_minimum_msat = cmp:: max( $directional_info. htlc_minimum_msat, old_entry. htlc_minimum_msat) ;
623
630
old_entry. effective_htlc_minimum_msat = effective_htlc_minimum_msat;
631
+ old_entry. overpaid_fee_msat = overpaid_fee_msat;
624
632
}
625
633
}
626
634
}
@@ -806,11 +814,11 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
806
814
// We "propagate" the fees one hop backward (topologically) here,
807
815
// so that fees paid for a HTLC forwarding on the current channel are
808
816
// associated with the previous channel (where they will be subtracted).
809
- ordered_hops. last_mut ( ) . unwrap ( ) . route_hop . fee_msat = new_entry. hop_use_fee_msat ;
817
+ ordered_hops. last_mut ( ) . unwrap ( ) . route_hop . fee_msat = new_entry. hop_use_fee_msat + ordered_hops . last_mut ( ) . unwrap ( ) . overpaid_fee_msat ;
810
818
ordered_hops. last_mut ( ) . unwrap ( ) . route_hop . cltv_expiry_delta = new_entry. route_hop . cltv_expiry_delta ;
811
819
ordered_hops. push ( new_entry. clone ( ) ) ;
812
820
}
813
- ordered_hops. last_mut ( ) . unwrap ( ) . route_hop . fee_msat = value_contribution_msat;
821
+ ordered_hops. last_mut ( ) . unwrap ( ) . route_hop . fee_msat = value_contribution_msat + ordered_hops . last_mut ( ) . unwrap ( ) . overpaid_fee_msat ;
814
822
ordered_hops. last_mut ( ) . unwrap ( ) . hop_use_fee_msat = 0 ;
815
823
ordered_hops. last_mut ( ) . unwrap ( ) . route_hop . cltv_expiry_delta = final_cltv;
816
824
0 commit comments