fix: ensure auto-swap blocks until swap is completed, fix interval between auto swaps (#1608)

This commit is contained in:
Roland 2025-08-15 13:30:43 +07:00 committed by GitHub
parent 8340496ded
commit 2c69cd9f5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -191,10 +191,9 @@ func (svc *swapsService) EnableAutoSwapOut() error {
logger.Logger.Info("Starting auto swap workflow")
go func() {
ticker := time.NewTicker(1 * time.Hour)
for {
select {
case <-ticker.C:
case <-time.After(1 * time.Hour):
logger.Logger.Debug("Checking to see if we can swap")
balance, err := svc.lnClient.GetBalances(ctx, false)
if err != nil {
@ -347,7 +346,13 @@ func (svc *swapsService) SwapOut(amount uint64, destination string, autoSwap boo
logger.Logger.WithField("swapId", swap.Id).Info("Swap created")
go svc.startSwapOutListener(&dbSwap)
if autoSwap {
// block until the swap finishes to ensure we can't do multiple concurrent auto swaps
svc.startSwapOutListener(&dbSwap)
} else {
// run in parallel as we need to return the swap ID in the HTTP response
go svc.startSwapOutListener(&dbSwap)
}
return &SwapResponse{
SwapId: swap.Id,