@@ -574,6 +574,17 @@ func newSuggestions() *Suggestions {
574574 }
575575}
576576
577+ func (s * Suggestions ) addSwap (swap swapSuggestion ) error {
578+ out , ok := swap .(* loopOutSwapSuggestion )
579+ if ! ok {
580+ return fmt .Errorf ("unexpected swap type: %T" , swap )
581+ }
582+
583+ s .OutSwaps = append (s .OutSwaps , out .OutRequest )
584+
585+ return nil
586+ }
587+
577588// singleReasonSuggestion is a helper function which returns a set of
578589// suggestions where all of our rules are disqualified due to a reason that
579590// applies to all of them (such as being out of budget).
@@ -693,7 +704,7 @@ func (m *Manager) SuggestSwaps(ctx context.Context, autoloop bool) (
693704 traffic := m .currentSwapTraffic (loopOut , loopIn )
694705
695706 var (
696- suggestions []loop. OutRequest
707+ suggestions []swapSuggestion
697708 disqualified = make (map [lnwire.ShortChannelID ]Reason )
698709 )
699710
@@ -719,7 +730,7 @@ func (m *Manager) SuggestSwaps(ctx context.Context, autoloop bool) (
719730 return nil , err
720731 }
721732
722- suggestions = append (suggestions , * suggestion )
733+ suggestions = append (suggestions , suggestion )
723734 }
724735
725736 // Finally, run through all possible swaps, excluding swaps that are
@@ -736,7 +747,7 @@ func (m *Manager) SuggestSwaps(ctx context.Context, autoloop bool) (
736747
737748 // Sort suggestions by amount in descending order.
738749 sort .SliceStable (suggestions , func (i , j int ) bool {
739- return suggestions [i ].Amount > suggestions [j ].Amount
750+ return suggestions [i ].amount () > suggestions [j ].amount ()
740751 })
741752
742753 // Run through our suggested swaps in descending order of amount and
@@ -745,11 +756,14 @@ func (m *Manager) SuggestSwaps(ctx context.Context, autoloop bool) (
745756
746757 // setReason is a helper that adds a swap's channels to our disqualified
747758 // list with the reason provided.
748- setReason := func (reason Reason , swap loop.OutRequest ) {
749- for _ , id := range swap .OutgoingChanSet {
750- chanID := lnwire .NewShortChanIDFromInt (id )
759+ setReason := func (reason Reason , swap swapSuggestion ) {
760+ for _ , channel := range swap .channels () {
761+ _ , ok := m .params .ChannelRules [channel ]
762+ if ! ok {
763+ continue
764+ }
751765
752- resp .DisqualifiedChans [chanID ] = reason
766+ resp .DisqualifiedChans [channel ] = reason
753767 }
754768 }
755769
@@ -773,17 +787,17 @@ func (m *Manager) SuggestSwaps(ctx context.Context, autoloop bool) (
773787 continue
774788 }
775789
776- fees := worstCaseOutFees (
777- swap .MaxPrepayRoutingFee , swap .MaxSwapRoutingFee ,
778- swap .MaxSwapFee , swap .MaxMinerFee , swap .MaxPrepayAmount ,
779- )
790+ fees := swap .fees ()
780791
781792 // If the maximum fee we expect our swap to use is less than the
782793 // amount we have available, we add it to our set of swaps that
783794 // fall within the budget and decrement our available amount.
784795 if fees <= available {
785796 available -= fees
786- resp .OutSwaps = append (resp .OutSwaps , swap )
797+
798+ if err := resp .addSwap (swap ); err != nil {
799+ return nil , err
800+ }
787801 } else {
788802 setReason (ReasonBudgetInsufficient , swap )
789803 }
@@ -796,7 +810,7 @@ func (m *Manager) SuggestSwaps(ctx context.Context, autoloop bool) (
796810// swap request for the rule provided.
797811func (m * Manager ) suggestSwap (ctx context.Context , traffic * swapTraffic ,
798812 balance * balances , rule * ThresholdRule , restrictions * Restrictions ,
799- autoloop bool ) (* loop. OutRequest , error ) {
813+ autoloop bool ) (swapSuggestion , error ) {
800814
801815 // Check whether we can perform a swap.
802816 err := traffic .maySwap (balance .pubkey , balance .channelID )
@@ -811,7 +825,14 @@ func (m *Manager) suggestSwap(ctx context.Context, traffic *swapTraffic,
811825 return nil , newReasonError (ReasonLiquidityOk )
812826 }
813827
814- return m .loopOutSwap (ctx , amount , balance , autoloop )
828+ swap , err := m .loopOutSwap (ctx , amount , balance , autoloop )
829+ if err != nil {
830+ return nil , err
831+ }
832+
833+ return & loopOutSwapSuggestion {
834+ OutRequest : * swap ,
835+ }, nil
815836}
816837
817838// loopOutSwap creates a loop out swap with the amount provided for the balance
0 commit comments