Skip to content

Commit

Permalink
fix: token registry cache (#1450) (#1456)
Browse files Browse the repository at this point in the history
* fix: token registry cache

* changelog

(cherry picked from commit 60b7c2d)

Co-authored-by: Robert Zaremba <robert@zaremba.ch>
  • Loading branch information
mergify[bot] and robert-zaremba authored Sep 28, 2022
1 parent f4274ce commit 9626e2f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 27 deletions.
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

0 comments on commit 9626e2f

Please sign in to comment.