Skip to content

Commit

Permalink
revert: skip processed swap
Browse files Browse the repository at this point in the history
  • Loading branch information
j75689 committed Jan 4, 2024
1 parent 2dd2ba1 commit 3959f78
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 27 deletions.
11 changes: 0 additions & 11 deletions plugins/tokens/plugin.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tokens

import (
"bytes"
"encoding/binary"
"fmt"

Expand Down Expand Up @@ -87,14 +86,7 @@ func EndBlocker(ctx sdk.Context, timelockKeeper timelock.Keeper, swapKeeper swap
swapIterator := swapKeeper.GetSwapIterator(ctx)
defer swapIterator.Close()
i = 0
lastProcessedRefundSwapKey := swapKeeper.GetLatestProcessedRefundSwapKey(ctx)
for ; swapIterator.Valid(); swapIterator.Next() {
if len(lastProcessedRefundSwapKey) > 0 &&
bytes.Compare(swapIterator.Key(), lastProcessedRefundSwapKey) <= 0 {
// skip the processed swap
continue
}

if i >= MaxUnlockItems {
break
}
Expand All @@ -118,11 +110,8 @@ func EndBlocker(ctx sdk.Context, timelockKeeper timelock.Keeper, swapKeeper swap
}

logger.Info("succeed to refund swap", "swapId", swapID, "swap", fmt.Sprintf("%+v", swapItem))
lastProcessedRefundSwapKey = swapIterator.Key()
i++
}

swapKeeper.SetLatestProcessedRefundSwapKey(ctx, lastProcessedRefundSwapKey)
}

// EndBreatheBlock processes the breathe block lifecycle event.
Expand Down
10 changes: 0 additions & 10 deletions plugins/tokens/swap/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,6 @@ func (kp *Keeper) GetSwap(ctx sdk.Context, swapID SwapBytes) *AtomicSwap {
return &swap
}

func (kp *Keeper) GetLatestProcessedRefundSwapKey(ctx sdk.Context) []byte {
kvStore := ctx.KVStore(kp.storeKey)
return kvStore.Get(LatestProcessedRefundSwapKey)
}

func (kp *Keeper) SetLatestProcessedRefundSwapKey(ctx sdk.Context, key []byte) {
kvStore := ctx.KVStore(kp.storeKey)
kvStore.Set(LatestProcessedRefundSwapKey, key)
}

func (kp *Keeper) GetSwapIterator(ctx sdk.Context) (iterator store.Iterator) {
kvStore := ctx.KVStore(kp.storeKey)
return sdk.KVStorePrefixIterator(kvStore, HashKey)
Expand Down
11 changes: 5 additions & 6 deletions plugins/tokens/swap/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ const (
)

var (
HashKey = []byte{0x01}
SwapCreatorQueueKey = []byte{0x02}
SwapRecipientQueueKey = []byte{0x03}
SwapCloseTimeKey = []byte{0x04}
SwapIndexKey = []byte{0x05}
LatestProcessedRefundSwapKey = []byte{0x06}
HashKey = []byte{0x01}
SwapCreatorQueueKey = []byte{0x02}
SwapRecipientQueueKey = []byte{0x03}
SwapCloseTimeKey = []byte{0x04}
SwapIndexKey = []byte{0x05}
)

func BuildHashKey(randomNumberHash []byte) []byte {
Expand Down

0 comments on commit 3959f78

Please sign in to comment.