Skip to content

Commit

Permalink
Merge PR cosmos#4206: Param Change Proposal
Browse files Browse the repository at this point in the history
* Add params error types

* Update param module keeper to take a codespace

* Update imports

* Implement SetRaw and SetRawWithSubkey

* Implement ParamChange and update aliases

* Add types codec

* Implement ParameterChangeProposal

* Implement TestParameterChangeProposal

* Fix linting errors

* Update tags

* Implement content

* Updata params aliases

* Finish params handler and proposal types

* Move deposit and vote logic to types package

* Move proposal type to types package

* Move errors to types package

* Update proposal

* Move gov messages to types package

* Minor updates to naming

* Move keys to types package

* Move codec to types package

* Move proposal types to types package

* Update aliases

* Add governance alias types

* Implement governance router

* Update gov aliases

* Update gov keeper

* Update private functions needed for the keeper

* Update godocs

* Update the gov message handler

* Update Gaia app

* Make updates to auth

* Update the message codec in the keeper

* Update gov end blocker

* Update types tests

* Minor tweaks

* Add legacy genesis logic

* Update gov aliases

* Move gov keys to types package

* Revertt to using gov/types in params

* Implement params handler test

* Update governance tests

* Fix endblocker tests

* Fix governance querier tests

* Add seal support to gov router

* Update simulationCreateMsgSubmitProposal

* Disable software upgrade proposals

* Move params keys to types package

* Implement param module proposal client logic

* Update gov client logic

* Update gaia app client hooks

* Fix linting errors

* Fix ValidateBasic

* Remove legacy files

* Update paramchange to use strings

* Update paramchange cli cmd

* Update ValidateBasic and errors

* Use PostCommands when adding child cmds

* Fix codec logic

* Update params client and handler

* Update IsValidProposalType

* Update SubmitProposal to test exec

* Implement TestGaiaCLISubmitParamChangeProposal

* Implement TestSubmitParamChangeProposal

* Update swagger.yaml

* Update gaiacli.md

* Update gov spec docs

* Fix linting errors

* Fix unit tests

* Add pending log entries

* Update docs

* Update docs

* Update client/lcd/swagger-ui/swagger.yaml

Co-Authored-By: alexanderbez <[email protected]>

* Update docs/cosmos-hub/gaiacli.md

Co-Authored-By: alexanderbez <[email protected]>

* Update cmd/gaia/cli_test/test_helpers.go

Co-Authored-By: alexanderbez <[email protected]>

* Update client/lcd/test_helpers.go

Co-Authored-By: alexanderbez <[email protected]>

* Update docs/cosmos-hub/gaiacli.md

Co-Authored-By: alexanderbez <[email protected]>

* Update docs/cosmos-hub/gaiacli.md

Co-Authored-By: alexanderbez <[email protected]>

* Update docs/cosmos-hub/gaiacli.md

Co-Authored-By: alexanderbez <[email protected]>

* Update x/gov/types/proposal.go

Co-Authored-By: alexanderbez <[email protected]>

* Update docs/cosmos-hub/gaiacli.md

Co-Authored-By: alexanderbez <[email protected]>

* Update docs/cosmos-hub/gaiacli.md

Co-Authored-By: alexanderbez <[email protected]>

* Address PR comments

* Update docs/cosmos-hub/gaiacli.md

Co-Authored-By: alexanderbez <[email protected]>

* Update gov docs to include quorum notes

* Add logs to handleParameterChangeProposal

* Update docs/spec/governance/02_state.md

Co-Authored-By: alexanderbez <[email protected]>

* Support and use new StatusFailed when proposal passes but fails exec

* Add docs/notes warning on param validity

* Update docs

* Update docs/spec/governance/02_state.md

Co-Authored-By: alexanderbez <[email protected]>

* Update docs/spec/governance/02_state.md

Co-Authored-By: alexanderbez <[email protected]>

* Minor doc update

* Update x/gov/client/cli/tx.go

Co-Authored-By: alexanderbez <[email protected]>

* Fix usage of fromAddr

* Rige code style  suggestion

* Update x/params/types/proposal.go

