-
Notifications
You must be signed in to change notification settings - Fork 0
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: ensure state compatibility with v1 #9
Conversation
WalkthroughThe changes in this pull request involve significant modifications to the Changes
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
🧹 Outside diff range and nitpick comments (2)
keeper/keeper.go (1)
92-93
: LGTM! Initialization maintains storage structure while adapting key types.
The initialization correctly uses BytesKey while preserving the storage prefixes and schema names, ensuring data organization remains clear despite the simplified key type.
Consider documenting the key format in comments or constants to ensure consistent key generation across the codebase, especially important for v1 compatibility.
keeper/state_entitlements.go (1)
Line range hint 84-138
: Refactor repetitive key parsing logic into a helper function.
The code for extracting roles from keys is duplicated across multiple functions (GetCapabilityRoles
, GetUserRoles
, etc.). Refactoring this logic into a shared helper function will improve maintainability and reduce redundancy.
Here's an example of a helper function:
func extractRoleFromKey(key []byte) (entitlements.Role, error) {
if len(key) < 8 {
return 0, errors.New("key too short to extract role")
}
role := binary.BigEndian.Uint64(key[len(key)-8:])
return entitlements.Role(role), nil
}
Modify your functions to use the helper:
- role := binary.BigEndian.Uint64(key[len(key)-8:])
+ role, err := extractRoleFromKey(key)
+ if err != nil {
+ // Handle the error appropriately
+ continue
+ }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (6)
- keeper/keeper.go (2 hunks)
- keeper/msg_server_entitlements_test.go (2 hunks)
- keeper/state_entitlements.go (4 hunks)
- types/aggregator/keys.go (0 hunks)
- types/entitlements/keys.go (1 hunks)
- types/keys.go (0 hunks)
💤 Files with no reviewable changes (2)
- types/aggregator/keys.go
- types/keys.go
🔇 Additional comments (7)
types/entitlements/keys.go (1)
22-22
: LGTM! Successfully fixes v1 compatibility.
The direct concatenation approach aligns with v1's key generation strategy by avoiding the extra delimiter bytes that were causing compatibility issues.
keeper/keeper.go (2)
Line range hint 119-134
: Verify role-based security checks remain functional.
The SendRestrictionFn relies on role-based access control through CanCall. Given the key type changes, we should verify that all role checks still work correctly.
Let's verify the role check implementations:
✅ Verification successful
Based on the results, I can now generate the final response:
Role-based security checks are correctly implemented and remain functional.
The verification shows that the role-based access control system is properly implemented with:
CanCall
implementation inkeeper/state_entitlements.go
correctly uses byte arrays for user addresses- Role lookups are handled through collections.Map with BytesKey:
UserRoles
for storing user-to-role mappingsRoleCapabilities
for storing method-to-role mappings
- Key type changes are consistently applied across all role-related functions
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for CanCall implementations to verify role check logic
rg "func.*CanCall" -A 10
# Look for other role-based security checks
rg "UserRoles|RoleCapabilities" -A 3 --type go
Length of output: 22348
49-50
: LGTM! Field type changes align with v1 compatibility goals.
The simplified key types ([]byte) will allow for direct key concatenation matching v1's approach, while removing the collections.Pair delimiter issue.
Let's verify the key format compatibility:
✅ Verification successful
Field type changes are correctly implemented for key compatibility
The verification confirms:
- No remaining usage of
collections.Pair
in the codebase - Key generation in both
CapabilityRoleKey
andUserRoleKey
functions uses direct byte concatenation:CapabilityRoleKey
: concatenates method string bytes with role uint64 bytesUserRoleKey
: concatenates address bytes with role uint64 bytes
This implementation matches the PR's goal of fixing state compatibility by removing the delimiter-based collections.Pair
and using direct byte concatenation instead.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for any remaining collections.Pair usage in key generation
rg -l "collections\.Pair.*string.*uint64" || echo "No collections.Pair usage found"
# Search for key generation logic to verify concatenation approach
rg "func.*[Kk]ey.*Role" -A 5
Length of output: 767
Script:
#!/bin/bash
# Let's verify if there are any v1 key generation functions to compare with
rg -B 2 -A 3 "v1.*[Kk]ey.*Role|legacy.*[Kk]ey.*Role"
# Also check for any migration code that handles key conversion
rg -B 2 -A 3 "func.*[Mm]igrate.*[Rr]ole|func.*[Cc]onvert.*[Rr]ole"
Length of output: 123
keeper/msg_server_entitlements_test.go (3)
322-322
: LGTM: Key codec change aligns with v1 compatibility fix.
The change from composite key codec to BytesKey is correct and aligns with the PR objective of ensuring state compatibility between v1 and v2.
467-467
: LGTM: Key codec change aligns with v1 compatibility fix.
The change from composite key codec to BytesKey is correct and aligns with the PR objective of ensuring state compatibility between v1 and v2.
322-322
: Verify key format compatibility with v1.
While the key codec changes look correct, let's verify that the actual key format matches v1's implementation.
Also applies to: 467-467
✅ Verification successful
Let me search for the key format implementation to verify compatibility.
Key format implementation is correct and consistent
The key format implementation in the codebase is consistent and follows a clear pattern:
UserRoleKey
: Concatenates the address bytes with an 8-byte big-endian encoded role valueCapabilityRoleKey
: Concatenates the method string bytes with an 8-byte big-endian encoded role value
The implementation ensures unique keys for both user roles and role capabilities, maintaining compatibility with the collections interface.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Search for v1 key format implementation to verify compatibility
# Expected: Find key concatenation implementation in v1 codebase
# Look for key generation or state management code in v1
rg -g '!{test,vendor}/*' -A 5 'func.*[Ss]et.*[Rr]ole'
rg -g '!{test,vendor}/*' -A 5 'func.*[Ss]et.*[Cc]apability'
Length of output: 139729
Script:
#!/bin/bash
# Search for key format implementation
rg -g '!{test,vendor}/*' "CapabilityRoleKey|UserRoleKey" -A 3
Length of output: 1173
keeper/state_entitlements.go (1)
11-11
: Importing encoding/binary
is appropriate for key handling.
The import is necessary for processing byte slices and extracting roles from keys.
This PR addresses state compatibility issues when upgrading the Halo module from
v1
tov2
The underlying issue was that
collections.Pair
inserts an extra delimiter byte to distinguish between the two keys. However, with the manual state management included in v1, we simply concatenated the two keys together.We've used the latest commit on this branch to patch a Noble testnet node, and can confirm it is working as expected:
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores