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 val denylist #1268

Merged
merged 20 commits into from
Mar 21, 2024
Merged

Feat: Add val denylist #1268

merged 20 commits into from
Mar 21, 2024

Conversation

tuantran1702
Copy link
Contributor

@tuantran1702 tuantran1702 commented Mar 13, 2024

1. Summary

Fixes #1131

2.Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

3. Implementation details

4. How to test/use

5. Checklist

  • Does the Readme need to be updated?

6. Limitations (optional)

7. Future Work (optional)

Summary by CodeRabbit

  • New Features
    • Introduced a deny list functionality for managing validators in an interchain staking system, allowing for setting, retrieving, checking, and removing validators for specific zones.
  • Tests
    • Added test cases for the deny list management in the interchain staking system, including scenarios for storing, getting, and deleting validators.
    • Implemented a new test to verify the functionality of the zone validator deny list, covering various scenarios and error handling.

Copy link
Contributor

coderabbitai bot commented Mar 13, 2024

Warning

Rate Limit Exceeded

@tropicaldog has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 20 minutes and 36 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 535b758 and bfd7a71.

Walkthrough

The updates introduce a deny list functionality for validators in an interchain staking system, allowing for better management and governance by enabling the addition or removal of validators from the deny list. This feature supports operations such as setting, retrieving, checking, and removing validators for a specific zone, and includes tests to ensure reliability and correctness.

Changes

File Path Change Summary
.../deny_list.go Introduced functionality for managing a deny list of validators for a zone.
.../deny_list_test.go Added test cases for the deny list management in the interchain staking keeper.
.../grpc_query_test.go New test function for testing zone validator deny list functionality.
.../types/keys.go Added functions for handling deny list key prefixes for validators.

Assessment against linked issues

