Skip to content

Commit

Permalink
chore: x/gov v1 API audit changes (cosmos#11474)
Browse files Browse the repository at this point in the history
## Description

ref: cosmos#11086 

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
likhita-809 authored Apr 5, 2022
1 parent 37a52af commit 210e109
Show file tree
Hide file tree
Showing 27 changed files with 870 additions and 139 deletions.
2 changes: 1 addition & 1 deletion api/cosmos/gov/v1/gov.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/cosmos/gov/v1/query.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/cosmos/gov/v1beta1/gov.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/cosmos/gov/v1beta1/query.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/cosmos/gov/v1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ message Proposal {

// ProposalStatus enumerates the valid statuses of a proposal.
enum ProposalStatus {
// PROPOSAL_STATUS_UNSPECIFIED defines the default propopsal status.
// PROPOSAL_STATUS_UNSPECIFIED defines the default proposal status.
PROPOSAL_STATUS_UNSPECIFIED = 0;
// PROPOSAL_STATUS_DEPOSIT_PERIOD defines a proposal status during the deposit
// period.
Expand Down
2 changes: 1 addition & 1 deletion proto/cosmos/gov/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ message QueryVoteRequest {
// proposal_id defines the unique id of the proposal.
uint64 proposal_id = 1;

// voter defines the oter address for the proposals.
// voter defines the voter address for the proposals.
string voter = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

Expand Down
2 changes: 1 addition & 1 deletion proto/cosmos/gov/v1beta1/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ message Proposal {
enum ProposalStatus {
option (gogoproto.goproto_enum_prefix) = false;

// PROPOSAL_STATUS_UNSPECIFIED defines the default propopsal status.
// PROPOSAL_STATUS_UNSPECIFIED defines the default proposal status.
PROPOSAL_STATUS_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "StatusNil"];
// PROPOSAL_STATUS_DEPOSIT_PERIOD defines a proposal status during the deposit
// period.
Expand Down
2 changes: 1 addition & 1 deletion proto/cosmos/gov/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ message QueryVoteRequest {
// proposal_id defines the unique id of the proposal.
uint64 proposal_id = 1;

// voter defines the oter address for the proposals.
// voter defines the voter address for the proposals.
string voter = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

Expand Down
8 changes: 4 additions & 4 deletions x/gov/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ $ %s query gov proposal 1
return cmd
}

// GetCmdQueryProposals implements a query proposals command. Command to Get a
// Proposal Information.
// GetCmdQueryProposals implements a query proposals command. Command to Get
// Proposals Information.
func GetCmdQueryProposals() *cobra.Command {
cmd := &cobra.Command{
Use: "proposals",
Expand Down Expand Up @@ -179,7 +179,7 @@ $ %s query gov proposals --page=2 --limit=100
}

// GetCmdQueryVote implements the query proposal vote command. Command to Get a
// Proposal Information.
// Vote Information.
func GetCmdQueryVote() *cobra.Command {
cmd := &cobra.Command{
Use: "vote [proposal-id] [voter-addr]",
Expand Down Expand Up @@ -337,7 +337,7 @@ $ %[1]s query gov votes 1 --page=2 --limit=100
}

// GetCmdQueryDeposit implements the query proposal deposit command. Command to
// get a specific Deposit Information
// get a specific Deposit Information.
func GetCmdQueryDeposit() *cobra.Command {
cmd := &cobra.Command{
Use: "deposit [proposal-id] [depositer-addr]",
Expand Down
2 changes: 1 addition & 1 deletion x/gov/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var ProposalFlags = []string{
// NewTxCmd returns the transaction commands for this module
// governance ModuleClient is slightly different from other ModuleClients in that
// it contains a slice of "proposal" child commands. These commands are respective
// to proposal type handlers that are implemented in other modules but are mounted
// to the proposal type handlers that are implemented in other modules but are mounted
// under the governance CLI (eg. parameter change proposals).
func NewTxCmd(legacyPropCmds []*cobra.Command) *cobra.Command {
govTxCmd := &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion x/gov/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (s *IntegrationTestSuite) TestCmdTally() {
func (s *IntegrationTestSuite) TestNewCmdSubmitProposal() {
val := s.network.Validators[0]

// Create an legacy proposal JSON, make sure it doesn't pass this new CLI
// Create a legacy proposal JSON, make sure it doesn't pass this new CLI
// command.
invalidProp := `{
"title": "",
Expand Down
4 changes: 2 additions & 2 deletions x/gov/client/utils/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (p Proposer) String() string {
}

// QueryDepositsByTxQuery will query for deposits via a direct txs tags query. It
// will fetch and build deposits directly from the returned txs and return a
// will fetch and build deposits directly from the returned txs and returns a
// JSON marshalled result or any error that occurred.
//
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
Expand Down Expand Up @@ -103,7 +103,7 @@ func QueryDepositsByTxQuery(clientCtx client.Context, params v1.QueryProposalPar
}

// QueryVotesByTxQuery will query for votes via a direct txs tags query. It
// will fetch and build votes directly from the returned txs and return a JSON
// will fetch and build votes directly from the returned txs and returns a JSON
// marshalled result or any error that occurred.
func QueryVotesByTxQuery(clientCtx client.Context, params v1.QueryProposalVotesParams) ([]byte, error) {
var (
Expand Down
4 changes: 2 additions & 2 deletions x/gov/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (keeper Keeper) DeleteAndBurnDeposits(ctx sdk.Context, proposalID uint64) {
})
}

// IterateAllDeposits iterates over the all the stored deposits and performs a callback function
// IterateAllDeposits iterates over all the stored deposits and performs a callback function
func (keeper Keeper) IterateAllDeposits(ctx sdk.Context, cb func(deposit v1.Deposit) (stop bool)) {
store := ctx.KVStore(keeper.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.DepositsKeyPrefix)
Expand All @@ -91,7 +91,7 @@ func (keeper Keeper) IterateAllDeposits(ctx sdk.Context, cb func(deposit v1.Depo
}
}

// IterateDeposits iterates over the all the proposals deposits and performs a callback function
// IterateDeposits iterates over all the proposals deposits and performs a callback function
func (keeper Keeper) IterateDeposits(ctx sdk.Context, proposalID uint64, cb func(deposit v1.Deposit) (stop bool)) {
store := ctx.KVStore(keeper.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.DepositsKey(proposalID))
Expand Down
6 changes: 3 additions & 3 deletions x/gov/keeper/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
)

// SubmitProposal create new proposal given an array of messages
// SubmitProposal creates a new proposal given an array of messages
func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, metadata string) (v1.Proposal, error) {
err := keeper.assertMetadataLength(metadata)
if err != nil {
Expand Down Expand Up @@ -91,7 +91,7 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, metadat
return proposal, nil
}

// GetProposal get proposal from store by ProposalID.
// GetProposal gets a proposal from store by ProposalID.
// Panics if can't unmarshal the proposal.
func (keeper Keeper) GetProposal(ctx sdk.Context, proposalID uint64) (v1.Proposal, bool) {
store := ctx.KVStore(keeper.storeKey)
Expand All @@ -109,7 +109,7 @@ func (keeper Keeper) GetProposal(ctx sdk.Context, proposalID uint64) (v1.Proposa
return proposal, true
}

// SetProposal set a proposal to store.
// SetProposal sets a proposal to store.
// Panics if can't marshal the proposal.
func (keeper Keeper) SetProposal(ctx sdk.Context, proposal v1.Proposal) {
bz, err := keeper.MarshalProposal(proposal)
Expand Down
2 changes: 1 addition & 1 deletion x/gov/keeper/tally.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal v1.Proposal) (passes bool,

if val, ok := currValidators[valAddrStr]; ok {
// There is no need to handle the special case that validator address equal to voter address.
// Because voter's voting power will tally again even if there will deduct voter's voting power from validator.
// Because voter's voting power will tally again even if there will be deduction of voter's voting power from validator.
val.DelegatorDeductions = val.DelegatorDeductions.Add(delegation.GetShares())
currValidators[valAddrStr] = val

Expand Down
4 changes: 2 additions & 2 deletions x/gov/keeper/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (keeper Keeper) SetVote(ctx sdk.Context, vote v1.Vote) {
store.Set(types.VoteKey(vote.ProposalId, addr), bz)
}

// IterateAllVotes iterates over the all the stored votes and performs a callback function
// IterateAllVotes iterates over all the stored votes and performs a callback function
func (keeper Keeper) IterateAllVotes(ctx sdk.Context, cb func(vote v1.Vote) (stop bool)) {
store := ctx.KVStore(keeper.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.VotesKeyPrefix)
Expand All @@ -104,7 +104,7 @@ func (keeper Keeper) IterateAllVotes(ctx sdk.Context, cb func(vote v1.Vote) (sto
}
}

// IterateVotes iterates over the all the proposals votes and performs a callback function
// IterateVotes iterates over all the proposals votes and performs a callback function
func (keeper Keeper) IterateVotes(ctx sdk.Context, proposalID uint64, cb func(vote v1.Vote) (stop bool)) {
store := ctx.KVStore(keeper.storeKey)
iterator := sdk.KVStorePrefixIterator(store, types.VotesKey(proposalID))
Expand Down
2 changes: 1 addition & 1 deletion x/gov/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

// TestRandomizedGenState tests the normal scenario of applying RandomizedGenState.
// Abonormal scenarios are not tested here.
// Abnormal scenarios are not tested here.
func TestRandomizedGenState(t *testing.T) {
interfaceRegistry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(interfaceRegistry)
Expand Down
8 changes: 4 additions & 4 deletions x/gov/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestWeightedOperations(t *testing.T) {
}

// TestSimulateMsgSubmitProposal tests the normal scenario of a valid message of type TypeMsgSubmitProposal.
// Abnormal scenarios, where the message is created by an errors are not tested here.
// Abnormal scenarios, where errors occur, are not tested here.
func TestSimulateMsgSubmitProposal(t *testing.T) {
app, ctx := createTestApp(t, false)

Expand Down Expand Up @@ -131,7 +131,7 @@ func TestSimulateMsgSubmitProposal(t *testing.T) {
}

// TestSimulateMsgDeposit tests the normal scenario of a valid message of type TypeMsgDeposit.
// Abnormal scenarios, where the message is created by an errors are not tested here.
// Abnormal scenarios, where errors occur, are not tested here.
func TestSimulateMsgDeposit(t *testing.T) {
app, ctx := createTestApp(t, false)
blockTime := time.Now().UTC()
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestSimulateMsgDeposit(t *testing.T) {
}

// TestSimulateMsgVote tests the normal scenario of a valid message of type TypeMsgVote.
// Abnormal scenarios, where the message is created by an errors are not tested here.
// Abnormal scenarios, where errors occur, are not tested here.
func TestSimulateMsgVote(t *testing.T) {
app, ctx := createTestApp(t, false)
blockTime := time.Now().UTC()
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestSimulateMsgVote(t *testing.T) {
}

// TestSimulateMsgVoteWeighted tests the normal scenario of a valid message of type TypeMsgVoteWeighted.
// Abnormal scenarios, where the message is created by an errors are not tested here.
// Abnormal scenarios, where errors occur, are not tested here.
func TestSimulateMsgVoteWeighted(t *testing.T) {
app, ctx := createTestApp(t, false)
blockTime := time.Now().UTC()
Expand Down
4 changes: 2 additions & 2 deletions x/gov/spec/01_concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ according to the final tally of the proposal:
* All refunded or burned deposits are removed from the state. Events are issued when
burning or refunding a deposit.

## Voting
## Vote

### Participants

Expand Down Expand Up @@ -169,7 +169,7 @@ Later, we may add permissioned keys that could only sign txs from certain module
## Software Upgrade

If proposals are of type `SoftwareUpgradeProposal`, then nodes need to upgrade
their software to the new version that was voted. This process is divided in
their software to the new version that was voted. This process is divided into
two steps.

### Signal
Expand Down
6 changes: 3 additions & 3 deletions x/gov/spec/02_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ to discuss and debate the proposal. In most cases, it is encouraged to have an o
system that supports the on-chain governance process. To accommodate for this, a
proposal contains a special `metadata` field, an array of bytes, which can be used to
add context to the proposal. The `metadata` field allows custom use for networks, however,
it is expected that the field contain a URL or some form of CID using a system such as
it is expected that the field contains a URL or some form of CID using a system such as
[IPFS](https://docs.ipfs.io/concepts/content-addressing/). To support the case of
interoperability across networks, the SDK recommends that the `metadata` represents
the following `JSON` template:
Expand Down Expand Up @@ -93,7 +93,7 @@ type ProposalStatus byte


const (
StatusNil ProposalStatus = 0x00
StatusNil ProposalStatus = 0x00
StatusDepositPeriod ProposalStatus = 0x01 // Proposal is submitted. Participants can deposit on it but not vote
StatusVotingPeriod ProposalStatus = 0x02 // MinDeposit is reached, participants can vote
StatusPassed ProposalStatus = 0x03 // Proposal passed and successfully executed
Expand Down Expand Up @@ -177,7 +177,7 @@ And the pseudocode for the `ProposalProcessingQueue`:

tallyingParam = load(GlobalParams, 'TallyingParam')

// Update tally if validator voted they voted
// Update tally if validator voted
for each validator in validators
if tmpValMap(validator).HasVoted
proposal.updateTally(tmpValMap(validator).Vote, (validator.TotalShares - tmpValMap(validator).Minus))
Expand Down
2 changes: 1 addition & 1 deletion x/gov/spec/03_messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ upon receiving txGovDeposit from sender do
// There is no proposal for this proposalID
throw

if (txGovDeposit.Deposit.Atoms <= 0) OR (sender.AtomBalance < txGovDeposit.Deposit.Atoms) OR (proposal.CurrentStatus != ProposalStatusOpen)
if (txGovDeposit.Deposit.Atoms <= 0) OR (sender.AtomBalance < txGovDeposit.Deposit.Atoms) OR (proposal.CurrentStatus != ProposalStatusOpen)

// deposit is negative or null
// OR sender has insufficient funds
Expand Down
Loading

0 comments on commit 210e109

Please sign in to comment.