diff --git a/store/types/gas.go b/store/types/gas.go index b13f99a98e..40d829f9f3 100644 --- a/store/types/gas.go +++ b/store/types/gas.go @@ -261,6 +261,19 @@ type GasConfig struct { IterNextCostFlat Gas } +// KVGasConfigAfterNagqu returns a gas config after Nagqu harfork for KVStores. +func KVGasConfigAfterNagqu() GasConfig { + return GasConfig{ + HasCost: 0, + DeleteCost: 1000, + ReadCostFlat: 0, + ReadCostPerByte: 0, + WriteCostFlat: 2000, + WriteCostPerByte: 30, + IterNextCostFlat: 0, + } +} + // KVGasConfig returns a default gas config for KVStores. func KVGasConfig() GasConfig { return GasConfig{ diff --git a/types/context.go b/types/context.go index 65bd578092..795e36a420 100644 --- a/types/context.go +++ b/types/context.go @@ -313,13 +313,24 @@ func (c Context) Value(key interface{}) interface{} { // Store / Caching // ---------------------------------------------------------------------------- +// KVStoreWithZeroRead fetches a KVStore from the MultiStore. +func (c Context) KVStoreWithZeroRead(key storetypes.StoreKey) storetypes.KVStore { + return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.gasMeter, storetypes.KVGasConfigAfterNagqu()) +} + // KVStore fetches a KVStore from the MultiStore. func (c Context) KVStore(key storetypes.StoreKey) storetypes.KVStore { + if c.upgradeChecker != nil && c.upgradeChecker(c, Nagqu) { + return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.gasMeter, storetypes.KVGasConfigAfterNagqu()) + } return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.gasMeter, c.kvGasConfig) } // TransientStore fetches a TransientStore from the MultiStore. func (c Context) TransientStore(key storetypes.StoreKey) storetypes.KVStore { + if c.upgradeChecker != nil && c.upgradeChecker(c, Nagqu) { + return c.MultiStore().GetKVStore(key) + } return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.gasMeter, c.kvGasConfig) } diff --git a/types/upgrade.go b/types/upgrade.go new file mode 100644 index 0000000000..b444a101df --- /dev/null +++ b/types/upgrade.go @@ -0,0 +1,9 @@ +package types + +const ( + // EnablePublicDelegationUpgrade is the upgrade name for enabling public delegation + EnablePublicDelegationUpgrade = "EnablePublicDelegationUpgrade" + + // Nagqu is the upgrade name for following features: + Nagqu = "Nagqu" +) diff --git a/x/upgrade/keeper/keeper.go b/x/upgrade/keeper/keeper.go index d418d7aaee..2f492123ff 100644 --- a/x/upgrade/keeper/keeper.go +++ b/x/upgrade/keeper/keeper.go @@ -249,7 +249,7 @@ func encodeDoneKey(name string, height int64) []byte { // GetDoneHeight returns the height at which the given upgrade was executed func (k Keeper) GetDoneHeight(ctx sdk.Context, name string) int64 { - iter := sdk.KVStorePrefixIterator(ctx.KVStore(k.storeKey), []byte{types.DoneByte}) + iter := sdk.KVStorePrefixIterator(ctx.KVStoreWithZeroRead(k.storeKey), []byte{types.DoneByte}) defer iter.Close() for ; iter.Valid(); iter.Next() { diff --git a/x/upgrade/types/upgrade_config.go b/x/upgrade/types/upgrade_config.go index 4e65fd6bf8..742585bccd 100644 --- a/x/upgrade/types/upgrade_config.go +++ b/x/upgrade/types/upgrade_config.go @@ -2,14 +2,16 @@ package types import ( "math" + + "github.com/cosmos/cosmos-sdk/types" ) const ( // EnablePublicDelegationUpgrade is the upgrade name for enabling public delegation - EnablePublicDelegationUpgrade = "EnablePublicDelegationUpgrade" + EnablePublicDelegationUpgrade = types.EnablePublicDelegationUpgrade // Nagqu is the upgrade name for following features: - Nagqu = "Nagqu" + Nagqu = types.Nagqu ) // The default upgrade config for networks