loopd: check loop in timeout already before a new block comes in

pull/34/head
Joost Jager 5 years ago
parent b5d2fb3894
commit e765baa1f9
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7

@ -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…
Cancel
Save