Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chg: address gov PR comments #15

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions tests/e2e/gov/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,7 @@ func (s *E2ETestSuite) TestNewCmdWeightedVote() {
for _, tc := range testCases {
tc := tc
s.Run(tc.name, func() {
// TODO HV2: changed from NewCmdWeightedVote to NewCmdVote. Fix tests accordingly.
cmd := cli.NewCmdVote()
cmd := cli.NewCmdWeightedVote()
clientCtx := val.ClientCtx
var txResp sdk.TxResponse

Expand Down
3 changes: 1 addition & 2 deletions x/feegrant/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,7 @@ func (s *CLITestSuite) msgVote(clientCtx client.Context, from, id, vote string,
}, commonArgs...)

args = append(args, extraArgs...)
// TODO HV2: changed from NewCmdWeightedVote to NewCmdVote. Fix tests accordingly.
cmd := govcli.NewCmdVote()
cmd := govcli.NewCmdWeightedVote()

out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args)

Expand Down
2 changes: 2 additions & 0 deletions x/gov/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func (keeper Keeper) GetDeposits(ctx context.Context, proposalID uint64) (deposi

// DeleteAndBurnDeposits deletes and burns all the deposits on a specific proposal.
func (keeper Keeper) DeleteAndBurnDeposits(ctx context.Context, proposalID uint64) error {
// HV2: no support in heimdall for burn deposits
panic(errors.ErrPanic)
coinsToBurn := sdk.NewCoins()
err := keeper.IterateDeposits(ctx, proposalID, func(key collections.Pair[uint64, sdk.AccAddress], deposit v1.Deposit) (stop bool, err error) {
coinsToBurn = coinsToBurn.Add(deposit.Amount...)
Expand Down
16 changes: 8 additions & 8 deletions x/gov/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ func NewKeeper(
config.MaxMetadataLen = types.DefaultConfig().MaxMetadataLen
}

// Enforce MaxOptionsLen to be 1.
if config.MaxOptionsLen != 1 {
config.MaxOptionsLen = types.DefaultConfig().MaxOptionsLen
// Enforce MaxVoteOptionsLen to be 1.
if config.MaxVoteOptionsLen != 1 {
config.MaxVoteOptionsLen = types.DefaultConfig().MaxVoteOptionsLen
}

sb := collections.NewSchemaBuilder(storeService)
Expand Down Expand Up @@ -189,11 +189,11 @@ func (k Keeper) assertMetadataLength(metadata string) error {
return nil
}

// assertOptionsLength returns an error if given options length
// is greater than a pre-defined MaxOptionsLen.
func (k Keeper) assertOptionsLength(options v1.WeightedVoteOptions) error {
if uint64(len(options)) > k.config.MaxOptionsLen {
return types.ErrTooManyVoteOptions.Wrapf("got %d options, maximum allowed is %d", len(options), k.config.MaxOptionsLen)
// assertVoteOptionsLength returns an error if given vote options length
// is greater than a pre-defined MaxVoteOptionsLen.
func (k Keeper) assertVoteOptionsLength(options v1.WeightedVoteOptions) error {
if uint64(len(options)) > k.config.MaxVoteOptionsLen {
return types.ErrTooManyVoteOptions.Wrapf("got %d options, maximum allowed is %d", len(options), k.config.MaxVoteOptionsLen)
}
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions x/gov/keeper/tally.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,17 @@ func (keeper Keeper) Tally(ctx context.Context, proposal v1.Proposal) (passes, b
*/

// HV2: check on the length of the options.
// This should never fail as all votes must have only 1 option
err := keeper.assertOptionsLength(val.Vote)
// This should never fail as all votes must have only 1 option, hence we panic if something goes wrong
err := keeper.assertVoteOptionsLength(val.Vote)
if err != nil {
return false, false, tallyResults, err
panic(err)
}

for _, option := range val.Vote {
// HV2: check on the weight of the option.
// This should never fail as the only option should have weight=1
// This should never fail as the only option should have weight=1, hence we panic if something goes wrong
if !v1.ValidWeightedVoteOption(*option) {
return false, false, tallyResults, err
panic(err)
}
weight, _ := math.LegacyNewDecFromStr(option.Weight)
subPower := votingPower.Mul(weight)
Expand Down
5 changes: 3 additions & 2 deletions x/gov/keeper/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ func (keeper Keeper) AddVote(ctx context.Context, proposalID uint64, voterAddr s

// HV2: check on the length of the options. This should never fail as it is only used by `MsgServer.Vote`.
// There, `v1.NewNonSplitVoteOption` is used to enforce the constraints (only 1 option with weight=1)
err = keeper.assertOptionsLength(options)
// Hence, we panic if something goes wrong
err = keeper.assertVoteOptionsLength(options)
if err != nil {
return err
panic(err)
}

// HV2: check on the weight of the option. This should never fail as it is only used by `MsgServer.Vote`.
Expand Down
8 changes: 4 additions & 4 deletions x/gov/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ package types
type Config struct {
// MaxMetadataLen defines the maximum proposal metadata length.
MaxMetadataLen uint64
// MaxOptionsLen defines the maximum number of options a proposal can have.
MaxOptionsLen uint64
// MaxVoteOptionsLen defines the maximum number of options a proposal can have.
MaxVoteOptionsLen uint64
}

// DefaultConfig returns the default config for gov.
func DefaultConfig() Config {
return Config{
MaxMetadataLen: 255,
MaxOptionsLen: 1,
MaxMetadataLen: 255,
MaxVoteOptionsLen: 1,
}
}
7 changes: 5 additions & 2 deletions x/upgrade/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import (
)

const (
// TODO HV2: ProposalTypeSoftwareUpgrade was removed. What to do with it?
// ProposalTypeCancelSoftwareUpgrade was not even there in heimdall's gov/types/proposal.go. What to do with it?
/* TODO HV2: ProposalTypeSoftwareUpgrade was removed. What to do with it?
ProposalTypeCancelSoftwareUpgrade was not even there in heimdall's gov/types/proposal.go.
Also, ProposalTypeCancelSoftwareUpgrade depends on ProposalTypeSoftwareUpgrade semantically,
so whatever we do with one, we should do with the other.
*/

ProposalTypeSoftwareUpgrade string = "SoftwareUpgrade"
ProposalTypeCancelSoftwareUpgrade string = "CancelSoftwareUpgrade"
Expand Down
Loading