Skip to content

Commit

Permalink
x/oracle: cache removed; gen export fix: panic when jail-list is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Kornilov committed Jul 13, 2021
1 parent 388be4d commit 5714753
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 34 deletions.
5 changes: 3 additions & 2 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ func (app *DnApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []s
// update bond intra-tx counters.
store := ctx.KVStore(app.keys[stakingtypes.StoreKey])
iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
counter := int16(0)

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Key()[1:])
Expand All @@ -169,7 +168,9 @@ func (app *DnApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []s
}

app.StakingKeeper.SetValidator(ctx, validator)
counter++
if validator.IsJailed() {
app.StakingKeeper.DeleteValidatorByPowerIndex(ctx, validator)
}
}

iter.Close()
Expand Down
8 changes: 0 additions & 8 deletions x/oracle/keeper/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import (

// GetAsset returns an types.Asset if exists.
func (k Keeper) GetAsset(ctx sdk.Context, assetCode dnTypes.AssetCode) *types.Asset {
if cachedValue, found := k.cache.assets[assetCode.String()]; found {
return &cachedValue
}

store := ctx.KVStore(k.storeKey)
assetStore := prefix.NewStore(store, types.AssetsPrefix)
key, _ := assetCode.Marshal()
Expand All @@ -26,8 +22,6 @@ func (k Keeper) GetAsset(ctx sdk.Context, assetCode dnTypes.AssetCode) *types.As
asset := &types.Asset{}
k.cdc.MustUnmarshalBinaryBare(bz, asset)

k.cache.assets[asset.AssetCode.String()] = *asset

return asset
}

Expand Down Expand Up @@ -74,6 +68,4 @@ func (k Keeper) setAsset(ctx sdk.Context, asset types.Asset) {

bz := k.cdc.MustMarshalBinaryBare(&asset)
assetStore.Set(key, bz)

k.cache.assets[asset.AssetCode.String()] = asset
}
12 changes: 0 additions & 12 deletions x/oracle/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ type Keeper struct {
storeKey sdk.StoreKey
cdc codec.BinaryMarshaler
paramSpace paramTypes.Subspace
//
cache *keeperCache
}

// keeperCache optimized Gas usage for frequent PostPrice operations.
type keeperCache struct {
oracles map[string]types.Oracle // key: AccAddress
assets map[string]types.Asset // key: AssetCode
}

// IsNominee checks if nominee exist within keeper parameters and returns sdk wrapped error.
Expand Down Expand Up @@ -57,9 +49,5 @@ func NewKeeper(
cdc: cdc,
storeKey: storeKey,
paramSpace: paramSpace,
cache: &keeperCache{
oracles: make(map[string]types.Oracle),
assets: make(map[string]types.Asset),
},
}
}
12 changes: 0 additions & 12 deletions x/oracle/keeper/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (

// GetOracle returns an types.Oracle if exists.
func (k Keeper) GetOracle(ctx sdk.Context, addr string) *types.Oracle {
if cachedValue, found := k.cache.oracles[addr]; found {
return &cachedValue
}

store := ctx.KVStore(k.storeKey)
oracleStore := prefix.NewStore(store, types.OraclesPrefix)
key := types.GetOraclesKey(addr)
Expand All @@ -24,8 +20,6 @@ func (k Keeper) GetOracle(ctx sdk.Context, addr string) *types.Oracle {
oracle := &types.Oracle{}
k.cdc.MustUnmarshalBinaryBare(bz, oracle)

k.cache.oracles[addr] = *oracle

return oracle
}

Expand Down Expand Up @@ -60,10 +54,6 @@ func (k Keeper) SetOracle(ctx sdk.Context, msg types.MsgSetOracle) error {

// hasOracle checks if types.Oracle with addr is registered.
func (k Keeper) hasOracle(ctx sdk.Context, addr string) bool {
if _, found := k.cache.oracles[addr]; found {
return found
}

store := ctx.KVStore(k.storeKey)
oracleStore := prefix.NewStore(store, types.OraclesPrefix)
key := types.GetOraclesKey(addr)
Expand All @@ -79,6 +69,4 @@ func (k Keeper) setOracle(ctx sdk.Context, oracle types.Oracle) {

bz := k.cdc.MustMarshalBinaryBare(&oracle)
oracleStore.Set(key, bz)

k.cache.oracles[oracle.AccAddress] = oracle
}

0 comments on commit 5714753

Please sign in to comment.