Address PR comments

This commit is contained in:
Jack Zampolin 2018-12-11 13:10:42 -08:00
parent 97efff8af6
commit 26a31926f8
2 changed files with 4 additions and 2 deletions

View File

@ -11,6 +11,8 @@ import (
"github.com/cosmos/cosmos-sdk/x/stake/types" "github.com/cosmos/cosmos-sdk/x/stake/types"
) )
const aminoCacheSize = 500
// keeper of the stake store // keeper of the stake store
type Keeper struct { type Keeper struct {
storeKey sdk.StoreKey storeKey sdk.StoreKey
@ -34,7 +36,7 @@ func NewKeeper(cdc *codec.Codec, key, tkey sdk.StoreKey, ck bank.Keeper, paramst
bankKeeper: ck, bankKeeper: ck,
paramstore: paramstore.WithTypeTable(ParamTypeTable()), paramstore: paramstore.WithTypeTable(ParamTypeTable()),
hooks: nil, hooks: nil,
validatorCache: make(map[string]cachedValidator, 500), validatorCache: make(map[string]cachedValidator, aminoCacheSize),
validatorCacheList: list.New(), validatorCacheList: list.New(),
codespace: codespace, codespace: codespace,
} }

View File

@ -42,7 +42,7 @@ func (k Keeper) GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator ty
k.validatorCacheList.PushBack(cachedVal) k.validatorCacheList.PushBack(cachedVal)
// if the cache is too big, pop off the last element from it // if the cache is too big, pop off the last element from it
if k.validatorCacheList.Len() > 500 { if k.validatorCacheList.Len() > aminoCacheSize {
valToRemove := k.validatorCacheList.Remove(k.validatorCacheList.Front()).(cachedValidator) valToRemove := k.validatorCacheList.Remove(k.validatorCacheList.Front()).(cachedValidator)
delete(k.validatorCache, valToRemove.marshalled) delete(k.validatorCache, valToRemove.marshalled)
} }