Skip to content

Commit eb6b476

Browse files
committed
looprpc: add autoloop parameters to rpc server
1 parent 8166d93 commit eb6b476

File tree

5 files changed

+267
-145
lines changed

5 files changed

+267
-145
lines changed

liquidity/liquidity.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ type Manager struct {
362362
}
363363

364364
// Run periodically checks whether we should automatically dispatch a loop out.
365+
// We run this loop even if automated swaps are not currently enabled rather
366+
// than managing starting and stopping the ticker as our parameters are updated.
365367
func (m *Manager) Run(ctx context.Context) error {
366368
m.cfg.AutoOutTicker.Resume()
367369
defer m.cfg.AutoOutTicker.Stop()

loopd/swapclient_server.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,22 @@ func (s *swapClientServer) GetLiquidityParams(_ context.Context,
578578
SweepFeeRateSatPerVbyte: uint64(satPerByte),
579579
SweepConfTarget: cfg.SweepConfTarget,
580580
FailureBackoffSec: uint64(cfg.FailureBackOff.Seconds()),
581+
AutoLoopOut: cfg.AutoOut,
582+
AutoOutBudgetSat: uint64(cfg.AutoFeeBudget),
583+
AutoMaxInFlight: uint64(cfg.MaxAutoInFlight),
581584
Rules: make(
582585
[]*looprpc.LiquidityRule, 0, len(cfg.ChannelRules),
583586
),
584587
}
585588

589+
// Zero golang time is different to a zero unix time, so we only set
590+
// our start date if it is non-zero.
591+
if !cfg.AutoFeeStartDate.IsZero() {
592+
rpcCfg.AutoOutBudgetStartSec = uint64(
593+
cfg.AutoFeeStartDate.Unix(),
594+
)
595+
}
596+
586597
for channel, rule := range cfg.ChannelRules {
587598
rpcRule := &looprpc.LiquidityRule{
588599
ChannelId: channel.ToUint64(),
@@ -617,12 +628,22 @@ func (s *swapClientServer) SetLiquidityParams(_ context.Context,
617628
SweepConfTarget: in.Parameters.SweepConfTarget,
618629
FailureBackOff: time.Duration(in.Parameters.FailureBackoffSec) *
619630
time.Second,
631+
AutoOut: in.Parameters.AutoLoopOut,
632+
AutoFeeBudget: btcutil.Amount(in.Parameters.AutoOutBudgetSat),
633+
MaxAutoInFlight: int(in.Parameters.AutoMaxInFlight),
620634
ChannelRules: make(
621635
map[lnwire.ShortChannelID]*liquidity.ThresholdRule,
622636
len(in.Parameters.Rules),
623637
),
624638
}
625639

640+
// Zero unix time is different to zero golang time.
641+
if in.Parameters.AutoOutBudgetStartSec != 0 {
642+
params.AutoFeeStartDate = time.Unix(
643+
int64(in.Parameters.AutoOutBudgetStartSec), 0,
644+
)
645+
}
646+
626647
for _, rule := range in.Parameters.Rules {
627648
var (
628649
shortID = lnwire.NewShortChanIDFromInt(rule.ChannelId)

0 commit comments

Comments
 (0)