liquidity: rename ticker and default to autoloop

pull/331/head
carla 3 years ago
parent 71ace95ac8
commit 24aa429aa0
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -91,7 +91,7 @@ func newAutoloopTestCtx(t *testing.T, parameters Parameters,
testCtx.lnd.Channels = channels testCtx.lnd.Channels = channels
cfg := &Config{ cfg := &Config{
AutoOutTicker: ticker.NewForce(DefaultAutoOutTicker), AutoloopTicker: ticker.NewForce(DefaultAutoloopTicker),
LoopOutRestrictions: func(context.Context) (*Restrictions, error) { LoopOutRestrictions: func(context.Context) (*Restrictions, error) {
return <-testCtx.loopOutRestrictions, nil return <-testCtx.loopOutRestrictions, nil
}, },
@ -182,7 +182,7 @@ func (c *autoloopTestCtx) autoloop(minAmt, maxAmt btcutil.Amount,
expectedSwaps []loopOutRequestResp) { expectedSwaps []loopOutRequestResp) {
// Tick our autoloop ticker to force assessing whether we want to loop. // Tick our autoloop ticker to force assessing whether we want to loop.
c.manager.cfg.AutoOutTicker.Force <- testTime c.manager.cfg.AutoloopTicker.Force <- testTime
// Send a mocked response from the server with the swap size limits. // Send a mocked response from the server with the swap size limits.
c.loopOutRestrictions <- NewRestrictions(minAmt, maxAmt) c.loopOutRestrictions <- NewRestrictions(minAmt, maxAmt)

@ -96,9 +96,9 @@ const (
// suggestions as a dry-run). // suggestions as a dry-run).
defaultMaxInFlight = 1 defaultMaxInFlight = 1
// DefaultAutoOutTicker is the default amount of time between automated // DefaultAutoloopTicker is the default amount of time between automated
// loop out checks. // swap checks.
DefaultAutoOutTicker = time.Minute * 10 DefaultAutoloopTicker = time.Minute * 10
// autoloopSwapInitiator is the value we send in the initiator field of // autoloopSwapInitiator is the value we send in the initiator field of
// a swap request when issuing an automatic swap. // a swap request when issuing an automatic swap.
@ -182,10 +182,10 @@ var (
// Config contains the external functionality required to run the // Config contains the external functionality required to run the
// liquidity manager. // liquidity manager.
type Config struct { type Config struct {
// AutoOutTicker determines how often we should check whether we want // AutoloopTicker determines how often we should check whether we want
// to dispatch an automated loop out. We use a force ticker so that // to dispatch an automated swap. We use a force ticker so that we can
// we can trigger autoloop in itests. // trigger autoloop in itests.
AutoOutTicker *ticker.Force AutoloopTicker *ticker.Force
// LoopOutRestrictions returns the restrictions that the server applies // LoopOutRestrictions returns the restrictions that the server applies
// to loop out swaps. // to loop out swaps.
@ -431,12 +431,12 @@ type Manager struct {
// We run this loop even if automated swaps are not currently enabled rather // We run this loop even if automated swaps are not currently enabled rather
// than managing starting and stopping the ticker as our parameters are updated. // than managing starting and stopping the ticker as our parameters are updated.
func (m *Manager) Run(ctx context.Context) error { func (m *Manager) Run(ctx context.Context) error {
m.cfg.AutoOutTicker.Resume() m.cfg.AutoloopTicker.Resume()
defer m.cfg.AutoOutTicker.Stop() defer m.cfg.AutoloopTicker.Stop()
for { for {
select { select {
case <-m.cfg.AutoOutTicker.Ticks(): case <-m.cfg.AutoloopTicker.Ticks():
if err := m.autoloop(ctx); err != nil { if err := m.autoloop(ctx); err != nil {
log.Errorf("autoloop failed: %v", err) log.Errorf("autoloop failed: %v", err)
} }
@ -528,7 +528,7 @@ func (m *Manager) autoloop(ctx context.Context) error {
// ForceAutoLoop force-ticks our auto-out ticker. // ForceAutoLoop force-ticks our auto-out ticker.
func (m *Manager) ForceAutoLoop(ctx context.Context) error { func (m *Manager) ForceAutoLoop(ctx context.Context) error {
select { select {
case m.cfg.AutoOutTicker.Force <- m.cfg.Clock.Now(): case m.cfg.AutoloopTicker.Force <- m.cfg.Clock.Now():
return nil return nil
case <-ctx.Done(): case <-ctx.Done():

@ -36,8 +36,8 @@ func getClient(config *Config, lnd *lndclient.LndServices) (*loop.Client,
func getLiquidityManager(client *loop.Client) *liquidity.Manager { func getLiquidityManager(client *loop.Client) *liquidity.Manager {
mngrCfg := &liquidity.Config{ mngrCfg := &liquidity.Config{
AutoOutTicker: ticker.NewForce(liquidity.DefaultAutoOutTicker), AutoloopTicker: ticker.NewForce(liquidity.DefaultAutoloopTicker),
LoopOut: client.LoopOut, LoopOut: client.LoopOut,
LoopOutRestrictions: func(ctx context.Context) ( LoopOutRestrictions: func(ctx context.Context) (
*liquidity.Restrictions, error) { *liquidity.Restrictions, error) {

Loading…
Cancel
Save