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

refactor: remove unnecessary config.Seal() #3786

Merged
merged 2 commits into from
Aug 20, 2024

Conversation

rootulp
Copy link
Collaborator

@rootulp rootulp commented Aug 16, 2024

  • Add unit tests to cosmos SDK config set up
  • Remove an unnecessary config.Seal invocation that has been around for a long time but isn't necessary because the init() command always sets and seals the config.

@rootulp rootulp added the backport:v2.x PR will be backported automatically to the v2.x branch upon merging label Aug 16, 2024
@rootulp rootulp self-assigned this Aug 16, 2024
@rootulp rootulp requested a review from a team as a code owner August 16, 2024 15:49
@rootulp rootulp requested review from cmwaters and evan-forbes and removed request for a team August 16, 2024 15:49
Copy link
Contributor

coderabbitai bot commented Aug 16, 2024

Walkthrough

Walkthrough

The recent changes introduce a new configuration setup for the Cosmos SDK, enhancing the application's interaction with the Cosmos blockchain. A new file, sdk_config.go, defines initialization logic for setting Bech32 address prefixes, ensuring compliance with address standards. Additionally, unit tests in sdk_config_test.go validate these configurations. Modifications in root.go streamline the initialization process by removing explicit sealing of the SDK configuration, potentially simplifying the application's configuration lifecycle.

Changes

Files Change Summary
app/sdk_config.go, app/sdk_config_test.go Introduced sdk_config.go for Cosmos SDK configuration and sdk_config_test.go for testing address prefixes.
cmd/celestia-appd/cmd/root.go Removed lines sealing the SDK configuration during root command initialization, simplifying the process.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant SDK
    participant Config

    App->>SDK: Initialize
    SDK->>Config: GetConfig()
    Config->>Config: Set Address Prefixes
    Config->>Config: Seal Configuration
    App->>SDK: Use Configuration
Loading
sequenceDiagram
    participant App
    participant SDK
    participant Config

    App->>SDK: Initialize
    SDK->>Config: GetConfig()
    Config->>Config: Set Address Prefixes
    Config-->>App: Configuration Ready
    App->>SDK: Use Configuration
Loading

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit 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 as 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.

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

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.

@celestia-bot celestia-bot requested a review from a team August 16, 2024 15:49
@rootulp rootulp marked this pull request as draft August 16, 2024 16:09
@rootulp
Copy link
Collaborator Author

rootulp commented Aug 16, 2024

I may expose a method on the config to check if it's sealed or not and then conditionally seal it.

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

Comment on lines +9 to +14
func setCosmosSDKConfig() {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
config.Seal()
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider configuration flexibility.

The setCosmosSDKConfig function hardcodes Bech32 prefixes. Consider parameterizing these values to allow for greater flexibility and reusability in different environments or tests.

func setCosmosSDKConfig(prefixes map[string]string) {
	config := sdk.GetConfig()
	config.SetBech32PrefixForAccount(prefixes["accAddr"], prefixes["accPub"])
	config.SetBech32PrefixForValidator(prefixes["valAddr"], prefixes["valPub"])
	config.SetBech32PrefixForConsensusNode(prefixes["consAddr"], prefixes["consPub"])
	config.Seal()
}

Comment on lines +10 to +17
func Test_setCosmosSDKConfig(t *testing.T) {
config := sdk.GetConfig()
assert.Equal(t, Bech32PrefixAccAddr, config.GetBech32AccountAddrPrefix())
assert.Equal(t, Bech32PrefixAccPub, config.GetBech32AccountPubPrefix())
assert.Equal(t, Bech32PrefixValAddr, config.GetBech32ValidatorAddrPrefix())
assert.Equal(t, Bech32PrefixValPub, config.GetBech32ValidatorPubPrefix())
assert.Equal(t, Bech32PrefixConsAddr, config.GetBech32ConsensusAddrPrefix())
assert.Equal(t, Bech32PrefixConsPub, config.GetBech32ConsensusPubPrefix())
Copy link
Contributor

Choose a reason for hiding this comment

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

Call setCosmosSDKConfig in the test.

The test Test_setCosmosSDKConfig does not call the setCosmosSDKConfig function, which is necessary to verify its behavior. Add the function call to ensure the test is valid.

func Test_setCosmosSDKConfig(t *testing.T) {
	setCosmosSDKConfig() // Ensure this function is called
	config := sdk.GetConfig()
	assert.Equal(t, Bech32PrefixAccAddr, config.GetBech32AccountAddrPrefix())
	assert.Equal(t, Bech32PrefixAccPub, config.GetBech32AccountPubPrefix())
	assert.Equal(t, Bech32PrefixValAddr, config.GetBech32ValidatorAddrPrefix())
	assert.Equal(t, Bech32PrefixValPub, config.GetBech32ValidatorPubPrefix())
	assert.Equal(t, Bech32PrefixConsAddr, config.GetBech32ConsensusAddrPrefix())
	assert.Equal(t, Bech32PrefixConsPub, config.GetBech32ConsensusPubPrefix())
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@rootulp I also agree with this comment, the setCosmosSDKConfig() looks like missing, (or if not, adding some clarifying comments would be helpful).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's invoked via init(). In general I think init() should be avoided because it makes it harder to unit test.

@rootulp rootulp marked this pull request as ready for review August 19, 2024 17:16
@rootulp rootulp enabled auto-merge (squash) August 19, 2024 17:16
Copy link
Contributor

@staheri14 staheri14 left a comment

Choose a reason for hiding this comment

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

LGTM! Included some comments.

cmd/celestia-appd/cmd/root.go Show resolved Hide resolved
Comment on lines +10 to +17
func Test_setCosmosSDKConfig(t *testing.T) {
config := sdk.GetConfig()
assert.Equal(t, Bech32PrefixAccAddr, config.GetBech32AccountAddrPrefix())
assert.Equal(t, Bech32PrefixAccPub, config.GetBech32AccountPubPrefix())
assert.Equal(t, Bech32PrefixValAddr, config.GetBech32ValidatorAddrPrefix())
assert.Equal(t, Bech32PrefixValPub, config.GetBech32ValidatorPubPrefix())
assert.Equal(t, Bech32PrefixConsAddr, config.GetBech32ConsensusAddrPrefix())
assert.Equal(t, Bech32PrefixConsPub, config.GetBech32ConsensusPubPrefix())
Copy link
Contributor

Choose a reason for hiding this comment

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

@rootulp I also agree with this comment, the setCosmosSDKConfig() looks like missing, (or if not, adding some clarifying comments would be helpful).

Copy link
Contributor

@staheri14 staheri14 left a comment

Choose a reason for hiding this comment

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

LGTM!

@rootulp rootulp merged commit 9c9e77a into celestiaorg:main Aug 20, 2024
31 of 32 checks passed
mergify bot pushed a commit that referenced this pull request Aug 20, 2024
- Add unit tests to cosmos SDK config set up
- Remove an unnecessary `config.Seal` invocation that has been around
for a [long
time](5e4a1dc#diff-9e0425d31b7cf4072a746feb0c6bc1e0045b639e01dd0b5ac2f08e8c2952c886R120)
but isn't necessary because the `init()` command always sets and seals
the config.

(cherry picked from commit 9c9e77a)

# Conflicts:
#	cmd/celestia-appd/cmd/root.go
@rootulp rootulp deleted the rp/refactor-config-seal branch August 20, 2024 18:54
rootulp added a commit that referenced this pull request Aug 20, 2024
- Add unit tests to cosmos SDK config set up
- Remove an unnecessary `config.Seal` invocation that has been around
for a [long
time](5e4a1dc#diff-9e0425d31b7cf4072a746feb0c6bc1e0045b639e01dd0b5ac2f08e8c2952c886R120)
but isn't necessary because the `init()` command always sets and seals
the config.<hr>This is an automatic backport of pull request #3786 done
by [Mergify](https://mergify.com).

---------

Co-authored-by: Rootul P <rootulp@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:v2.x PR will be backported automatically to the v2.x branch upon merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants