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: reintegrate globalfee, upgraded and improved #415

Merged
merged 5 commits into from
Nov 5, 2024

Conversation

johnletey
Copy link
Member

For the initial testnet upgrade of v8 Helium, our team removed the GlobalFee module in favor of validators configuring the accepted gas prices themselves. Obviously, this is not ideal as the module also allowed certain messages to bypass the gas prices (like CCTP transactions), allowing easier usage of the Noble chain.

This PR reintegrates a Noble owned version of the module, that has been upgraded to Cosmos SDK v0.50!

@johnletey johnletey self-assigned this Oct 24, 2024
Copy link

coderabbitai bot commented Oct 24, 2024

Walkthrough

The changes introduce the globalfee module into the application by adding a new field GlobalFeeKeeper to the App structure in app.go. This integration requires updates to the NewApp function and the RegisterUpgradeHandler method to accommodate the new dependency. Additionally, the upgrade/store.go file is modified to recognize the globalfee module during store upgrades. The upgrade/upgrade.go file is also updated to enhance the upgrade handler's functionality, specifically for managing global fee messages and parameters during upgrades.

Changes

File Change Summary
app.go Added GlobalFeeKeeper *globalfeekeeper.Keeper to App; updated NewApp and RegisterUpgradeHandler to include GlobalFeeKeeper.
upgrade/store.go Added import for globalfeetypes; modified storeUpgrades to include globalfeetypes.ModuleName.
upgrade/upgrade.go Added imports for globalfeekeeper, globalfeetypes, clienttypes, and channeltypes; updated CreateUpgradeHandler to include globalFeeKeeper and manage global fee messages; added GetModuleMessages function.

Possibly related PRs

  • feat: export wired registries for reuse by integrators #417: The changes in this PR involve modifications to the dependency injection mechanism and the export of the ModuleBasicManager, which may relate to the integration of the globalfee module and its management within the application's architecture, as seen in the main PR's updates to the NewApp function and upgrade handler.

Suggested reviewers

  • g-luca

Poem

In the burrow where changes bloom,
Global fees now have more room.
With a keeper to guide the way,
Upgrades will dance, fees at play.
Hops of joy, let’s cheer and sing,
For a brighter fee-handling spring! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ed4834e and 2de4f37.

⛔ Files ignored due to path filters (3)
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
  • go.work.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (3)
  • app.go (7 hunks)
  • upgrade/store.go (2 hunks)
  • upgrade/upgrade.go (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • upgrade/store.go
🔇 Additional comments (11)
app.go (5)

57-57: LGTM: Import statements are properly organized.

The new imports for the globalfee module are correctly placed and follow the existing pattern of organizing imports by module category.

Also applies to: 94-94


145-145: LGTM: GlobalFeeKeeper field is properly integrated.

The GlobalFeeKeeper field is correctly added to the App struct and appropriately placed in the Noble Modules section.


221-221: LGTM: GlobalFeeKeeper is properly injected.

The GlobalFeeKeeper is correctly added to the dependency injection system, following the established pattern.


Line range hint 296-305: Verify upgrade migration path.

The GlobalFeeKeeper is correctly added to the upgrade handler. However, since this is a reintegration of a previously removed module:

  1. Ensure there's a clean upgrade path from chains that previously had the module
  2. Verify state migration for chains that never had the module
#!/bin/bash
# Look for any existing globalfee migrations or state handling
rg -A 10 "globalfee.*migration|migration.*globalfee"

# Check for any existing globalfee state management
ast-grep --pattern 'func $_($$) {
  $$$
  globalfee
  $$$
}'

238-238: Verify impact on existing transactions.

The integration of globalfee.TxFeeChecker is correct, but as this affects transaction processing, please ensure:

  1. Existing transactions continue to work as expected
  2. CCTP transactions can properly bypass gas prices as mentioned in the PR objectives
upgrade/upgrade.go (6)

19-20: LGTM: Import changes are appropriate

The new imports are necessary for the GlobalFee module integration and message handling functionality.

Also applies to: 29-29, 49-50, 55-56


63-63: LGTM: Function signature updates are well-structured

The addition of registry and globalFeeKeeper parameters aligns with the PR's objective of reintegrating the GlobalFee module.

Also applies to: 72-72


96-97: LGTM: GlobalFee parameter subspace initialization is correct

The GlobalFee module's parameter subspace is properly initialized following the same pattern as other modules.


161-166: Add suggested message types from previous review

Based on previous review comments, consider adding these additional message types:

 bypassMessages := []string{
     sdk.MsgTypeURL(&clienttypes.MsgUpdateClient{}),
     sdk.MsgTypeURL(&channeltypes.MsgRecvPacket{}),
     sdk.MsgTypeURL(&channeltypes.MsgTimeout{}),
     sdk.MsgTypeURL(&channeltypes.MsgAcknowledgement{}),
+    "/cosmos.upgrade.v1beta1.MsgCancelUpgrade",
+    "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade",
+    "/ibc.core.channel.v1.MsgTimeoutOnClose",
+    "/ibc.core.client.v1.MsgRecoverClient",
 }

167-170: Consider using module constants for consistency

As suggested in a previous review, consider using module name constants instead of hardcoded strings:

-bypassMessages = append(bypassMessages, GetModuleMessages(registry, "circle")...)
-bypassMessages = append(bypassMessages, GetModuleMessages(registry, "aura")...)
-bypassMessages = append(bypassMessages, GetModuleMessages(registry, "halo")...)
-bypassMessages = append(bypassMessages, GetModuleMessages(registry, "florin")...)
+bypassMessages = append(bypassMessages, GetModuleMessages(registry, circletypes.ModuleName)...)
+bypassMessages = append(bypassMessages, GetModuleMessages(registry, auratypes.ModuleName)...)
+bypassMessages = append(bypassMessages, GetModuleMessages(registry, halotypes.ModuleName)...)
+bypassMessages = append(bypassMessages, GetModuleMessages(registry, florintypes.ModuleName)...)

258-268: LGTM: GetModuleMessages implementation is clean and efficient

The utility function is well-implemented with proper filtering and sorting of message types.


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

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

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

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

CodeRabbit Commands (Invoked using PR comments)

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

Other keywords and placeholders

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

CodeRabbit Configuration File (.coderabbit.yaml)

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

Documentation and Community

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

@johnletey johnletey marked this pull request as ready for review October 31, 2024 11:09
@johnletey johnletey requested a review from a team as a code owner October 31, 2024 11:09
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
upgrade/upgrade.go (1)

139-158: Consider adding transaction boundary.

The bypass message migration involves multiple state changes. Consider wrapping these operations in a transaction to ensure atomicity.

Would you like me to provide an implementation using the Cosmos SDK transaction management?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7d282f5 and bb7b2a3.

⛔ Files ignored due to path filters (4)
  • app.yaml is excluded by !**/*.yaml
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
  • go.work.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (3)
  • app.go (7 hunks)
  • upgrade/store.go (2 hunks)
  • upgrade/upgrade.go (5 hunks)
🔇 Additional comments (11)
upgrade/store.go (2)

10-10: LGTM: Clean import addition

The import follows the existing pattern of organizing imports by their source (Cosmos SDK vs Noble modules).


21-21: Verify upgrade handler implementation for globalfee module

The addition of globalfeetypes.ModuleName to store upgrades is correct. However, ensure that the corresponding upgrade handler properly handles the module's state initialization.

Let's verify the upgrade handler implementation:

✅ Verification successful

Let me try a different search strategy to verify the upgrade handler implementation.


Let me try one final search strategy focusing on the upgrade package and store upgrades.


Upgrade handler implementation for globalfee module is properly configured

The verification shows that:

  • The globalfee module is correctly added to store upgrades
  • The upgrade handler properly initializes the globalfee module's parameters through its key table setup in upgrade/upgrade.go
  • The upgrade handler is properly registered in the app initialization
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check upgrade handler implementation for globalfee module

# Test 1: Look for upgrade handler that handles globalfee initialization
echo "Checking upgrade handlers for globalfee initialization..."
rg -l "globalfee.*[Ii]nit|[Ii]nit.*globalfee" --type go

# Test 2: Check for any migration functions
echo "Checking for migration functions..."
rg "func.*[Mm]igrate.*globalfee|globalfee.*[Mm]igrate" --type go

# Test 3: Verify proper keeper initialization
echo "Checking keeper initialization..."
ast-grep --pattern 'func $_(app *App) $_ {
  $$$
  globalfee$_
  $$$
}'

Length of output: 481


Script:

#!/bin/bash
# Search for upgrade handler registration and implementation
echo "Checking upgrade handler registration..."
rg -A 5 "RegisterUpgradeHandler.*v17" --type go

echo "Checking app initialization of globalfee..."
rg -A 10 "NewApp.*func" --type go

echo "Checking upgrade store keys..."
rg -A 5 -B 5 "StoreUpgrades.*globalfee" --type go

# Look for any globalfee related code in upgrade handlers
echo "Checking globalfee in upgrade handlers..."
rg "globalfee" app/upgrades/ || echo "No matches in upgrades directory"

Length of output: 647


Script:

#!/bin/bash
# Search for upgrade-related files and globalfee references
echo "Searching for upgrade-related files..."
fd -e go upgrade

echo "Checking store upgrades implementation..."
rg -A 10 "StoreUpgrades" --type go

echo "Checking globalfee module initialization..."
rg -A 10 "globalfeetypes.ModuleName" --type go

echo "Looking for upgrade handler in any directory..."
rg -A 5 "RegisterUpgradeHandler" --type go

Length of output: 2134

upgrade/upgrade.go (4)

13-13: LGTM: Required imports for GlobalFee integration.

The new imports are correctly added to support the GlobalFee module integration:

  • codectypes for interface registry
  • globalfeekeeper and globalfeetypes for the GlobalFee module

Also applies to: 37-38


45-45: LGTM: Handler signature updated with required dependencies.

The CreateUpgradeHandler signature is properly updated to include:

  • registry codectypes.InterfaceRegistry for message type resolution
  • globalFeeKeeper *globalfeekeeper.Keeper for GlobalFee operations

Also applies to: 54-54


78-79: LGTM: GlobalFee param table initialization.

Correctly initializes the GlobalFee parameter table during migration, maintaining consistency with other module parameter migrations.


139-158: Verify error handling in bypass message migration.

The GlobalFee bypass message migration logic looks sound, but let's ensure robust error handling:

Additionally, consider these improvements:

  1. Add logging for skipped messages that couldn't be resolved
  2. Consider batching the bypass message operations to improve performance
 // Remove unsupported messages from GlobalFee bypass list.
 oldBypassMessages, err := globalFeeKeeper.GetBypassMessages(ctx)
 if err != nil {
     return vm, err
 }
 err = globalFeeKeeper.BypassMessages.Clear(ctx, nil)
 if err != nil {
     return vm, err
 }
+logger.Info("Migrating GlobalFee bypass messages")
+skippedMessages := 0
 for _, bypassMessage := range oldBypassMessages {
     resolved, err := registry.Resolve(bypassMessage)
     if err != nil || resolved == nil {
+        skippedMessages++
+        logger.Debug("Skipping unresolvable bypass message", "type", bypassMessage)
         continue
     }

     err = globalFeeKeeper.BypassMessages.Set(ctx, bypassMessage)
     if err != nil {
         return vm, err
     }
 }
+logger.Info("Completed GlobalFee bypass message migration", 
+    "total", len(oldBypassMessages),
+    "skipped", skippedMessages)
✅ Verification successful

The search results show consistent error handling patterns throughout the upgrade module, where errors are properly propagated using return vm, err. The GlobalFee bypass message migration follows the same pattern as other sections of the code, with proper error handling for all operations including getting messages, clearing, and setting new values.

The error handling in bypass message migration is consistent and robust

The suggested improvements in the review comment for adding logging and batching are valid optimizations but not critical issues. The core error handling implementation is sound and follows the established patterns in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar error handling patterns in other migration functions
rg -A 3 "return\s+vm,\s*err" upgrade/

Length of output: 1003

app.go (5)

43-43: LGTM: Import statements follow the established pattern.

The globalfee module and its keeper are properly imported, maintaining consistency with the existing import structure.

Also applies to: 80-80


131-131: LGTM: App struct modification follows established patterns.

The GlobalFeeKeeper field is correctly added to the App struct, maintaining consistency with other Noble module keepers.


207-207: LGTM: Dependency injection properly configured.

The GlobalFeeKeeper is correctly integrated into the dependency injection system, following the established module organization pattern.


Line range hint 282-291: LGTM: Upgrade handler properly configured with GlobalFeeKeeper.

The GlobalFeeKeeper is correctly added to the upgrade handler parameters, maintaining alphabetical ordering and ensuring proper state migration capabilities during upgrades.


224-224: Verify the TxFeeChecker configuration.

The TxFeeChecker is properly configured using the globalfee module's checker function. This setup will enable the intended fee bypass functionality for specific messages.

Let's verify the fee checker implementation:

upgrade/upgrade.go Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bb7b2a3 and ed4834e.

📒 Files selected for processing (1)
  • upgrade/upgrade.go (7 hunks)
🔇 Additional comments (1)
upgrade/upgrade.go (1)

244-254: Verify module name prefixes in message type URLs

In the GetModuleMessages function, using strings.HasPrefix may unintentionally include messages from other modules if their message type URLs share similar prefixes. Ensure that the module names provided accurately correspond to the message type URL prefixes to prevent unintended messages from being added to the bypass list.

To confirm that only the intended messages are included, you can run the following script:

✅ Verification successful

Based on the results, I can now generate a final response since we have clear evidence of how GetModuleMessages is used in the codebase.

Module name prefixes are correctly used in message filtering

The usage of strings.HasPrefix in GetModuleMessages is appropriate for this codebase. The function is specifically used to collect messages from well-defined modules ("circle", "aura", "halo", "florin") with clear namespace boundaries. These module names are used as direct prefixes for their respective message type URLs, which follows the standard Cosmos SDK message naming convention of /<module_name>/....

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: List all registered message type URLs and check their prefixes.

# List all message implementations registered in the codec
ast-grep --pattern $'func (*$Type) XXX_MessageName() string {\n return "$msgTypeURL"\n}' --lang go | \
jq -r '.nodes[].captures[]?.["$msgTypeURL"]' | \
sort | uniq | while read -r msgTypeURL; do
    echo "$msgTypeURL"
done | grep "^/$MODULE_NAME\." | sort

# Replace $MODULE_NAME with the actual module name (e.g., "circle", "aura")

Length of output: 407


Script:

#!/bin/bash
# Let's try a different approach to find message type URLs in the codebase
# Search for message type URL patterns in proto files and Go files

echo "Searching in proto files for message definitions:"
fd '\.proto$' --exec rg -l 'message\s+\w+\s*{' {} | while read -r file; do
  echo "=== $file ==="
  rg 'message\s+\w+\s*{' "$file" -A 1
done

echo -e "\nSearching in Go files for message registrations:"
rg -g '*.go' 'RegisterImplementations.*sdk\.Msg' -A 2 -B 2

echo -e "\nSearching for message type URL constants or string literals:"
rg -g '*.go' '(const\s+.*TypeURL|MsgType.*=.*"/[^"]+")' 

Length of output: 546


Script:

#!/bin/bash
# Let's examine the usage context of GetModuleMessages and analyze the module names
# This will help us understand how the function is used and what module names are passed

# First, find where GetModuleMessages is called
echo "=== GetModuleMessages usage ==="
rg "GetModuleMessages\(" -B 3 -A 3

# Look for module name constants or variables that might be used
echo -e "\n=== Module name definitions ==="
rg "ModuleName\s*=\s*[\"'].*[\"']"

# Check for any message registration patterns that might show module prefixes
echo -e "\n=== Message registration patterns ==="
rg "RegisterInterfaces|RegisterInterface|RegisterImplementation" -B 2 -A 2

Length of output: 2119

upgrade/upgrade.go Show resolved Hide resolved
@boojamya boojamya merged commit ea3adaf into main Nov 5, 2024
35 checks passed
@boojamya boojamya deleted the john/reintegrate-globalfee branch November 5, 2024 20:58
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.

2 participants