Skip to content

Commit

Permalink
fix: token registry cache
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Sep 27, 2022
1 parent ae43ccb commit f04c92d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 27 deletions.
6 changes: 0 additions & 6 deletions x/leverage/keeper/gas.go

This file was deleted.

20 changes: 5 additions & 15 deletions x/leverage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/hashicorp/golang-lru/simplelru"
"github.com/tendermint/tendermint/libs/log"

"github.com/umee-network/umee/v3/x/leverage/types"
Expand All @@ -22,8 +21,6 @@ type Keeper struct {
hooks types.Hooks
bankKeeper types.BankKeeper
oracleKeeper types.OracleKeeper

tokenRegCache simplelru.LRUCache
}

func NewKeeper(
Expand All @@ -38,19 +35,12 @@ func NewKeeper(
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}

const tokenRegCacheSize = 100
tokenRegCache, err := simplelru.NewLRU(tokenRegCacheSize, nil)
if err != nil {
return Keeper{}, err
}

return Keeper{
cdc: cdc,
storeKey: storeKey,
paramSpace: paramSpace,
bankKeeper: bk,
oracleKeeper: ok,
tokenRegCache: tokenRegCache,
cdc: cdc,
storeKey: storeKey,
paramSpace: paramSpace,
bankKeeper: bk,
oracleKeeper: ok,
}, nil
}

Expand Down
6 changes: 0 additions & 6 deletions x/leverage/keeper/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,11 @@ func (k Keeper) SetTokenSettings(ctx sdk.Context, token types.Token) error {

k.hooks.AfterTokenRegistered(ctx, token)
store.Set(tokenKey, bz)
k.tokenRegCache.Add(token.BaseDenom, token)
ctx.GasMeter().ConsumeGas(gasCacheUpdate, "cache update")
return nil
}

// GetTokenSettings gets a token from the x/leverage module's KVStore.
func (k Keeper) GetTokenSettings(ctx sdk.Context, denom string) (types.Token, error) {
ctx.GasMeter().ConsumeGas(gasCacheAccess, "cache access")
if v, ok := k.tokenRegCache.Get(denom); ok {
return v.(types.Token), nil
}
store := ctx.KVStore(k.storeKey)
tokenKey := types.CreateRegisteredTokenKey(denom)

Expand Down

0 comments on commit f04c92d

Please sign in to comment.