@@ -46,6 +46,7 @@ import (
4646 "github.com/lightninglabs/loop"
4747 "github.com/lightninglabs/loop/labels"
4848 "github.com/lightninglabs/loop/loopdb"
49+ "github.com/lightninglabs/loop/swap"
4950 "github.com/lightningnetwork/lnd/clock"
5051 "github.com/lightningnetwork/lnd/funding"
5152 "github.com/lightningnetwork/lnd/lnwallet/chainfee"
@@ -96,9 +97,9 @@ const (
9697 // suggestions as a dry-run).
9798 defaultMaxInFlight = 1
9899
99- // DefaultAutoOutTicker is the default amount of time between automated
100- // loop out checks.
101- DefaultAutoOutTicker = time .Minute * 10
100+ // DefaultAutoloopTicker is the default amount of time between automated
101+ // swap checks.
102+ DefaultAutoloopTicker = time .Minute * 10
102103
103104 // autoloopSwapInitiator is the value we send in the initiator field of
104105 // a swap request when issuing an automatic swap.
@@ -182,14 +183,15 @@ var (
182183// Config contains the external functionality required to run the
183184// liquidity manager.
184185type Config struct {
185- // AutoOutTicker determines how often we should check whether we want
186- // to dispatch an automated loop out . We use a force ticker so that
187- // we can trigger autoloop in itests.
188- AutoOutTicker * ticker.Force
186+ // AutoloopTicker determines how often we should check whether we want
187+ // to dispatch an automated swap . We use a force ticker so that we can
188+ // trigger autoloop in itests.
189+ AutoloopTicker * ticker.Force
189190
190- // LoopOutRestrictions returns the restrictions that the server applies
191- // to loop out swaps.
192- LoopOutRestrictions func (ctx context.Context ) (* Restrictions , error )
191+ // Restrictions returns the restrictions that the server applies to
192+ // swaps.
193+ Restrictions func (ctx context.Context , swapType swap.Type ) (
194+ * Restrictions , error )
193195
194196 // Lnd provides us with access to lnd's rpc servers.
195197 Lnd * lndclient.LndServices
@@ -220,8 +222,8 @@ type Config struct {
220222// Parameters is a set of parameters provided by the user which guide
221223// how we assess liquidity.
222224type Parameters struct {
223- // AutoOut enables automatic dispatch of loop out swaps.
224- AutoOut bool
225+ // Autoloop enables automatic dispatch of swaps.
226+ Autoloop bool
225227
226228 // AutoFeeBudget is the total amount we allow to be spent on
227229 // automatically dispatched swaps. Once this budget has been used, we
@@ -431,12 +433,12 @@ type Manager struct {
431433// We run this loop even if automated swaps are not currently enabled rather
432434// than managing starting and stopping the ticker as our parameters are updated.
433435func (m * Manager ) Run (ctx context.Context ) error {
434- m .cfg .AutoOutTicker .Resume ()
435- defer m .cfg .AutoOutTicker .Stop ()
436+ m .cfg .AutoloopTicker .Resume ()
437+ defer m .cfg .AutoloopTicker .Stop ()
436438
437439 for {
438440 select {
439- case <- m .cfg .AutoOutTicker .Ticks ():
441+ case <- m .cfg .AutoloopTicker .Ticks ():
440442 if err := m .autoloop (ctx ); err != nil {
441443 log .Errorf ("autoloop failed: %v" , err )
442444 }
@@ -466,7 +468,7 @@ func (m *Manager) GetParameters() Parameters {
466468// SetParameters updates our current set of parameters if the new parameters
467469// provided are valid.
468470func (m * Manager ) SetParameters (ctx context.Context , params Parameters ) error {
469- restrictions , err := m .cfg .LoopOutRestrictions (ctx )
471+ restrictions , err := m .cfg .Restrictions (ctx , swap . TypeOut )
470472 if err != nil {
471473 return err
472474 }
@@ -510,6 +512,15 @@ func (m *Manager) autoloop(ctx context.Context) error {
510512 }
511513
512514 for _ , swap := range swaps {
515+ // If we don't actually have dispatch of swaps enabled, log
516+ // suggestions.
517+ if ! m .params .Autoloop {
518+ log .Debugf ("recommended autoloop: %v sats over " +
519+ "%v" , swap .Amount , swap .OutgoingChanSet )
520+
521+ continue
522+ }
523+
513524 // Create a copy of our range var so that we can reference it.
514525 swap := swap
515526 loopOut , err := m .cfg .LoopOut (ctx , & swap )
@@ -528,7 +539,7 @@ func (m *Manager) autoloop(ctx context.Context) error {
528539// ForceAutoLoop force-ticks our auto-out ticker.
529540func (m * Manager ) ForceAutoLoop (ctx context.Context ) error {
530541 select {
531- case m .cfg .AutoOutTicker .Force <- m .cfg .Clock .Now ():
542+ case m .cfg .AutoloopTicker .Force <- m .cfg .Clock .Now ():
532543 return nil
533544
534545 case <- ctx .Done ():
@@ -538,11 +549,11 @@ func (m *Manager) ForceAutoLoop(ctx context.Context) error {
538549
539550// SuggestSwaps returns a set of swap suggestions based on our current liquidity
540551// balance for the set of rules configured for the manager, failing if there are
541- // no rules set. It takes an autoOut boolean that indicates whether the
552+ // no rules set. It takes an autoloop boolean that indicates whether the
542553// suggestions are being used for our internal autolooper. This boolean is used
543554// to determine the information we add to our swap suggestion and whether we
544555// return any suggestions.
545- func (m * Manager ) SuggestSwaps (ctx context.Context , autoOut bool ) (
556+ func (m * Manager ) SuggestSwaps (ctx context.Context , autoloop bool ) (
546557 []loop.OutRequest , error ) {
547558
548559 m .paramsLock .Lock ()
@@ -587,7 +598,7 @@ func (m *Manager) SuggestSwaps(ctx context.Context, autoOut bool) (
587598
588599 // Get the current server side restrictions, combined with the client
589600 // set restrictions, if any.
590- outRestrictions , err := m .getLoopOutRestrictions (ctx )
601+ restrictions , err := m .getSwapRestrictions (ctx , swap . TypeOut )
591602 if err != nil {
592603 return nil , err
593604 }
@@ -646,7 +657,7 @@ func (m *Manager) SuggestSwaps(ctx context.Context, autoOut bool) (
646657
647658 balance := newBalances (channel )
648659
649- suggestion := rule .suggestSwap (balance , outRestrictions )
660+ suggestion := rule .suggestSwap (balance , restrictions )
650661
651662 // We can have nil suggestions in the case where no action is
652663 // required, so we skip over them.
@@ -681,7 +692,7 @@ func (m *Manager) SuggestSwaps(ctx context.Context, autoOut bool) (
681692 }
682693
683694 outRequest , err := m .makeLoopOutRequest (
684- ctx , suggestion , quote , autoOut ,
695+ ctx , suggestion , quote , autoloop ,
685696 )
686697 if err != nil {
687698 return nil , err
@@ -728,29 +739,17 @@ func (m *Manager) SuggestSwaps(ctx context.Context, autoOut bool) (
728739 }
729740 }
730741
731- // If we are getting suggestions for automatically dispatched swaps,
732- // and they are not enabled in our parameters, we just log the swap
733- // suggestions and return an empty set of suggestions.
734- if autoOut && ! m .params .AutoOut {
735- for _ , swap := range inBudget {
736- log .Debugf ("recommended autoloop: %v sats over " +
737- "%v" , swap .Amount , swap .OutgoingChanSet )
738- }
739-
740- return nil , nil
741- }
742-
743742 return inBudget , nil
744743}
745744
746- // getLoopOutRestrictions queries the server for its latest swap size
747- // restrictions, validates client restrictions (if present) against these
748- // values and merges the client's custom requirements with the server's limits
749- // to produce a single set of limitations for our swap.
750- func (m * Manager ) getLoopOutRestrictions (ctx context.Context ) (* Restrictions ,
751- error ) {
745+ // getSwapRestrictions queries the server for its latest swap size restrictions,
746+ // validates client restrictions (if present) against these values and merges
747+ // the client's custom requirements with the server's limits to produce a single
748+ // set of limitations for our swap.
749+ func (m * Manager ) getSwapRestrictions (ctx context.Context , swapType swap. Type ) (
750+ * Restrictions , error ) {
752751
753- restrictions , err := m .cfg .LoopOutRestrictions (ctx )
752+ restrictions , err := m .cfg .Restrictions (ctx , swapType )
754753 if err != nil {
755754 return nil , err
756755 }
@@ -791,7 +790,7 @@ func (m *Manager) getLoopOutRestrictions(ctx context.Context) (*Restrictions,
791790// non-auto requests, because the client api will set it anyway).
792791func (m * Manager ) makeLoopOutRequest (ctx context.Context ,
793792 suggestion * LoopOutRecommendation , quote * loop.LoopOutQuote ,
794- autoOut bool ) (loop.OutRequest , error ) {
793+ autoloop bool ) (loop.OutRequest , error ) {
795794
796795 prepayMaxFee := ppmToSat (
797796 quote .PrepayAmount , m .params .MaximumPrepayRoutingFeePPM ,
@@ -815,8 +814,8 @@ func (m *Manager) makeLoopOutRequest(ctx context.Context,
815814 Initiator : autoloopSwapInitiator ,
816815 }
817816
818- if autoOut {
819- request .Label = labels .AutoOutLabel ( )
817+ if autoloop {
818+ request .Label = labels .AutoloopLabel ( swap . TypeOut )
820819
821820 addr , err := m .cfg .Lnd .WalletKit .NextAddr (ctx )
822821 if err != nil {
@@ -882,7 +881,7 @@ func (m *Manager) checkExistingAutoLoops(ctx context.Context,
882881 var summary existingAutoLoopSummary
883882
884883 for _ , out := range loopOuts {
885- if out .Contract .Label != labels .AutoOutLabel ( ) {
884+ if out .Contract .Label != labels .AutoloopLabel ( swap . TypeOut ) {
886885 continue
887886 }
888887
0 commit comments