mirror of
https://github.com/lightninglabs/loop
synced 2024-11-04 06:00:21 +00:00
loopin: finalize swap if unsifficient confirmed funds
This commit is contained in:
parent
0bd4b7cf89
commit
caa646367f
@ -43,6 +43,10 @@ var (
|
||||
// is too soon for us.
|
||||
ErrExpiryTooFar = errors.New("swap expiry too far")
|
||||
|
||||
// ErrInsufficientBalance indicates insufficient confirmed balance to
|
||||
// publish a swap.
|
||||
ErrInsufficientBalance = errors.New("insufficient confirmed balance")
|
||||
|
||||
// serverRPCTimeout is the maximum time a gRPC request to the server
|
||||
// should be allowed to take.
|
||||
serverRPCTimeout = 30 * time.Second
|
||||
|
16
loopin.go
16
loopin.go
@ -530,6 +530,13 @@ func (s *loopInSwap) execute(mainCtx context.Context,
|
||||
// error occurs.
|
||||
err = s.executeSwap(mainCtx)
|
||||
|
||||
// If there are insufficient confirmed funds to publish the swap, we
|
||||
// finalize its state so a new swap will be published if funds become
|
||||
// available.
|
||||
if errors.Is(err, ErrInsufficientBalance) {
|
||||
return err
|
||||
}
|
||||
|
||||
// Stop the execution if the swap has been abandoned.
|
||||
if err != nil && s.state == loopdb.StateFailAbandoned {
|
||||
return err
|
||||
@ -781,7 +788,14 @@ func (s *loopInSwap) publishOnChainHtlc(ctx context.Context) (bool, error) {
|
||||
}}, feeRate, labels.LoopInHtlcLabel(swap.ShortHash(&s.hash)),
|
||||
)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("send outputs: %v", err)
|
||||
s.log.Errorf("send outputs: %v", err)
|
||||
s.setState(loopdb.StateFailInsufficientConfirmedBalance)
|
||||
|
||||
// If we cannot send out this update, there is nothing we can
|
||||
// do.
|
||||
_ = s.persistAndAnnounceState(ctx)
|
||||
|
||||
return false, ErrInsufficientBalance
|
||||
}
|
||||
|
||||
txHash := tx.TxHash()
|
||||
|
Loading…
Reference in New Issue
Block a user