@@ -623,10 +623,18 @@ func (s *loopInSwap) executeSwap(globalCtx context.Context) error {
623
623
}
624
624
625
625
// Verify that the confirmed (external) htlc value matches the swap
626
- // amount. Otherwise, fail the swap immediately.
627
- if htlcValue != s .LoopInContract .AmountRequested {
626
+ // amount. If the amounts mismatch we update the swap state to indicate
627
+ // this, but end processing the swap. Instead, we continue to wait for
628
+ // the htlc to expire and publish a timeout tx to reclaim the funds. We
629
+ // skip this part if the swap was recovered from this state.
630
+ if s .state != loopdb .StateFailIncorrectHtlcAmt &&
631
+ htlcValue != s .LoopInContract .AmountRequested {
632
+
628
633
s .setState (loopdb .StateFailIncorrectHtlcAmt )
629
- return s .persistAndAnnounceState (globalCtx )
634
+ err = s .persistAndAnnounceState (globalCtx )
635
+ if err != nil {
636
+ log .Errorf ("Error persisting state: %v" , err )
637
+ }
630
638
}
631
639
632
640
// The server is expected to see the htlc on-chain and know that it can
@@ -1032,7 +1040,16 @@ func (s *loopInSwap) processHtlcSpend(ctx context.Context,
1032
1040
// We needed another on chain tx to sweep the timeout clause,
1033
1041
// which we now include in our costs.
1034
1042
s .cost .Onchain += sweepFee
1035
- s .setState (loopdb .StateFailTimeout )
1043
+
1044
+ // If the swap is in state StateFailIncorrectHtlcAmt we know
1045
+ // that the deposited htlc amount wasn't equal to the contract
1046
+ // amount. We can finalize the swap by setting an appropriate
1047
+ // state.
1048
+ if s .state == loopdb .StateFailIncorrectHtlcAmt {
1049
+ s .setState (loopdb .StateFailIncorrectHtlcAmtSwept )
1050
+ } else {
1051
+ s .setState (loopdb .StateFailTimeout )
1052
+ }
1036
1053
1037
1054
// Now that the timeout tx confirmed, we can safely cancel the
1038
1055
// swap invoice. We still need to query the final invoice state.
0 commit comments