Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: token registry cache #1450

Merged
merged 3 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

## [v3.0.1](https://github.com/umee-network/umee/releases/tag/v3.0.1) - 2022-09-28

### Fixes

- [1450](https://github.com/umee-network/umee/pull/1450) fix: token registry cache which caused v3.0.0 halt.

## [v3.0.0](https://github.com/umee-network/umee/releases/tag/v3.0.0) - 2022-09-22

### State Machine Breaking
Expand Down
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