Skip to content

Commit

Permalink
Add new param setting in upgrade handler (#875) (#877)
Browse files Browse the repository at this point in the history
* 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 acbe656)
  • Loading branch information
channa-figure authored Jun 17, 2022
1 parent 90bb1e8 commit c040d56
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 81 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 9 additions & 38 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 {
Expand Down
35 changes: 0 additions & 35 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
6 changes: 3 additions & 3 deletions internal/handlers/msg_service_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

}

Expand Down
8 changes: 4 additions & 4 deletions x/msgfees/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/msgfees/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c040d56

Please sign in to comment.