diff --git a/Gopkg.lock b/Gopkg.lock index d51165233fbd..e6f15683550e 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -34,11 +34,11 @@ [[projects]] branch = "master" - digest = "1:6aabc1566d6351115d561d038da82a4c19b46c3b6e17f4a0a2fa60260663dc79" + digest = "1:2c00f064ba355903866cbfbf3f7f4c0fe64af6638cc7d1b8bdcf3181bc67f1d8" name = "github.com/btcsuite/btcd" packages = ["btcec"] pruneopts = "UT" - revision = "9a2f9524024889e129a5422aca2cff73cb3eabf6" + revision = "fdfc19097e7ac6b57035062056f5b7b4638b8898" [[projects]] digest = "1:386de157f7d19259a7f9c81f26ce011223ce0f090353c1152ffdf730d7d10ac2" @@ -71,7 +71,7 @@ version = "v1.4.7" [[projects]] - digest = "1:fa30c0652956e159cdb97dcb2ef8b8db63ed668c02a5c3a40961c8f0641252fe" + digest = "1:fdf5169073fb0ad6dc12a70c249145e30f4058647bea25f0abd48b6d9f228a11" name = "github.com/go-kit/kit" packages = [ "log", @@ -103,7 +103,7 @@ version = "v1.7.0" [[projects]] - digest = "1:212285efb97b9ec2e20550d81f0446cb7897e57cbdfd7301b1363ab113d8be45" + digest = "1:35621fe20f140f05a0c4ef662c26c0ab4ee50bca78aa30fe87d33120bd28165e" name = "github.com/gogo/protobuf" packages = [ "gogoproto", @@ -118,7 +118,7 @@ version = "v1.1.1" [[projects]] - digest = "1:cb22af0ed7c72d495d8be1106233ee553898950f15fd3f5404406d44c2e86888" + digest = "1:17fe264ee908afc795734e8c4e63db2accabaf57326dbf21763a7d6b86096260" name = "github.com/golang/protobuf" packages = [ "proto", @@ -165,13 +165,12 @@ [[projects]] branch = "master" - digest = "1:ac64f01acc5eeea9dde40e326de6b6471e501392ec06524c3b51033aa50789bc" + digest = "1:12247a2e99a060cc692f6680e5272c8adf0b8f572e6bce0d7095e624c958a240" name = "github.com/hashicorp/hcl" packages = [ ".", "hcl/ast", "hcl/parser", - "hcl/printer", "hcl/scanner", "hcl/strconv", "hcl/token", @@ -232,11 +231,11 @@ [[projects]] branch = "master" - digest = "1:5ab79470a1d0fb19b041a624415612f8236b3c06070161a910562f2b2d064355" + digest = "1:e730597b38a4d56e2361e0b6236cb800e52c73cace2ff91396f4ff35792ddfa7" name = "github.com/mitchellh/mapstructure" packages = ["."] pruneopts = "UT" - revision = "f15292f7a699fcc1a38a80977f80a046874ba8ac" + revision = "bb74f1db0675b241733089d5a1faa5dd8b0ef57b" [[projects]] digest = "1:95741de3af260a92cc5c7f3f3061e85273f5a81b5db20d4bd68da74bd521675e" @@ -263,7 +262,7 @@ version = "v1.0.0" [[projects]] - digest = "1:98225904b7abff96c052b669b25788f18225a36673fba022fb93514bb9a2a64e" + digest = "1:c1a04665f9613e082e1209cf288bf64f4068dcd6c87a64bf1c4ff006ad422ba0" name = "github.com/prometheus/client_golang" packages = [ "prometheus", @@ -274,15 +273,15 @@ [[projects]] branch = "master" - digest = "1:0f37e09b3e92aaeda5991581311f8dbf38944b36a3edec61cc2d1991f527554a" + digest = "1:32d10bdfa8f09ecf13598324dba86ab891f11db3c538b6a34d1c3b5b99d7c36b" name = "github.com/prometheus/client_model" packages = ["go"] pruneopts = "UT" - revision = "5c3871d89910bfb32f5fcab2aa4b9ec68e65a99f" + revision = "99fa1f4be8e564e8a6b613da7fa6f46c9edafc6c" [[projects]] branch = "master" - digest = "1:4d291d51042ed9de40eef61a3c1b56e969d6e0f8aa5fd3da5e958ec66bee68e4" + digest = "1:e469cd65badf7694aeb44874518606d93c1d59e7735d3754ad442782437d3cc3" name = "github.com/prometheus/common" packages = [ "expfmt", @@ -294,7 +293,7 @@ [[projects]] branch = "master" - digest = "1:55d7449d6987dabf272b4e81b2f9c449f05b17415c939b68d1e82f57e3374b7f" + digest = "1:20d9bb50dbee172242f9bcd6ec24a917dd7a5bb17421bf16a79c33111dea7db1" name = "github.com/prometheus/procfs" packages = [ ".", @@ -313,7 +312,7 @@ revision = "e2704e165165ec55d062f5919b4b29494e9fa790" [[projects]] - digest = "1:37ace7f35375adec11634126944bdc45a673415e2fcc07382d03b75ec76ea94c" + digest = "1:bd1ae00087d17c5a748660b8e89e1043e1e5479d0fea743352cda2f8dd8c4f84" name = "github.com/spf13/afero" packages = [ ".", @@ -332,7 +331,7 @@ version = "v1.2.0" [[projects]] - digest = "1:627ab2f549a6a55c44f46fa24a4307f4d0da81bfc7934ed0473bf38b24051d26" + digest = "1:7ffc0983035bc7e297da3688d9fe19d60a420e9c38bef23f845c53788ed6a05e" name = "github.com/spf13/cobra" packages = ["."] pruneopts = "UT" @@ -364,7 +363,7 @@ version = "v1.0.0" [[projects]] - digest = "1:73697231b93fb74a73ebd8384b68b9a60c57ea6b13c56d2425414566a72c8e6d" + digest = "1:7e8d267900c7fa7f35129a2a37596e38ed0f11ca746d6d9ba727980ee138f9f6" name = "github.com/stretchr/testify" packages = [ "assert", @@ -376,7 +375,7 @@ [[projects]] branch = "master" - digest = "1:922191411ad8f61bcd8018ac127589bb489712c1d1a0ab2497aca4b16de417d2" + digest = "1:b3cfb8d82b1601a846417c3f31c03a7961862cb2c98dcf0959c473843e6d9a2b" name = "github.com/syndtr/goleveldb" packages = [ "leveldb", @@ -397,7 +396,7 @@ [[projects]] branch = "master" - digest = "1:203b409c21115233a576f99e8f13d8e07ad82b25500491f7e1cca12588fb3232" + digest = "1:087aaa7920e5d0bf79586feb57ce01c35c830396ab4392798112e8aae8c47722" name = "github.com/tendermint/ed25519" packages = [ ".", @@ -424,7 +423,7 @@ version = "v0.9.2" [[projects]] - digest = "1:049c779b867a182cea567c65d7c81e3b9e4e4a7eece4c35a19639f75d2aa7da9" + digest = "1:e10e95fd9f0a3a31686c9696f8995f6c04b0bc1b4ed0562a4f53cddc0b89d059" name = "github.com/tendermint/tendermint" packages = [ "abci/client", @@ -499,7 +498,7 @@ [[projects]] branch = "master" - digest = "1:e8206c1653e050116ec8c9a823a86413fc9f9ee3c2f3ae977c96d6a1747f7325" + digest = "1:65a21a9e051d54eb6a3f70c659a765f706a998d9287c302269f4ed8054b2a852" name = "golang.org/x/crypto" packages = [ "blowfish", @@ -515,10 +514,10 @@ "salsa20/salsa", ] pruneopts = "UT" - revision = "c126467f60eb25f8f27e5a981f32a87e3965053f" + revision = "a49355c7e3f8fe157a85be2f77e6e269a0f89602" [[projects]] - digest = "1:04dda8391c3e2397daf254ac68003f30141c069b228d06baec8324a5f81dc1e9" + digest = "1:d36f55a999540d29b6ea3c2ea29d71c76b1d9853fdcd3e5c5cb4836f2ba118f1" name = "golang.org/x/net" packages = [ "context", @@ -539,10 +538,10 @@ name = "golang.org/x/sys" packages = ["unix"] pruneopts = "UT" - revision = "ac767d655b305d4e9612f5f6e33120b9176c4ad4" + revision = "1b2967e3c290b7c545b3db0deeda16e9be4f98a2" [[projects]] - digest = "1:7509ba4347d1f8de6ae9be8818b0cd1abc3deeffe28aeaf4be6d4b6b5178d9ca" + digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18" name = "golang.org/x/text" packages = [ "collate", @@ -570,10 +569,10 @@ name = "google.golang.org/genproto" packages = ["googleapis/rpc/status"] pruneopts = "UT" - revision = "02b4e95473316948020af0b7a4f0f22c73929b0e" + revision = "e92b116572682a5b432ddd840aeaba2a559eeff1" [[projects]] - digest = "1:4515e3030c440845b046354fd5d57671238428b820deebce2e9dabb5cd3c51ac" + digest = "1:2dab32a43451e320e49608ff4542fdfc653c95dcc35d0065ec9c6c3dd540ed74" name = "google.golang.org/grpc" packages = [ ".", diff --git a/PENDING.md b/PENDING.md index ec7941b86fa9..d1b1fbef5225 100644 --- a/PENDING.md +++ b/PENDING.md @@ -24,6 +24,7 @@ BREAKING CHANGES * `gaiacli gov deposit --depositer` * `gaiacli gov vote --voter` * [x/gov] Added tags sub-package, changed tags to use dash-case +* [x/gov] Governance parameters are now stored in globalparams store FEATURES * [lcd] Can now query governance proposals by ProposalStatus @@ -47,6 +48,7 @@ IMPROVEMENTS * [x/bank] Unit tests are now table-driven * [tests] Fixes ansible scripts to work with AWS too * [tests] \#1806 CLI tests are now behind the build flag 'cli_test', so go test works on a new repo +* [x/gov] Initial governance parameters can now be set in the genesis file BUG FIXES * \#1666 Add intra-tx counter to the genesis validators @@ -55,4 +57,4 @@ BUG FIXES * \#1766 Fixes bad example for keybase identity * \#1804 Fixes gen-tx genesis generation logic temporarily until upstream updates * \#1799 Fix `gaiad export` -* \#1828 Force user to specify amount on create-validator command by removing default \ No newline at end of file +* \#1828 Force user to specify amount on create-validator command by removing default diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index 837ce5a1064f..3181356579aa 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -91,7 +91,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio app.ibcMapper = ibc.NewMapper(app.cdc, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace)) app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams) app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.coinKeeper, app.RegisterCodespace(stake.DefaultCodespace)) - app.govKeeper = gov.NewKeeper(app.cdc, app.keyGov, app.coinKeeper, app.stakeKeeper, app.RegisterCodespace(gov.DefaultCodespace)) + app.govKeeper = gov.NewKeeper(app.cdc, app.keyGov, app.paramsKeeper.Setter(), app.coinKeeper, app.stakeKeeper, app.RegisterCodespace(gov.DefaultCodespace)) app.feeCollectionKeeper = auth.NewFeeCollectionKeeper(app.cdc, app.keyFeeCollection) app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.paramsKeeper.Getter(), app.RegisterCodespace(slashing.DefaultCodespace)) diff --git a/x/gov/genesis.go b/x/gov/genesis.go index 40218ca8689c..950f3c9ef96d 100644 --- a/x/gov/genesis.go +++ b/x/gov/genesis.go @@ -6,12 +6,18 @@ import ( // GenesisState - all staking state that must be provided at genesis type GenesisState struct { - StartingProposalID int64 `json:"starting_proposalID"` + StartingProposalID int64 `json:"starting_proposalID"` + DepositProcedure DepositProcedure `json:"deposit_period"` + VotingProcedure VotingProcedure `json:"voting_period"` + TallyingProcedure TallyingProcedure `json:"tallying_procedure"` } -func NewGenesisState(startingProposalID int64) GenesisState { +func NewGenesisState(startingProposalID int64, dp DepositProcedure, vp VotingProcedure, tp TallyingProcedure) GenesisState { return GenesisState{ StartingProposalID: startingProposalID, + DepositProcedure: dp, + VotingProcedure: vp, + TallyingProcedure: tp, } } @@ -19,6 +25,18 @@ func NewGenesisState(startingProposalID int64) GenesisState { func DefaultGenesisState() GenesisState { return GenesisState{ StartingProposalID: 1, + DepositProcedure: DepositProcedure{ + MinDeposit: sdk.Coins{sdk.NewCoin("steak", 10)}, + MaxDepositPeriod: 200, + }, + VotingProcedure: VotingProcedure{ + VotingPeriod: 200, + }, + TallyingProcedure: TallyingProcedure{ + Threshold: sdk.NewRat(1, 2), + Veto: sdk.NewRat(1, 3), + GovernancePenalty: sdk.NewRat(1, 100), + }, } } @@ -29,13 +47,22 @@ func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState) { // TODO: Handle this with #870 panic(err) } + k.setDepositProcedure(ctx, data.DepositProcedure) + k.setVotingProcedure(ctx, data.VotingProcedure) + k.setTallyingProcedure(ctx, data.TallyingProcedure) } // WriteGenesis - output genesis parameters func WriteGenesis(ctx sdk.Context, k Keeper) GenesisState { - initalProposalID, _ := k.getNewProposalID(ctx) + startingProposalID, _ := k.getNewProposalID(ctx) + depositProcedure := k.GetDepositProcedure(ctx) + votingProcedure := k.GetVotingProcedure(ctx) + tallyingProcedure := k.GetTallyingProcedure(ctx) return GenesisState{ - initalProposalID, + StartingProposalID: startingProposalID, + DepositProcedure: depositProcedure, + VotingProcedure: votingProcedure, + TallyingProcedure: tallyingProcedure, } } diff --git a/x/gov/handler.go b/x/gov/handler.go index 04a68ccbbb8b..58e062d0d147 100644 --- a/x/gov/handler.go +++ b/x/gov/handler.go @@ -118,7 +118,7 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags, nonVotingVals activeProposal := keeper.ActiveProposalQueuePop(ctx) proposalStartBlock := activeProposal.GetVotingStartBlock() - votingPeriod := keeper.GetVotingProcedure().VotingPeriod + votingPeriod := keeper.GetVotingProcedure(ctx).VotingPeriod if ctx.BlockHeight() < proposalStartBlock+votingPeriod { continue } @@ -144,7 +144,7 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags, nonVotingVals return resTags, nonVotingVals } func shouldPopInactiveProposalQueue(ctx sdk.Context, keeper Keeper) bool { - depositProcedure := keeper.GetDepositProcedure() + depositProcedure := keeper.GetDepositProcedure(ctx) peekProposal := keeper.InactiveProposalQueuePeek(ctx) if peekProposal == nil { @@ -158,7 +158,7 @@ func shouldPopInactiveProposalQueue(ctx sdk.Context, keeper Keeper) bool { } func shouldPopActiveProposalQueue(ctx sdk.Context, keeper Keeper) bool { - votingProcedure := keeper.GetVotingProcedure() + votingProcedure := keeper.GetVotingProcedure(ctx) peekProposal := keeper.ActiveProposalQueuePeek(ctx) if peekProposal == nil { diff --git a/x/gov/keeper.go b/x/gov/keeper.go index 572c5388eb10..4f49cac582c6 100644 --- a/x/gov/keeper.go +++ b/x/gov/keeper.go @@ -4,10 +4,21 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" wire "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/bank" + "github.com/cosmos/cosmos-sdk/x/params" +) + +// nolint +const ( + ParamStoreKeyDepositProcedure = "gov/depositprocedure" + ParamStoreKeyVotingProcedure = "gov/votingprocedure" + ParamStoreKeyTallyingProcedure = "gov/tallyingprocedure" ) // Governance Keeper type Keeper struct { + // The reference to the ParamSetter to get and set Global Params + ps params.Setter + // The reference to the CoinKeeper to modify balances ck bank.Keeper @@ -28,9 +39,10 @@ type Keeper struct { } // NewGovernanceMapper returns a mapper that uses go-wire to (binary) encode and decode gov types. -func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ck bank.Keeper, ds sdk.DelegationSet, codespace sdk.CodespaceType) Keeper { +func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ps params.Setter, ck bank.Keeper, ds sdk.DelegationSet, codespace sdk.CodespaceType) Keeper { return Keeper{ storeKey: key, + ps: ps, ck: ck, ds: ds, vs: ds.GetValidatorSet(), @@ -128,34 +140,37 @@ func (keeper Keeper) activateVotingPeriod(ctx sdk.Context, proposal Proposal) { // ===================================================== // Procedures -var ( - defaultMinDeposit int64 = 10 - defaultMaxDepositPeriod int64 = 10000 - defaultVotingPeriod int64 = 10000 -) +// Returns the current Deposit Procedure from the global param store +func (keeper Keeper) GetDepositProcedure(ctx sdk.Context) DepositProcedure { + var depositProcedure DepositProcedure + keeper.ps.Get(ctx, ParamStoreKeyDepositProcedure, &depositProcedure) + return depositProcedure +} -// Gets procedure from store. TODO: move to global param store and allow for updating of this -func (keeper Keeper) GetDepositProcedure() DepositProcedure { - return DepositProcedure{ - MinDeposit: sdk.Coins{sdk.NewCoin("steak", defaultMinDeposit)}, - MaxDepositPeriod: defaultMaxDepositPeriod, - } +// Returns the current Voting Procedure from the global param store +func (keeper Keeper) GetVotingProcedure(ctx sdk.Context) VotingProcedure { + var votingProcedure VotingProcedure + keeper.ps.Get(ctx, ParamStoreKeyVotingProcedure, &votingProcedure) + return votingProcedure } -// Gets procedure from store. TODO: move to global param store and allow for updating of this -func (keeper Keeper) GetVotingProcedure() VotingProcedure { - return VotingProcedure{ - VotingPeriod: defaultVotingPeriod, - } +// Returns the current Tallying Procedure from the global param store +func (keeper Keeper) GetTallyingProcedure(ctx sdk.Context) TallyingProcedure { + var tallyingProcedure TallyingProcedure + keeper.ps.Get(ctx, ParamStoreKeyTallyingProcedure, &tallyingProcedure) + return tallyingProcedure } -// Gets procedure from store. TODO: move to global param store and allow for updating of this -func (keeper Keeper) GetTallyingProcedure() TallyingProcedure { - return TallyingProcedure{ - Threshold: sdk.NewRat(1, 2), - Veto: sdk.NewRat(1, 3), - GovernancePenalty: sdk.NewRat(1, 100), - } +func (keeper Keeper) setDepositProcedure(ctx sdk.Context, depositProcedure DepositProcedure) { + keeper.ps.Set(ctx, ParamStoreKeyDepositProcedure, &depositProcedure) +} + +func (keeper Keeper) setVotingProcedure(ctx sdk.Context, votingProcedure VotingProcedure) { + keeper.ps.Set(ctx, ParamStoreKeyVotingProcedure, &votingProcedure) +} + +func (keeper Keeper) setTallyingProcedure(ctx sdk.Context, tallyingProcedure TallyingProcedure) { + keeper.ps.Set(ctx, ParamStoreKeyTallyingProcedure, &tallyingProcedure) } // ===================================================== @@ -262,7 +277,7 @@ func (keeper Keeper) AddDeposit(ctx sdk.Context, proposalID int64, depositerAddr // Check if deposit tipped proposal into voting period // Active voting period if so activatedVotingPeriod := false - if proposal.GetStatus() == StatusDepositPeriod && proposal.GetTotalDeposit().IsGTE(keeper.GetDepositProcedure().MinDeposit) { + if proposal.GetStatus() == StatusDepositPeriod && proposal.GetTotalDeposit().IsGTE(keeper.GetDepositProcedure(ctx).MinDeposit) { keeper.activateVotingPeriod(ctx, proposal) activatedVotingPeriod = true } diff --git a/x/gov/keeper_test.go b/x/gov/keeper_test.go index 988a8a6a7e05..786953fd3aa5 100644 --- a/x/gov/keeper_test.go +++ b/x/gov/keeper_test.go @@ -10,13 +10,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// overwrite defaults for testing -func init() { - defaultMinDeposit = 10 - defaultMaxDepositPeriod = 200 - defaultVotingPeriod = 200 -} - func TestGetSetProposal(t *testing.T) { mapp, keeper, _, _, _, _ := getMockApp(t, 0) mapp.BeginBlock(abci.RequestBeginBlock{}) diff --git a/x/gov/tally.go b/x/gov/tally.go index 2d8e85f7b2c6..4246b244d21e 100644 --- a/x/gov/tally.go +++ b/x/gov/tally.go @@ -81,7 +81,7 @@ func tally(ctx sdk.Context, keeper Keeper, proposal Proposal) (passes bool, nonV totalVotingPower = totalVotingPower.Add(votingPower) } - tallyingProcedure := keeper.GetTallyingProcedure() + tallyingProcedure := keeper.GetTallyingProcedure(ctx) // If no one votes, proposal fails if totalVotingPower.Sub(results[OptionAbstain]).Equal(sdk.ZeroRat()) { diff --git a/x/gov/test_common.go b/x/gov/test_common.go index 7ea85fc72db6..6c418f683887 100644 --- a/x/gov/test_common.go +++ b/x/gov/test_common.go @@ -6,6 +6,8 @@ import ( "sort" "testing" + "github.com/cosmos/cosmos-sdk/x/params" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -24,15 +26,17 @@ func getMockApp(t *testing.T, numGenAccs int) (*mock.App, Keeper, stake.Keeper, stake.RegisterWire(mapp.Cdc) RegisterWire(mapp.Cdc) + keyGlobalParams := sdk.NewKVStoreKey("params") keyStake := sdk.NewKVStoreKey("stake") keyGov := sdk.NewKVStoreKey("gov") + pk := params.NewKeeper(mapp.Cdc, keyGlobalParams) ck := bank.NewKeeper(mapp.AccountMapper) sk := stake.NewKeeper(mapp.Cdc, keyStake, ck, mapp.RegisterCodespace(stake.DefaultCodespace)) - keeper := NewKeeper(mapp.Cdc, keyGov, ck, sk, DefaultCodespace) + keeper := NewKeeper(mapp.Cdc, keyGov, pk.Setter(), ck, sk, DefaultCodespace) mapp.Router().AddRoute("gov", NewHandler(keeper)) - require.NoError(t, mapp.CompleteSetup([]*sdk.KVStoreKey{keyStake, keyGov})) + require.NoError(t, mapp.CompleteSetup([]*sdk.KVStoreKey{keyStake, keyGov, keyGlobalParams})) mapp.SetEndBlocker(getEndBlocker(keeper)) mapp.SetInitChainer(getInitChainer(mapp, keeper, sk))