Skip to content

Commit

Permalink
Merge pull request #234 from terra-project/feature/adopt-gov-module
Browse files Browse the repository at this point in the history
Feature/adopt gov module
  • Loading branch information
dokwon authored Sep 24, 2019
2 parents bd2705c + db32666 commit c276f99
Show file tree
Hide file tree
Showing 32 changed files with 2,111 additions and 30 deletions.
25 changes: 22 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"

treasuryclient "github.com/terra-project/core/x/treasury/client"

"github.com/terra-project/core/x/auth"
"github.com/terra-project/core/x/bank"
"github.com/terra-project/core/x/crisis"
distr "github.com/terra-project/core/x/distribution"
"github.com/terra-project/core/x/genaccounts"
"github.com/terra-project/core/x/genutil"
"github.com/terra-project/core/x/gov"
"github.com/terra-project/core/x/market"
"github.com/terra-project/core/x/oracle"
"github.com/terra-project/core/x/params"
Expand Down Expand Up @@ -50,6 +55,7 @@ var (
bank.AppModuleBasic{},
staking.AppModuleBasic{},
distr.AppModuleBasic{},
gov.NewAppModuleBasic(paramsclient.ProposalHandler, distrclient.ProposalHandler, treasuryclient.TaxRateUpdateProposalHandler, treasuryclient.RewardWeightUpdateProposalHandler),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
Expand All @@ -68,6 +74,7 @@ var (
treasury.ModuleName: {supply.Minter},
staking.BondedPoolName: {supply.Burner, supply.Staking},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
gov.ModuleName: {supply.Burner},
}
)

Expand Down Expand Up @@ -100,6 +107,7 @@ type TerraApp struct {
slashingKeeper slashing.Keeper
oracleKeeper oracle.Keeper
distrKeeper distr.Keeper
govKeeper gov.Keeper
crisisKeeper crisis.Keeper
paramsKeeper params.Keeper
marketKeeper market.Keeper
Expand All @@ -122,7 +130,7 @@ func NewTerraApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
keys := sdk.NewKVStoreKeys(
bam.MainStoreKey, auth.StoreKey, staking.StoreKey,
supply.StoreKey, distr.StoreKey, slashing.StoreKey,
params.StoreKey, oracle.StoreKey,
gov.StoreKey, params.StoreKey, oracle.StoreKey,
market.StoreKey, treasury.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(staking.TStoreKey, params.TStoreKey)
Expand All @@ -142,6 +150,7 @@ func NewTerraApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
stakingSubspace := app.paramsKeeper.Subspace(staking.DefaultParamspace)
distrSubspace := app.paramsKeeper.Subspace(distr.DefaultParamspace)
slashingSubspace := app.paramsKeeper.Subspace(slashing.DefaultParamspace)
govSubspace := app.paramsKeeper.Subspace(gov.DefaultParamspace)
crisisSubspace := app.paramsKeeper.Subspace(crisis.DefaultParamspace)
oracleSubspace := app.paramsKeeper.Subspace(oracle.DefaultParamspace)
marketSubspace := app.paramsKeeper.Subspace(market.DefaultParamspace)
Expand All @@ -166,6 +175,15 @@ func NewTerraApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
app.supplyKeeper, app.marketKeeper, &stakingKeeper, app.distrKeeper,
oracle.ModuleName, distr.ModuleName, treasury.DefaultCodespace)

// register the proposal types
govRouter := gov.NewRouter()
govRouter.AddRoute(gov.RouterKey, gov.ProposalHandler).
AddRoute(params.RouterKey, params.NewParamChangeProposalHandler(app.paramsKeeper)).
AddRoute(distr.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.distrKeeper)).
AddRoute(treasury.RouterKey, treasury.NewTreasuryPolicyUpdateHandler(app.treasuryKeeper))
app.govKeeper = gov.NewKeeper(app.cdc, keys[gov.StoreKey], app.paramsKeeper, govSubspace,
app.supplyKeeper, &stakingKeeper, gov.DefaultCodespace, govRouter)

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.stakingKeeper = *stakingKeeper.SetHooks(
Expand All @@ -179,6 +197,7 @@ func NewTerraApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
crisis.NewAppModule(&app.crisisKeeper),
supply.NewAppModule(app.supplyKeeper, app.accountKeeper),
distr.NewAppModule(app.distrKeeper, app.supplyKeeper),
gov.NewAppModule(app.govKeeper, app.supplyKeeper),
slashing.NewAppModule(app.slashingKeeper, app.stakingKeeper),
staking.NewAppModule(app.stakingKeeper, app.distrKeeper, app.accountKeeper, app.supplyKeeper),
market.NewAppModule(app.marketKeeper),
Expand All @@ -192,13 +211,13 @@ func NewTerraApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest
app.mm.SetOrderBeginBlockers(distr.ModuleName, slashing.ModuleName)

// After slashing actions, update prev day issuance of market module
app.mm.SetOrderEndBlockers(crisis.ModuleName, oracle.ModuleName, market.ModuleName, treasury.ModuleName, staking.ModuleName)
app.mm.SetOrderEndBlockers(crisis.ModuleName, oracle.ModuleName, gov.ModuleName, market.ModuleName, treasury.ModuleName, staking.ModuleName)

// genutils must occur after staking so that pools are properly
// initialized with tokens from genesis accounts.
app.mm.SetOrderInitGenesis(genaccounts.ModuleName, distr.ModuleName,
staking.ModuleName, auth.ModuleName, bank.ModuleName, slashing.ModuleName,
oracle.ModuleName, market.ModuleName, treasury.ModuleName,
oracle.ModuleName, market.ModuleName, treasury.ModuleName, gov.ModuleName,
supply.ModuleName, crisis.ModuleName, genutil.ModuleName)

app.mm.RegisterInvariants(&app.crisisKeeper)
Expand Down
4 changes: 2 additions & 2 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/terra-project/core/x/staking"
)

