Skip to content

Commit

Permalink
fix: update cache when assetID updated in params (#214)
Browse files Browse the repository at this point in the history
* fix: update cache when assetID updated in params

* fix:update params with latest params when do recache

* remove debug log
  • Loading branch information
leonz789 authored Oct 14, 2024
1 parent 8f0eb00 commit 2b7a55c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions x/oracle/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func (k Keeper) RegisterNewTokenAndSetTokenFeeder(ctx sdk.Context, oInfo *types.
if t.Name == oInfo.Token.Name && t.ChainID == chainID {
t.AssetID = strings.Join([]string{t.AssetID, oInfo.AssetID}, ",")
k.SetParams(ctx, p)
if !ctx.IsCheckTx() {
_ = GetAggregatorContext(ctx, k)
cs.AddCache(cache.ItemP(p))
}
// there should have been existing tokenFeeder running(currently we register tokens from assets-module and with infinite endBlock)
return nil
}
Expand Down
2 changes: 0 additions & 2 deletions x/oracle/keeper/query_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package keeper

import (
"context"
"fmt"

"github.com/ExocoreNetwork/exocore/x/oracle/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -14,7 +13,6 @@ func (k Keeper) TokenIndexes(goCtx context.Context, req *types.QueryTokenIndexes
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
fmt.Println("debug----keeper.TokenIndexes")

ctx := sdk.UnwrapSDKContext(goCtx)
ret := k.GetTokens(ctx)
Expand Down
6 changes: 6 additions & 0 deletions x/oracle/keeper/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ func recacheAggregatorContext(ctx sdk.Context, agc *aggregator.AggregatorContext
if updated := c.GetCache(&pRet); !updated {
c.AddCache(cache.ItemP(*p))
}
// TODO: these 4 lines are mainly used for hot fix
// since the latest params stored in KV for recache should be the same with the latest params, so these lines are just duplicated actions if everything is fine.
*p = k.GetParams(ctx)
agc.SetParams(p)
setCommonParams(p)
c.AddCache(cache.ItemP(*p))

return true
}
Expand Down

0 comments on commit 2b7a55c

Please sign in to comment.