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

feat: add tally result querier #266

Merged
merged 4 commits into from
Sep 24, 2024
Merged

feat: add tally result querier #266

merged 4 commits into from
Sep 24, 2024

Conversation

beer-1
Copy link
Member

@beer-1 beer-1 commented Sep 23, 2024

Description

New Endpoints

  • initia/gov/v1/tally_result
message TallyResult {
  uint64 tally_height = 1;
  string total_staking_power = 2 [(cosmos_proto.scalar) = "cosmos.Int"];
  string total_vesting_power = 3 [(cosmos_proto.scalar) = "cosmos.Int"];

  // v1_result is the original TallyResult from cosmos-sdk,
  // which contains both staking and vesting power.
  cosmos.gov.v1.TallyResult v1_tally_result = 4;
}

vote quorum is calculated with total_staking_power + total_vesting_power.


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 in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • 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 in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

@beer-1 beer-1 requested a review from a team as a code owner September 23, 2024 13:08
Copy link

coderabbitai bot commented Sep 23, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

Walkthrough

The changes involve modifications to the governance module, specifically within the gov.proto, query.proto, and related Go files. Key updates include the introduction of a new TallyResult message, enhancements to the Proposal message structure, and the addition of a new RPC method for querying tally results. The internal logic for handling tally results has been refined, with adjustments made to various functions to accommodate the new data structures and improve clarity and functionality in governance proposal processing.

Changes

Files Change Summary
proto/initia/gov/v1/gov.proto Added TallyResult message, updated Proposal to use TallyResult, and reformatted import statements for clarity.
proto/initia/gov/v1/query.proto Introduced TallyResult RPC method and associated request/response messages. Adjusted import order and made minor formatting changes.
x/gov/keeper/tally.go Updated Tally function to change return type to customtypes.TallyResult and refined voting power calculation logic.
x/gov/keeper/grpc_query.go Refactored TallyResult method to simplify control flow by delegating tally calculations to a custom query server.
proto/ibc/applications/perm/v1/genesis.proto Reformatted channel_states field declaration for improved readability.
proto/ibc/applications/perm/v1/query.proto Adjusted alignment of port_id field declaration for consistency.
proto/ibc/applications/perm/v1/tx.proto Reformatted option declarations and adjusted spacing for authority, channel_id, and port_id fields for consistency.
proto/ibc/applications/perm/v1/types.proto Modified alignment of field declarations in ChannelState and HaltState messages for improved readability.

Possibly related PRs

  • fix: apply audit #229: The changes in x/gov/keeper/tally.go involve modifications to the Tally function, which is directly related to the new TallyResult message introduced in the main PR's gov.proto file, as both deal with tallying results in governance proposals.
  • feat: add channel halt feature from the permissioned relayers #256: The changes in x/gov/keeper/proposal.go include updates to proposal handling, which is relevant to the modifications made in the Proposal message in the main PR, particularly regarding how tally results are represented.

🐰 In the meadow, changes bloom,
Tally results dispel the gloom.
Proposals now with clearer sight,
Governance shines, oh what a delight!
With each vote, a hop, a cheer,
In our world, the path is clear! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Sep 23, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

Outside diff range and nitpick comments (6)
proto/initia/gov/v1/query.proto (1)

107-120: LGTM: New message types for TallyResult query

The new message types QueryTallyResultRequest and QueryTallyResultResponse are well-defined and consistent with the PR objectives. The use of uint64 for proposal_id and the options set on the tally_result field are appropriate.

Consider adding a comment to explain the purpose of the amino.dont_omitempty option on the tally_result field, as it might not be immediately clear to all developers why this is necessary.

x/gov/keeper/tally_test.go (2)

178-179: LGTM! Consider adding a comment for clarity.

The changes correctly reflect the new structure of tallyResults, accessing the counts through V1TallyResult. This is consistent with the restructuring mentioned in the PR summary.