// ExportAppStateAndValidators export the state of terra for a genesis file
// ExportAppStateAndValidators exports the state of terra for a genesis file
func (app *TerraApp) ExportAppStateAndValidators(forZeroHeight bool, jailWhiteList []string,
) (appState json.RawMessage, validators []tmtypes.GenesisValidator, err error) {

Expand All @@ -34,7 +34,7 @@ func (app *TerraApp) ExportAppStateAndValidators(forZeroHeight bool, jailWhiteLi
return appState, validators, nil
}

// prepForZeroHeightGenesis prepare for fresh start at zero height
// prepForZeroHeightGenesis prepares for fresh start at zero height
// NOTE zero height genesis is a temporary feature which will be deprecated
// in favour of export at a block height
func (app *TerraApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []string) {
Expand Down
69 changes: 69 additions & 0 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import (
distr "github.com/cosmos/cosmos-sdk/x/distribution"
distrsim "github.com/cosmos/cosmos-sdk/x/distribution/simulation"
"github.com/cosmos/cosmos-sdk/x/gov"
govsim "github.com/cosmos/cosmos-sdk/x/gov/simulation"
"github.com/cosmos/cosmos-sdk/x/params"
paramsim "github.com/cosmos/cosmos-sdk/x/params/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingsim "github.com/cosmos/cosmos-sdk/x/slashing/simulation"
Expand All @@ -41,6 +43,7 @@ import (
"github.com/terra-project/core/x/oracle"
oraclesim "github.com/terra-project/core/x/oracle/simulation"
"github.com/terra-project/core/x/treasury"
treasurysim "github.com/terra-project/core/x/treasury/simulation"
)

func init() {
Expand Down Expand Up @@ -252,6 +255,72 @@ func testAndRunTxs(app *TerraApp) []simulation.WeightedOperation {
}(nil),
distrsim.SimulateMsgWithdrawValidatorCommission(app.accountKeeper, app.distrKeeper),
},
{
func(_ *rand.Rand) int {
var v int
ap.GetOrGenerate(cdc, OpWeightSubmitVotingSlashingTextProposal, &v, nil,
func(_ *rand.Rand) {
v = 5
})
return v
}(nil),
govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, govsim.SimulateTextProposalContent),
},
{
func(_ *rand.Rand) int {
var v int
ap.GetOrGenerate(cdc, OpWeightSubmitVotingSlashingCommunitySpendProposal, &v, nil,
func(_ *rand.Rand) {
v = 5
})
return v
}(nil),
govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, distrsim.SimulateCommunityPoolSpendProposalContent(app.distrKeeper)),
},
{
func(_ *rand.Rand) int {
var v int
ap.GetOrGenerate(cdc, OpWeightSubmitVotingSlashingParamChangeProposal, &v, nil,
func(_ *rand.Rand) {
v = 5
})
return v
}(nil),
govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, paramsim.SimulateParamChangeProposalContent),
},
{
func(_ *rand.Rand) int {
var v int
ap.GetOrGenerate(cdc, OpWeightSubmitVotingSlashingTaxRateUpdateProposal, &v, nil,
func(_ *rand.Rand) {
v = 5
})
return v
}(nil),
govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, treasurysim.SimulateTaxRateUpdateProposalContent(app.treasuryKeeper)),
},
{
func(_ *rand.Rand) int {
var v int
ap.GetOrGenerate(cdc, OpWeightSubmitVotingSlashingRewardWeightUpdateProposal, &v, nil,
func(_ *rand.Rand) {
v = 5
})
return v
}(nil),
govsim.SimulateSubmittingVotingAndSlashingForProposal(app.govKeeper, treasurysim.SimulateRewardWeightUpdateProposalContent(app.treasuryKeeper)),
},
{
func(_ *rand.Rand) int {
var v int
ap.GetOrGenerate(cdc, OpWeightMsgDeposit, &v, nil,
func(_ *rand.Rand) {
v = 100
})
return v
}(nil),
govsim.SimulateMsgDeposit(app.govKeeper),
},
{
func(_ *rand.Rand) int {
var v int
Expand Down
Loading

0 comments on commit c276f99

Please sign in to comment.