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

fix: state export for gov module constitution #8777

Merged
merged 5 commits into from
Oct 23, 2024
Merged

Conversation

PaddyMc
Copy link
Collaborator

@PaddyMc PaddyMc commented Oct 15, 2024

What is the purpose of the change

Currently the export of Osmosis to genesis state isn't working as expected because of the export of gov is missing a gov collection key.

see: https://github.com/cosmos/cosmos-sdk/issues/21887

Testing and Verifying

Unit test:

  • cd ./app/upgrades/v27
  • go test ./...

in-place-testnet:

  • do the in-place-testnet dance
  • osmosisd export --modules-to-export "gov"

Query:
osmosisd q gov constitution

BUG:

panic: collections: not found: key 'no_key' of type string

goroutine 4433 [running]:
github.com/cosmos/cosmos-sdk/x/gov.AppModule.ExportGenesis({{{0x6283970, 0xc000fae690}, {0x0, 0x0, 0x0}, {0x6200fc8, 0xc00217ee40}}, 0xc0043a8408, {0x6241700, 0xc000356500}, ...}, ...)
	github.com/cosmos/cosmos-sdk@v0.50.9/x/gov/module.go:310 +0xbf
github.com/cosmos/cosmos-sdk/types/module.(*Manager).ExportGenesisForModules.func2({0x789e1f0e1468, 0xc0043ccfc0}, 0xc063aa9260)
	github.com/cosmos/cosmos-sdk@v0.50.9/types/module/module.go:578 +0x12d
created by github.com/cosmos/cosmos-sdk/types/module.(*Manager).ExportGenesisForModules in goroutine 1
	github.com/cosmos/cosmos-sdk@v0.50.9/types/module/module.go:576 +0x770

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes?
  • Changelog entry added to Unreleased section of CHANGELOG.md?

Where is the change documented?

  • Specification (x/{module}/README.md)
  • Osmosis documentation site
  • Code comments?
  • N/A

@github-actions github-actions bot added the C:app-wiring Changes to the app folder label Oct 15, 2024
@PaddyMc PaddyMc marked this pull request as ready for review October 17, 2024 14:34
Copy link
Contributor

coderabbitai bot commented Oct 17, 2024

Walkthrough

The pull request introduces updates to the CHANGELOG.md file, enhancing its structure and adding entries for various releases of the Osmosis project, including a bug fix for the governance module. Additionally, it modifies the app/upgrades/v27/upgrades.go file to improve the upgrade handler functionality by adding a new function for initializing a constitution collection. A new test suite is also introduced in upgrades_test.go to validate the upgrade logic and governance module behavior for version 27.

Changes

File Change Summary
CHANGELOG.md Updated format and added entries under "Unreleased" for state breaking, config, and bug fixes.
Updated entries for versions v26.0.1 and v26.0.0 detailing features, improvements, and bug fixes.
app/upgrades/v27/upgrades.go Added import for govkeeper, updated CreateUpgradeHandler to initialize constitution collection, and defined InitializeConstitutionCollection function.
app/upgrades/v27/upgrades_test.go Introduced a test suite with methods to validate upgrade logic and governance module behavior.

Possibly related PRs

  • misc: Add missing CHANGELOG #8686: This PR adds a missing changelog entry related to additional queries in the x/gauges module, which is relevant to the updates made in the main PR regarding the changelog.
  • chore: updating binary json file #8698: This PR updates the changelog to reflect various modifications, including a chore to bump the cosmwasm-optimizer, which is also documented in the main PR's changelog updates.
  • fix: supply offsets for osmo token #8751: This PR addresses supply offsets for the osmo token, which is mentioned in the changelog updates of the main PR, indicating a direct connection to the changes made.
  • chore: bump cometbft/cosmos-sdk versions #8779: This PR updates the changelog to include entries for the bump of the cometbft/cosmos-sdk versions, which aligns with the systematic approach to documenting changes in the main PR's updates to the changelog.

Suggested reviewers

  • czarcas7ic
  • nicolaslara
  • AlpinYukseloglu

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1136871 and 460563b.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • app/upgrades/v27/upgrades.go (2 hunks)
  • app/upgrades/v27/upgrades_test.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • CHANGELOG.md
  • app/upgrades/v27/upgrades.go
  • app/upgrades/v27/upgrades_test.go

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
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 (8)
app/upgrades/v27/upgrades_test.go (3)

21-23: Consider using a more realistic upgrade height.

The v27UpgradeHeight constant is set to 10, which seems quite low for a real-world scenario. Consider using a more realistic value or adding a comment explaining why this specific value was chosen for the test.


50-59: Consider making the time increment configurable.

The dummyUpgrade function correctly simulates the upgrade process. However, the time increment of 1 second is arbitrary. Consider making this value configurable or add a comment explaining why 1 second was chosen. This would make the test more flexible and self-documenting.

For example:

const upgradeTimeIncrement = time.Second // Arbitrary time increment for upgrade simulation

// ...

s.Ctx = s.Ctx.WithHeaderInfo(header.Info{
    Height: v27UpgradeHeight,
    Time: s.Ctx.BlockTime().Add(upgradeTimeIncrement),
}).WithBlockHeight(v27UpgradeHeight)

69-75: Consider using a constant for the expected constitution value.

The ExecuteGovModuleConstitutionTest method correctly verifies the state of the constitution after the upgrade. However, the expected constitution value is hardcoded. Consider defining this as a constant at the package level for better maintainability and to make it easier to update if needed.

For example:

const expectedConstitution = "This chain has no constitution."

// ...

func (s *UpgradeTestSuite) ExecuteGovModuleConstitutionTest() {
    // ...
    s.Require().Equal(expectedConstitution, post)
}
CHANGELOG.md (5)

Line range hint 1-49: Well-organized unreleased section with room for improvement

The unreleased section of the changelog is well-structured, clearly separating state breaking changes, config changes, and state compatible changes. It provides a good overview of the upcoming features and fixes. However, some entries could benefit from more detailed explanations or links to relevant issues/PRs for better context.

Consider adding more context to some entries, such as brief explanations of the impact of certain changes or links to related issues/PRs for readers who want to dive deeper into specific changes.


Line range hint 51-55: Concise and clear bug fix entries

The v26.0.1 section effectively communicates the minor CLI bug fixes addressed in this release. The fixes for the vesting by duration command and pagination in x/incentives module queries are clearly stated.

Consider adding the PR numbers or links for these fixes to make it easier for developers to reference the specific changes if needed.


Line range hint 57-190: Comprehensive changelog with room for consistency improvements

The v26.0.0 section provides a detailed and extensive overview of the major release changes, covering breaking changes, new features, bug fixes, and improvements across multiple modules. The inclusion of SDK updates and config changes is particularly helpful for users and developers.

  1. Improve consistency by adding PR numbers to all entries, not just some.
  2. Consider providing brief explanations for more technical changes to help users understand their impact.
  3. Group related changes together (e.g., all SDK-related changes in one subsection) to improve readability.
  4. For entries like "Remove x/Bech32IBC", consider adding a brief explanation of why this module was removed and its impact on users.

Line range hint 192-1160: Valuable historical changelog with opportunities for improvement

The inclusion of changelogs for older releases, dating back to v1.0.0, provides a valuable historical record of the project's evolution. This information is crucial for users and developers who need to understand the changes between different versions.

  1. Strive for consistent levels of detail across all release entries. Some releases have very detailed changelogs, while others are quite brief.
  2. For major releases or significant changes, consider adding more context or explanations, especially in older entries where the reasons for changes might not be immediately apparent to new users.
  3. Use consistent formatting and structure across all release entries to improve readability.
  4. Consider adding links to relevant discussions, proposals, or design documents for major feature additions or breaking changes, particularly in older releases.

Line range hint 1-1160: Comprehensive changelog with room for consistency and clarity improvements

This CHANGELOG.md file provides a detailed and valuable history of the project's evolution from v1.0.0 to the latest unreleased changes. It covers a wide range of updates including features, bug fixes, improvements, and breaking changes across multiple releases.

To further improve this already informative changelog:

  1. Standardize the format and level of detail across all releases for better consistency.
  2. Always include PR/issue numbers for easy reference.
  3. Provide more context for major changes, especially in older releases.
  4. Group related changes together within each release (e.g., by module or type of change).
  5. Consider adding a brief summary at the top of each major release highlighting the most significant changes.
  6. Ensure all entries clearly indicate whether they are features, bug fixes, or breaking changes.
  7. For breaking changes, always include upgrade instructions or links to upgrade guides.

These improvements would make the changelog even more useful for both users and developers, providing a clearer picture of the project's development over time.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8a70876 and 87b7462.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • app/upgrades/v27/upgrades.go (2 hunks)
  • app/upgrades/v27/upgrades_test.go (1 hunks)
🧰 Additional context used
🔇 Additional comments (6)
app/upgrades/v27/upgrades_test.go (4)

3-19: LGTM: Import statements are well-organized and relevant.

The import statements are properly grouped and include all necessary packages for the test suite. There are no unused imports.


25-28: LGTM: UpgradeTestSuite struct is well-defined.

The UpgradeTestSuite struct is properly structured for a test suite. It embeds apptesting.KeeperTestHelper for common testing utilities and includes a preModule field to test the pre-block logic of the upgrade module.


30-32: LGTM: TestUpgradeTestSuite function is correctly implemented.

The TestUpgradeTestSuite function properly uses suite.Run to execute the test suite, following the standard pattern for testify suites.


61-67: LGTM: PrepareGovModuleConstitutionTest method is well-implemented.

The PrepareGovModuleConstitutionTest method correctly verifies the initial state of the constitution before the upgrade. It uses proper error handling and assertions to ensure the constitution is initially empty.

app/upgrades/v27/upgrades.go (2)

7-9: Appropriate addition of necessary imports

The added imports for sdk and govkeeper are required for the new functionality and are correctly referenced.


40-44: Initialization function correctly sets the default constitution

