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(collections): Multi RefKeys method and reverse Triple iterator support #21496

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

oren-lava
Copy link
Contributor

@oren-lava oren-lava commented Sep 1, 2024

Description

Closes: #21091

Added the RefKeys() method for the Multi type to get a full list of the existing reference keys (with option for unique list). Also, added missing support of reverse iterator for a Triple collection (always used order=OrderAscending without option to edit).


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 (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • 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.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

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

Summary by CodeRabbit

  • New Features

    • Introduced a method to retrieve reference keys with an option for uniqueness, enhancing data handling capabilities.
    • Added functionality to specify the order of results in range queries, allowing for ascending or descending retrieval.
    • Enhanced redelegation retrieval methods to allow for more nuanced control over range parameters.
  • Bug Fixes

    • Improved test coverage for reference key retrieval and range queries to ensure expected behavior under various conditions.

Copy link
Contributor

coderabbitai bot commented Sep 1, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes introduce a new RefKeys method to the Multi struct in the indexes package, allowing retrieval of reference keys from a MultiIterator. Additionally, several functions in the collections/triple.go file are modified to include an options parameter, enabling results to be returned in either ascending or descending order. Test cases are updated to validate these new functionalities.

Changes

Files Change Summary
collections/indexes/multi.go Added RefKeys method to Multi struct for retrieving reference keys with uniqueness option.
collections/indexes/multi_test.go Enhanced TestMultiIndex to validate RefKeys method functionality under various conditions.
collections/triple.go Modified three functions to include an options parameter for result ordering.
collections/triple_test.go Updated TestTripleRange to test reverse iteration for NewPrefixedTripleRange and NewSuperPrefixedTripleRange.

Assessment against linked issues

Objective Addressed Explanation
Add RefKeys() method to collections MultiIterator
Ensure RefKeys() retrieves reference keys correctly
Allow iteration over results in reverse order for range functions

Possibly related PRs

Suggested labels

C:x/auth, C:x/accounts, C:x/tx, C:server/v2, C:Simulations

Suggested reviewers

  • julienrbrt
  • akhilkumarpilli
  • lucaslopezf
  • kocubinski
  • facundomedica
  • sontrinh16
  • testinginprod

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.

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.

@@ -3,6 +3,8 @@
import (
"context"
"errors"
"fmt"
"reflect"

Check notice

Code scanning / CodeQL

Sensitive package import Note

Certain system packages contain functions which may be a possible source of non-determinism
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: 0

Outside diff range, codebase verification and nitpick comments (1)
collections/indexes/multi.go (1)

128-158: LGTM! Consider adding documentation comments.

The RefKeys method is well-implemented and handles both unique and non-unique scenarios effectively. The sanity check is a good practice to prevent misuse of the method.

To improve the usability of the method, consider adding documentation comments to explain its usage and behavior. For example:

// RefKeys returns a list of all the MultiIterator's reference keys.
// If the "unique" argument is enabled, it returns a unique list of reference keys.
// Note: The reference key type must be comparable when using the "unique" option.
func (m *Multi[ReferenceKey, PrimaryKey, Value]) RefKeys(ctx context.Context, unique bool) ([]ReferenceKey, error) {
  // ...
}
Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f79b380 and af2f94c.

Files selected for processing (4)
  • collections/indexes/multi.go (2 hunks)
  • collections/indexes/multi_test.go (2 hunks)
  • collections/triple.go (1 hunks)
  • collections/triple_test.go (2 hunks)
Additional context used
Path-based instructions (4)
collections/triple_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

collections/indexes/multi_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

collections/indexes/multi.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

collections/triple.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

GitHub Check: CodeQL
collections/indexes/multi.go

[notice] 7-7: Sensitive package import
Certain system packages contain functions which may be a possible source of non-determinism

Additional comments not posted (10)
collections/triple_test.go (4)

10-10: LGTM!

The import of the coretesting package is necessary for using the coretesting.Context() and coretesting.KVStoreService() functions in the test.


42-56: LGTM!

The changes enhance the test coverage by validating the new reverse iteration feature for the NewPrefixedTripleRange function. The test cases are correctly implemented and cover both the default and reverse iteration scenarios.


59-59: LGTM!

The change updates the call to NewSuperPrefixedTripleRange to include the new reverse parameter set to false, which is necessary to match the updated function signature and maintain the default iteration order.


65-73: LGTM!

The changes enhance the test coverage by validating the new reverse iteration feature for the NewSuperPrefixedTripleRange function. The test case is correctly implemented and covers the reverse iteration scenario.

collections/indexes/multi_test.go (2)

29-35: LGTM!

The test code correctly verifies the behavior of the RefKeys method by:

  • Retrieving reference keys without filtering and expecting two instances of "milan".
  • Retrieving reference keys with filtering and expecting a single instance of "milan".

The code changes are approved.


54-57: LGTM!

The test code correctly verifies the behavior of the RefKeys method after a reference update operation by expecting to see both "milan" and "new york" as valid reference keys.

The code changes are approved.

collections/triple.go (4)

278-286: LGTM!

The changes to introduce the reverse parameter and conditionally set the order variable look good. This is a useful enhancement that allows for specifying the order of the range. The implementation is straightforward and maintains the existing coding style.


292-301: LGTM!

The changes to introduce the reverse parameter and conditionally set the order variable are consistent with the updates made to NewPrefixUntilTripleRange. The implementation is straightforward and maintains the existing coding style.


307-316: LGTM!

The changes to introduce the reverse parameter and conditionally set the order variable are consistent with the updates made to the other range functions. The implementation is straightforward and maintains the existing coding style.


Line range hint 1-318: Conforms to the Uber Go Style Guide

The Go code in this file follows the naming conventions, formatting, and code organization recommended by the Uber Go Style Guide. The changes introduced are consistent with the existing style and conventions used throughout the file. No deviations from the style guide were observed.

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: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f79b380 and af2f94c.

Files selected for processing (4)
  • collections/indexes/multi.go (2 hunks)
  • collections/indexes/multi_test.go (2 hunks)
  • collections/triple.go (1 hunks)
  • collections/triple_test.go (2 hunks)
Additional context used
Path-based instructions (4)
collections/triple_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

collections/indexes/multi_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

collections/indexes/multi.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

collections/triple.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

GitHub Check: CodeQL
collections/indexes/multi.go

[notice] 7-7: Sensitive package import
Certain system packages contain functions which may be a possible source of non-determinism

Additional comments not posted (8)
collections/triple_test.go (2)

42-56: Review of reverse iteration functionality in NewPrefixedTripleRange.

The test case for NewPrefixedTripleRange with the reverse flag set to true correctly verifies that the keys are returned in reverse order. The use of require.Equal to compare the keys ensures that the test will accurately reflect discrepancies in the order of keys.

This test effectively validates the new functionality, ensuring that the reverse iteration works as expected.


59-73: Review of reverse iteration functionality in NewSuperPrefixedTripleRange.

The test case for NewSuperPrefixedTripleRange with the reverse flag set to true correctly checks that the keys are returned in reverse order. The loop at lines 71-72 effectively compares each key against the expected key in reverse order, ensuring that the functionality behaves as intended.

This test is well-constructed and confirms that the reverse iteration feature is implemented correctly.

collections/indexes/multi_test.go (2)

29-35: LGTM!

The test cases correctly validate the behavior of the RefKeys method with and without filtering.


54-57: LGTM!

The assertion correctly validates that the reference keys are updated after the replace operation.

collections/indexes/multi.go (1)

128-158: LGTM!

The RefKeys method is well-implemented with proper error handling and comments. The logic for handling duplicates using a map to track visited keys is efficient.

collections/triple.go (3)

278-286: Approve the changes to NewPrefixUntilTripleRange.

The addition of the reverse parameter is implemented correctly, allowing the function to handle both ascending and descending orders based on the parameter. It's recommended to add documentation to explain the purpose and effect of the reverse parameter to aid users in understanding its usage.


292-301: Approve the changes to NewPrefixedTripleRange.

The implementation of the reverse parameter is consistent and correct, allowing the function to handle both ascending and descending orders. Similar to the previous function, adding documentation for the reverse parameter would be beneficial for users.


307-316: Approve the changes to NewSuperPrefixedTripleRange.

The implementation of the reverse parameter is consistent and correct across all modified functions. Adding documentation for the reverse parameter would enhance user understanding and ensure correct usage.

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: 0

Outside diff range, codebase verification and nitpick comments (4)
x/staking/keeper/query_utils.go (1)

110-110: LGTM! Consider adding a comment to clarify the purpose of the new argument.

The code change looks good. The addition of the false argument to collections.NewPrefixedTripleRange is likely used to control the order of the range query results. Setting it to false suggests that the results will be returned in the default ascending order.

To improve code readability, consider adding a comment to clarify the purpose of the new argument. For example:

// Set the second argument to false to return the results in ascending order
rng := collections.NewPrefixedTripleRange[[]byte, []byte, []byte](delegator, false)
x/staking/keeper/delegation.go (3)

424-424: [Nitpick] Clarify the impact and motivation behind the false parameter.

The addition of the false parameter to collections.NewPrefixedTripleRange suggests a change in the underlying logic for handling the range. This may influence the behavior of the GetRedelegations method in terms of data retrieval capabilities or performance characteristics.

Please provide clarification on:

  1. The motivation behind adding the false parameter.
  2. The implications of this change on the method's behavior and performance.

444-444: [Nitpick] Clarify the impact and motivation behind the false parameter.

The addition of the false parameter to collections.NewPrefixedTripleRange suggests a change in the underlying logic for handling the range. This may influence the behavior of the GetRedelegationsFromSrcValidator method in terms of data retrieval capabilities or performance characteristics.

Please provide clarification on:

  1. The motivation behind adding the false parameter.
  2. The implications of this change on the method's behavior and performance.

465-465: [Nitpick] Clarify the impact and motivation behind the false parameter.

The addition of the false parameter to collections.NewSuperPrefixedTripleRange suggests a change in the underlying logic for handling the range. This may influence the behavior of the HasReceivingRedelegation method in terms of data retrieval capabilities or performance characteristics.

Please provide clarification on:

  1. The motivation behind adding the false parameter.
  2. The implications of this change on the method's behavior and performance.
Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between af2f94c and e1a1811.

Files selected for processing (5)
  • collections/README.md (2 hunks)
  • x/distribution/keeper/hooks.go (1 hunks)
  • x/feegrant/keeper/keeper.go (1 hunks)
  • x/staking/keeper/delegation.go (3 hunks)
  • x/staking/keeper/query_utils.go (1 hunks)
Additional context used
Path-based instructions (5)
x/staking/keeper/query_utils.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/distribution/keeper/hooks.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/feegrant/keeper/keeper.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/staking/keeper/delegation.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

collections/README.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

Additional comments not posted (4)
x/distribution/keeper/hooks.go (1)

113-113: Verify the purpose and impact of the additional parameter in NewPrefixedTripleRange.

The change introduces an additional boolean parameter false to the NewPrefixedTripleRange function when calling the Clear method of ValidatorSlashEvents. This suggests a refinement in how validator slash events are managed and could influence the outcome of the Clear operation.

To ensure that the change aligns with the intended behavior, please verify the following:

  1. What is the purpose of the additional boolean parameter in NewPrefixedTripleRange?
  2. How does this parameter affect the behavior of the range being cleared?
  3. Confirm that the change produces the desired outcome in terms of managing validator slash events.

You can use the following script to analyze the usage of NewPrefixedTripleRange and its impact on the Clear operation:

Examining the results will provide insights into how the additional parameter is used and its effect on the clearing of validator slash events.

Verification successful

The additional boolean parameter in NewPrefixedTripleRange determines the order of the range.

The boolean parameter added to NewPrefixedTripleRange specifies the order in which the range is processed: false for ascending and true for descending. In the context of ValidatorSlashEvents.Clear, setting this parameter to false ensures that the slash events are cleared in ascending order. This change likely aligns with the intended behavior if the order of clearing is crucial for the operation's logic. Please verify that this order is necessary for maintaining consistency or correctness in managing validator slash events.

  • File: x/distribution/keeper/hooks.go
  • Line: 113
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash

# Search for usage of NewPrefixedTripleRange
rg --type go --context 5 'NewPrefixedTripleRange'

# Search for Clear method calls on ValidatorSlashEvents
rg --type go --context 5 'ValidatorSlashEvents.Clear'

Length of output: 6295

x/feegrant/keeper/keeper.go (1)

297-297: Clarify the impact of the boolean parameter in NewPrefixUntilTripleRange.

The addition of the false parameter to the NewPrefixUntilTripleRange function call changes the behavior of the range used to identify expired allowances. It's important to clarify whether this change to an exclusive endpoint was intended and to verify that it aligns with the expected functionality of the RemoveExpiredAllowances method.

Verification successful

The reverse parameter in NewPrefixUntilTripleRange affects range order, not inclusivity.

The addition of the false parameter to the NewPrefixUntilTripleRange function call specifies that the range should be in ascending order. This change aligns with the expected behavior of iterating over expired allowances chronologically and does not impact the functionality of the RemoveExpiredAllowances method. No further action is needed regarding this change.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the behavior of the `NewPrefixUntilTripleRange` function with the `false` parameter.

# Test: Search for the function definition and usage. Expect: Documentation or comments explaining the parameter's impact.
rg --type go -A 5 $'NewPrefixUntilTripleRange'

Length of output: 1135

collections/README.md (2)

1169-1169: Verify the new boolean parameter in function calls.

The addition of a new boolean parameter to the NewPrefixedTripleRange function call in the RedelegationsByDelegator method should be verified for correctness and intended behavior. This change is crucial as it likely alters how the range generation for redelegations is handled.


1178-1178: Verify the new boolean parameter in function calls.

Similarly, the addition of a new boolean parameter to the NewSuperPrefixedTripleRange function call in the RedelegationsByDelegatorAndValidator method should be verified. This parameter affects the behavior of the range generation, which is critical for the correct processing of redelegations.

Verification successful

Verification of the boolean parameter in NewSuperPrefixedTripleRange is complete.

The boolean parameter in the NewSuperPrefixedTripleRange function affects the order of the range, which is crucial for redelegation processing. It is used in x/staking/keeper/delegation.go with the parameter set to false, indicating ascending order. The functionality is also tested for both ascending and descending orders in collections/triple_test.go. The impact of the parameter is verified and aligns with the intended behavior.

  • x/staking/keeper/delegation.go: Usage with false for ascending order.
  • collections/triple_test.go: Tests for both true and false values.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new boolean parameter in function calls within the `RedelegationsByDelegatorAndValidator` method.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type markdown -A 5 $'NewSuperPrefixedTripleRange'

Length of output: 465


Script:

#!/bin/bash
# Find the implementation of the NewSuperPrefixedTripleRange function
ast-grep --lang go --pattern 'func NewSuperPrefixedTripleRange[$$$]($_, $_, $_) $_ { $$$ }'

# Locate the RedelegationsByDelegatorAndValidator method to examine its usage of NewSuperPrefixedTripleRange
rg 'func RedelegationsByDelegatorAndValidator' -A 20

Length of output: 799


Script:

#!/bin/bash
# Search for the usage of NewSuperPrefixedTripleRange in Go files to verify the impact of the boolean parameter
rg 'NewSuperPrefixedTripleRange' --type go -A 5

Length of output: 1960

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: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between af2f94c and e1a1811.

Files selected for processing (5)
  • collections/README.md (2 hunks)
  • x/distribution/keeper/hooks.go (1 hunks)
  • x/feegrant/keeper/keeper.go (1 hunks)
  • x/staking/keeper/delegation.go (3 hunks)
  • x/staking/keeper/query_utils.go (1 hunks)
Additional context used
Path-based instructions (5)
x/staking/keeper/query_utils.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/distribution/keeper/hooks.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/feegrant/keeper/keeper.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/staking/keeper/delegation.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

collections/README.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

Additional comments not posted (20)
x/staking/keeper/query_utils.go (1)

110-110: Filters are correctly implemented. Suggest renaming the boolean parameter and adding documentation.

The implementation of the source and destination validator address filters looks good. The Walk function is correctly updated to respect these filters.

Suggestions:

  1. Consider renaming the boolean parameter passed to NewPrefixedTripleRange from false to ascending for better readability.
  2. Add documentation for the function signature changes, explaining the purpose of the new parameters srcValAddress and dstValAddress.

Also, verify that all callers of this function are updated to pass the new parameters.

Run the following script to find all callers and ensure they are passing the new parameters:

Verification successful

All callers of GetAllRedelegations have been updated.

The function GetAllRedelegations is only called in the test file x/staking/keeper/delegation_test.go, and all calls have been updated to pass the new parameters. No other callers exist in the codebase that require updates.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all callers of `GetAllRedelegations` are passing the new parameters.

# Test: Search for calls to `GetAllRedelegations`. Expect: All calls are passing 3 parameters.
rg --type go --context 5 $'GetAllRedelegations\('

Length of output: 2267


Script:

#!/bin/bash
# Description: Search for all occurrences of `GetAllRedelegations` in the codebase to verify that all callers are updated.

# Search for calls to `GetAllRedelegations` across the codebase.
rg --type go 'GetAllRedelegations\('

Length of output: 333

x/distribution/keeper/hooks.go (1)

113-113: Verify the addition of the boolean parameter in NewPrefixedTripleRange.

The change at line 113 involves adding a boolean parameter to the NewPrefixedTripleRange function call. This parameter likely alters the behavior of how ranges are defined for clearing validator slash events. It's crucial to:

  • Verify the correctness and necessity of this parameter. Ensure that it aligns with the intended functionality and does not introduce regressions.
  • Assess the impact on existing functionality. Check if this change affects other parts of the system that use NewPrefixedTripleRange.
  • Review related documentation or comments to ensure they are updated to reflect this change.
Verification successful

The addition of the boolean parameter in NewPrefixedTripleRange is correct and consistent.

The boolean parameter added to the NewPrefixedTripleRange function call in x/distribution/keeper/hooks.go is consistently used across the codebase. It determines the order of the range (ascending or descending), and its usage is well-documented and tested. There are no indications of regressions or unintended side effects.

  • The change aligns with the intended functionality and is supported by test cases in collections/triple_test.go.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `NewPrefixedTripleRange` with the new boolean parameter across the codebase.

# Test: Search for the function usage. Expect: Consistent usage of the new parameter across all calls.
rg --type go -A 5 $'NewPrefixedTripleRange'

Length of output: 3330

x/feegrant/keeper/keeper.go (1)

297-297: Review the addition of the boolean parameter in NewPrefixUntilTripleRange.

The addition of the false parameter to the NewPrefixUntilTripleRange function call modifies how the range is defined for iterating over the grants. It's important to understand the specific behavior this boolean controls—whether it affects the inclusivity of the range endpoints or the direction of iteration.

Given the critical nature of the function in managing fee allowances, I recommend:

  • Verifying the behavior of this parameter in different scenarios to ensure it aligns with the intended functionality.
  • Adding comments to clarify the role of this parameter for future maintainability.
Verification successful

The boolean parameter in NewPrefixUntilTripleRange controls iteration order.

The false parameter in the NewPrefixUntilTripleRange function call specifies that the range should be iterated in ascending order. This is crucial for the correct operation of the RemoveExpiredAllowances function, ensuring expired allowances are processed in the intended sequence.

  • Consider adding comments to clarify the role of this parameter for future maintainability.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the behavior of the boolean parameter in different scenarios.

# Test: Search for the function usage and related documentation. Expect: Documentation or comments explaining the parameter's behavior.
rg --type go -A 5 $'NewPrefixUntilTripleRange'

Length of output: 1135

x/staking/keeper/delegation.go (3)

424-424: Verify the impact of the boolean parameter on data retrieval.

The addition of the false parameter to the NewPrefixedTripleRange function call changes how the range is defined, potentially affecting the data retrieved by this method. Ensure that this change aligns with the intended behavior and does not introduce any unintended side effects.


444-444: Verify the impact of the boolean parameter on data retrieval.

The addition of the false parameter to the NewPrefixedTripleRange function call changes how the range is defined, potentially affecting the data retrieved by this method. Ensure that this change aligns with the intended behavior and does not introduce any unintended side effects.


465-465: Verify the impact of the boolean parameter on data retrieval.

The addition of the false parameter to the NewSuperPrefixedTripleRange function call changes how the range is defined, potentially affecting the data retrieved by this method. Ensure that this change aligns with the intended behavior and does not introduce any unintended side effects.

collections/README.md (14)

Line range hint 1-14: Introduction Section: Clear and Informative

The introductory section provides a clear and concise explanation of the purpose and benefits of the Collections library within the Cosmos SDK context.


Line range hint 20-22: Installation Instructions: Correct and Standard

The provided Go get command is the standard method for installing Go modules and is correctly formatted for the collections library.


Line range hint 26-34: Core Types Section: Well-Documented

The core types section effectively outlines the different APIs available in the Collections library, providing a clear understanding of each type's purpose.


Line range hint 36-116: Preliminary Components Section: Detailed and Practical

This section provides a thorough explanation of the foundational components like SchemaBuilder and Prefix, enhanced by practical examples and clear descriptions.


Line range hint 118-166: Key and Value Codecs Section: Informative and Clear

The explanations and examples provided in this section effectively demonstrate the role and implementation of key and value codecs within the library.


Line range hint 168-250: Map Section: Comprehensive and Practical

The Map section is well-documented, providing a comprehensive overview of its capabilities and practical examples that clearly demonstrate how to use this collection type.


Line range hint 252-286: KeySet Section: Clearly Explained

The KeySet section effectively explains this collection type and provides a practical example, enhancing understanding of its use and implementation.


Line range hint 288-316: Item Section: Well-Explained

The Item section provides a clear explanation of the collection type and includes a practical example that demonstrates its use effectively.


Line range hint 318-416: Iteration Section: Detailed and Practical

This section thoroughly explains the iteration capabilities of different collection types and provides practical examples that demonstrate these capabilities effectively.


Line range hint 418-496: Composite Keys Section: Comprehensive and Clear

The section on composite keys is well-explained, with a detailed example that effectively demonstrates how to implement and use composite keys within the library.


Line range hint 498-576: Indexed Map Section: Thorough and Informative

The IndexedMap section is thoroughly explained, with a detailed example that clearly demonstrates the capabilities and use cases of this collection type.


Line range hint 578-610: Collections with Interfaces as Values Section: Clear and Practical

This section effectively explains how to handle collections with interface values, providing a practical example that demonstrates the implementation clearly.


Line range hint 612-1178: Triple Key Section: Well-Documented and Practical

The Triple key section provides a clear explanation of this key type and includes practical examples that demonstrate its use effectively.


Line range hint 1180-1208: Advanced Usages Section: Informative and Relevant

The advanced usages section is well-explained, providing a clear understanding of alternative value codecs and their practical applications.

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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between af2f94c and e1a1811.

Files selected for processing (5)
  • collections/README.md (2 hunks)
  • x/distribution/keeper/hooks.go (1 hunks)
  • x/feegrant/keeper/keeper.go (1 hunks)
  • x/staking/keeper/delegation.go (3 hunks)
  • x/staking/keeper/query_utils.go (1 hunks)
Additional context used
Path-based instructions (5)
x/staking/keeper/query_utils.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/distribution/keeper/hooks.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/feegrant/keeper/keeper.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/staking/keeper/delegation.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

collections/README.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

Learnings (1)
x/distribution/keeper/hooks.go (1)
Learnt from: atheeshp
PR: cosmos/cosmos-sdk#18236
File: x/slashing/keeper/hooks.go:104-113
Timestamp: 2023-11-21T11:45:40.885Z
Learning: The `AfterConsensusPubKeyUpdate` function in `x/slashing/keeper/hooks.go` is part of an interface and requires a parameter for coins, as clarified by the user atheeshp. This parameter is to be kept even if it's not currently used within the function, to maintain interface consistency and support future use cases.
Additional comments not posted (6)
x/staking/keeper/query_utils.go (1)

110-110: Review the use of the new collections.NewPrefixedTripleRange function.

The introduction of the false parameter in the NewPrefixedTripleRange function call at line 110 is a significant change. This parameter likely controls the direction of the range query, aligning with the PR's objective to support reverse iteration. However, it's crucial to verify that this change does not affect other functionalities of the GetAllRedelegations function, especially the filtering logic based on source and destination validator addresses.

Ensure that the new parameter is correctly implemented and thoroughly tested to confirm that it behaves as expected without unintended side effects.

Verification successful

Verification successful: The use of collections.NewPrefixedTripleRange with the false parameter is consistent and correct.

The change to use collections.NewPrefixedTripleRange with the false parameter in the GetAllRedelegations function aligns with the intended behavior of ascending order iteration. This is consistent with its usage across the codebase and is supported by existing test cases. There are no indications of unintended side effects on the function's filtering logic.

  • The NewPrefixedTripleRange function is well-documented and tested for both ascending and descending orders.
  • The change maintains consistency with other parts of the codebase using the same parameter.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the behavior of the new parameter in the `NewPrefixedTripleRange` function.

# Test: Search for the function usage and its impact on the behavior of the `GetAllRedelegations` function.
rg --type go -A 5 $'NewPrefixedTripleRange'

Length of output: 3330

x/distribution/keeper/hooks.go (1)

113-113: LGTM!

The code change is approved. Adding the false argument to NewPrefixedTripleRange constructor likely affects how the range is defined or how slashing events are cleared based on the new parameter.

x/feegrant/keeper/keeper.go (2)

297-297: Clarify the purpose and impact of the additional parameter in NewPrefixUntilTripleRange.

The instantiation of the rng variable now includes an additional boolean parameter false in the NewPrefixUntilTripleRange function call. This change likely alters the behavior of the range created for iterating over expired grants.

Please provide clarification on the purpose and impact of this additional parameter. Consider adding a comment to explain the parameter's significance and how it affects the identification and processing of expired grants.


Line range hint 1-323: Rest of the code looks good!

The other parts of the file appear to be in order and adhere to the Uber Go Style Guide. No deviations or issues were found.

collections/README.md (2)

1169-1169: Verify the impact of the boolean parameter on iteration behavior.

The addition of a boolean parameter to the NewPrefixedTripleRange function, as indicated by the AI-generated summary, suggests a change in how ranges are created and potentially how iteration is handled. It's crucial to ensure that this change does not adversely affect existing functionality or expected behavior in iteration processes.

Verification successful

The boolean parameter in NewPrefixedTripleRange is well-tested and does not adversely affect iteration behavior.

The NewPrefixedTripleRange function's boolean parameter is used to control the order of iteration, and its impact is verified through test cases that cover both ascending and descending orders. This ensures that the function behaves as expected without affecting existing functionality.

  • The function is defined in collections/triple.go and used in various parts of the codebase.
  • Test cases in collections/triple_test.go confirm the correct behavior for both false and true values of the parameter.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the boolean parameter on iteration behavior.

# Test: Search for the usage of `NewPrefixedTripleRange` in the codebase. Expect: Only occurrences with the new boolean parameter.
rg --type go -A 5 $'NewPrefixedTripleRange'

Length of output: 3330


1178-1178: Assess the addition of the boolean parameter in NewSuperPrefixedTripleRange.

Similar to the previous function, the introduction of a boolean parameter in NewSuperPrefixedTripleRange may influence the behavior of range creation and iteration. This change needs careful evaluation to ensure it aligns with the intended functionality and does not introduce regressions or unexpected behaviors.

Verification successful

Boolean Parameter in NewSuperPrefixedTripleRange is Well-Integrated

The addition of the boolean parameter in NewSuperPrefixedTripleRange is used to control the order of iteration, and its integration appears to be intentional and well-tested. The function's behavior with both true and false values is verified in the test cases, ensuring that it aligns with the intended functionality without introducing regressions.

  • The function is defined in collections/triple.go and used in x/staking/keeper/delegation.go.
  • Test cases in collections/triple_test.go confirm the functionality for both parameter values.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Assess the addition of the boolean parameter in `NewSuperPrefixedTripleRange`.

# Test: Search for the usage of `NewSuperPrefixedTripleRange` in the codebase. Expect: Only occurrences with the new boolean parameter.
rg --type go -A 5 $'NewSuperPrefixedTripleRange'

Length of output: 1960

x/staking/keeper/delegation.go Outdated Show resolved Hide resolved
x/staking/keeper/delegation.go Outdated Show resolved Hide resolved
x/staking/keeper/delegation.go Outdated Show resolved Hide resolved
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution ❤️
IMHO, we shouldn't break the APIs but introduce new functions.

@@ -275,29 +275,44 @@ func (t tripleKeyCodec[K1, K2, K3]) SizeNonTerminal(key Triple[K1, K2, K3]) int

// NewPrefixUntilTripleRange defines a collection query which ranges until the provided Pair prefix.
// Unstable: this API might change in the future.
func NewPrefixUntilTripleRange[K1, K2, K3 any](k1 K1) Ranger[Triple[K1, K2, K3]] {
func NewPrefixUntilTripleRange[K1, K2, K3 any](k1 K1, reverse bool) Ranger[Triple[K1, K2, K3]] {
Copy link
Member

Choose a reason for hiding this comment

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

Can we not break the API, please? We strive to have more stable APIs.
Additionally, I am super a fan of just having a bool in the function.

Can create new APIs instead? Like NewPrefixUntilTripleRangeReversed or something alike.

Copy link
Contributor Author

@oren-lava oren-lava Sep 2, 2024

Choose a reason for hiding this comment

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

Sure.
I thought maybe turn it to a variadic function so the reverse bool will be optional. By doing that, the API won't break but will be able to support reverse iteration.
Your solution obviously works too, but it add 3 functions that are basically the same code but with the "order" field set to reverse which is a sort of code duplication.

What approach should I take?

Copy link
Member

Choose a reason for hiding this comment

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

Adding options would work too yes 👍🏾.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done. see 1b1d1a7

@oren-lava
Copy link
Contributor Author

Also, not sure how to fix the failed "Changelog Reminder" check. @julienrbrt can you explain?

@julienrbrt
Copy link
Member

Also, not sure how to fix the failed "Changelog Reminder" check. @julienrbrt can you explain?

Don't worry about it, it is fine, it breaks with external contributors.

@github-actions github-actions bot removed C:x/distribution distribution module related C:x/feegrant labels Sep 2, 2024
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: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e1a1811 and 1b1d1a7.

Files selected for processing (2)
  • collections/triple.go (1 hunks)
  • collections/triple_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • collections/triple.go
  • collections/triple_test.go

collections/triple.go Outdated Show resolved Hide resolved
@@ -121,6 +123,40 @@ func (m *Multi[ReferenceKey, PrimaryKey, Value]) MatchExact(ctx context.Context,
return m.Iterate(ctx, collections.NewPrefixedPairRange[ReferenceKey, PrimaryKey](refKey))
}

// RefKeys returns a list of all the MultiIterator's reference keys (may contain duplicates).
// Enable the "unique" argument to get a unique list of reference keys (the reference key must be comparable)
func (m *Multi[ReferenceKey, PrimaryKey, Value]) RefKeys(ctx context.Context, unique bool) ([]ReferenceKey, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be documented as expensive call since it can end up iterating over a loooot of data.

return nil, fmt.Errorf("cannot retrieve unique reference keys since type is not comparable: %T", reflect.TypeOf((*ReferenceKey)(nil)))
}

iter, err := m.refKeys.Iterate(ctx, nil)
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 should RawIterate getting bytes, then use the bytes as map index. (can be efficiently done with unsafe)
then convert them to the real type later using the key codec

Copy link
Contributor Author

@oren-lava oren-lava Sep 3, 2024

Choose a reason for hiding this comment

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

not sure I follow. IterateRaw uses an untyped range but returns a typed iterator. So we're not getting bytes out of it. Can you write a small pseudo code of what you meant? (or explain in other words?) @testinginprod

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@julienrbrt any chance you get what he meant?

Copy link
Member

Choose a reason for hiding this comment

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

Not really. @testinginprod care to ellaborate?

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: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1b1d1a7 and bc0f060.

Files selected for processing (2)
  • collections/triple.go (1 hunks)
  • collections/triple_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • collections/triple.go
  • collections/triple_test.go

@julienrbrt julienrbrt requested review from testinginprod and removed request for alpe, ziscky and JulianToledano September 2, 2024 18:22
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: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bc0f060 and 7e970f2.

Files selected for processing (2)
  • collections/triple.go (1 hunks)
  • collections/triple_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • collections/triple_test.go
Additional context used
Path-based instructions (1)
collections/triple.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (3)
collections/triple.go (3)

308-314: LGTM!

The code changes are approved.


318-325: LGTM!

The code changes are approved.


329-336: LGTM!

The code changes are approved.

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: 2

🧹 Outside diff range and nitpick comments (2)
collections/triple.go (2)

342-352: LGTM! Consider enhancing the documentation.

The implementation of NewPrefixUntilTripleRangeReversed looks good. It correctly adds reverse order iteration functionality.

Consider adding a brief example in the function's documentation to illustrate its usage, which could help developers understand how to utilize this new feature effectively.


342-374: Summary: Reverse iteration support for Triple keys

The additions of NewPrefixUntilTripleRangeReversed, NewPrefixedTripleRangeReversed, and NewSuperPrefixedTripleRangeReversed functions successfully implement reverse order iteration for Triple keys. These changes enhance the flexibility of the Triple collection, allowing for more diverse use cases in data traversal.

The implementations are consistent with the existing codebase and correctly utilize the OrderDescending option. However, please ensure that the documentation errors in the function comments are addressed as mentioned in the previous review comments.

Consider adding unit tests to verify the correct behavior of these new reverse iteration functions, especially edge cases and their interaction with existing forward iteration methods.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7e970f2 and a723a09.

📒 Files selected for processing (1)
  • collections/triple.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
collections/triple.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Comment on lines +365 to +374
// NewSuperPrefixedTripleRange provides a Range for all keys prefixed with the given
// first and second parts of the Triple key in reverse order.
func NewSuperPrefixedTripleRangeReversed[K1, K2, K3 any](k1 K1, k2 K2) Ranger[Triple[K1, K2, K3]] {
key := TripleSuperPrefix[K1, K2, K3](k1, k2)
return &Range[Triple[K1, K2, K3]]{
start: RangeKeyExact(key),
end: RangeKeyPrefixEnd(key),
order: OrderDescending,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Correct the function name in the comment.

The implementation of NewSuperPrefixedTripleRangeReversed is correct and consistent with the other reverse order functions.

The comment above the function has an incorrect function name. It should be "NewSuperPrefixedTripleRangeReversed" instead of "NewSuperPrefixedTripleRange". Please update the comment to reflect the correct function name:

-// NewSuperPrefixedTripleRange provides a Range for all keys prefixed with the given
+// NewSuperPrefixedTripleRangeReversed provides a Range for all keys prefixed with the given
 // first and second parts of the Triple key in reverse order.
📝 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
// NewSuperPrefixedTripleRange provides a Range for all keys prefixed with the given
// first and second parts of the Triple key in reverse order.
func NewSuperPrefixedTripleRangeReversed[K1, K2, K3 any](k1 K1, k2 K2) Ranger[Triple[K1, K2, K3]] {
key := TripleSuperPrefix[K1, K2, K3](k1, k2)
return &Range[Triple[K1, K2, K3]]{
start: RangeKeyExact(key),
end: RangeKeyPrefixEnd(key),
order: OrderDescending,
}
}
// NewSuperPrefixedTripleRangeReversed provides a Range for all keys prefixed with the given
// first and second parts of the Triple key in reverse order.
func NewSuperPrefixedTripleRangeReversed[K1, K2, K3 any](k1 K1, k2 K2) Ranger[Triple[K1, K2, K3]] {
key := TripleSuperPrefix[K1, K2, K3](k1, k2)
return &Range[Triple[K1, K2, K3]]{
start: RangeKeyExact(key),
end: RangeKeyPrefixEnd(key),
order: OrderDescending,
}
}

Comment on lines +354 to +363
// NewPrefixedTripleRange provides a Range for all keys prefixed with the given
// first part of the Triple key in reverse order.
func NewPrefixedTripleRangeReversed[K1, K2, K3 any](k1 K1) Ranger[Triple[K1, K2, K3]] {
key := TriplePrefix[K1, K2, K3](k1)
return &Range[Triple[K1, K2, K3]]{
start: RangeKeyExact(key),
end: RangeKeyPrefixEnd(key),
order: OrderDescending,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Correct the function name in the comment.

The implementation of NewPrefixedTripleRangeReversed is correct and consistent with the other reverse order functions.

The comment above the function has an incorrect function name. It should be "NewPrefixedTripleRangeReversed" instead of "NewPrefixedTripleRange". Please update the comment to reflect the correct function name:

-// NewPrefixedTripleRange provides a Range for all keys prefixed with the given
+// NewPrefixedTripleRangeReversed provides a Range for all keys prefixed with the given
 // first part of the Triple key in reverse order.
📝 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
// NewPrefixedTripleRange provides a Range for all keys prefixed with the given
// first part of the Triple key in reverse order.
func NewPrefixedTripleRangeReversed[K1, K2, K3 any](k1 K1) Ranger[Triple[K1, K2, K3]] {
key := TriplePrefix[K1, K2, K3](k1)
return &Range[Triple[K1, K2, K3]]{
start: RangeKeyExact(key),
end: RangeKeyPrefixEnd(key),
order: OrderDescending,
}
}
// NewPrefixedTripleRangeReversed provides a Range for all keys prefixed with the given
// first part of the Triple key in reverse order.
func NewPrefixedTripleRangeReversed[K1, K2, K3 any](k1 K1) Ranger[Triple[K1, K2, K3]] {
key := TriplePrefix[K1, K2, K3](k1)
return &Range[Triple[K1, K2, K3]]{
start: RangeKeyExact(key),
end: RangeKeyPrefixEnd(key),
order: OrderDescending,
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Add RefKeys() method to collections MultiIterator
5 participants