From 423b9f74dc56365b5d9bd22afb7bc60c7cf606f0 Mon Sep 17 00:00:00 2001 From: Leon <156270887+leonz789@users.noreply.github.com> Date: Tue, 3 Sep 2024 11:22:39 +0800 Subject: [PATCH] fix(oracle):remove expired msgindex, keep at least params cache (#161) --- x/oracle/keeper/cache/caches.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/x/oracle/keeper/cache/caches.go b/x/oracle/keeper/cache/caches.go index 7f9a4c150..47db24b53 100644 --- a/x/oracle/keeper/cache/caches.go +++ b/x/oracle/keeper/cache/caches.go @@ -65,13 +65,16 @@ func (c cacheMsgs) commit(ctx sdk.Context, k common.KeeperOracle) { recentMsgs.Msgs = append(recentMsgs.Msgs, &msgTmp) } index, _ := k.GetIndexRecentMsg(ctx) - for i, b := range index.Index { - if b >= block-uint64(common.MaxNonce) { - index.Index = index.Index[i:] + + i := 0 + for ; i < len(index.Index); i++ { + b := index.Index[i] + if b > block-uint64(common.MaxNonce) { break } k.RemoveRecentMsg(ctx, b) } + index.Index = index.Index[i:] k.SetRecentMsg(ctx, recentMsgs) @@ -116,11 +119,13 @@ func (c *cacheParams) commit(ctx sdk.Context, k common.KeeperOracle) { for ; i < len(index.Index); i++ { b := index.Index[i] if b >= block-uint64(common.MaxNonce) { - index.Index = index.Index[i:] break } k.RemoveRecentParams(ctx, b) } + if i > 0 && i == len(index.Index) { + i-- + } index.Index = index.Index[i:] // remove and append for KVStore index.Index = append(index.Index, block)