Skip to content

Commit

Permalink
fix(oracle):remove expired msgindex, keep at least params cache (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonz789 authored Sep 3, 2024
1 parent 1c687b3 commit 423b9f7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions x/oracle/keeper/cache/caches.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 423b9f7

Please sign in to comment.