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

MsgFees param store migration #1936

Merged
merged 7 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* Attribute module param migration [#1927](https://github.com/provenance-io/provenance/pull/1927)
* Marker module param migration [#1934](https://github.com/provenance-io/provenance/pull/1934)
* Metadata module param migration [#1932](https://github.com/provenance-io/provenance/pull/1932)
* Msgfees module param migration [#1936](https://github.com/provenance-io/provenance/pull/1936)
* Restore the hold module [#1930](https://github.com/provenance-io/provenance/pull/1930).
* Restore gov-prop cli commands and fix next key decoding [#1930](https://github.com/provenance-io/provenance/pull/1930).
* Switch to InputOutputCoinsProv for exchange transfers [#1930](https://github.com/provenance-io/provenance/pull/1930).
Expand Down
9 changes: 4 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,9 @@ func New(
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), appCodec, homePath, app.BaseApp, govAuthority)

app.MsgFeesKeeper = msgfeeskeeper.NewKeeper(
appCodec, keys[msgfeestypes.StoreKey], app.GetSubspace(msgfeestypes.ModuleName),
authtypes.FeeCollectorName, pioconfig.GetProvenanceConfig().FeeDenom,
app.SimulateProv, app.txConfig.TxDecoder(), interfaceRegistry,
appCodec, keys[msgfeestypes.StoreKey], authtypes.FeeCollectorName,
pioconfig.GetProvenanceConfig().FeeDenom, app.SimulateProv,
app.txConfig.TxDecoder(), interfaceRegistry,
)

pioMsgFeesRouter := app.MsgServiceRouter().(*piohandlers.PioMsgServiceRouter)
Expand Down Expand Up @@ -1361,8 +1361,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypesv1.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)

paramsKeeper.Subspace(nametypes.ModuleName) // TODO[1760]: params: Migrate name params.
paramsKeeper.Subspace(msgfeestypes.ModuleName) // TODO[1760]: params: Migrate msgFees params.
paramsKeeper.Subspace(nametypes.ModuleName) // TODO[1760]: params: Migrate name params.
paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(triggertypes.ModuleName) // TODO[1760]: params: Migrate trigger params.

Expand Down
34 changes: 34 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
attributetypes "github.com/provenance-io/provenance/x/attribute/types"
markertypes "github.com/provenance-io/provenance/x/marker/types"
metadatatypes "github.com/provenance-io/provenance/x/metadata/types"
msgfeestypes "github.com/provenance-io/provenance/x/msgfees/types"
)

// appUpgrade is an internal structure for defining all things for an upgrade.
Expand Down Expand Up @@ -68,6 +69,7 @@ var upgrades = map[string]appUpgrade{
migrateAttributeParams(ctx, app)
migrateMarkerParams(ctx, app)
migrateMetadataOSLocatorParams(ctx, app)
migrateMsgFeesParams(ctx, app)

vm, err = runModuleMigrations(ctx, app, vm)
if err != nil {
Expand Down Expand Up @@ -107,6 +109,7 @@ var upgrades = map[string]appUpgrade{
migrateAttributeParams(ctx, app)
migrateMarkerParams(ctx, app)
migrateMetadataOSLocatorParams(ctx, app)
migrateMsgFeesParams(ctx, app)

vm, err = runModuleMigrations(ctx, app, vm)
if err != nil {
Expand Down Expand Up @@ -396,3 +399,34 @@ func migrateMetadataOSLocatorParams(ctx sdk.Context, app *App) {
ctx.Logger().Info("Done migrating metadata os locator params.")

}

// migrateMsgFeesParams migrates to new MsgFees Params store
// TODO: Remove with the umber handlers.
func migrateMsgFeesParams(ctx sdk.Context, app *App) {
ctx.Logger().Info("Migrating msgfees params.")
msgFeesParamSpace := app.ParamsKeeper.Subspace(msgfeestypes.ModuleName).WithKeyTable(msgfeestypes.ParamKeyTable())

var floorGasPrice sdk.Coin
if msgFeesParamSpace.Has(ctx, msgfeestypes.ParamStoreKeyFloorGasPrice) {
msgFeesParamSpace.Get(ctx, msgfeestypes.ParamStoreKeyFloorGasPrice, &floorGasPrice)
}

var nhashPerUsdMil uint64
if msgFeesParamSpace.Has(ctx, msgfeestypes.ParamStoreKeyNhashPerUsdMil) {
msgFeesParamSpace.Get(ctx, msgfeestypes.ParamStoreKeyNhashPerUsdMil, &nhashPerUsdMil)
}

var conversionFeeDenom string
if msgFeesParamSpace.Has(ctx, msgfeestypes.ParamStoreKeyConversionFeeDenom) {
msgFeesParamSpace.Get(ctx, msgfeestypes.ParamStoreKeyConversionFeeDenom, &conversionFeeDenom)
}

migratedParams := msgfeestypes.Params{
FloorGasPrice: floorGasPrice,
NhashPerUsdMil: nhashPerUsdMil,
ConversionFeeDenom: conversionFeeDenom,
}
app.MsgFeesKeeper.SetParams(ctx, migratedParams)

ctx.Logger().Info("Done migrating msgfees params.")
}
nullpointer0x00 marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ func (s *UpgradeTestSuite) TestUmberRC1() {
"INF Done migrating marker params.",
"INF Migrating metadata os locator params.",
"INF Done migrating metadata os locator params.",
"INF Migrating msgfees params.",
"INF Done migrating msgfees params.",
"INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.",
"INF Updating IBC AllowedClients.",
"INF Done updating IBC AllowedClients.",
Expand All @@ -412,6 +414,8 @@ func (s *UpgradeTestSuite) TestUmber() {
"INF Done migrating marker params.",
"INF Migrating metadata os locator params.",
"INF Done migrating metadata os locator params.",
"INF Migrating msgfees params.",
"INF Done migrating msgfees params.",
"INF Starting module migrations. This may take a significant amount of time to complete. Do not restart node.",
"INF Updating IBC AllowedClients.",
"INF Done updating IBC AllowedClients.",
Expand Down
43 changes: 0 additions & 43 deletions x/msgfees/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
cosmosauthtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/provenance-io/provenance/x/msgfees/types"
)
Expand All @@ -28,7 +27,6 @@ type baseAppSimulateFunc func(txBytes []byte) (sdk.GasInfo, *sdk.Result, sdk.Con
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
paramSpace paramtypes.Subspace
feeCollectorName string // name of the FeeCollector ModuleAccount
defaultFeeDenom string
simulateFunc baseAppSimulateFunc
Expand All @@ -42,21 +40,15 @@ type Keeper struct {
func NewKeeper(
cdc codec.BinaryCodec,
key storetypes.StoreKey,
paramSpace paramtypes.Subspace,
feeCollectorName string,
defaultFeeDenom string,
simulateFunc baseAppSimulateFunc,
txDecoder sdk.TxDecoder,
registry cdctypes.InterfaceRegistry,
) Keeper {
if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())
}

return Keeper{
storeKey: key,
cdc: cdc,
paramSpace: paramSpace,
feeCollectorName: feeCollectorName,
defaultFeeDenom: defaultFeeDenom,
simulateFunc: simulateFunc,
Expand All @@ -80,41 +72,6 @@ func (k Keeper) GetFeeCollectorName() string {
return k.feeCollectorName
}

// GetFloorGasPrice returns the current minimum gas price in sdk.Coin used in calculations for charging additional fees
func (k Keeper) GetFloorGasPrice(ctx sdk.Context) sdk.Coin {
min := types.DefaultFloorGasPrice()
if k.paramSpace.Has(ctx, types.ParamStoreKeyFloorGasPrice) {
k.paramSpace.Get(ctx, types.ParamStoreKeyFloorGasPrice, &min)
}
return min
}

// GetNhashPerUsdMil returns the current nhash amount per usd mil.
//
// Conversions:
// - x nhash/usd-mil = 1,000,000/x usd/hash
// - y usd/hash = 1,000,000/y nhash/usd-mil
//
// Examples:
// - 40,000,000 nhash/usd-mil = 1,000,000/40,000,000 usd/hash = $0.025/hash,
// - $0.040/hash = 1,000,000/0.040 nhash/usd-mil = 25,000,000 nhash/usd-mil
func (k Keeper) GetNhashPerUsdMil(ctx sdk.Context) uint64 {
rateInMils := types.DefaultParams().NhashPerUsdMil
if k.paramSpace.Has(ctx, types.ParamStoreKeyNhashPerUsdMil) {
k.paramSpace.Get(ctx, types.ParamStoreKeyNhashPerUsdMil, &rateInMils)
}
return rateInMils
}

// GetConversionFeeDenom returns the conversion fee denom
func (k Keeper) GetConversionFeeDenom(ctx sdk.Context) string {
conversionFeeDenom := types.DefaultParams().ConversionFeeDenom
if k.paramSpace.Has(ctx, types.ParamStoreKeyConversionFeeDenom) {
k.paramSpace.Get(ctx, types.ParamStoreKeyConversionFeeDenom, &conversionFeeDenom)
}
return conversionFeeDenom
}

// SetMsgFee sets the additional fee schedule for a Msg
func (k Keeper) SetMsgFee(ctx sdk.Context, msgFees types.MsgFee) error {
store := ctx.KVStore(k.storeKey)
Expand Down
43 changes: 37 additions & 6 deletions x/msgfees/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,45 @@ import (

// GetParams returns the total set of distribution parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
return types.Params{
FloorGasPrice: k.GetFloorGasPrice(ctx),
NhashPerUsdMil: k.GetNhashPerUsdMil(ctx),
ConversionFeeDenom: k.GetConversionFeeDenom(ctx),
store := ctx.KVStore(k.storeKey)
params = types.DefaultParams() // Initialize with defaults

bz := store.Get(types.ParamStoreKey)
if bz != nil {
k.cdc.MustUnmarshal(bz, &params) // Deserialize parameters
}
return params
}

// SetParams sets the account parameters to the param space.
// SetParams sets the account parameters to the store.
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, &params)
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&params) // Serialize parameters
store.Set(types.ParamStoreKey, bz)
}

// GetFloorGasPrice returns the current minimum gas price in sdk.Coin used in calculations for charging additional fees
func (k Keeper) GetFloorGasPrice(ctx sdk.Context) sdk.Coin {
params := k.GetParams(ctx)
return params.FloorGasPrice
}

// GetNhashPerUsdMil returns the current nhash amount per usd mil.
//
// Conversions:
// - x nhash/usd-mil = 1,000,000/x usd/hash
// - y usd/hash = 1,000,000/y nhash/usd-mil
//
// Examples:
// - 40,000,000 nhash/usd-mil = 1,000,000/40,000,000 usd/hash = $0.025/hash,
// - $0.040/hash = 1,000,000/0.040 nhash/usd-mil = 25,000,000 nhash/usd-mil
func (k Keeper) GetNhashPerUsdMil(ctx sdk.Context) uint64 {
params := k.GetParams(ctx)
return params.NhashPerUsdMil
}

// GetConversionFeeDenom returns the conversion fee denom
func (k Keeper) GetConversionFeeDenom(ctx sdk.Context) string {
params := k.GetParams(ctx)
return params.ConversionFeeDenom
}
53 changes: 53 additions & 0 deletions x/msgfees/keeper/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package keeper_test

import (
"testing"
"time"

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/provenance-io/provenance/app"
simapp "github.com/provenance-io/provenance/app"
"github.com/provenance-io/provenance/x/msgfees/types"
"github.com/stretchr/testify/suite"
)

type MsgFeesParamTestSuite struct {
suite.Suite

app *app.App
ctx sdk.Context
}

func (s *MsgFeesParamTestSuite) SetupTest() {
s.app = simapp.Setup(s.T())
s.ctx = s.app.BaseApp.NewContextLegacy(false, cmtproto.Header{Time: time.Now()})
}

func TestMsgFeesParamTestSuite(t *testing.T) {
suite.Run(t, new(MsgFeesParamTestSuite))
}

func (s *MsgFeesParamTestSuite) TestGetSetParams() {
defaultParams := s.app.MsgFeesKeeper.GetParams(s.ctx)
s.Require().Equal(types.DefaultFloorGasPrice(), defaultParams.FloorGasPrice, "Default FloorGasPrice should match")
s.Require().Equal(types.DefaultParams().NhashPerUsdMil, defaultParams.NhashPerUsdMil, "Default NhashPerUsdMil should match")
s.Require().Equal(types.DefaultParams().ConversionFeeDenom, defaultParams.ConversionFeeDenom, "Default ConversionFeeDenom should match")

newFloorGasPrice := sdk.NewInt64Coin("nhash", 100)
newNhashPerUsdMil := uint64(25000000)
newConversionFeeDenom := "usd"

newParams := types.Params{
FloorGasPrice: newFloorGasPrice,
NhashPerUsdMil: newNhashPerUsdMil,
ConversionFeeDenom: newConversionFeeDenom,
}

s.app.MsgFeesKeeper.SetParams(s.ctx, newParams)

updatedParams := s.app.MsgFeesKeeper.GetParams(s.ctx)
s.Require().Equal(newFloorGasPrice, updatedParams.FloorGasPrice, "Updated FloorGasPrice should match")
s.Require().Equal(newNhashPerUsdMil, updatedParams.NhashPerUsdMil, "Updated NhashPerUsdMil should match")
s.Require().Equal(newConversionFeeDenom, updatedParams.ConversionFeeDenom, "Updated ConversionFeeDenom should match")
}
2 changes: 1 addition & 1 deletion x/msgfees/keeper/proposal_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type IntegrationTestSuite struct {
func (s *IntegrationTestSuite) SetupSuite() {
s.app = provenance.Setup(s.T())
s.ctx = s.app.BaseApp.NewContext(false)
s.k = msgfeeskeeper.NewKeeper(s.app.AppCodec(), s.app.GetKey(msgfeestypes.ModuleName), s.app.GetSubspace(msgfeestypes.ModuleName), "", pioconfig.GetProvenanceConfig().FeeDenom, nil, nil, s.app.InterfaceRegistry())
s.k = msgfeeskeeper.NewKeeper(s.app.AppCodec(), s.app.GetKey(msgfeestypes.ModuleName), "", pioconfig.GetProvenanceConfig().FeeDenom, nil, nil, s.app.InterfaceRegistry())
s.accountAddr = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
}

Expand Down
5 changes: 1 addition & 4 deletions x/msgfees/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ var _ types.QueryServer = Keeper{}

func (k Keeper) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
c := sdk.UnwrapSDKContext(ctx)
var params types.Params
k.paramSpace.GetParamSet(c, &params)

return &types.QueryParamsResponse{Params: params}, nil
return &types.QueryParamsResponse{Params: k.GetParams(c)}, nil
}

func (k Keeper) QueryAllMsgFees(c context.Context, req *types.QueryAllMsgFeesRequest) (*types.QueryAllMsgFeesResponse, error) {
Expand Down
3 changes: 1 addition & 2 deletions x/msgfees/simulation/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ func TestProposalContents(t *testing.T) {
accounts := simtypes.RandomAccounts(r, 3)

// execute ProposalContents function
weightedProposalContent := simulation.ProposalContents(keeper.NewKeeper(app.AppCodec(), app.GetKey(types.ModuleName),
app.GetSubspace(types.ModuleName), "", pioconfig.GetProvenanceConfig().FeeDenom, nil, nil, app.InterfaceRegistry()))
weightedProposalContent := simulation.ProposalContents(keeper.NewKeeper(app.AppCodec(), app.GetKey(types.ModuleName), "", pioconfig.GetProvenanceConfig().FeeDenom, nil, nil, app.InterfaceRegistry()))
require.Len(t, weightedProposalContent, 2)

w0 := weightedProposalContent[0]
Expand Down
2 changes: 2 additions & 0 deletions x/msgfees/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func GetMsgFeeKey(msgType string) []byte {

var (
MsgFeeKeyPrefix = []byte{0x00}

ParamStoreKey = []byte{0x01}
)

func GetCompositeKey(msgType string, recipient string) string {
Expand Down
1 change: 1 addition & 0 deletions x/msgfees/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func DefaultFloorGasPrice() sdk.Coin {

var DefaultNhashPerUsdMil = uint64(25_000_000)

// TODO: remove with the umber (v1.19.x) handlers.
var (
// ParamStoreKeyFloorGasPrice if msg fees are paid in the same denom as base default gas is paid, then use this to differentiate between base price
// and additional fees.
Expand Down
Loading