fix: ensure stage is changed if funds are locked, even in error case (#319)

This commit is contained in:
noot
2023-02-26 14:16:12 +01:00
committed by GitHub
parent 93b8a9dacf
commit b6a7047204
4 changed files with 12 additions and 2 deletions

View File

@@ -193,7 +193,9 @@ func (s *swapState) handleEvent(event Event) {
err := s.handleEventETHLocked(e)
if err != nil {
e.errCh <- fmt.Errorf("failed to handle EventETHLocked: %w", err)
return
if !s.fundsLocked {
return
}
}
err = s.setNextExpectedEvent(EventContractReadyType)

View File

@@ -71,6 +71,8 @@ type swapState struct {
// tracks the state of the swap
nextExpectedEvent EventType
// set to true once funds are locked
fundsLocked bool
// channels
@@ -529,6 +531,7 @@ func (s *swapState) lockFunds(amount *coins.PiconeroAmount) (*message.NotifyXMRL
}
log.Infof("Successfully locked XMR funds: txID=%s address=%s block=%d",
transfer.TxID, swapDestAddr, transfer.Height)
s.fundsLocked = true
txID, err := types.HexToHash(transfer.TxID)
if err != nil {

View File

@@ -229,7 +229,9 @@ func (s *swapState) handleEvent(event Event) {
err := s.handleEventKeysReceived(e)
if err != nil {
e.errCh <- fmt.Errorf("failed to handle %s: %w", e.Type(), err)
return
if !s.fundsLocked {
return
}
}
err = s.setNextExpectedEvent(EventXMRLockedType)

View File

@@ -77,6 +77,8 @@ type swapState struct {
// tracks the state of the swap
nextExpectedEvent EventType
// set to true once funds are locked
fundsLocked bool
// channels
@@ -613,6 +615,7 @@ func (s *swapState) lockAsset() (ethcommon.Hash, error) {
return ethcommon.Hash{}, fmt.Errorf("timeouts not found in transaction receipt's logs: %w", err)
}
s.fundsLocked = true
s.setTimeouts(t0, t1)
s.contractSwap = &contracts.SwapFactorySwap{