Co-Authored-By: alexanderbez <[email protected]>

* Fix CI lint errors

* Update NewModuleClient godoc

* Add godoc to rtr.Seal() call

* Rename files

* Rename NewProposalHandler
  • Loading branch information
alexanderbez authored and rigelrozanski committed Apr 30, 2019
1 parent 1306a25 commit 5ca93ac
Show file tree
Hide file tree
Showing 74 changed files with 2,806 additions and 1,405 deletions.
4 changes: 4 additions & 0 deletions .pending/breaking/sdk/3565-Updates-to-the-governance-module
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#3565 Updates to the governance module:
* Rename JSON field from `proposal_content` to `content`
* Rename JSON field from `proposal_id` to `id`
* Disable `ProposalTypeSoftwareUpgrade` temporarily
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#3565 Implement parameter change proposal support.
Parameter change proposals can be submitted through the CLI
or a REST endpoint. See docs for further usage.
37 changes: 37 additions & 0 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,43 @@ func TestSubmitProposal(t *testing.T) {
require.Equal(t, proposalID, proposer.ProposalID)
}

func TestSubmitParamChangeProposal(t *testing.T) {
kb, err := keys.NewKeyBaseFromDir(InitClientHome(t, ""))
require.NoError(t, err)
addr, seed := CreateAddr(t, name1, pw, kb)
cleanup, _, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr}, true)
defer cleanup()

acc := getAccount(t, port, addr)
initialBalance := acc.GetCoins()

// create proposal tx
proposalTokens := sdk.TokensFromTendermintPower(5)
resultTx := doSubmitParamChangeProposal(t, port, seed, name1, pw, addr, proposalTokens, fees)
tests.WaitForHeight(resultTx.Height+1, port)

// check if tx was committed
require.Equal(t, uint32(0), resultTx.Code)

var proposalID uint64
bz, err := hex.DecodeString(resultTx.Data)
require.NoError(t, err)
cdc.MustUnmarshalBinaryLengthPrefixed(bz, &proposalID)

// verify balance
acc = getAccount(t, port, addr)
expectedBalance := initialBalance[0].Sub(fees[0])
require.Equal(t, expectedBalance.Amount.Sub(proposalTokens), acc.GetCoins().AmountOf(sdk.DefaultBondDenom))

// query proposal
proposal := getProposal(t, port, proposalID)
require.Equal(t, "Test", proposal.GetTitle())

proposer := getProposer(t, port, proposalID)
require.Equal(t, addr.String(), proposer.Proposer)
require.Equal(t, proposalID, proposer.ProposalID)
}

func TestDeposit(t *testing.T) {
kb, err := keys.NewKeyBaseFromDir(InitClientHome(t, ""))
require.NoError(t, err)
Expand Down
57 changes: 57 additions & 0 deletions client/lcd/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,49 @@ paths:
description: Invalid query parameters
500:
description: Internal Server Error
/gov/proposals/param_change:
post:
summary: Generate a parameter change proposal transaction
description: Generate a parameter change proposal transaction
consumes:
- application/json
produces:
- application/json
tags:
- ICS22
parameters:
- description: The parameter change proposal body that contains all parameter changes
name: post_proposal_body
in: body
required: true
schema:
type: object
properties:
base_req:
$ref: "#/definitions/BaseReq"
title:
type: string
description:
type: string
proposer:
$ref: "#/definitions/Address"
deposit:
type: array
items:
$ref: "#/definitions/Coin"
changes:
type: array
items:
$ref: "#/definitions/ParamChange"
responses:
200:
description: The transaction was succesfully generated
schema:
$ref: "#/definitions/StdTx"
400:
description: Invalid proposal body
500:
description: Internal Server Error
/gov/proposals/{proposalId}:
get:
summary: Query a proposal
Expand Down Expand Up @@ -2367,3 +2410,17 @@ definitions:
type: string
missed_blocks_counter:
type: string
ParamChange:
type: object
subspace:
type: string
description: The parameter module subspace
key:
type: string
description: The parameter key
subkey:
type: string
description: An optional parameter subkey
value:
type: string
description: The new parameter value
48 changes: 45 additions & 3 deletions client/lcd/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"bytes"
"encoding/json"
"fmt"
"regexp"

"io/ioutil"
"net"
"net/http"
"os"
"path/filepath"
"regexp"
"sort"
"strings"
"testing"
Expand All @@ -22,6 +21,7 @@ import (
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/utils"
"github.com/cosmos/cosmos-sdk/crypto/keys"
"github.com/cosmos/cosmos-sdk/x/params"

"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/client/tx"
Expand All @@ -43,6 +43,8 @@ import (
govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
gcutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
mintrest "github.com/cosmos/cosmos-sdk/x/mint/client/rest"
paramsrest "github.com/cosmos/cosmos-sdk/x/params/client/rest"
paramscutils "github.com/cosmos/cosmos-sdk/x/params/client/utils"
"github.com/cosmos/cosmos-sdk/x/slashing"
slashingrest "github.com/cosmos/cosmos-sdk/x/slashing/client/rest"
"github.com/cosmos/cosmos-sdk/x/staking"
Expand Down Expand Up @@ -411,7 +413,7 @@ func registerRoutes(rs *RestServer) {
distrrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, distr.StoreKey)
stakingrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
slashingrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
govrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
govrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, paramsrest.ProposalRESTHandler(rs.CliCtx, rs.Cdc))
mintrest.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
}

Expand Down Expand Up @@ -1151,6 +1153,46 @@ func doSubmitProposal(
return txResp
}

func doSubmitParamChangeProposal(
t *testing.T, port, seed, name, pwd string, proposerAddr sdk.AccAddress,
amount sdk.Int, fees sdk.Coins,
) sdk.TxResponse {

acc := getAccount(t, port, proposerAddr)
accnum := acc.GetAccountNumber()
sequence := acc.GetSequence()
chainID := viper.GetString(client.FlagChainID)
from := acc.GetAddress().String()

baseReq := rest.NewBaseReq(from, "", chainID, "", "", accnum, sequence, fees, nil, false)
pr := paramscutils.ParamChangeProposalReq{
BaseReq: baseReq,
Title: "Test",
Description: "test",
Proposer: proposerAddr,
Deposit: sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, amount)},
Changes: []params.ParamChange{
params.NewParamChange("staking", "MaxValidators", "", "105"),
},
}

req, err := cdc.MarshalJSON(pr)
require.NoError(t, err)

resp, body := Request(t, port, "POST", "/gov/proposals/param_change", req)
fmt.Println(resp)
require.Equal(t, http.StatusOK, resp.StatusCode, body)

resp, body = signAndBroadcastGenTx(t, port, name, pwd, body, acc, client.DefaultGasAdjustment, false)
require.Equal(t, http.StatusOK, resp.StatusCode, body)

var txResp sdk.TxResponse
err = cdc.UnmarshalJSON([]byte(body), &txResp)
require.NoError(t, err)

return txResp
}

// GET /gov/proposals Query proposals
func getProposalsAll(t *testing.T, port string) []gov.Proposal {
res, body := Request(t, port, "GET", "/gov/proposals", nil)
Expand Down
19 changes: 13 additions & 6 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ import (
"os"
"sort"

abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"

bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -23,6 +18,11 @@ import (
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"

abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
)

const (
Expand Down Expand Up @@ -97,7 +97,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
tkeyParams: sdk.NewTransientStoreKey(params.TStoreKey),
}

app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams)
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams, params.DefaultCodespace)

// define the accountKeeper
app.accountKeeper = auth.NewAccountKeeper(
Expand Down Expand Up @@ -140,11 +140,17 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest b
&stakingKeeper, app.paramsKeeper.Subspace(slashing.DefaultParamspace),
slashing.DefaultCodespace,
)

govRouter := gov.NewRouter()
govRouter.AddRoute(gov.RouterKey, gov.ProposalHandler).
AddRoute(params.RouterKey, params.NewParamChangeProposalHandler(app.paramsKeeper))

