@@ -141,7 +141,10 @@ struct RouteGraphNode {
141
141
// - how much is needed for a path being constructed
142
142
// - how much value can channels following this node (up to the destination) can contribute,
143
143
// considering their capacity and fees
144
- value_contribution_msat : u64
144
+ value_contribution_msat : u64 ,
145
+ /// The maximum htlc_minimum_msat along the path, taking into consideration the fees required
146
+ /// to meet the minimum over the hops required to get there.
147
+ path_htlc_minimum_msat : u64 ,
145
148
}
146
149
147
150
impl cmp:: Ord for RouteGraphNode {
@@ -432,7 +435,7 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
432
435
// $next_hops_fee_msat represents the fees paid for using all the channel *after* this one,
433
436
// since that value has to be transferred over this channel.
434
437
( $chan_id: expr, $src_node_id: expr, $dest_node_id: expr, $directional_info: expr, $capacity_sats: expr, $chan_features: expr, $next_hops_fee_msat: expr,
435
- $next_hops_value_contribution: expr ) => {
438
+ $next_hops_value_contribution: expr, $incl_fee_next_hops_htlc_minimum_msat : expr ) => {
436
439
// Channels to self should not be used. This is more of belt-and-suspenders, because in
437
440
// practice these cases should be caught earlier:
438
441
// - for regular channels at channel announcement (TODO)
@@ -494,14 +497,16 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
494
497
// Can't overflow due to how the values were computed right above.
495
498
None => unreachable!( ) ,
496
499
} ;
500
+ let over_path_minimum_msat = amount_to_transfer_over_msat >= $directional_info. htlc_minimum_msat &&
501
+ amount_to_transfer_over_msat >= $incl_fee_next_hops_htlc_minimum_msat;
497
502
498
503
// If HTLC minimum is larger than the amount we're going to transfer, we shouldn't
499
504
// bother considering this channel.
500
505
// Since we're choosing amount_to_transfer_over_msat as maximum possible, it can
501
506
// be only reduced later (not increased), so this channel should just be skipped
502
507
// as not sufficient.
503
508
// TODO: Explore simply adding fee to hit htlc_minimum_msat
504
- if contributes_sufficient_value && amount_to_transfer_over_msat >= $directional_info . htlc_minimum_msat {
509
+ if contributes_sufficient_value && over_path_minimum_msat {
505
510
let hm_entry = dist. entry( & $src_node_id) ;
506
511
let old_entry = hm_entry. or_insert_with( || {
507
512
// If there was previously no known way to access
@@ -573,6 +578,10 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
573
578
lowest_fee_to_peer_through_node: total_fee_msat,
574
579
lowest_fee_to_node: $next_hops_fee_msat as u64 + hop_use_fee_msat,
575
580
value_contribution_msat: value_contribution_msat,
581
+ path_htlc_minimum_msat: match compute_fees( $incl_fee_next_hops_htlc_minimum_msat, $directional_info. fees) {
582
+ Some ( fee_msat) => cmp:: max( fee_msat, $directional_info. htlc_minimum_msat) ,
583
+ None => u64 :: max_value( ) ,
584
+ } ,
576
585
} ;
577
586
578
587
// Update the way of reaching $src_node_id with the given $chan_id (from $dest_node_id),
@@ -632,10 +641,10 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
632
641
// meaning how much will be paid in fees after this node (to the best of our knowledge).
633
642
// This data can later be helpful to optimize routing (pay lower fees).
634
643
macro_rules! add_entries_to_cheapest_to_target_node {
635
- ( $node: expr, $node_id: expr, $fee_to_target_msat: expr, $next_hops_value_contribution: expr ) => {
644
+ ( $node: expr, $node_id: expr, $fee_to_target_msat: expr, $next_hops_value_contribution: expr, $incl_fee_next_hops_htlc_minimum_msat : expr ) => {
636
645
if first_hops. is_some( ) {
637
646
if let Some ( & ( ref first_hop, ref features, ref outbound_capacity_msat) ) = first_hop_targets. get( & $node_id) {
638
- add_entry!( first_hop, * our_node_id, $node_id, dummy_directional_info, Some ( outbound_capacity_msat / 1000 ) , features. to_context( ) , $fee_to_target_msat, $next_hops_value_contribution) ;
647
+ add_entry!( first_hop, * our_node_id, $node_id, dummy_directional_info, Some ( outbound_capacity_msat / 1000 ) , features. to_context( ) , $fee_to_target_msat, $next_hops_value_contribution, $incl_fee_next_hops_htlc_minimum_msat ) ;
639
648
}
640
649
}
641
650
@@ -655,15 +664,15 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
655
664
if first_hops. is_none( ) || chan. node_two != * our_node_id {
656
665
if let Some ( two_to_one) = chan. two_to_one. as_ref( ) {
657
666
if two_to_one. enabled {
658
- add_entry!( chan_id, chan. node_two, chan. node_one, two_to_one, chan. capacity_sats, chan. features, $fee_to_target_msat, $next_hops_value_contribution) ;
667
+ add_entry!( chan_id, chan. node_two, chan. node_one, two_to_one, chan. capacity_sats, chan. features, $fee_to_target_msat, $next_hops_value_contribution, $incl_fee_next_hops_htlc_minimum_msat ) ;
659
668
}
660
669
}
661
670
}
662
671
} else {
663
672
if first_hops. is_none( ) || chan. node_one != * our_node_id {
664
673
if let Some ( one_to_two) = chan. one_to_two. as_ref( ) {
665
674
if one_to_two. enabled {
666
- add_entry!( chan_id, chan. node_one, chan. node_two, one_to_two, chan. capacity_sats, chan. features, $fee_to_target_msat, $next_hops_value_contribution) ;
675
+ add_entry!( chan_id, chan. node_one, chan. node_two, one_to_two, chan. capacity_sats, chan. features, $fee_to_target_msat, $next_hops_value_contribution, $incl_fee_next_hops_htlc_minimum_msat ) ;
667
676
}
668
677
}
669
678
@@ -689,7 +698,7 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
689
698
// place where it could be added.
690
699
if first_hops. is_some ( ) {
691
700
if let Some ( & ( ref first_hop, ref features, ref outbound_capacity_msat) ) = first_hop_targets. get ( & payee) {
692
- add_entry ! ( first_hop, * our_node_id, payee, dummy_directional_info, Some ( outbound_capacity_msat / 1000 ) , features. to_context( ) , 0 , recommended_value_msat) ;
701
+ add_entry ! ( first_hop, * our_node_id, payee, dummy_directional_info, Some ( outbound_capacity_msat / 1000 ) , features. to_context( ) , 0 , recommended_value_msat, 0 ) ;
693
702
}
694
703
}
695
704
@@ -702,7 +711,7 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
702
711
// If not, targets.pop() will not even let us enter the loop in step 2.
703
712
None => { } ,
704
713
Some ( node) => {
705
- add_entries_to_cheapest_to_target_node ! ( node, payee, 0 , recommended_value_msat) ;
714
+ add_entries_to_cheapest_to_target_node ! ( node, payee, 0 , recommended_value_msat, 0 ) ;
706
715
} ,
707
716
}
708
717
@@ -721,7 +730,7 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
721
730
// bit lazy here. In the future, we should pull them out via our
722
731
// ChannelManager, but there's no reason to waste the space until we
723
732
// need them.
724
- add_entry ! ( first_hop, * our_node_id , hop. src_node_id, dummy_directional_info, Some ( outbound_capacity_msat / 1000 ) , features. to_context( ) , 0 , recommended_value_msat) ;
733
+ add_entry ! ( first_hop, * our_node_id , hop. src_node_id, dummy_directional_info, Some ( outbound_capacity_msat / 1000 ) , features. to_context( ) , 0 , recommended_value_msat, 0 ) ;
725
734
true
726
735
} else {
727
736
// In any other case, only add the hop if the source is in the regular network
@@ -731,17 +740,17 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
731
740
if have_hop_src_in_graph {
732
741
// BOLT 11 doesn't allow inclusion of features for the last hop hints, which
733
742
// really sucks, cause we're gonna need that eventually.
734
- let last_hop_htlc_minimum_msat : u64 = match hop. htlc_minimum_msat {
743
+ let last_path_htlc_minimum_msat : u64 = match hop. htlc_minimum_msat {
735
744
Some ( htlc_minimum_msat) => htlc_minimum_msat,
736
745
None => 0
737
746
} ;
738
747
let directional_info = DummyDirectionalChannelInfo {
739
748
cltv_expiry_delta : hop. cltv_expiry_delta as u32 ,
740
- htlc_minimum_msat : last_hop_htlc_minimum_msat ,
749
+ htlc_minimum_msat : last_path_htlc_minimum_msat ,
741
750
htlc_maximum_msat : hop. htlc_maximum_msat ,
742
751
fees : hop. fees ,
743
752
} ;
744
- add_entry ! ( hop. short_channel_id, hop. src_node_id, payee, directional_info, None :: <u64 >, ChannelFeatures :: empty( ) , 0 , recommended_value_msat) ;
753
+ add_entry ! ( hop. short_channel_id, hop. src_node_id, payee, directional_info, None :: <u64 >, ChannelFeatures :: empty( ) , 0 , recommended_value_msat, 0 ) ;
745
754
}
746
755
}
747
756
@@ -758,7 +767,7 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
758
767
// Both these cases (and other cases except reaching recommended_value_msat) mean that
759
768
// paths_collection will be stopped because found_new_path==false.
760
769
// This is not necessarily a routing failure.
761
- ' path_construction: while let Some ( RouteGraphNode { pubkey, lowest_fee_to_node, value_contribution_msat, .. } ) = targets. pop ( ) {
770
+ ' path_construction: while let Some ( RouteGraphNode { pubkey, lowest_fee_to_node, value_contribution_msat, path_htlc_minimum_msat , .. } ) = targets. pop ( ) {
762
771
763
772
// Since we're going payee-to-payer, hitting our node as a target means we should stop
764
773
// traversing the graph and arrange the path out of what we found.
@@ -855,7 +864,7 @@ pub fn get_route<L: Deref>(our_node_id: &PublicKey, network: &NetworkGraph, paye
855
864
match network. get_nodes ( ) . get ( & pubkey) {
856
865
None => { } ,
857
866
Some ( node) => {
858
- add_entries_to_cheapest_to_target_node ! ( node, & pubkey, lowest_fee_to_node, value_contribution_msat) ;
867
+ add_entries_to_cheapest_to_target_node ! ( node, & pubkey, lowest_fee_to_node, value_contribution_msat, path_htlc_minimum_msat ) ;
859
868
} ,
860
869
}
861
870
}
0 commit comments