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

fix: Fix inactive vals and min stake handling in ConsumerAdditionProposal conversion #2181

Merged
merged 7 commits into from
Aug 28, 2024

Conversation

p-offtermatt
Copy link
Contributor

@p-offtermatt p-offtermatt commented Aug 28, 2024

Fixes how consumer proposals are constructed.

The main changes are:

  • query.proto, query.pb.go, grpc_query.go and grpc_query_test.go: Add allow_inactive_validators and min_stake to the Chain struct, to also include this info when list-consumer-chains is queried. Closes MinStake and AllowInactiveValidators are missing from Chain struct #2180
  • tests/e2e/actions.go: Fixes the consumer addition and modification actions to make the templates include the AllowInactiveVals and the MinStake fields
  • main.go, steps.go: Introduce a test scenario raised by @fastfadingviolets
  • hooks.go, proposal.go: The actual bug fix. Wires correctly how the proposals are constructed from the ConsumerAddition message

Summary by CodeRabbit

  • New Features
    • Introduced minimum stake and inactive validator allowance settings for consumer chain proposals.
    • Enhanced proposal submission process to include new parameters related to validator activity and stake requirements.
  • Bug Fixes
    • Improved test coverage for validator management scenarios, ensuring more robust validation logic.
  • Documentation
    • Updated test functions and structures to reflect new parameters and their implications for consumer chain configurations.

@github-actions github-actions bot added C:Testing Assigned automatically by the PR labeler C:x/provider Assigned automatically by the PR labeler labels Aug 28, 2024
@p-offtermatt p-offtermatt marked this pull request as ready for review August 28, 2024 10:35
@p-offtermatt p-offtermatt requested a review from a team as a code owner August 28, 2024 10:35
Copy link
Contributor

coderabbitai bot commented Aug 28, 2024

Walkthrough

Walkthrough

The changes introduce two new fields, min_stake and allow_inactive_vals, to the Chain message in the query.proto file. These fields are incorporated into various functions and structures across multiple files, enhancing the proposal submission process and validator management within the interchain security framework. The modifications ensure that proposals can specify validator activity and stake requirements, impacting validation processes and governance.

Changes

File(s) Change Summary
proto/interchain_security/ccv/provider/v1/query.proto Added fields uint64 min_stake and bool allow_inactive_vals to the Chain message.
tests/e2e/actions.go Updated submitConsumerAdditionProposal and submitConsumerModificationProposal functions to include new parameters for min_stake and allow_inactive_vals.
tests/e2e/main.go Added a new test case "inactive-vals-topN-100" to evaluate inactive validators under specific conditions.
tests/e2e/steps.go Introduced stepsInactiveValsTopN100 function to simulate blockchain actions involving validators and their powers, including inactive validators.
x/ccv/provider/keeper/grpc_query.go Enhanced GetConsumerChain function to include new variables allowInactiveVals and minStake in the returned types.Chain struct.
x/ccv/provider/keeper/grpc_query_test.go Updated TestGetConsumerChain to utilize new parameters for testing scenarios involving inactive validators and minimum stakes.
x/ccv/provider/keeper/hooks.go Modified GetConsumerAdditionFromProp to return additional fields MinStake and AllowInactiveVals in the proposal handling.
x/ccv/provider/keeper/proposal.go Updated HandleConsumerAdditionProposal to include new fields MinStake and AllowInactiveVals sourced from the proposal for better control over validator management.

Possibly related issues


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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
Contributor

@mpoke mpoke left a comment

Choose a reason for hiding this comment

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

LGTM

tests/e2e/steps.go Outdated Show resolved Hide resolved
Copy link
Contributor

@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: 3

Outside diff range, codebase verification and nitpick comments (2)
x/ccv/provider/keeper/proposal.go (1)

47-48: Review: Addition of MinStake and AllowInactiveVals fields to ConsumerAdditionProposal

The addition of MinStake and AllowInactiveVals fields to the ConsumerAdditionProposal struct is a significant change. These fields allow for more granular control over validator participation in consumer chains, which is crucial for maintaining the integrity and security of the interchain operations.

  • MinStake: This field likely sets a threshold for the minimum stake that validators must have to participate, which is important for ensuring that only sufficiently backed validators can influence the chain.
  • AllowInactiveVals: This field allows proposals to include inactive validators. This could be useful in scenarios where validators are temporarily inactive but still trusted based on past interactions.

Considerations:

  • Ensure that the rest of the system correctly interprets these new fields, particularly in functions that process these proposals.
  • It might be beneficial to add validation logic within this function or upstream to ensure that the values provided for these fields meet system-wide business rules (e.g., MinStake should be non-negative).

Code Quality:

  • The code adheres to the Uber Golang style guide, with proper naming conventions and struct initialization.
  • Error handling and propagation are consistent with the rest of the module's practices.

The changes are well-integrated and follow the project's coding standards.

Consider implementing additional validation for the new fields if not already present elsewhere in the system to prevent invalid data from being processed without detection.

tests/e2e/actions.go (1)

637-638: Best Practice: Avoid Magic Numbers

The JSON template in submitConsumerModificationProposal uses magic numbers directly in the string.

Replace these magic numbers with named constants or configuration values to make the code more readable and maintainable.

-    "min_stake": %d,
-    "allow_inactive_vals": %t
+    "min_stake": %d, // use a named constant or configuration value
+    "allow_inactive_vals": %t // use a named constant or configuration value

Define these constants at the beginning of your file or fetch them from a configuration management system.

Comment on lines +617 to +618
"min_stake": %d,
"allow_inactive_vals": %t
Copy link
Contributor

Choose a reason for hiding this comment

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

Code Quality Improvement: Use Struct for Parameters

The function submitConsumerModificationProposal uses many parameters directly in the JSON template string. This can be error-prone and hard to maintain.

Consider defining a struct for these parameters and marshal it to JSON. This approach enhances code readability and maintainability.

type ConsumerModificationParams struct {
    MinStake           uint64 `json:"min_stake"`
    AllowInactiveVals  bool   `json:"allow_inactive_vals"`
    // include other fields...
}

params := ConsumerModificationParams{
    MinStake:          action.MinStake,
    AllowInactiveVals: action.AllowInactiveVals,
    // set other fields...
}
jsonStr, err := json.Marshal(params)
if err != nil {
    log.Fatal(err)
}

Use this jsonStr in your template.

Comment on lines +594 to +595
AllowInactiveVals bool
MinStake uint64
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor Suggestion: Consistent Parameter Ordering

The addition of AllowInactiveVals and MinStake parameters in SubmitConsumerModificationProposalAction struct should follow a consistent order across similar functions to improve readability and maintainability.

Consider reordering the parameters to match the order used in other related structs or function signatures for consistency.

 type SubmitConsumerModificationProposalAction struct {
 	Chain              ChainID
 	From               ValidatorID
 	Deposit            uint
 	ConsumerChain      ChainID
 	TopN               uint32
 	ValidatorsPowerCap uint32
 	ValidatorSetCap    uint32
 	Allowlist          []string
 	Denylist           []string
+	AllowInactiveVals  bool
+	MinStake           uint64
-	AllowInactiveVals  bool
-	MinStake           uint64
 }

Committable suggestion was skipped due to low confidence.

@@ -299,7 +299,9 @@
"validator_set_cap": %d,
"allowlist": %s,
"denylist": %s,
"authority": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn"
"authority": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
Copy link
Contributor

Choose a reason for hiding this comment

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

Security Issue: Exposed API Key

The hardcoded API key in the JSON template might expose sensitive operations to unauthorized access.

Consider removing the hardcoded API key or replacing it with a secure method of fetching it, such as environment variables or secure vault solutions.

-   "authority": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
+   "authority": os.Getenv("AUTHORITY_KEY"),

Ensure to import the os package at the beginning of the file.

Committable suggestion was skipped due to low confidence.

Tools
Gitleaks

302-302: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

@mpoke mpoke enabled auto-merge August 28, 2024 11:02
@mpoke mpoke added this pull request to the merge queue Aug 28, 2024
Merged via the queue into main with commit ccdb89b Aug 28, 2024
15 of 16 checks passed
@mpoke mpoke deleted the ph/inactive-vals-fix branch August 28, 2024 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:Testing Assigned automatically by the PR labeler C:x/provider Assigned automatically by the PR labeler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MinStake and AllowInactiveValidators are missing from Chain struct
3 participants