Objective Addressed Explanation
Add Validator deny list (#1131)
Implement get, getAll, set, delete, iterator, query
Ensure aggregation excludes denied validators (#1131)
Proposal type for add/remove from denyList (#1131) The summary does not explicitly mention the implementation of proposal types for adding or removing validators from the deny list.

🐇✨

In the realm of chains where validators roam,
A list was crafted in the keeper's home.
"Deny!" said the rabbit, with a governance vote,
Ensuring the chain's integrity stayed afloat.
🌟📜🚫
With tests and keys, the feature was made,
A hop towards trust, in the blockchain glade.
🐾🌿🔒

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-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

vercel bot commented Mar 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
quicksilver ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 21, 2024 4:47pm

@tuantran1702 tuantran1702 changed the title Tuan/add val denylist Feat: Add val denylist Mar 13, 2024
Copy link

codecov bot commented Mar 14, 2024

Codecov Report

Attention: Patch coverage is 82.22222% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 63.33%. Comparing base (87683af) to head (bfd7a71).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1268      +/-   ##
==========================================
+ Coverage   63.26%   63.33%   +0.07%     
==========================================
  Files         170      171       +1     
  Lines       11269    11314      +45     
==========================================
+ Hits         7129     7166      +37     
- Misses       3415     3421       +6     
- Partials      725      727       +2     
Flag Coverage Δ
unittests 63.33% <82.22%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
x/interchainstaking/keeper/grpc_query.go 90.76% <100.00%> (+0.31%) ⬆️
x/interchainstaking/keeper/deny_list.go 93.75% <93.75%> (ø)
x/interchainstaking/keeper/keeper.go 73.71% <33.33%> (-0.25%) ⬇️
x/interchainstaking/types/keys.go 29.62% <0.00%> (-2.38%) ⬇️

)

// SetZoneValidatorToDenyList sets the zone validator deny list
func (k *Keeper) SetZoneValidatorToDenyList(ctx sdk.Context, chainID string, validator types.Validator) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Storing the entire validator would be super inefficient, storage wise. We probably only want to store []string (or maybe []bytes, as addressBytes has length 20, rather than 57-61 bytes for a bech32'd valoper), or perhaps a map[string]bool, which would involve storing more data, but able to look up the validator without iterator when we check whether a given val is on the list.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can improve this further by just passing in the valoper address string, rather than the validator object.

Similarly, on retrieval we can just return []string - the reason being that all uses of this besides tests don't actually care about the validator object.

Now store validator address bytes instead of serialized form of the Validator struct
@tuantran1702 tuantran1702 marked this pull request as ready for review March 20, 2024 05:23
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.

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 472f56b and 90ee8dd.
Files ignored due to path filters (1)
  • x/interchainstaking/types/query.pb.go is excluded by: !**/*.pb.go
Files selected for processing (9)
  • proto/quicksilver/interchainstaking/v1/query.proto (1 hunks)
  • x/interchainstaking/keeper/deny_list.go (1 hunks)
  • x/interchainstaking/keeper/deny_list_test.go (1 hunks)
  • x/interchainstaking/keeper/grpc_query.go (1 hunks)
  • x/interchainstaking/keeper/keeper.go (3 hunks)
  • x/interchainstaking/types/deny_list.go (1 hunks)
  • x/interchainstaking/types/deny_list_test.go (1 hunks)
  • x/interchainstaking/types/error.go (1 hunks)
  • x/interchainstaking/types/keys.go (2 hunks)
Files skipped from review due to trivial changes (1)
  • x/interchainstaking/types/deny_list_test.go
Additional comments: 4
x/interchainstaking/types/error.go (1)
  • 9-9: The addition of ErrValidatorAlreadyInDenyList is appropriate and follows the existing pattern for error definitions. Good job maintaining consistency.
x/interchainstaking/keeper/deny_list_test.go (1)
  • 1-103: The tests provided for the deny list functionality cover basic operations such as adding, retrieving, and deleting validators. It's good practice to also include tests for error paths and edge cases to ensure the deny list behaves as expected under all conditions.

Consider expanding the test coverage to include scenarios such as attempting to add a validator that already exists in the deny list, or trying to remove a validator that isn't present.

proto/quicksilver/interchainstaking/v1/query.proto (1)
  • 258-265: The introduction of QueryDenyListRequest and QueryDenyListResponse messages for querying the deny list is well-defined and follows protobuf best practices. These changes are crucial for supporting the new deny list functionality via gRPC queries.
x/interchainstaking/keeper/keeper.go (1)
  • 7-7: The addition of the "slices" package is appropriate for the use of slices.Contains later in the code. This is a standard library package introduced in Go 1.18, which provides generic functions for slice manipulation. Ensure that the Go version used in this project supports generics.

x/interchainstaking/keeper/keeper.go Show resolved Hide resolved
Comment on lines 9 to 28
func MustMarshalValidator(cdc codec.BinaryCodec, validator Validator) []byte {
return cdc.MustMarshal(&validator)
}

func UnmarshalValidator(cdc codec.BinaryCodec, value []byte) (Validator, error) {
if len(value) == 0 {
return Validator{}, errors.New("unable to unmarshal zero-length byte slice")
}
validator := Validator{}
err := cdc.Unmarshal(value, &validator)
return validator, err
}

func MustUnmarshalValidator(cdc codec.BinaryCodec, value []byte) Validator {
validator, err := UnmarshalValidator(cdc, value)
if err != nil {
panic(err)
}
return validator
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The functions for marshaling and unmarshaling Validator objects are correctly implemented following Cosmos SDK conventions. However, it's important to ensure comprehensive test coverage for these critical serialization and deserialization operations.

Consider adding unit tests to cover these new functions and ensure they behave as expected under various conditions, including error scenarios.

Comment on lines 10 to 53
func (k *Keeper) SetZoneValidatorToDenyList(ctx sdk.Context, chainID string, validator types.Validator) error {
store := ctx.KVStore(k.storeKey)

key := types.GetDeniedValidatorKey(chainID, validator.ValoperAddress)
addrBytes, err := sdk.ValAddressFromBech32(validator.ValoperAddress)
if err != nil {
return err
}
store.Set(key, addrBytes.Bytes())
return nil
}

// GetZoneValidatorDenyList get the validator deny list of a specific zone
func (k *Keeper) GetZoneValidatorDenyList(ctx sdk.Context, chainID string) (denyList []string) {
k.IterateZoneDeniedValidator(ctx, chainID, func(validator string) bool {
denyList = append(denyList, validator)
return false
})

return denyList
}

func (k *Keeper) GetDeniedValidatorInDenyList(ctx sdk.Context, chainID string, validatorAddress string) (types.Validator, bool) {
key := types.GetDeniedValidatorKey(chainID, validatorAddress)
store := ctx.KVStore(k.storeKey)
bz := store.Get(key)
if bz == nil {
return types.Validator{}, false
}

val, found := k.GetValidator(ctx, chainID, bz)
if !found {
return types.Validator{}, false
}

return val, true
}

// RemoveValidatorFromDenyList removes a validator from the deny list. Panic if the validator is not in the deny list
func (k *Keeper) RemoveValidatorFromDenyList(ctx sdk.Context, chainID string, validator types.Validator) {
store := ctx.KVStore(k.storeKey)
key := types.GetDeniedValidatorKey(chainID, validator.ValoperAddress)
store.Delete(key)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation for managing the deny list, including adding, retrieving, and removing validators, is efficient and addresses previous concerns about storage inefficiency by using sdk.ValAddressFromBech32. However, it's crucial to ensure error paths are also covered by tests to maintain robustness.

Consider adding tests to cover error scenarios, such as invalid validator addresses or issues during the retrieval process.

Comment on lines 166 to 178
func GetZoneValidatorAddrsByConsAddrKey(chainID string) []byte {
return append(KeyPrefixValidatorAddrsByConsAddr, []byte(chainID)...)
}

// GetDeniedValidatorKey gets the validator deny list key prefix for a given chain.
func GetDeniedValidatorKey(chainID string, validatorAddress string) []byte {
return append(KeyPrefixDeniedValidator, append([]byte(chainID), []byte(validatorAddress)...)...)
}

// GetZoneValidatorDenyListKey gets the validator deny list key prefix for a given chain.
func GetZoneDeniedValidatorKey(chainID string) []byte {
return append(KeyPrefixDeniedValidator, []byte(chainID)...)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [66-178]

The addition of GetDeniedValidatorKey and GetZoneDeniedValidatorKey functions for managing storage keys related to the deny list is correctly implemented, following the established patterns for key management in the module. However, it's important to ensure these key generation functions are covered by tests to verify their correctness and prevent potential issues with key collisions or misinterpretations.

Consider adding tests to cover these new key management functions, ensuring they generate the expected keys under various conditions.

x/interchainstaking/keeper/grpc_query.go 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.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 90ee8dd and 68ed749.
Files selected for processing (1)
  • x/interchainstaking/keeper/intent_test.go (3 hunks)

x/interchainstaking/keeper/intent_test.go Outdated Show resolved Hide resolved
x/interchainstaking/keeper/intent_test.go 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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 68ed749 and 6a2caf7.
Files selected for processing (1)
  • x/interchainstaking/keeper/intent_test.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/interchainstaking/keeper/intent_test.go

tuantran1702 and others added 2 commits March 21, 2024 20:31
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6a2caf7 and 8d708d3.
Files selected for processing (2)
  • x/interchainstaking/keeper/grpc_query_test.go (1 hunks)
  • x/interchainstaking/keeper/intent_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/interchainstaking/keeper/intent_test.go
Additional comments: 1
x/interchainstaking/keeper/grpc_query_test.go (1)
  • 1350-1403: The test function TestKeeper_ZoneValidatorDenyList provides a good foundation for testing the deny list functionality. However, there are a few suggestions for improvement:
  • Error Handling for "zone not found": The test case named "zone not found" sets wantErr to false, which might be misleading since the expectation for a zone not found scenario could logically be an error or a specific response indicating the absence of the zone. Consider clarifying the expected behavior in this scenario.
  • Setup Repetition: The suite.SetupTest() and suite.setupTestZones() are called at the beginning of each test case run. If these methods are idempotent and necessary for each test case, this is fine. However, if they are resetting the state and not required to be run before each case, consider moving them to a setup block that runs once before all test cases to improve test efficiency.
  • Asserting on Specific Error Messages: When expecting errors, it's a good practice to assert on specific error messages or types. This ensures that the test fails for the right reason and not due to some unrelated error.
  • Use of suite.Empty and suite.NotNil: While checking the denyList content, using suite.Empty and suite.NotNil is good. However, for a more robust test, consider also checking the length of denyList.Validators directly when tc.expectedLength is not 1 to ensure the test is explicitly checking the expected conditions.

Consider these suggestions to enhance the test's clarity, robustness, and efficiency.

Copy link
Contributor

@joe-bowman joe-bowman left a comment

Choose a reason for hiding this comment

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

Some comments here to make things a little more efficient.

We should create the key from the validator address bytes, not the bech32 string

We should just pass the string around, not the validator itself.

There is. no need to look up the validator - we just care about the address.

)

// SetZoneValidatorToDenyList sets the zone validator deny list
func (k *Keeper) SetZoneValidatorToDenyList(ctx sdk.Context, chainID string, validator types.Validator) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can improve this further by just passing in the valoper address string, rather than the validator object.

Similarly, on retrieval we can just return []string - the reason being that all uses of this besides tests don't actually care about the validator object.

x/interchainstaking/keeper/deny_list.go Outdated Show resolved Hide resolved
x/interchainstaking/keeper/deny_list.go Outdated Show resolved Hide resolved
x/interchainstaking/types/keys.go Outdated Show resolved Hide resolved
x/interchainstaking/keeper/deny_list.go Outdated Show resolved Hide resolved
x/interchainstaking/keeper/intent_test.go 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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8d708d3 and 5e84ab6.
Files selected for processing (4)
  • x/interchainstaking/keeper/deny_list.go (1 hunks)
  • x/interchainstaking/keeper/deny_list_test.go (1 hunks)
  • x/interchainstaking/keeper/grpc_query_test.go (1 hunks)
  • x/interchainstaking/types/keys.go (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • x/interchainstaking/keeper/deny_list.go
  • x/interchainstaking/keeper/grpc_query_test.go
  • x/interchainstaking/types/keys.go
Additional comments: 1
x/interchainstaking/keeper/deny_list_test.go (1)
  • 8-101: The test cases for storing, getting, and deleting validators from the deny list are well-structured and cover the essential functionalities. However, consider adding assertions for error conditions and edge cases, such as attempting to delete a validator that is not in the deny list or adding a validator that is already in the deny list. This will ensure the robustness of the deny list functionality under various conditions.

x/interchainstaking/keeper/deny_list_test.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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5e84ab6 and 535b758.
Files selected for processing (1)
  • x/interchainstaking/keeper/deny_list_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • x/interchainstaking/keeper/deny_list_test.go

Copy link
Contributor

@joe-bowman joe-bowman left a comment

Choose a reason for hiding this comment

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

lgtm

@faddat faddat merged commit 47d8bc1 into main Mar 21, 2024
25 of 26 checks passed
@tuantran1702 tuantran1702 deleted the tuan/add-val-denylist branch March 22, 2024 01:37
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.

Add Validator deny list
3 participants