Consider adding a brief comment explaining the V1TallyResult structure for better clarity:

// Accessing counts through V1TallyResult due to restructuring of tally results
require.Equal(t, tallyResults.V1TallyResult.YesCount, math.LegacyNewDec(1_500_000+100_000_000).TruncateInt().String())
require.Equal(t, tallyResults.V1TallyResult.NoCount, math.LegacyNewDec(100_000_000).TruncateInt().String())

Remaining References to tallyResults Found

The restructuring of tallyResults is not fully applied. The following files still reference the old tallyResults structure:

  • x/gov/abci.go

    • Lines related to handleTallyResult
    • Direct assignments to proposal.FinalTallyResult
  • x/gov/keeper/tally_test.go

    • Assertions on tallyResults.V1TallyResult.YesCount and NoCount

Please update these references to align with the new tallyResults structure to ensure consistency and prevent potential issues.

Analysis chain

Line range hint 1-179: Comprehensive test coverage maintained with minimal changes.

The changes to Test_Tally are minimal and don't affect the overall structure or logic of the tests. The test coverage remains thorough, including various scenarios such as regular votes and vesting votes. The restructuring of tallyResults is correctly reflected in the final assertions.

To ensure that all necessary changes have been made, please run the following script to check for any remaining references to the old tallyResults structure:

This will help verify that the restructuring has been consistently applied across the codebase.


Line range hint 1-179: Further verification required for tallyResults restructuring.

The previous script did not produce any output, which might indicate that there are no remaining references to YesCount or NoCount. To ensure that the restructuring of tallyResults has been consistently applied across the codebase, please run the following additional script:

This will help identify any lingering references or usages of tallyResults that may need to be addressed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to the old tallyResults structure

# Test: Search for direct access to YesCount or NoCount on tallyResults
rg --type go 'tallyResults\.(YesCount|NoCount)' x/gov/

Length of output: 56


Script:

#!/bin/bash
# Description: Check for any remaining references to the tallyResults structure

# Broader search for any usage of tallyResults
rg --type go 'tallyResults' x/gov/ --context 2

Length of output: 7105

x/gov/abci.go (1)

Line range hint 223-336: Summary: Introduction of custom TallyResult type

The changes in this file are part of the larger feature addition described in the PR objectives. The introduction of customtypes.TallyResult aligns with the new TallyResult message structure mentioned in the PR summary. These modifications appear to be setting the groundwork for handling the new fields like tally_height, total_staking_power, and total_vesting_power.

A few points to consider:

  1. Ensure that the new customtypes.TallyResult includes all the fields mentioned in the PR summary (tally_height, total_staking_power, total_vesting_power, and v1_tally_result).
  2. Verify that the quorum calculation logic (summing total_staking_power and total_vesting_power) is implemented correctly, possibly in the Tally function called earlier in this file.
  3. Update any documentation or comments related to the handleTallyResult function to reflect the usage of the new custom type.

Consider adding a comment above the handleTallyResult function explaining the structure and purpose of the new customtypes.TallyResult, especially highlighting how it differs from the standard v1.TallyResult.

x/gov/keeper/custom_grpc_query_test.go (2)

191-191: Use ctx.BlockTime() instead of time.Now().UTC() for consistent test timing

Using ctx.BlockTime() ensures that the test remains consistent and does not depend on the actual current time. Replace time.Now().UTC() with ctx.BlockTime() to utilize the context's block time.

Apply this diff to use the context's block time:

-ctx = ctx.WithBlockTime(time.Now().UTC().Add(time.Minute * 15))
+ctx = ctx.WithBlockTime(ctx.BlockTime().Add(time.Minute * 15))

199-200: Clarify the magic numbers used in tally result comparisons

The use of magic numbers like 1_500_000 and 100_000_000 may reduce code clarity. Consider defining constants or adding comments to explain the significance of these values in the context of the test.

For example:

const (
    vestingVotePower    = 1_500_000
    validatorVotePower  = 100_000_000
)

// Then use these constants in your assertions
require.Equal(t, tallyResults.V1TallyResult.YesCount, math.LegacyNewDec(vestingVotePower + validatorVotePower).TruncateInt().String())
require.Equal(t, tallyResults.V1TallyResult.NoCount, math.LegacyNewDec(validatorVotePower).TruncateInt().String())
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 690c6d0 and 50d3984.

Files ignored due to path filters (4)
  • client/docs/swagger-ui/swagger.yaml is excluded by !**/*.yaml
  • x/gov/types/gov.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/gov/types/query.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/gov/types/query.pb.gw.go is excluded by !**/*.pb.gw.go, !**/*.pb.gw.go
Files selected for processing (9)
  • proto/initia/gov/v1/gov.proto (7 hunks)
  • proto/initia/gov/v1/query.proto (4 hunks)
  • x/gov/abci.go (2 hunks)
  • x/gov/keeper/custom_grpc_query.go (1 hunks)
  • x/gov/keeper/custom_grpc_query_test.go (2 hunks)
  • x/gov/keeper/grpc_query.go (1 hunks)
  • x/gov/keeper/tally.go (5 hunks)
  • x/gov/keeper/tally_test.go (1 hunks)
  • x/gov/types/proposal.go (4 hunks)
Additional context used
buf
proto/initia/gov/v1/gov.proto

4-4: import "amino/amino.proto": file does not exist

(COMPILE)

proto/initia/gov/v1/query.proto

4-4: import "amino/amino.proto": file does not exist

(COMPILE)

Additional comments not posted (20)
proto/initia/gov/v1/query.proto (2)

36-39: LGTM: New TallyResult RPC method

The addition of the TallyResult RPC method aligns well with the PR objectives. The method signature and HTTP endpoint are appropriately defined for querying the tally of a proposal vote.


Line range hint 1-120: Overall assessment: Well-implemented changes for tally result querying

The changes to this file successfully implement the new tally result querying functionality as outlined in the PR objectives. The new RPC method and associated message types are well-defined and consistent. Minor suggestions for improvement have been made, but overall, the implementation is solid.

x/gov/abci.go (2)

336-336: LGTM: Simplified assignment of FinalTallyResult

The direct assignment of tallyResults to proposal.FinalTallyResult is a clean simplification. This change suggests that the customtypes.TallyResult is now directly compatible with the FinalTallyResult field of the proposal.


223-223: Verify compatibility of customtypes.TallyResult

The change from v1.TallyResult to customtypes.TallyResult is noted. This shift to a custom type could provide more flexibility or additional fields specific to your project's needs.

Please ensure that customtypes.TallyResult maintains compatibility with any external systems or modules that may depend on the standard v1.TallyResult structure. Run the following script to verify the structure of the custom type:

Verification successful

Compatibility of customtypes.TallyResult Verified

The structure of customtypes.TallyResult includes a reference to v1.TallyResult, ensuring that compatibility with existing systems and modules is maintained. The additional fields provide extended functionality without disrupting the original type's integrity.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the structure of customtypes.TallyResult

# Test: Check the definition of customtypes.TallyResult
rg --type go -A 10 'type TallyResult struct' x/gov/types

Length of output: 1122

x/gov/types/proposal.go (4)

8-8: Import the necessary package for math operations

The cosmossdk.io/math package is appropriately imported to utilize math.ZeroInt() in the EmptyTallyResult() function.


28-28: Initialize FinalTallyResult using EmptyTallyResult()

The FinalTallyResult is now initialized using the EmptyTallyResult() function, which provides a structured TallyResult with zero values. This promotes code consistency and reuse.


65-65: Update FinalTallyResult assignment in ToV1() method

In the ToV1() method, FinalTallyResult is correctly assigned using p.FinalTallyResult.V1TallyResult to ensure proper conversion to the v1 Proposal type.


145-155: Add EmptyTallyResult() function for consistent initialization

The EmptyTallyResult() function provides a standardized way to initialize TallyResult with zero values, enhancing code reuse and maintainability.

x/gov/keeper/custom_grpc_query_test.go (4)

129-129: Verify that passing nil as proposal content is appropriate

Passing nil as the proposal content in SubmitProposal may lead to unexpected behavior if the content is required. Please ensure that nil is acceptable in this context, or provide valid proposal content to avoid potential issues.


181-189: Ensure vestingVoter is properly initialized

vestingVoter is set to addrs[1], but it's not clear where addrs is defined or initialized. Verify that vestingVoter is correctly initialized to prevent potential nil pointer dereferences or index out-of-range errors.


192-194: Verify the necessity of using cacheCtx for the Tally operation

The use of cacheCtx in the Tally operation may not be necessary if the state modifications do not need to be discarded. Ensure that cacheCtx is required for your test scenario; otherwise, consider using ctx directly to avoid unnecessary complexity.


202-205: Ensure the tally result from the query matches expected values

While comparing tallyResults with res.TallyResult, ensure that all fields (including TotalStakingPower and TotalVestingPower) are as expected. This can help catch any discrepancies in the tally calculation.

You can enhance the assertion:

require.Equal(t, tallyResults.V1TallyResult, res.TallyResult.V1TallyResult)
require.Equal(t, tallyResults.TotalStakingPower, res.TallyResult.TotalStakingPower)
require.Equal(t, tallyResults.TotalVestingPower, res.TallyResult.TotalVestingPower)
proto/initia/gov/v1/gov.proto (2)

169-172: Update handling of final_tally_result in Proposal

The Proposal message now uses the new TallyResult message for final_tally_result. Ensure that all logic related to proposal handling, especially when accessing or modifying final_tally_result, is updated to accommodate the new structure.

Run the following script to identify all Go code that accesses final_tally_result within Proposal:

#!/bin/bash
# Description: Find all usages of `final_tally_result` in Go files.

rg --type go 'Proposal.*final_tally_result'

145-154: Ensure compatibility with the new TallyResult message

The introduction of the new TallyResult message with additional fields (tally_height, total_staking_power, total_vesting_power, and v1_tally_result) is a significant change. Verify that all parts of the codebase that interact with TallyResult are updated accordingly, and that serialization/deserialization processes handle the new structure properly.

Run the following script to find all usages of cosmos.gov.v1.TallyResult that may need to be updated:

x/gov/keeper/tally.go (6)

22-22: Function signature updated to return customtypes.TallyResult

The Tally function now returns tallyResults of type customtypes.TallyResult, aligning with the updated data structures.


35-36: Proper initialization of totalStakingPower and totalVestingPower

Initializing totalStakingPower and totalVestingPower to zero ensures accurate accumulation of voting power.


179-185: Construct customtypes.TallyResult correctly

The tallyResults object is constructed appropriately with the updated fields:

  • V1TallyResult
  • TallyHeight
  • TotalStakingPower
  • TotalVestingPower

187-189: Correctly handle case when totalPower is zero

The check for zero totalPower ensures that proposals fail when there are no staked or vesting coins, which is logical and prevents division by zero errors later in the code.


194-194: Calculate percentVoting using totalVotingPower and totalPower

The calculation of percentVoting is updated to use the new totalPower, correctly reflecting the sum of staking and vesting power, ensuring the quorum is based on the combined total.


111-111: Type mismatch when adding amount to totalVestingPower

Ensure that amount returned from k.vestingKeeper.GetUnclaimedVestedAmount is of type math.Int, consistent with totalVestingPower.

To verify the return type of GetUnclaimedVestedAmount, run the following script:

Comment on lines +141 to +159
switch {
case proposal.Status == v1.StatusDepositPeriod:
tallyResult = customtypes.EmptyTallyResult()

case proposal.Status == v1.StatusPassed || proposal.Status == v1.StatusRejected:
tallyResult = proposal.FinalTallyResult

default:
// proposal is in voting period
params, err := q.Keeper.Params.Get(ctx)
if err != nil {
return nil, err
}

_, _, _, tallyResult, err = q.Keeper.Tally(ctx, params, proposal)
if err != nil {
return nil, err
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitly handle all proposal statuses to improve code clarity

In the switch statement starting at line 141~, consider explicitly handling all possible proposal statuses. Currently, the code uses a default case to handle proposals in the voting period and any other statuses. Explicitly listing all statuses can enhance readability and prevent unexpected behaviors if new statuses are introduced in the future.

Apply this change to explicitly handle the StatusVotingPeriod and return an error for any unanticipated statuses:

 switch {
 case proposal.Status == v1.StatusDepositPeriod:
   tallyResult = customtypes.EmptyTallyResult()

+case proposal.Status == v1.StatusVotingPeriod:
   // proposal is in voting period
   params, err := q.Keeper.Params.Get(ctx)
   if err != nil {
     return nil, err
   }

   _, _, _, tallyResult, err = q.Keeper.Tally(ctx, params, proposal)
   if err != nil {
     return nil, err
   }
+default:
+  return nil, status.Errorf(codes.InvalidArgument, "invalid proposal status: %s", proposal.Status.String())
 }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
switch {
case proposal.Status == v1.StatusDepositPeriod:
tallyResult = customtypes.EmptyTallyResult()
case proposal.Status == v1.StatusPassed || proposal.Status == v1.StatusRejected:
tallyResult = proposal.FinalTallyResult
default:
// proposal is in voting period
params, err := q.Keeper.Params.Get(ctx)
if err != nil {
return nil, err
}
_, _, _, tallyResult, err = q.Keeper.Tally(ctx, params, proposal)
if err != nil {
return nil, err
}
}
switch {
case proposal.Status == v1.StatusDepositPeriod:
tallyResult = customtypes.EmptyTallyResult()
case proposal.Status == v1.StatusPassed || proposal.Status == v1.StatusRejected:
tallyResult = proposal.FinalTallyResult
case proposal.Status == v1.StatusVotingPeriod:
// proposal is in voting period
params, err := q.Keeper.Params.Get(ctx)
if err != nil {
return nil, err
}
_, _, _, tallyResult, err = q.Keeper.Tally(ctx, params, proposal)
if err != nil {
return nil, err
}
default:
return nil, status.Errorf(codes.InvalidArgument, "invalid proposal status: %s", proposal.Status.String())
}

x/gov/keeper/custom_grpc_query_test.go Show resolved Hide resolved
proto/initia/gov/v1/gov.proto Show resolved Hide resolved
proto/initia/gov/v1/gov.proto Outdated Show resolved Hide resolved
x/gov/keeper/tally.go Show resolved Hide resolved
x/gov/keeper/grpc_query.go Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 50d3984 and 5aab762.

Files ignored due to path filters (2)
  • client/docs/swagger-ui/swagger.yaml is excluded by !**/*.yaml
  • x/gov/types/gov.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
Files selected for processing (7)
  • proto/ibc/applications/perm/v1/genesis.proto (1 hunks)
  • proto/ibc/applications/perm/v1/query.proto (1 hunks)
  • proto/ibc/applications/perm/v1/tx.proto (3 hunks)
  • proto/ibc/applications/perm/v1/types.proto (1 hunks)
  • proto/initia/gov/v1/gov.proto (4 hunks)
  • proto/initia/gov/v1/query.proto (3 hunks)
  • x/gov/keeper/tally.go (5 hunks)
Files skipped from review due to trivial changes (4)
  • proto/ibc/applications/perm/v1/genesis.proto
  • proto/ibc/applications/perm/v1/query.proto
  • proto/ibc/applications/perm/v1/tx.proto
  • proto/ibc/applications/perm/v1/types.proto
Files skipped from review as they are similar to previous changes (1)
  • x/gov/keeper/tally.go
Additional context used
buf
proto/initia/gov/v1/gov.proto

4-4: import "amino/amino.proto": file does not exist

(COMPILE)

proto/initia/gov/v1/query.proto

4-4: import "amino/amino.proto": file does not exist

(COMPILE)

Additional comments not posted (6)
proto/initia/gov/v1/query.proto (3)

35-39: Approve addition of TallyResult RPC method

The new TallyResult RPC method is a valuable addition to the Query service. It provides a way to query the tally of votes for a specific proposal, which is consistent with the governance functionality. The method signature and HTTP endpoint are well-defined and follow the existing patterns in the service.


107-111: Approve QueryTallyResultRequest message definition

The QueryTallyResultRequest message is well-defined and consistent with other request messages in the file. It contains a single proposal_id field of type uint64, which is appropriate for identifying a specific proposal for tally querying.


113-117: Approve QueryTallyResultResponse message and verify TallyResult type

The QueryTallyResultResponse message is well-defined and consistent with other response messages in the file. The use of gogoproto.nullable = false ensures that the tally_result field is always present, which is good for API consistency.

However, please ensure that the TallyResult type is properly defined, likely in the initia/gov/v1/gov.proto file, as it's not defined in this file.

To verify the TallyResult type definition, you can run the following script:

#!/bin/bash
# Search for TallyResult definition in .proto files
echo "Searching for TallyResult definition:"
rg -t proto 'message TallyResult'
proto/initia/gov/v1/gov.proto (3)

4-4: Import "amino/amino.proto" still does not exist.

The import statement references a file that does not exist, which will lead to compilation errors.

Tools
buf

4-4: import "amino/amino.proto": file does not exist

(COMPILE)


123-131: Introduction of new TallyResult message enhances governance functionality.

The addition of the TallyResult message with fields tally_height, total_staking_power, total_vesting_power, and v1_tally_result provides a more detailed representation of tally results, improving clarity and functionality.


147-147: Updated final_tally_result field to use new TallyResult type.

Changing the final_tally_result field in the Proposal message to use the new TallyResult message ensures consistency with the updated tally structure.

proto/initia/gov/v1/query.proto Show resolved Hide resolved
Copy link

codecov bot commented Sep 23, 2024

Codecov Report

Attention: Patch coverage is 44.26230% with 34 lines in your changes missing coverage. Please review.

Project coverage is 40.72%. Comparing base (051d6e6) to head (1aa3162).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
x/gov/keeper/custom_grpc_query.go 32.25% 16 Missing and 5 partials ⚠️
x/gov/types/proposal.go 0.00% 10 Missing ⚠️
x/gov/keeper/grpc_query.go 0.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #266      +/-   ##
==========================================
+ Coverage   40.70%   40.72%   +0.02%     
==========================================
  Files         264      264              
  Lines       25230    25255      +25     
==========================================
+ Hits        10269    10286      +17     
- Misses      13371    13374       +3     
- Partials     1590     1595       +5     
Files with missing lines Coverage Δ
x/gov/abci.go 27.44% <100.00%> (ø)
x/gov/keeper/tally.go 69.39% <100.00%> (+1.21%) ⬆️
x/gov/keeper/grpc_query.go 0.00% <0.00%> (ø)
x/gov/types/proposal.go 0.00% <0.00%> (ø)
x/gov/keeper/custom_grpc_query.go 38.94% <32.25%> (-3.25%) ⬇️

@beer-1 beer-1 merged commit 0e53148 into main Sep 24, 2024
8 of 9 checks passed
@beer-1 beer-1 deleted the feat/tally-result branch September 24, 2024 02:53
@coderabbitai coderabbitai bot mentioned this pull request Sep 24, 2024
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant