removed use of caches in the stake keeper
This commit is contained in:
parent
4cbf253c14
commit
ac56ac8e5b
|
@ -31,6 +31,7 @@ FEATURES
|
|||
* [stake] Seperation of fee distribution to a new module
|
||||
* [stake] Creation of a validator/delegation generics in `/types`
|
||||
* [stake] Helper Description of the store in x/stake/store.md
|
||||
* [stake] removed use of caches in the stake keeper
|
||||
|
||||
BUG FIXES
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ func DefaultGenesisState() GenesisState {
|
|||
// InitGenesis - store genesis parameters
|
||||
func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState) {
|
||||
k.setPool(ctx, data.Pool)
|
||||
k.setParams(ctx, data.Params)
|
||||
k.setNewParams(ctx, data.Params)
|
||||
for _, validator := range data.Validators {
|
||||
k.setValidator(ctx, validator)
|
||||
}
|
||||
|
|
|
@ -15,10 +15,6 @@ type Keeper struct {
|
|||
cdc *wire.Codec
|
||||
coinKeeper bank.Keeper
|
||||
|
||||
// caches
|
||||
pool Pool
|
||||
params Params
|
||||
|
||||
// codespace
|
||||
codespace sdk.CodespaceType
|
||||
}
|
||||
|
@ -461,12 +457,11 @@ func (k Keeper) removeDelegation(ctx sdk.Context, bond Delegation) {
|
|||
//_______________________________________________________________________
|
||||
|
||||
// load/save the global staking params
|
||||
func (k Keeper) GetParams(ctx sdk.Context) (params Params) {
|
||||
// check if cached before anything
|
||||
if !k.params.equal(Params{}) {
|
||||
return k.params
|
||||
}
|
||||
func (k Keeper) GetParams(ctx sdk.Context) Params {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
return k.getParams(store)
|
||||
}
|
||||
func (k Keeper) getParams(store sdk.KVStore) (params Params) {
|
||||
b := store.Get(ParamKey)
|
||||
if b == nil {
|
||||
panic("Stored params should not have been nil")
|
||||
|
@ -475,17 +470,24 @@ func (k Keeper) GetParams(ctx sdk.Context) (params Params) {
|
|||
k.cdc.MustUnmarshalBinary(b, ¶ms)
|
||||
return
|
||||
}
|
||||
func (k Keeper) setParams(ctx sdk.Context, params Params) {
|
||||
|
||||
func (k Keeper) setNewParams(ctx sdk.Context, params Params) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
b := k.cdc.MustMarshalBinary(params)
|
||||
store.Set(ParamKey, b)
|
||||
}
|
||||
|
||||
func (k Keeper) setParams(ctx sdk.Context, params Params) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
exParams := k.getParams(store)
|
||||
|
||||
// if max validator count changes, must recalculate validator set
|
||||
if k.params.MaxValidators != params.MaxValidators {
|
||||
if exParams.MaxValidators != params.MaxValidators {
|
||||
pool := k.GetPool(ctx)
|
||||
k.updateBondedValidators(ctx, store, pool, nil)
|
||||
}
|
||||
k.params = params // update the cache
|
||||
b := k.cdc.MustMarshalBinary(params)
|
||||
store.Set(ParamKey, b)
|
||||
}
|
||||
|
||||
//_______________________________________________________________________
|
||||
|
@ -496,10 +498,6 @@ func (k Keeper) GetPool(ctx sdk.Context) (pool Pool) {
|
|||
return k.getPool(store)
|
||||
}
|
||||
func (k Keeper) getPool(store sdk.KVStore) (pool Pool) {
|
||||
// check if cached before anything
|
||||
if !k.pool.equal(Pool{}) {
|
||||
return k.pool
|
||||
}
|
||||
b := store.Get(PoolKey)
|
||||
if b == nil {
|
||||
panic("Stored pool should not have been nil")
|
||||
|
@ -512,7 +510,6 @@ func (k Keeper) setPool(ctx sdk.Context, p Pool) {
|
|||
store := ctx.KVStore(k.storeKey)
|
||||
b := k.cdc.MustMarshalBinary(p)
|
||||
store.Set(PoolKey, b)
|
||||
k.pool = Pool{} //clear the cache
|
||||
}
|
||||
|
||||
//__________________________________________________________________________
|
||||
|
|
|
@ -103,7 +103,7 @@ func createTestInput(t *testing.T, isCheckTx bool, initCoins int64) (sdk.Context
|
|||
ck := bank.NewKeeper(accountMapper)
|
||||
keeper := NewKeeper(cdc, keyStake, ck, DefaultCodespace)
|
||||
keeper.setPool(ctx, initialPool())
|
||||
keeper.setParams(ctx, defaultParams())
|
||||
keeper.setNewParams(ctx, defaultParams())
|
||||
|
||||
// fill all the addresses with some coins
|
||||
for _, addr := range addrs {
|
||||
|
|
Loading…
Reference in New Issue