Skip to content

Commit

Permalink
feat(x/gov): validators can only vote with own stake (#20)
Browse files Browse the repository at this point in the history
Change #7 so that validators are allowed to vote, but cannot use
delegations in governance to increase their voting power, they can only
vote with their own stake. This seems more sensible wrt the previous
solution of removing their ability to vote entirely.

This also addresses #19 as I added comments in the README, and also che
changelog should be good. Therefore with this PR we should be able to
also merge the feat branch back into main and close #6
  • Loading branch information
giunatale authored Feb 21, 2024
1 parent 80e9d23 commit f0a1898
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 182 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

* Forked `x/gov` module from Cosmos SDK v0.46.16 for custom modifications
([#4](https://github.com/atomone-hub/govgen/pull/4)).
* Removed ability for validators to vote on proposals
([#10](https://github.com/atomone-hub/govgen/pull/10)).
* Removed ability for validators to vote on proposals with delegations, they can only use their own stake
([#20](https://github.com/atomone-hub/govgen/pull/20)).
* Remove community spend proposal
([#13](https://github.com/atomone-hub/govgen/pull/13)).
* Adapt voting period to proposal type.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ The following modifications have been made to the Cosmos Hub software to create
4. Revert to standard Cosmos SDK v0.46.16 without the Liquid Staking Module (LSM)
5. Changed Bech32 prefixes to `govgen` (see `cmd/govgend/cmd/config.go`)
6. Reduced hard-coded ante min-deposit percentage to 1% (see `ante/gov_ante.go:minInitialDepositFraction`)
7. Removed ability for validators to vote on proposals with delegations, they can only use their own stake
8. Remove community spend proposal
9. Allow selecting different voting periods for different proposal types
4 changes: 2 additions & 2 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func appModules(
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
Expand All @@ -122,7 +122,7 @@ func simulationModules(
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper),
Expand Down
2 changes: 1 addition & 1 deletion x/gov/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
govgenhelpers "github.com/atomone-hub/govgen/app/helpers"
)

func createValidators(t *testing.T, ctx sdk.Context, app *govgenapp.GovGenApp, powers []int64) ([]sdk.AccAddress, []sdk.ValAddress) { //nolint: thelper,unparam
func createValidators(t *testing.T, ctx sdk.Context, app *govgenapp.GovGenApp, powers []int64) ([]sdk.AccAddress, []sdk.ValAddress) { //nolint: thelper
addrs := govgenhelpers.AddTestAddrsIncremental(app, ctx, 5, sdk.NewInt(30000000))
valAddrs := govgenhelpers.ConvertAddrsToValAddrs(addrs)
pks := govgenhelpers.CreateTestPubKeys(5)
Expand Down
13 changes: 1 addition & 12 deletions x/gov/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

govgenhelpers "github.com/atomone-hub/govgen/app/helpers"
"github.com/atomone-hub/govgen/x/gov/types"
Expand Down Expand Up @@ -715,17 +714,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryDeposits() {
func (suite *KeeperTestSuite) TestGRPCQueryTally() {
app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient

_, valAddrs := createValidators(suite.T(), ctx, app, []int64{5, 5, 5})
addrs := govgenhelpers.AddTestAddrs(app, ctx, 3, sdk.NewInt(50000000))

delTokens := app.StakingKeeper.TokensFromConsensusPower(ctx, 5)
val1, found := app.StakingKeeper.GetValidator(ctx, valAddrs[0])
suite.Require().True(found)

for _, addr := range addrs {
_, err := app.StakingKeeper.Delegate(ctx, addr, delTokens, stakingtypes.Unbonded, val1, true)
suite.Require().NoError(err)
}
addrs, _ := createValidators(suite.T(), ctx, app, []int64{5, 5, 5})

var (
req *types.QueryTallyResultRequest
Expand Down
4 changes: 4 additions & 0 deletions x/gov/keeper/tally.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal types.Proposal) (passes boo
return false
})

/* DISABLED on GovGen - Voting can only be done with your own stake
// iterate over the validators again to tally their voting power
for _, val := range currValidators {
if len(val.Vote) == 0 {
Expand All @@ -87,6 +89,8 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal types.Proposal) (passes boo
totalVotingPower = totalVotingPower.Add(votingPower)
}
*/

tallyParams := keeper.GetTallyParams(ctx)
tallyResults = types.NewTallyResultFromMap(results)

Expand Down
Loading

0 comments on commit f0a1898

Please sign in to comment.