Skip to content

Commit caa6463

Browse files
committed
loopin: finalize swap if unsifficient confirmed funds
1 parent 0bd4b7c commit caa6463

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ var (
4343
// is too soon for us.
4444
ErrExpiryTooFar = errors.New("swap expiry too far")
4545

46+
// ErrInsufficientBalance indicates insufficient confirmed balance to
47+
// publish a swap.
48+
ErrInsufficientBalance = errors.New("insufficient confirmed balance")
49+
4650
// serverRPCTimeout is the maximum time a gRPC request to the server
4751
// should be allowed to take.
4852
serverRPCTimeout = 30 * time.Second

loopin.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,13 @@ func (s *loopInSwap) execute(mainCtx context.Context,
530530
// error occurs.
531531
err = s.executeSwap(mainCtx)
532532

533+
// If there are insufficient confirmed funds to publish the swap, we
534+
// finalize its state so a new swap will be published if funds become
535+
// available.
536+
if errors.Is(err, ErrInsufficientBalance) {
537+
return err
538+
}
539+
533540
// Stop the execution if the swap has been abandoned.
534541
if err != nil && s.state == loopdb.StateFailAbandoned {
535542
return err
@@ -781,7 +788,14 @@ func (s *loopInSwap) publishOnChainHtlc(ctx context.Context) (bool, error) {
781788
}}, feeRate, labels.LoopInHtlcLabel(swap.ShortHash(&s.hash)),
782789
)
783790
if err != nil {
784-
return false, fmt.Errorf("send outputs: %v", err)
791+
s.log.Errorf("send outputs: %v", err)
792+
s.setState(loopdb.StateFailInsufficientConfirmedBalance)
793+
794+
// If we cannot send out this update, there is nothing we can
795+
// do.
796+
_ = s.persistAndAnnounceState(ctx)
797+
798+
return false, ErrInsufficientBalance
785799
}
786800

787801
txHash := tx.TxHash()

0 commit comments

Comments
 (0)