The InitializeConstitutionCollection function accurately sets the default constitution in the governance keeper, aligning with the cosmos-sdk v5 governance migration guidelines.

Comment on lines 34 to 48
func (s *UpgradeTestSuite) TestUpgrade() {
s.Setup()
s.preModule = upgrade.NewAppModule(s.App.UpgradeKeeper, addresscodec.NewBech32Codec("osmo"))

s.PrepareGovModuleConstitutionTest()

// Run the upgrade
dummyUpgrade(s)
s.Require().NotPanics(func() {
_, err := s.preModule.PreBlock(s.Ctx)
s.Require().NoError(err)
})

s.ExecuteGovModuleConstitutionTest()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding more specific error checks for pre-block execution.

The TestUpgrade method provides a good coverage of the upgrade scenario. However, the error handling for the pre-block execution could be more specific. Instead of just checking for panics, consider adding assertions for expected behavior or specific error types.

For example:

preBlockResp, err := s.preModule.PreBlock(s.Ctx)
s.Require().NoError(err)
// Add more specific checks on preBlockResp if applicable

This would provide more detailed validation of the upgrade process.

Comment on lines +29 to +35
sdkCtx := sdk.UnwrapSDKContext(ctx)

err = InitializeConstitutionCollection(sdkCtx, *keepers.GovKeeper)
if err != nil {
sdkCtx.Logger().Error("Error initializing Constitution Collection:", "message", err.Error())
}

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

Handle errors properly after initializing the constitution collection

Currently, if InitializeConstitutionCollection returns an error, it is logged but not propagated. To prevent the application from running in a faulty state, consider returning the error to halt the upgrade process if initialization fails.

Apply this diff to handle the error appropriately:

 		err = InitializeConstitutionCollection(sdkCtx, *keepers.GovKeeper)
 		if err != nil {
-			sdkCtx.Logger().Error("Error initializing Constitution Collection:", "message", err.Error())
+			return nil, err
 		}

This change ensures that the upgrade handler returns the error, stopping the upgrade if the constitution collection fails to initialize.

📝 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
sdkCtx := sdk.UnwrapSDKContext(ctx)
err = InitializeConstitutionCollection(sdkCtx, *keepers.GovKeeper)
if err != nil {
sdkCtx.Logger().Error("Error initializing Constitution Collection:", "message", err.Error())
}
sdkCtx := sdk.UnwrapSDKContext(ctx)
err = InitializeConstitutionCollection(sdkCtx, *keepers.GovKeeper)
if err != nil {
return nil, err
}

@PaddyMc PaddyMc added the V:state/breaking State machine breaking PR label Oct 17, 2024
@mattverse mattverse self-assigned this Oct 18, 2024
Comment on lines +40 to +44
// setting the default constitution for the chain
// this is in line with cosmos-sdk v5 gov migration: https://github.com/cosmos/cosmos-sdk/blob/v0.50.10/x/gov/migrations/v5/store.go#L57
func InitializeConstitutionCollection(ctx sdk.Context, govKeeper govkeeper.Keeper) error {
return govKeeper.Constitution.Set(ctx, "This chain has no constitution.")
}
Copy link
Member

Choose a reason for hiding this comment

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

Does this imply none of the v5 gov migrations were run? Do we need to do the others as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The migration on v0.50 didn't function as expected eg

    50:	// setting the default constitution for the chain
    51:	// this is in line with cosmos-sdk v5 gov migration: https://github.com/cosmos/cosmos-sdk/blob/v0.50.10/x/gov/migrations/v5/store.go#L57
    52:	func InitializeConstitutionCollection(ctx sdk.Context, govKeeper govkeeper.Keeper) error {
    53:		ok, err := govKeeper.Constitution.Has(ctx)
=>  54:		if !ok || err != nil {
    55:			if err := govKeeper.Constitution.Set(ctx, "This chain has no constitution."); err != nil {
    56:				return err
    57:			}
    58:		}
    59:	
(dlv) p ok
true
(dlv) p err
error nil
(dlv) s
> github.com/osmosis-labs/osmosis/v26/app/upgrades/v27.InitializeConstitutionCollection() ./upgrades.go:60 (PC: 0x49c4319)
    55:			if err := govKeeper.Constitution.Set(ctx, "This chain has no constitution."); err != nil {
    56:				return err
    57:			}
    58:		}
    59:	
=>  60:		return nil

https://github.com/cosmos/cosmos-sdk/blob/main/x/gov/migrations/v5/store.go#L56-L60

The rest ran, you can check by:

osmosisd q gov params --node https://rpc.osmosis.zone:443 --output json | jq

Copy link
Member

@czarcas7ic czarcas7ic left a comment

Choose a reason for hiding this comment

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

Would like clarity on if we need to run the other gov v5 migrations. Otherwise LGTM

@PaddyMc PaddyMc merged commit ec77e75 into main Oct 23, 2024
1 check passed
@PaddyMc PaddyMc deleted the fix/state-export-gov branch October 23, 2024 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:app-wiring Changes to the app folder V:state/breaking State machine breaking PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants