Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: export wired registries for reuse by integrators #417

Merged
merged 4 commits into from
Nov 1, 2024

Conversation

johnletey
Copy link
Member

Prior to Noble v8, the ModuleBasicManager was exported directly from Noble's application. This allowed integrators like Coinbase to easily register interfaces against a local interface registry in order to decode transactions successfully!

Since the Noble application now utilizes dependency injection, we need to export this value from the /cmd package.

This PR does exactly that!

@johnletey johnletey requested review from g-luca and boojamya October 29, 2024 08:31
@johnletey johnletey self-assigned this Oct 29, 2024
@johnletey johnletey requested a review from a team as a code owner October 29, 2024 08:31
Copy link

coderabbitai bot commented Oct 29, 2024

Walkthrough

The changes involve modifications across three files in the command-line application of the Cosmos SDK. In cmd/nobled/main.go, several Bech32 prefix variables and their associated configuration logic have been removed. The main function now initializes the root command directly. In cmd/root.go, the NewRootCmd function has been restructured to simplify initialization and expand gas price handling. New functions and Bech32 prefix variables have been added in cmd/init.go, which also introduces an Initialize function for application configuration and dependency injection.

Changes

File Change Summary
cmd/nobled/main.go Removed Bech32 prefix variables and related configuration logic. Updated import statement for os.
cmd/root.go Restructured NewRootCmd function, removed internal initialization components, expanded minimum gas prices handling, and eliminated commented-out IBC module registration.
cmd/init.go Added Bech32 prefix variables, introduced Initialize, ProvideClientContext, and ProvideKeyring functions for application setup and configuration.

Poem

In the land of code where rabbits play,
Bech32 prefixes hopped away.
With a new command, we leap and bound,
Simplified paths where joy is found.
Oh, what a change, so bright and clear,
A cosmos of code, let’s give a cheer! 🐇✨


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.

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

🧹 Outside diff range and nitpick comments (2)
cmd/root.go (1)

19-24: Well-structured dependency injection implementation!

The updated function signature improves modularity by accepting dependencies as parameters instead of creating them internally. This change not only supports the PR objective of making ModuleBasicManager accessible to integrators but also enhances testability and flexibility.

Consider documenting these parameters in the function's comment block to help integrators understand what configurations they need to provide.

cmd/commands.go (1)

Line range hint 119-127: Improve error handling structure

While the enhanced error checking is good, consider consolidating the validation checks at the beginning of the function for better readability and maintainability.

Consider restructuring like this:

 func appExport(
   logger log.Logger,
   db dbm.DB,
   traceStore io.Writer,
   height int64,
   forZeroHeight bool,
   jailAllowedAddrs []string,
   appOpts servertypes.AppOptions,
   modulesToExport []string,
 ) (servertypes.ExportedApp, error) {
+  // Validate inputs
+  homePath, ok := appOpts.Get(flags.FlagHome).(string)
+  if !ok || homePath == "" {
+    return servertypes.ExportedApp{}, errors.New("application home not set")
+  }
+
+  viperAppOpts, ok := appOpts.(*viper.Viper)
+  if !ok {
+    return servertypes.ExportedApp{}, errors.New("appOpts is not viper.Viper")
+  }
+
+  // Configure options
+  viperAppOpts.Set(server.FlagInvCheckPeriod, 1)
+  appOpts = viperAppOpts
+
   var (
     app *noble.App
     err error
   )
-
-  // this check is necessary as we use the flag in x/upgrade.
-  // we can exit more gracefully by checking the flag here.
-  homePath, ok := appOpts.Get(flags.FlagHome).(string)
-  if !ok || homePath == "" {
-    return servertypes.ExportedApp{}, errors.New("application home not set")
-  }
-
-  viperAppOpts, ok := appOpts.(*viper.Viper)
-  if !ok {
-    return servertypes.ExportedApp{}, errors.New("appOpts is not viper.Viper")
-  }
-
-  // overwrite the FlagInvCheckPeriod
-  viperAppOpts.Set(server.FlagInvCheckPeriod, 1)
-  appOpts = viperAppOpts
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7d282f5 and 7b14b8e.

📒 Files selected for processing (3)
  • cmd/commands.go (1 hunks)
  • cmd/nobled/main.go (2 hunks)
  • cmd/root.go (2 hunks)
🔇 Additional comments (5)
cmd/root.go (1)

62-62: Verify the expanded gas price configuration.

The minimum gas prices configuration now supports multiple denominations (uusdc, ausdy, ueure) all set to 0.

Please ensure:

  1. This change is intentional and documented
  2. The implications of zero-value gas prices are understood
✅ Verification successful

Gas price configuration change is intentional and properly integrated

The change to support multiple denominations (uusdc, ausdy, ueure) with zero minimum gas prices is verified to be intentional based on the following findings:

  1. These denominations are properly defined in the genesis configuration (local.sh) with correct metadata including descriptions and exponents:

    • uusdc: Circle USD Coin
    • ausdy: Ondo US Dollar Yield
    • ueure: Monerium EUR emoney
  2. The e2e tests extensively use these denominations, particularly uusdc, for testing gas fee payments and transactions, confirming their integration into the system's fee mechanism.

  3. The zero gas price configuration aligns with the testing environment setup, where the e2e tests show examples of transactions using these denominations for fees.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any documentation or configuration references to gas prices
# and verify if this change is documented

echo "Checking for gas price documentation..."
rg -i "gas.?price" --type md
rg -i "minimum.?gas" --type md

echo "Checking for related configuration files..."
fd -e toml -e yaml -x grep -l "minimum.*gas"

Length of output: 296


Script:

#!/bin/bash
# Let's try a broader search for gas-related configurations and documentation

# Search for any mentions of the specific denominations
echo "Checking for denomination references..."
rg -i "uusdc|ausdy|ueure"

# Search for gas-related configurations in Go files
echo "Checking gas configurations in Go files..."
rg -i "mingas|gas.?price" --type go -A 2 -B 2

# Look for app configuration or chain configuration files
echo "Looking for config files..."
fd "config|app" -e toml -e yaml -e json

# Check for any commit messages related to gas prices
echo "Checking recent commit messages..."
git log --grep="gas" --pretty=format:"%h %s" -n 5

Length of output: 10612

cmd/commands.go (3)

4-6: LGTM: Clean import organization

The added imports are necessary and properly utilized in the codebase.


Line range hint 128-152: LGTM: Robust app creation logic

The app creation logic properly handles both height-specific and regular initialization cases, with appropriate error handling. This maintains the necessary functionality for integrators while ensuring stability.


Line range hint 31-45: Verify ModuleBasicManager integration in command initialization

The command initialization correctly uses the basicManager parameter, which is crucial for the PR's objective of exporting ModuleBasicManager for integrators.

Let's verify the BasicManager usage across the codebase:

✅ Verification successful

ModuleBasicManager integration is correctly implemented

The verification confirms that ModuleBasicManager is properly integrated in the command initialization:

  • Correctly passed to genutilcli.InitCmd() in command initialization
  • Properly structured in the root command setup
  • Consistently used across cmd/root.go, cmd/commands.go, and cmd/nobled/main.go
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify BasicManager integration points
# Look for BasicManager usage in command initialization
rg -l "module\.BasicManager" 

# Look specifically for how it's exported and used
ast-grep --pattern 'type $x struct {
  $$$
  BasicManager $_
  $$$
}'

Length of output: 149


Script:

#!/bin/bash
# Let's examine the actual usage of BasicManager in these files
rg -A 5 "module\.BasicManager" cmd/

# Check how BasicManager is initialized and passed
ast-grep --pattern 'basicManager := module.NewBasicManager($$$)'

# Look for genutilcli.InitCmd usage with BasicManager
rg -A 3 "genutilcli.InitCmd"

Length of output: 1171

cmd/nobled/main.go (1)

54-59: Exported ModuleBasicManager for integrators

Exporting ModuleBasicManager by declaring it as a global variable aligns with the PR objectives of making it accessible for integrators. This change facilitates reuse by external partners as intended.

cmd/nobled/main.go Outdated Show resolved Hide resolved
cmd/nobled/main.go Outdated Show resolved Hide resolved
cmd/nobled/main.go Outdated Show resolved Hide resolved
@johnletey johnletey force-pushed the john/export-modulebasicmanager branch from 20fe551 to 30401ad Compare October 29, 2024 15:37
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: 5

🧹 Outside diff range and nitpick comments (1)
cmd/nobled/main.go (1)

Line range hint 13-18: LGTM! Clean and robust implementation.

The main function implementation is now more focused and robust:

  • Properly delegates initialization to the root command
  • Handles errors appropriately with user-friendly error output
  • Follows the principle of separation of concerns by moving configuration to init.go

This change aligns well with the transition to dependency injection and improves modularity.

The removal of direct Bech32 prefix configuration from main.go in favor of initialization in init.go is a good architectural decision as it:

  1. Reduces main.go's responsibilities
  2. Makes the configuration more maintainable
  3. Better supports the dependency injection pattern
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7b14b8e and 30401ad.

⛔ 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)
  • cmd/init.go (1 hunks)
  • cmd/nobled/main.go (1 hunks)
  • cmd/root.go (2 hunks)
🔇 Additional comments (4)
cmd/nobled/main.go (1)

5-6: LGTM! Clean import organization.

The import organization is clean and follows standard Go conventions.

cmd/root.go (2)

64-64: Verify ModuleBasicManager export configuration.

The change correctly uses externally provided ModuleBasicManager, aligning with the PR objective. However, we should verify that it's properly exported for integrators.

#!/bin/bash
# Description: Verify ModuleBasicManager is properly exported
# Test: Check if ModuleBasicManager is exported and accessible

# Look for ModuleBasicManager declaration
ast-grep --pattern 'var ModuleBasicManager = $$$'

# Check if it's used in package exports
rg -A 2 'ModuleBasicManager.*exported' 

18-18: Verify initialization order and side effects.

The newly added Initialize() call might have side effects that could impact the command setup. Please ensure that this is the correct point in the lifecycle for initialization.

✅ Verification successful

Initialization order is correct and safe

The Initialize() function is properly placed at the beginning of NewRootCmd. It sets up essential SDK configurations like Bech32 address prefixes, which should be done before any command setup. This is the only call to Initialize() in the codebase, avoiding any duplicate initialization concerns.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the Initialize function implementation and its usage
# Test: Look for Initialize function definition and other potential calls
ast-grep --pattern 'func Initialize() {
  $$$
}'

# Check for other Initialize calls to ensure we're not duplicating initialization
rg '\bInitialize\(\)'

Length of output: 234


Script:

#!/bin/bash
# Let's try a different approach to find the Initialize function and its usage

# Search for Initialize function definition
rg -l "func Initialize\(\)"

# Search for Initialize function calls with context
rg -A 3 -B 3 "Initialize\(\)"

# Look for any files that might contain initialization logic
fd -t f "init\.go$"

Length of output: 695

cmd/init.go (1)

123-126: ⚠️ Potential issue

Ensure clientCtx.Keyring is properly initialized before use

The call to clientCtx.Keyring.Backend() assumes that clientCtx.Keyring is initialized. If it's not set, this could lead to a nil pointer dereference. Verify that clientCtx.Keyring is properly initialized before this point.

Run the following script to check if clientCtx.Keyring is initialized before use:

cmd/root.go Show resolved Hide resolved
cmd/init.go Outdated Show resolved Hide resolved
cmd/init.go Show resolved Hide resolved
cmd/init.go Show resolved Hide resolved
cmd/init.go Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
@johnletey johnletey force-pushed the john/export-modulebasicmanager branch from 30401ad to 884d1e7 Compare October 29, 2024 17:10
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

Files that changed from the base of the PR and between 30401ad and 884d1e7.

📒 Files selected for processing (3)
  • cmd/init.go (1 hunks)
  • cmd/nobled/main.go (1 hunks)
  • cmd/root.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • cmd/init.go
  • cmd/nobled/main.go
🔇 Additional comments (2)
cmd/root.go (2)

57-57: Previous comment about configurable gas prices still applies

The previous suggestion about making gas prices configurable through a configuration file remains valid.


64-64: Verify ModuleBasicManager export configuration

The usage of ModuleBasicManager here aligns with the PR objective to make it available for integrators.

Let's verify the export configuration:

✅ Verification successful

Let me gather more information about the ModuleBasicManager declaration and usage.


ModuleBasicManager is properly exported and initialized

The verification shows that ModuleBasicManager is:

  • Correctly declared as an exported variable (uppercase first letter)
  • Properly initialized with module registrations
  • Used consistently in the codebase for module management
  • Available for integrators as intended by the PR objective
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that ModuleBasicManager is properly exported
# Expected: ModuleBasicManager should be exported from the package

# Check if ModuleBasicManager is exported (starts with uppercase)
rg -l "^var ModuleBasicManager" cmd/
# Check for any references to ModuleBasicManager in go.mod files that might use this export
rg "noble-assets/noble" -g "go.mod" 

Length of output: 171


Script:

#!/bin/bash
# Check the actual declaration and usage of ModuleBasicManager
rg "ModuleBasicManager" cmd/ -A 3 -B 3

# Check if it's exported in any package documentation
rg "ModuleBasicManager" -g "doc.go"

# Look for any exported package variables in cmd package
ast-grep --pattern 'var ModuleBasicManager = $_'

Length of output: 1317

cmd/root.go 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: 0

🧹 Outside diff range and nitpick comments (2)
cmd/root.go (2)

27-28: Consider avoiding global ClientCtx variable

Using a global ClientCtx variable could lead to concurrency issues and makes testing more difficult. Consider passing the context as a parameter to maintain dependency injection principles.

Example approach:

-ClientCtx = ClientCtx.WithCmdContext(cmd.Context())
-clientCtx, err := client.ReadPersistentCommandFlags(ClientCtx, cmd.Flags())
+func NewRootCmd(clientCtx client.Context) *cobra.Command {
+    // ...
+    clientCtx = clientCtx.WithCmdContext(cmd.Context())
+    updatedCtx, err := client.ReadPersistentCommandFlags(clientCtx, cmd.Flags())

64-64: Consider consistent dependency injection for ModuleBasicManager

While exporting ModuleBasicManager aligns with the PR objectives, accessing it as a global variable could lead to similar issues as with ClientCtx. Consider passing it as a parameter to maintain consistent dependency injection throughout the codebase.

Example approach:

-initRootCmd(rootCmd, ClientCtx.TxConfig, ModuleBasicManager)
+func NewRootCmd(clientCtx client.Context, moduleBasicManager *module.BasicManager) *cobra.Command {
+    // ...
+    initRootCmd(rootCmd, clientCtx.TxConfig, moduleBasicManager)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 884d1e7 and a553804.

📒 Files selected for processing (2)
  • cmd/init.go (1 hunks)
  • cmd/root.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/init.go
🔇 Additional comments (2)
cmd/root.go (2)

18-18: Error handling needed for Initialize()

A previous review has already identified this issue. The Initialize() call still lacks error handling for potential failures during setup.


57-57: Gas prices should be configurable

A previous review has already suggested making gas prices configurable instead of hardcoding them. This becomes even more important now with multiple currencies supported.

@johnletey johnletey requested a review from boojamya November 1, 2024 11:03
@johnletey johnletey changed the title chore: export ModuleBasicManager for reuse by integrators feat: export wired registries for reuse by integrators Nov 1, 2024
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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a553804 and c6eb5c4.

📒 Files selected for processing (1)
  • cmd/root.go (3 hunks)
🔇 Additional comments (2)
cmd/root.go (2)

32-32: Error handling still needed for Initialize()

The previous review comment about adding error handling for Initialize() is still valid and unaddressed.


71-71: Gas prices should be configurable

The previous review comment about making gas prices configurable is still valid and unaddressed.

cmd/root.go Show resolved Hide resolved
cmd/root.go Show resolved Hide resolved
@johnletey johnletey merged commit 411a17a into main Nov 1, 2024
35 checks passed
@johnletey johnletey deleted the john/export-modulebasicmanager branch November 1, 2024 21:47
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants