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

feat: disable mint/distr/staking/gov module #117

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
51 changes: 51 additions & 0 deletions app/upgrades/v6/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/functionx/fx-core/v6/app/keepers"
govtypes "github.com/functionx/fx-core/v6/x/gov/types"
)

func CreateUpgradeHandler(
Expand All @@ -16,6 +17,10 @@ func CreateUpgradeHandler(
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
cacheCtx, commit := ctx.CacheContext()

if err := UpdateParams(cacheCtx, app); err != nil {
return nil, err
}

ctx.Logger().Info("start to run v6 migrations...", "module", "upgrade")
toVM, err := mm.RunMigrations(cacheCtx, configurator, fromVM)
if err != nil {
Expand All @@ -27,3 +32,49 @@ func CreateUpgradeHandler(
return toVM, nil
}
}

func UpdateParams(cacheCtx sdk.Context, app *keepers.AppKeepers) error {
mintParams := app.MintKeeper.GetParams(cacheCtx)
mintParams.InflationMax = sdk.ZeroDec()
mintParams.InflationMin = sdk.ZeroDec()
if err := mintParams.Validate(); err != nil {
return err
}
app.MintKeeper.SetParams(cacheCtx, mintParams)

distrParams := app.DistrKeeper.GetParams(cacheCtx)
distrParams.CommunityTax = sdk.ZeroDec()
distrParams.BaseProposerReward = sdk.ZeroDec()
distrParams.BonusProposerReward = sdk.ZeroDec()
if err := distrParams.ValidateBasic(); err != nil {
return err
}
app.DistrKeeper.SetParams(cacheCtx, distrParams)

stakingParams := app.StakingKeeper.GetParams(cacheCtx)
stakingParams.UnbondingTime = 1
if err := stakingParams.Validate(); err != nil {
return err
}
app.StakingKeeper.SetParams(cacheCtx, stakingParams)

govTallyParams := app.GovKeeper.GetTallyParams(cacheCtx)
govTallyParams.Quorum = sdk.OneDec().String() // 100%
govTallyParams.Threshold = sdk.OneDec().String() // 100%
govTallyParams.VetoThreshold = sdk.OneDec().String() // 100%
app.GovKeeper.SetTallyParams(cacheCtx, govTallyParams)

app.GovKeeper.IterateParams(cacheCtx, func(param *govtypes.Params) (stop bool) {
param.Quorum = sdk.OneDec().String() // 100%
param.Threshold = sdk.OneDec().String() // 100%
param.VetoThreshold = sdk.OneDec().String() // 100%
if err := param.ValidateBasic(); err != nil {
panic(err)
}
if err := app.GovKeeper.SetParams(cacheCtx, param); err != nil {
panic(err)
}
return false
})
return nil
}
62 changes: 62 additions & 0 deletions app/upgrades/v6/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package v6_test

import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/functionx/fx-core/v6/app"
v6 "github.com/functionx/fx-core/v6/app/upgrades/v6"
"github.com/functionx/fx-core/v6/testutil/helpers"
fxtypes "github.com/functionx/fx-core/v6/types"
)

type UpgradeTestSuite struct {
suite.Suite

app *app.App
ctx sdk.Context
}

func TestUpgradeTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}

func (s *UpgradeTestSuite) SetupTest() {
valNumber := tmrand.Intn(5) + 5
valSet, valAccounts, valBalances := helpers.GenerateGenesisValidator(valNumber, sdk.Coins{})
s.app = helpers.SetupWithGenesisValSet(s.T(), valSet, valAccounts, valBalances...)
s.ctx = s.app.NewContext(false, tmproto.Header{
ChainID: fxtypes.MainnetChainId,
Height: s.app.LastBlockHeight() + 1,
ProposerAddress: valSet.Proposer.Address.Bytes(),
})
}

func (s *UpgradeTestSuite) CommitBlock(block int64) {
_ = s.app.Commit()
block--

ctx := s.ctx
nextBlockHeight := ctx.BlockHeight() + 1

_ = s.app.BeginBlock(abci.RequestBeginBlock{
Header: tmproto.Header{
Height: nextBlockHeight,
},
})
s.ctx = s.app.NewContext(false, ctx.BlockHeader())
s.ctx = s.ctx.WithBlockHeight(nextBlockHeight)
if block > 0 {
s.CommitBlock(block)
}
}

func (s *UpgradeTestSuite) TestUpdateParams() {
s.NoError(v6.UpdateParams(s.ctx, s.app.AppKeepers))
s.CommitBlock(10)
}
13 changes: 13 additions & 0 deletions x/gov/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ import (
"github.com/functionx/fx-core/v6/x/gov/types"
)

func (keeper Keeper) IterateParams(ctx sdk.Context, cb func(param *types.Params) (stop bool)) {
store := ctx.KVStore(keeper.storeKey)
iter := sdk.KVStorePrefixIterator(store, types.FxBaseParamsKeyPrefix)
defer iter.Close()
for ; iter.Valid(); iter.Next() {
var param types.Params
keeper.cdc.MustUnmarshal(iter.Value(), &param)
if cb(&param) {
break
}
}
}

// GetParams gets the gov module's parameters.
func (keeper Keeper) GetParams(ctx sdk.Context, msgType string) (params types.Params) {
store := ctx.KVStore(keeper.storeKey)
Expand Down
4 changes: 1 addition & 3 deletions x/gov/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, fxMetad
return v1.Proposal{}, errortypes.ErrInvalidRequest.Wrapf("invalid fx metadata content: %s", err)
}
if err := keeper.AssertFXMetadata(fxMD); err != nil {
if err != nil {
return v1.Proposal{}, err
}
return v1.Proposal{}, err
}

// Will hold a comma-separated string of all Msg type URLs.
Expand Down