mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
loopd: check loop in timeout already before a new block comes in
This commit is contained in:
parent
b5d2fb3894
commit
e765baa1f9
1 changed files with 19 additions and 5 deletions
24
loopin.go
24
loopin.go
|
|
@ -441,6 +441,22 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
|
|||
return fmt.Errorf("subscribe to swap invoice: %v", err)
|
||||
}
|
||||
|
||||
// checkTimeout publishes the timeout tx if the contract has expired.
|
||||
checkTimeout := func() error {
|
||||
if s.height >= s.LoopInContract.CltvExpiry {
|
||||
return s.publishTimeoutTx(ctx, htlc)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check timeout at current height. After a restart we may want to
|
||||
// publish the tx immediately.
|
||||
err = checkTimeout()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
htlcSpend := false
|
||||
invoiceFinalized := false
|
||||
for !htlcSpend || !invoiceFinalized {
|
||||
|
|
@ -454,11 +470,9 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
|
|||
case notification := <-s.blockEpochChan:
|
||||
s.height = notification.(int32)
|
||||
|
||||
if s.height >= s.LoopInContract.CltvExpiry {
|
||||
err := s.publishTimeoutTx(ctx, htlc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err := checkTimeout()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// The htlc spend is confirmed. Inspect the spending tx to
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue