From c040d562f054e3b696c74039010e8377b85e3f1d Mon Sep 17 00:00:00 2001 From: Carlton Hanna <73041609+channa-figure@users.noreply.github.com> Date: Fri, 17 Jun 2022 12:07:46 -0600 Subject: [PATCH] Add new param setting in upgrade handler (#875) (#877) * Add new upgrade handler, Clean up unused upgrade method and tests * Add changelog * Upgrade comment * Update nhash per usd for 0.04 hash price (cherry picked from commit acbe65661fc888e5d5092b8fbc1327ef006c0397) --- CHANGELOG.md | 4 ++ app/upgrades.go | 47 ++++---------------- app/upgrades_test.go | 35 --------------- internal/handlers/msg_service_router_test.go | 6 +-- x/msgfees/keeper/keeper_test.go | 8 ++-- x/msgfees/types/params.go | 2 +- 6 files changed, 21 insertions(+), 81 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db18910ac5..64afd4e1fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## Unreleased +### Bug Fixes + +* Add new `msgfees` `NhashPerUsdMil` default param to param space store on upgrade (PR [#875](https://github.com/provenance-io/provenance/issues/875)) + --- ## [v1.11.1-rc1](https://github.com/provenance-io/provenance/releases/tag/v1.11.1-rc1) - 2022-06-14 diff --git a/app/upgrades.go b/app/upgrades.go index 378819ed10..a3f317f5d6 100644 --- a/app/upgrades.go +++ b/app/upgrades.go @@ -7,14 +7,7 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - - 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" - nametypes "github.com/provenance-io/provenance/x/name/types" ) var ( @@ -34,40 +27,18 @@ type appUpgrade struct { } var handlers = map[string]appUpgrade{ - "lava": {}, // upgrade for 1.10.0 - "mango": {}, // upgrade for 1.11.1 + "lava": {}, // upgrade for 1.10.0 + "mango": { + Handler: func(app *App, ctx sdk.Context, plan upgradetypes.Plan) (module.VersionMap, error) { + params := app.MsgFeesKeeper.GetParams(ctx) + app.MsgFeesKeeper.SetParams(ctx, params) + versionMap := app.UpgradeKeeper.GetModuleVersionMap(ctx) + return versionMap, nil + }, + }, // upgrade for 1.11.x // TODO - Add new upgrade definitions here. } -// AddMsgBasedFees adds pio specific msg based fees for BindName, AddMarker, AddAttribute, WriteScope, P8EMemorializeContract requests for v1.8.0 upgrade -func AddMsgBasedFees(app *App, ctx sdk.Context) error { - ctx.Logger().Info("Adding a 10 hash (10,000,000,000 nhash) msg fee to MsgBindNameRequest (1/6)") - if err := app.MsgFeesKeeper.SetMsgFee(ctx, msgfeestypes.NewMsgFee(sdk.MsgTypeURL(&nametypes.MsgBindNameRequest{}), sdk.NewCoin("nhash", sdk.NewInt(10_000_000_000)))); err != nil { - return err - } - ctx.Logger().Info("Adding a 100 hash (100,000,000,000 nhash) msg fee to MsgAddMarkerRequest (2/6)") - if err := app.MsgFeesKeeper.SetMsgFee(ctx, msgfeestypes.NewMsgFee(sdk.MsgTypeURL(&markertypes.MsgAddMarkerRequest{}), sdk.NewCoin("nhash", sdk.NewInt(100_000_000_000)))); err != nil { - return err - } - ctx.Logger().Info("Adding a 10 hash (10,000,000,000 nhash) msg fee to MsgAddAttributeRequest (3/6)") - if err := app.MsgFeesKeeper.SetMsgFee(ctx, msgfeestypes.NewMsgFee(sdk.MsgTypeURL(&attributetypes.MsgAddAttributeRequest{}), sdk.NewCoin("nhash", sdk.NewInt(10_000_000_000)))); err != nil { - return err - } - ctx.Logger().Info("Adding a 10 hash (10,000,000,000 nhash) msg fee to MsgWriteScopeRequest (4/6)") - if err := app.MsgFeesKeeper.SetMsgFee(ctx, msgfeestypes.NewMsgFee(sdk.MsgTypeURL(&metadatatypes.MsgWriteScopeRequest{}), sdk.NewCoin("nhash", sdk.NewInt(10_000_000_000)))); err != nil { - return err - } - ctx.Logger().Info("Adding a 10 hash (10,000,000,000 nhash) msg fee to MsgP8EMemorializeContractRequest (5/6)") - if err := app.MsgFeesKeeper.SetMsgFee(ctx, msgfeestypes.NewMsgFee(sdk.MsgTypeURL(&metadatatypes.MsgP8EMemorializeContractRequest{}), sdk.NewCoin("nhash", sdk.NewInt(10_000_000_000)))); err != nil { - return err - } - ctx.Logger().Info("Adding a 100 hash (100,000,000,000 nhash) msg fee to MsgSubmitProposal (6/6)") - if err := app.MsgFeesKeeper.SetMsgFee(ctx, msgfeestypes.NewMsgFee(sdk.MsgTypeURL(&govtypes.MsgSubmitProposal{}), sdk.NewCoin("nhash", sdk.NewInt(100_000_000_000)))); err != nil { - return err - } - return nil -} - func InstallCustomUpgradeHandlers(app *App) { // Register all explicit appUpgrades for name, upgrade := range handlers { diff --git a/app/upgrades_test.go b/app/upgrades_test.go index 841d74ba1c..90ff9afd57 100644 --- a/app/upgrades_test.go +++ b/app/upgrades_test.go @@ -6,11 +6,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - - 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" - nametypes "github.com/provenance-io/provenance/x/name/types" ) type IntegrationTestSuite struct { @@ -24,33 +19,3 @@ func (s *IntegrationTestSuite) SetupSuite() { s.app = Setup(false) s.ctx = s.app.BaseApp.NewContext(false, tmproto.Header{}) } - -func (s *IntegrationTestSuite) TestMarkerProposals() { - err := AddMsgBasedFees(s.app, s.ctx) - s.Assert().NoError(err) - - msgfee, err := s.app.MsgFeesKeeper.GetMsgFee(s.ctx, sdk.MsgTypeURL(&nametypes.MsgBindNameRequest{})) - s.Assert().NoError(err) - s.Assert().NotNil(msgfee) - s.Assert().Equal(sdk.NewCoin("nhash", sdk.NewInt(10_000_000_000)), msgfee.AdditionalFee) - - msgfee, err = s.app.MsgFeesKeeper.GetMsgFee(s.ctx, sdk.MsgTypeURL(&markertypes.MsgAddMarkerRequest{})) - s.Assert().NoError(err) - s.Assert().NotNil(msgfee) - s.Assert().Equal(sdk.NewCoin("nhash", sdk.NewInt(100_000_000_000)), msgfee.AdditionalFee) - - msgfee, err = s.app.MsgFeesKeeper.GetMsgFee(s.ctx, sdk.MsgTypeURL(&attributetypes.MsgAddAttributeRequest{})) - s.Assert().NoError(err) - s.Assert().NotNil(msgfee) - s.Assert().Equal(sdk.NewCoin("nhash", sdk.NewInt(10_000_000_000)), msgfee.AdditionalFee) - - msgfee, err = s.app.MsgFeesKeeper.GetMsgFee(s.ctx, sdk.MsgTypeURL(&metadatatypes.MsgWriteScopeRequest{})) - s.Assert().NoError(err) - s.Assert().NotNil(msgfee) - s.Assert().Equal(sdk.NewCoin("nhash", sdk.NewInt(10_000_000_000)), msgfee.AdditionalFee) - - msgfee, err = s.app.MsgFeesKeeper.GetMsgFee(s.ctx, sdk.MsgTypeURL(&metadatatypes.MsgP8EMemorializeContractRequest{})) - s.Assert().NoError(err) - s.Assert().NotNil(msgfee) - s.Assert().Equal(sdk.NewCoin("nhash", sdk.NewInt(10_000_000_000)), msgfee.AdditionalFee) -} diff --git a/internal/handlers/msg_service_router_test.go b/internal/handlers/msg_service_router_test.go index a8eff448f0..5204d108c2 100644 --- a/internal/handlers/msg_service_router_test.go +++ b/internal/handlers/msg_service_router_test.go @@ -396,13 +396,13 @@ func TestMsgServiceAssessMsgFee(t *testing.T) { assert.Equal(t, addr2.String(), string(res.Events[8].Attributes[2].Value)) assert.Equal(t, "tx", res.Events[9].Type) assert.Equal(t, antewrapper.AttributeKeyAdditionalFee, string(res.Events[9].Attributes[0].Key)) - assert.Equal(t, "99999998nhash", string(res.Events[9].Attributes[0].Value)) + assert.Equal(t, "175000000nhash", string(res.Events[9].Attributes[0].Value)) assert.Equal(t, "tx", res.Events[10].Type) assert.Equal(t, antewrapper.AttributeKeyBaseFee, string(res.Events[10].Attributes[0].Key)) - assert.Equal(t, "150atom,1090500002nhash", string(res.Events[10].Attributes[0].Value)) + assert.Equal(t, "150atom,1015500000nhash", string(res.Events[10].Attributes[0].Value)) assert.Equal(t, "provenance.msgfees.v1.EventMsgFees", res.Events[11].Type) assert.Equal(t, "msg_fees", string(res.Events[11].Attributes[0].Key)) - assert.Equal(t, fmt.Sprintf("[{\"msg_type\":\"/provenance.msgfees.v1.MsgAssessCustomMsgFeeRequest\",\"count\":\"1\",\"total\":\"49999999nhash\",\"recipient\":\"\"},{\"msg_type\":\"/provenance.msgfees.v1.MsgAssessCustomMsgFeeRequest\",\"count\":\"1\",\"total\":\"49999999nhash\",\"recipient\":\"%s\"}]", addr2.String()), string(res.Events[11].Attributes[0].Value)) + assert.Equal(t, fmt.Sprintf("[{\"msg_type\":\"/provenance.msgfees.v1.MsgAssessCustomMsgFeeRequest\",\"count\":\"1\",\"total\":\"87500000nhash\",\"recipient\":\"\"},{\"msg_type\":\"/provenance.msgfees.v1.MsgAssessCustomMsgFeeRequest\",\"count\":\"1\",\"total\":\"87500000nhash\",\"recipient\":\"%s\"}]", addr2.String()), string(res.Events[11].Attributes[0].Value)) } diff --git a/x/msgfees/keeper/keeper_test.go b/x/msgfees/keeper/keeper_test.go index 0c6fc056fd..418ec43c28 100644 --- a/x/msgfees/keeper/keeper_test.go +++ b/x/msgfees/keeper/keeper_test.go @@ -81,20 +81,20 @@ func (s *TestSuite) TestConvertDenomToHash() { usdDollar := sdk.NewCoin(types.UsdDenom, sdk.NewInt(7_000)) // $7.00 == 100hash nhash, err := app.MsgFeesKeeper.ConvertDenomToHash(ctx, usdDollar) s.Assert().NoError(err) - s.Assert().Equal(sdk.NewCoin(types.NhashDenom, sdk.NewInt(99_999_998_000)), nhash) + s.Assert().Equal(sdk.NewCoin(types.NhashDenom, sdk.NewInt(175_000_000_000)), nhash) usdDollar = sdk.NewCoin(types.UsdDenom, sdk.NewInt(70)) // $7 == 1hash nhash, err = app.MsgFeesKeeper.ConvertDenomToHash(ctx, usdDollar) s.Assert().NoError(err) - s.Assert().Equal(sdk.NewCoin(types.NhashDenom, sdk.NewInt(999_999_980)), nhash) + s.Assert().Equal(sdk.NewCoin(types.NhashDenom, sdk.NewInt(1_750_000_000)), nhash) usdDollar = sdk.NewCoin(types.UsdDenom, sdk.NewInt(1_000)) // $1 == 14.2hash nhash, err = app.MsgFeesKeeper.ConvertDenomToHash(ctx, usdDollar) s.Assert().NoError(err) - s.Assert().Equal(sdk.NewCoin(types.NhashDenom, sdk.NewInt(14_285_714_000)), nhash) + s.Assert().Equal(sdk.NewCoin(types.NhashDenom, sdk.NewInt(25_000_000_000)), nhash) usdDollar = sdk.NewCoin(types.UsdDenom, sdk.NewInt(10)) nhash, err = app.MsgFeesKeeper.ConvertDenomToHash(ctx, usdDollar) s.Assert().NoError(err) - s.Assert().Equal(sdk.NewCoin(types.NhashDenom, sdk.NewInt(142_857_140)), nhash) + s.Assert().Equal(sdk.NewCoin(types.NhashDenom, sdk.NewInt(250_000_000)), nhash) jackTheCat := sdk.NewCoin("jackThecat", sdk.NewInt(70)) nhash, err = app.MsgFeesKeeper.ConvertDenomToHash(ctx, jackTheCat) diff --git a/x/msgfees/types/params.go b/x/msgfees/types/params.go index bc1301f2db..6942fe990e 100644 --- a/x/msgfees/types/params.go +++ b/x/msgfees/types/params.go @@ -17,7 +17,7 @@ var DefaultFloorGasPrice = sdk.Coin{ Denom: NhashDenom, } -var DefaultNhashPerUsdMil = uint64(14285714) +var DefaultNhashPerUsdMil = uint64(25_000_000) 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