File tree Expand file tree Collapse file tree 1 file changed +19
-5
lines changed
Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -441,6 +441,22 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
441441 return fmt .Errorf ("subscribe to swap invoice: %v" , err )
442442 }
443443
444+ // checkTimeout publishes the timeout tx if the contract has expired.
445+ checkTimeout := func () error {
446+ if s .height >= s .LoopInContract .CltvExpiry {
447+ return s .publishTimeoutTx (ctx , htlc )
448+ }
449+
450+ return nil
451+ }
452+
453+ // Check timeout at current height. After a restart we may want to
454+ // publish the tx immediately.
455+ err = checkTimeout ()
456+ if err != nil {
457+ return err
458+ }
459+
444460 htlcSpend := false
445461 invoiceFinalized := false
446462 for ! htlcSpend || ! invoiceFinalized {
@@ -454,11 +470,9 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
454470 case notification := <- s .blockEpochChan :
455471 s .height = notification .(int32 )
456472
457- if s .height >= s .LoopInContract .CltvExpiry {
458- err := s .publishTimeoutTx (ctx , htlc )
459- if err != nil {
460- return err
461- }
473+ err := checkTimeout ()
474+ if err != nil {
475+ return err
462476 }
463477
464478 // The htlc spend is confirmed. Inspect the spending tx to
You can’t perform that action at this time.
0 commit comments