diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e037e6deb..ac3c905426 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/app/app.go b/app/app.go index d7013845c7..26856fe656 100644 --- a/app/app.go +++ b/app/app.go @@ -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) @@ -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. diff --git a/app/upgrades.go b/app/upgrades.go index d1dbf5fa8f..7796560b3b 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -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. @@ -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 { @@ -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 { @@ -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.") +} diff --git a/app/upgrades_test.go b/app/upgrades_test.go index 4a7b0a6de9..a102dd8403 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -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.", @@ -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.", diff --git a/x/msgfees/keeper/keeper.go b/x/msgfees/keeper/keeper.go index 3a04a640f6..64510369a1 100644 --- a/x/msgfees/keeper/keeper.go +++ b/x/msgfees/keeper/keeper.go @@ -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" ) @@ -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 @@ -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, @@ -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) diff --git a/x/msgfees/keeper/params.go b/x/msgfees/keeper/params.go index 6dda907be2..0e1cc27496 100644 --- a/x/msgfees/keeper/params.go +++ b/x/msgfees/keeper/params.go @@ -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, ¶ms) // 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, ¶ms) + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(¶ms) // 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 } diff --git a/x/msgfees/keeper/params_test.go b/x/msgfees/keeper/params_test.go new file mode 100644 index 0000000000..8ee1bb3494 --- /dev/null +++ b/x/msgfees/keeper/params_test.go @@ -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") +} diff --git a/x/msgfees/keeper/proposal_handler_test.go b/x/msgfees/keeper/proposal_handler_test.go index a5cd74371a..770480d3b1 100644 --- a/x/msgfees/keeper/proposal_handler_test.go +++ b/x/msgfees/keeper/proposal_handler_test.go @@ -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()) } diff --git a/x/msgfees/keeper/query_server.go b/x/msgfees/keeper/query_server.go index d7cabed70c..3317dd79c8 100644 --- a/x/msgfees/keeper/query_server.go +++ b/x/msgfees/keeper/query_server.go @@ -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, ¶ms) - - 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) { diff --git a/x/msgfees/simulation/proposals_test.go b/x/msgfees/simulation/proposals_test.go index 830fddb800..73814e237c 100644 --- a/x/msgfees/simulation/proposals_test.go +++ b/x/msgfees/simulation/proposals_test.go @@ -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] diff --git a/x/msgfees/types/keys.go b/x/msgfees/types/keys.go index e648915863..dc18ab7379 100644 --- a/x/msgfees/types/keys.go +++ b/x/msgfees/types/keys.go @@ -30,7 +30,10 @@ func GetMsgFeeKey(msgType string) []byte { } var ( + //MsgFeeKeyPrefix prefix for msgfee entry MsgFeeKeyPrefix = []byte{0x00} + // ParamStoreKey key for msgfees module's params + ParamStoreKey = []byte{0x01} ) func GetCompositeKey(msgType string, recipient string) string { diff --git a/x/msgfees/types/params.go b/x/msgfees/types/params.go index 7d4beb31ea..521b92a0e7 100644 --- a/x/msgfees/types/params.go +++ b/x/msgfees/types/params.go @@ -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.