app.govKeeper = gov.NewKeeper(
app.cdc,
app.keyGov,
app.paramsKeeper, app.paramsKeeper.Subspace(gov.DefaultParamspace), app.bankKeeper, &stakingKeeper,
gov.DefaultCodespace,
govRouter,
)
app.crisisKeeper = crisis.NewKeeper(
app.paramsKeeper.Subspace(crisis.DefaultParamspace),
Expand Down Expand Up @@ -209,6 +215,7 @@ func MakeCodec() *codec.Codec {
staking.RegisterCodec(cdc)
distr.RegisterCodec(cdc)
slashing.RegisterCodec(cdc)
params.RegisterCodec(cdc)
gov.RegisterCodec(cdc)
auth.RegisterCodec(cdc)
crisis.RegisterCodec(cdc)
Expand Down
61 changes: 61 additions & 0 deletions cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,67 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
f.Cleanup()
}

func TestGaiaCLISubmitParamChangeProposal(t *testing.T) {
t.Parallel()
f := InitFixtures(t)

proc := f.GDStart()
defer proc.Stop(false)

fooAddr := f.KeyAddress(keyFoo)
fooAcc := f.QueryAccount(fooAddr)
startTokens := sdk.TokensFromTendermintPower(50)
require.Equal(t, startTokens, fooAcc.GetCoins().AmountOf(sdk.DefaultBondDenom))

// write proposal to file
proposalTokens := sdk.TokensFromTendermintPower(5)
proposal := fmt.Sprintf(`{
"title": "Param Change",
"description": "Update max validators",
"changes": [
{
"subspace": "staking",
"key": "MaxValidators",
"value": "105"
}
],
"deposit": [
{
"denom": "stake",
"amount": "%s"
}
]
}
`, proposalTokens.String())

proposalFile := WriteToNewTempFile(t, proposal)

// create the param change proposal
f.TxGovSubmitParamChangeProposal(keyFoo, proposalFile.Name(), sdk.NewCoin(denom, proposalTokens), "-y")
tests.WaitForNextNBlocksTM(1, f.Port)

// ensure transaction tags can be queried
txs := f.QueryTxs(1, 50, "action:submit_proposal", fmt.Sprintf("sender:%s", fooAddr))
require.Len(t, txs, 1)

// ensure deposit was deducted
fooAcc = f.QueryAccount(fooAddr)
require.Equal(t, startTokens.Sub(proposalTokens).String(), fooAcc.GetCoins().AmountOf(sdk.DefaultBondDenom).String())

// ensure proposal is directly queryable
proposal1 := f.QueryGovProposal(1)
require.Equal(t, uint64(1), proposal1.ProposalID)
require.Equal(t, gov.StatusDepositPeriod, proposal1.Status)

// ensure correct query proposals result
proposalsQuery := f.QueryGovProposals()
require.Equal(t, uint64(1), proposalsQuery[0].ProposalID)

// ensure the correct deposit amount on the proposal
deposit := f.QueryGovDeposit(1, fooAddr)
require.Equal(t, proposalTokens, deposit.Amount.AmountOf(denom))
}

func TestGaiaCLIQueryTxPagination(t *testing.T) {
t.Parallel()
f := InitFixtures(t)
Expand Down
14 changes: 14 additions & 0 deletions cmd/gaia/cli_test/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,20 @@ func (f *Fixtures) TxGovVote(proposalID int, option gov.VoteOption, from string,
return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), client.DefaultKeyPass)
}

// TxGovSubmitParamChangeProposal executes a CLI parameter change proposal
// submission.
func (f *Fixtures) TxGovSubmitParamChangeProposal(
from, proposalPath string, deposit sdk.Coin, flags ...string,
) (bool, string, string) {

cmd := fmt.Sprintf(
"%s tx gov submit-proposal param-change %s --from=%s %v",
f.GaiacliBinary, proposalPath, from, f.Flags(),
)

return executeWriteRetStdStreams(f.T, addFlags(cmd, flags), client.DefaultKeyPass)
}

//___________________________________________________________________________________
// gaiacli query account

Expand Down
Loading

0 comments on commit 5ca93ac

Please sign in to comment.