Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add hardfork logic for Nagqu #300

Merged
merged 2 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions store/types/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
14 changes: 14 additions & 0 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
)

// Nagqu defines the name of Nagqu upgrade
const Nagqu = "Nagqu"
j75689 marked this conversation as resolved.
Show resolved Hide resolved

/*
Context is an immutable object contains all information needed to
process a request.
Expand Down Expand Up @@ -313,13 +316,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)
}

Expand Down
2 changes: 1 addition & 1 deletion x/upgrade/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down