From 65bcf2ccac74e77721097b2fb4958fad4a40466e Mon Sep 17 00:00:00 2001 From: j75689 Date: Tue, 2 Jan 2024 17:28:41 +0800 Subject: [PATCH 01/10] fix: format refound logs and skip skip the processed swap --- plugins/tokens/plugin.go | 18 +++++++++++++++--- plugins/tokens/swap/keeper.go | 10 ++++++++++ plugins/tokens/swap/keys.go | 11 ++++++----- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/plugins/tokens/plugin.go b/plugins/tokens/plugin.go index 4b6fa35a1..1987c65bc 100644 --- a/plugins/tokens/plugin.go +++ b/plugins/tokens/plugin.go @@ -1,6 +1,7 @@ package tokens import ( + "bytes" "encoding/binary" "fmt" @@ -71,21 +72,29 @@ func EndBlocker(ctx sdk.Context, timelockKeeper timelock.Keeper, swapKeeper swap } addr, id, err := timelock.ParseKeyRecord(iterator.Key()) if err != nil { - logger.Error("ParseKeyRecord error", "error", err) + logger.Error("failed to parse timelock record", "error", err) continue } err = timelockKeeper.TimeUnlock(ctx, addr, id, true) if err != nil { - logger.Error("TimeUnlock error", "error", err) + logger.Error("failed to unlock the time locks", "error", err) continue } + logger.Info("succeed to unlock the time locks", "addr", addr, "id", id) i++ } 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 } @@ -104,9 +113,12 @@ func EndBlocker(ctx sdk.Context, timelockKeeper timelock.Keeper, swapKeeper swap SwapID: swapID, }) if !result.IsOK() { - logger.Error("Refund error", "swapId", swapID, "result", fmt.Sprintf("%+v", result)) + logger.Error("failed to refund swap", "swapId", swapID, "result", fmt.Sprintf("%+v", result)) continue } + + logger.Info("succeed to refund swap", "swapId", swapID, "swap", fmt.Sprintf("%+v", swapItem)) + swapKeeper.SetLatestProcessedRefundSwapKey(ctx, swapIterator.Key()) i++ } } diff --git a/plugins/tokens/swap/keeper.go b/plugins/tokens/swap/keeper.go index 060f77473..0649906f1 100644 --- a/plugins/tokens/swap/keeper.go +++ b/plugins/tokens/swap/keeper.go @@ -141,6 +141,16 @@ 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) diff --git a/plugins/tokens/swap/keys.go b/plugins/tokens/swap/keys.go index 2e88e1b70..5b9a12b13 100644 --- a/plugins/tokens/swap/keys.go +++ b/plugins/tokens/swap/keys.go @@ -11,11 +11,12 @@ const ( ) var ( - HashKey = []byte{0x01} - SwapCreatorQueueKey = []byte{0x02} - SwapRecipientQueueKey = []byte{0x03} - SwapCloseTimeKey = []byte{0x04} - SwapIndexKey = []byte{0x05} + HashKey = []byte{0x01} + SwapCreatorQueueKey = []byte{0x02} + SwapRecipientQueueKey = []byte{0x03} + SwapCloseTimeKey = []byte{0x04} + SwapIndexKey = []byte{0x05} + LatestProcessedRefundSwapKey = []byte{0x06} ) func BuildHashKey(randomNumberHash []byte) []byte { From b009e8b7e9de1c58a7771b15822a0c6261bd49d5 Mon Sep 17 00:00:00 2001 From: j75689 Date: Tue, 2 Jan 2024 17:31:02 +0800 Subject: [PATCH 02/10] chore: update cosmos-sdk --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 2f57b6354..d0071e2a6 100644 --- a/go.mod +++ b/go.mod @@ -166,7 +166,7 @@ require ( replace ( github.com/Shopify/sarama v1.26.1 => github.com/Shopify/sarama v1.21.0 // TODO: bump to official release - github.com/cosmos/cosmos-sdk => github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20231214014755-d940f55f667c + github.com/cosmos/cosmos-sdk => github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240102090244-4debe28f7148 github.com/grpc-ecosystem/grpc-gateway/v2 => github.com/prysmaticlabs/grpc-gateway/v2 v2.3.1-0.20210702154020-550e1cd83ec1 github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/go-amino => github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2 diff --git a/go.sum b/go.sum index 56f0890ef..bac94fe32 100644 --- a/go.sum +++ b/go.sum @@ -178,8 +178,8 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= -github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20231214014755-d940f55f667c h1:8R2s5MCR8ZYn5ChktnXmuwC1z5l0Ldrfpt8WdMqmOQE= -github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20231214014755-d940f55f667c/go.mod h1:OjdXpDHofs6gcPLM9oGD+mm8DPc6Lsevz0Kia53zt3Q= +github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240102090244-4debe28f7148 h1:3OioIsHoeq0klM1YLaZsmYme1Q+oCAO4zbvxEuno0fg= +github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240102090244-4debe28f7148/go.mod h1:OjdXpDHofs6gcPLM9oGD+mm8DPc6Lsevz0Kia53zt3Q= github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2 h1:iAlp9gqG0f2LGAauf3ZiijWlT6NI+W2r9y70HH9LI3k= github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2/go.mod h1:LiCO7jev+3HwLGAiN9gpD0z+jTz95RqgSavbse55XOY= github.com/bnb-chain/bnc-tendermint v0.32.3-bc.10 h1:E4iSwEbJCLYchHiHE1gnOM3jjmJXLBxARhy/RCl8CpI= From c3c1bd020027e113a50015da33813d25f521a33b Mon Sep 17 00:00:00 2001 From: j75689 Date: Tue, 2 Jan 2024 17:54:42 +0800 Subject: [PATCH 03/10] chore: update cosmos-sdk --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d0071e2a6..c7f9acb3e 100644 --- a/go.mod +++ b/go.mod @@ -166,7 +166,7 @@ require ( replace ( github.com/Shopify/sarama v1.26.1 => github.com/Shopify/sarama v1.21.0 // TODO: bump to official release - github.com/cosmos/cosmos-sdk => github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240102090244-4debe28f7148 + github.com/cosmos/cosmos-sdk => github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240102095228-21ae4531c279 github.com/grpc-ecosystem/grpc-gateway/v2 => github.com/prysmaticlabs/grpc-gateway/v2 v2.3.1-0.20210702154020-550e1cd83ec1 github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/go-amino => github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2 diff --git a/go.sum b/go.sum index bac94fe32..8568a0ce1 100644 --- a/go.sum +++ b/go.sum @@ -178,8 +178,8 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= -github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240102090244-4debe28f7148 h1:3OioIsHoeq0klM1YLaZsmYme1Q+oCAO4zbvxEuno0fg= -github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240102090244-4debe28f7148/go.mod h1:OjdXpDHofs6gcPLM9oGD+mm8DPc6Lsevz0Kia53zt3Q= +github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240102095228-21ae4531c279 h1:DFDFV0dL2mpFP1WdymlM2QWa6DepaMyAl9odA6ioRfY= +github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240102095228-21ae4531c279/go.mod h1:OjdXpDHofs6gcPLM9oGD+mm8DPc6Lsevz0Kia53zt3Q= github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2 h1:iAlp9gqG0f2LGAauf3ZiijWlT6NI+W2r9y70HH9LI3k= github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2/go.mod h1:LiCO7jev+3HwLGAiN9gpD0z+jTz95RqgSavbse55XOY= github.com/bnb-chain/bnc-tendermint v0.32.3-bc.10 h1:E4iSwEbJCLYchHiHE1gnOM3jjmJXLBxARhy/RCl8CpI= From 7338bf8cb5f4690d09416116111c8e3ee8bea277 Mon Sep 17 00:00:00 2001 From: j75689 Date: Wed, 3 Jan 2024 17:47:20 +0800 Subject: [PATCH 04/10] chore: update cosmos-sdk --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c7f9acb3e..c721364b1 100644 --- a/go.mod +++ b/go.mod @@ -166,7 +166,7 @@ require ( replace ( github.com/Shopify/sarama v1.26.1 => github.com/Shopify/sarama v1.21.0 // TODO: bump to official release - github.com/cosmos/cosmos-sdk => github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240102095228-21ae4531c279 + github.com/cosmos/cosmos-sdk => github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103094524-1b21736a0f68 github.com/grpc-ecosystem/grpc-gateway/v2 => github.com/prysmaticlabs/grpc-gateway/v2 v2.3.1-0.20210702154020-550e1cd83ec1 github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/go-amino => github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2 diff --git a/go.sum b/go.sum index 8568a0ce1..e2b06924a 100644 --- a/go.sum +++ b/go.sum @@ -178,8 +178,8 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= -github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240102095228-21ae4531c279 h1:DFDFV0dL2mpFP1WdymlM2QWa6DepaMyAl9odA6ioRfY= -github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240102095228-21ae4531c279/go.mod h1:OjdXpDHofs6gcPLM9oGD+mm8DPc6Lsevz0Kia53zt3Q= +github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103094524-1b21736a0f68 h1:1mC7R+6MpBC+DtQkQvf5YNzs7rIoLH3PQtobnjUwDWM= +github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103094524-1b21736a0f68/go.mod h1:OjdXpDHofs6gcPLM9oGD+mm8DPc6Lsevz0Kia53zt3Q= github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2 h1:iAlp9gqG0f2LGAauf3ZiijWlT6NI+W2r9y70HH9LI3k= github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2/go.mod h1:LiCO7jev+3HwLGAiN9gpD0z+jTz95RqgSavbse55XOY= github.com/bnb-chain/bnc-tendermint v0.32.3-bc.10 h1:E4iSwEbJCLYchHiHE1gnOM3jjmJXLBxARhy/RCl8CpI= From d5fe15b3a559782256a376360a1f1ef4d2fc8b13 Mon Sep 17 00:00:00 2001 From: j75689 Date: Wed, 3 Jan 2024 17:49:40 +0800 Subject: [PATCH 05/10] fix: SetLatestProcessedRefundSwapKey out of loop --- plugins/tokens/plugin.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/tokens/plugin.go b/plugins/tokens/plugin.go index 1987c65bc..d72674e10 100644 --- a/plugins/tokens/plugin.go +++ b/plugins/tokens/plugin.go @@ -118,9 +118,11 @@ func EndBlocker(ctx sdk.Context, timelockKeeper timelock.Keeper, swapKeeper swap } logger.Info("succeed to refund swap", "swapId", swapID, "swap", fmt.Sprintf("%+v", swapItem)) - swapKeeper.SetLatestProcessedRefundSwapKey(ctx, swapIterator.Key()) + lastProcessedRefundSwapKey = swapIterator.Key() i++ } + + swapKeeper.SetLatestProcessedRefundSwapKey(ctx, lastProcessedRefundSwapKey) } // EndBreatheBlock processes the breathe block lifecycle event. From ff7ab79eeb8c7b4c94d28d9e1e8823d468a2fedc Mon Sep 17 00:00:00 2001 From: j75689 Date: Wed, 3 Jan 2024 18:00:01 +0800 Subject: [PATCH 06/10] chore: update cosmos-sdk --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c721364b1..7d92153dd 100644 --- a/go.mod +++ b/go.mod @@ -166,7 +166,7 @@ require ( replace ( github.com/Shopify/sarama v1.26.1 => github.com/Shopify/sarama v1.21.0 // TODO: bump to official release - github.com/cosmos/cosmos-sdk => github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103094524-1b21736a0f68 + github.com/cosmos/cosmos-sdk => github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103095746-c27e6b7299b0 github.com/grpc-ecosystem/grpc-gateway/v2 => github.com/prysmaticlabs/grpc-gateway/v2 v2.3.1-0.20210702154020-550e1cd83ec1 github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/go-amino => github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2 diff --git a/go.sum b/go.sum index e2b06924a..280f4583b 100644 --- a/go.sum +++ b/go.sum @@ -178,8 +178,8 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= -github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103094524-1b21736a0f68 h1:1mC7R+6MpBC+DtQkQvf5YNzs7rIoLH3PQtobnjUwDWM= -github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103094524-1b21736a0f68/go.mod h1:OjdXpDHofs6gcPLM9oGD+mm8DPc6Lsevz0Kia53zt3Q= +github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103095746-c27e6b7299b0 h1:BTXj36nUNsGke1sBM/68hdT8rmw1i8DVbqqe/D6ghW4= +github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103095746-c27e6b7299b0/go.mod h1:OjdXpDHofs6gcPLM9oGD+mm8DPc6Lsevz0Kia53zt3Q= github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2 h1:iAlp9gqG0f2LGAauf3ZiijWlT6NI+W2r9y70HH9LI3k= github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2/go.mod h1:LiCO7jev+3HwLGAiN9gpD0z+jTz95RqgSavbse55XOY= github.com/bnb-chain/bnc-tendermint v0.32.3-bc.10 h1:E4iSwEbJCLYchHiHE1gnOM3jjmJXLBxARhy/RCl8CpI= From 2dd2ba1c11ddaabca442357bd691d4c56277e6a2 Mon Sep 17 00:00:00 2001 From: j75689 Date: Thu, 4 Jan 2024 01:20:39 +0800 Subject: [PATCH 07/10] chore: update cosmos-sdk --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7d92153dd..c8ecfffa0 100644 --- a/go.mod +++ b/go.mod @@ -166,7 +166,7 @@ require ( replace ( github.com/Shopify/sarama v1.26.1 => github.com/Shopify/sarama v1.21.0 // TODO: bump to official release - github.com/cosmos/cosmos-sdk => github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103095746-c27e6b7299b0 + github.com/cosmos/cosmos-sdk => github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103171952-b4ae22daa36f github.com/grpc-ecosystem/grpc-gateway/v2 => github.com/prysmaticlabs/grpc-gateway/v2 v2.3.1-0.20210702154020-550e1cd83ec1 github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/go-amino => github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2 diff --git a/go.sum b/go.sum index 280f4583b..08f0da705 100644 --- a/go.sum +++ b/go.sum @@ -178,8 +178,8 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= -github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103095746-c27e6b7299b0 h1:BTXj36nUNsGke1sBM/68hdT8rmw1i8DVbqqe/D6ghW4= -github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103095746-c27e6b7299b0/go.mod h1:OjdXpDHofs6gcPLM9oGD+mm8DPc6Lsevz0Kia53zt3Q= +github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103171952-b4ae22daa36f h1:zNiQKVLklepeMGDM04AEpPl1giwws4ncjb2wEeGrssU= +github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103171952-b4ae22daa36f/go.mod h1:OjdXpDHofs6gcPLM9oGD+mm8DPc6Lsevz0Kia53zt3Q= github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2 h1:iAlp9gqG0f2LGAauf3ZiijWlT6NI+W2r9y70HH9LI3k= github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2/go.mod h1:LiCO7jev+3HwLGAiN9gpD0z+jTz95RqgSavbse55XOY= github.com/bnb-chain/bnc-tendermint v0.32.3-bc.10 h1:E4iSwEbJCLYchHiHE1gnOM3jjmJXLBxARhy/RCl8CpI= From 3959f786bccbb237e340d4981dfd7b4942dc4bdc Mon Sep 17 00:00:00 2001 From: j75689 Date: Thu, 4 Jan 2024 14:40:51 +0800 Subject: [PATCH 08/10] revert: skip processed swap --- plugins/tokens/plugin.go | 11 ----------- plugins/tokens/swap/keeper.go | 10 ---------- plugins/tokens/swap/keys.go | 11 +++++------ 3 files changed, 5 insertions(+), 27 deletions(-) diff --git a/plugins/tokens/plugin.go b/plugins/tokens/plugin.go index d72674e10..1a41bf3ab 100644 --- a/plugins/tokens/plugin.go +++ b/plugins/tokens/plugin.go @@ -1,7 +1,6 @@ package tokens import ( - "bytes" "encoding/binary" "fmt" @@ -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 } @@ -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. diff --git a/plugins/tokens/swap/keeper.go b/plugins/tokens/swap/keeper.go index 0649906f1..060f77473 100644 --- a/plugins/tokens/swap/keeper.go +++ b/plugins/tokens/swap/keeper.go @@ -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) diff --git a/plugins/tokens/swap/keys.go b/plugins/tokens/swap/keys.go index 5b9a12b13..2e88e1b70 100644 --- a/plugins/tokens/swap/keys.go +++ b/plugins/tokens/swap/keys.go @@ -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 { From 7c60351c5ff20a3cb82844f23fbda84d9e54ea7e Mon Sep 17 00:00:00 2001 From: j75689 Date: Thu, 4 Jan 2024 14:44:06 +0800 Subject: [PATCH 09/10] chore: update cosmos-sdk --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c8ecfffa0..abc3e6f53 100644 --- a/go.mod +++ b/go.mod @@ -166,7 +166,7 @@ require ( replace ( github.com/Shopify/sarama v1.26.1 => github.com/Shopify/sarama v1.21.0 // TODO: bump to official release - github.com/cosmos/cosmos-sdk => github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103171952-b4ae22daa36f + github.com/cosmos/cosmos-sdk => github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240104054643-fdcabf60e075 github.com/grpc-ecosystem/grpc-gateway/v2 => github.com/prysmaticlabs/grpc-gateway/v2 v2.3.1-0.20210702154020-550e1cd83ec1 github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/go-amino => github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2 diff --git a/go.sum b/go.sum index 08f0da705..0d3d2a125 100644 --- a/go.sum +++ b/go.sum @@ -178,8 +178,8 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= -github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103171952-b4ae22daa36f h1:zNiQKVLklepeMGDM04AEpPl1giwws4ncjb2wEeGrssU= -github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240103171952-b4ae22daa36f/go.mod h1:OjdXpDHofs6gcPLM9oGD+mm8DPc6Lsevz0Kia53zt3Q= +github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240104054643-fdcabf60e075 h1:txA014vj+58zjE/N5C/oagM4QgF7gw/N8UNJfTahpAQ= +github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240104054643-fdcabf60e075/go.mod h1:OjdXpDHofs6gcPLM9oGD+mm8DPc6Lsevz0Kia53zt3Q= github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2 h1:iAlp9gqG0f2LGAauf3ZiijWlT6NI+W2r9y70HH9LI3k= github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2/go.mod h1:LiCO7jev+3HwLGAiN9gpD0z+jTz95RqgSavbse55XOY= github.com/bnb-chain/bnc-tendermint v0.32.3-bc.10 h1:E4iSwEbJCLYchHiHE1gnOM3jjmJXLBxARhy/RCl8CpI= From 7c025f97aaaedf72ed5246afc4dfcbd44ab285fe Mon Sep 17 00:00:00 2001 From: j75689 Date: Fri, 5 Jan 2024 10:33:05 +0800 Subject: [PATCH 10/10] chore: update cosmos-sdk --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index abc3e6f53..ad84f8173 100644 --- a/go.mod +++ b/go.mod @@ -166,7 +166,7 @@ require ( replace ( github.com/Shopify/sarama v1.26.1 => github.com/Shopify/sarama v1.21.0 // TODO: bump to official release - github.com/cosmos/cosmos-sdk => github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240104054643-fdcabf60e075 + github.com/cosmos/cosmos-sdk => github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240104113054-9e0aa252ecc4 github.com/grpc-ecosystem/grpc-gateway/v2 => github.com/prysmaticlabs/grpc-gateway/v2 v2.3.1-0.20210702154020-550e1cd83ec1 github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/go-amino => github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2 diff --git a/go.sum b/go.sum index 0d3d2a125..9d9ca4cb6 100644 --- a/go.sum +++ b/go.sum @@ -178,8 +178,8 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c= -github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240104054643-fdcabf60e075 h1:txA014vj+58zjE/N5C/oagM4QgF7gw/N8UNJfTahpAQ= -github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240104054643-fdcabf60e075/go.mod h1:OjdXpDHofs6gcPLM9oGD+mm8DPc6Lsevz0Kia53zt3Q= +github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240104113054-9e0aa252ecc4 h1:g3gYJ/nrm3P1GcRLQBmQErDHA6JNjtk5tsnLUiu+Dnc= +github.com/bnb-chain/bnc-cosmos-sdk v0.26.5-0.20240104113054-9e0aa252ecc4/go.mod h1:OjdXpDHofs6gcPLM9oGD+mm8DPc6Lsevz0Kia53zt3Q= github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2 h1:iAlp9gqG0f2LGAauf3ZiijWlT6NI+W2r9y70HH9LI3k= github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2/go.mod h1:LiCO7jev+3HwLGAiN9gpD0z+jTz95RqgSavbse55XOY= github.com/bnb-chain/bnc-tendermint v0.32.3-bc.10 h1:E4iSwEbJCLYchHiHE1gnOM3jjmJXLBxARhy/RCl8CpI=