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: Add sims export/import test and fix #23462

Merged
merged 2 commits into from
Jan 20, 2025
Merged

Conversation

alpe
Copy link
Contributor

@alpe alpe commented Jan 20, 2025

Description

See #23265

Fixes the genesis export/import for staking OldToNewConsAddrMap and ConsAddrToValidatorIdentifierMap.
This issue was discovered by the restored sims tests included in this PR.

make test-sim-import-export

Note: I had to add some doc and import cleanup for make proto-all.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for tracking multiple unbonding entries
    • Enhanced genesis state management for staking and protocol pool modules
    • Improved consensus address rotation tracking
  • Improvements

    • Simplified module dependencies
    • Updated store key handling
    • Enhanced simulation testing capabilities
  • Bug Fixes

    • Improved error handling in store decoding
    • Fixed potential nil value handling in simulation utilities
  • Technical Enhancements

    • Updated protobuf message definitions
    • Refined module manager functionality
    • Optimized import/export simulation processes

Copy link
Contributor

coderabbitai bot commented Jan 20, 2025

📝 Walkthrough

Walkthrough

This pull request introduces several enhancements across multiple modules in the Cosmos SDK, focusing on improving genesis state management, simulation testing, and module configurations. The changes include adding new message types for tracking unbonding entries, consensus address rotations, and distribution events. The modifications also update store key handling, introduce new utility functions for store comparisons, and refactor some existing simulation and decoding mechanisms.

Changes

File Change Summary
api/cosmos/accounts/defaults/lockup/v1/lockup.pulsar.go Added UnbondingEntries struct with methods for managing multiple unbonding entries
api/cosmos/staking/v1beta1/genesis.pulsar.go Added RotatedConsensusAddresses type and updated GenesisState with new fields for tracking address rotations
runtime/v2/manager.go Added StoreKeys() method to MM[T] struct for retrieving module store keys
simapp/v2/sim_test.go Added TestAppImportExport test function for simulating application state import/export
simapp/v2/sim_test_utils.go Added utility functions for comparing key-value stores in simulations
x/staking/keeper/genesis.go Enhanced InitGenesis and ExportGenesis methods to handle consensus address mappings

Suggested Labels

C:indexer/postgres

Suggested Reviewers

  • kocubinski
  • julienrbrt
  • sontrinh16
  • testinginprod
  • tac0turtle

Possibly Related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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.

@@ -133,7 +133,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {

// RegisterStoreDecoder registers a decoder for staking module's types
func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) {
sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc)
sdr[types.StoreKey] = simtypes.NewStoreDecoderFuncFromCollectionsSchema(am.keeper.Schema)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use default Collection based store decoder. The legacy one did not support all fields and panics

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Jan 20, 2025
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

nice! great catch for staking import/export 💪🏾

@julienrbrt julienrbrt enabled auto-merge January 20, 2025 09:42
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.staking.v1beta1.LastValidatorPower"))
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.staking.v1beta1.RotatedConsensusAddresses"))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}
panic(fmt.Errorf("message cosmos.staking.v1beta1.LastValidatorPower does not contain field %s", fd.FullName()))
panic(fmt.Errorf("message cosmos.staking.v1beta1.RotatedConsensusAddresses does not contain field %s", fd.FullName()))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
@@ -331,6 +360,32 @@
return nil, err
}

var initConsAddrs, rotatedConsAddrs []types.RotatedConsensusAddresses
err = k.ConsAddrToValidatorIdentifierMap.Walk(ctx, nil, func(newBz []byte, initBz []byte) (stop bool, err error) {

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This definition of err is never used.
initConsAddrs = append(initConsAddrs, types.RotatedConsensusAddresses{OldAddress: oldAddr, NewAddress: newAddr})
return false, nil
})
err = k.OldToNewConsAddrMap.Walk(ctx, nil, func(oldBz []byte, newBz []byte) (stop bool, err error) {

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This definition of err is never used.
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: 0

🧹 Nitpick comments (11)
api/cosmos/mint/v1beta1/mint.pulsar.go (1)

Line range hint 679-685: Improve field comments to comply with Go documentation conventions.

The comments for the newly added fields should be full sentences starting with a capital letter and ending with a period, following the Uber Go Style Guide.

Apply this diff to update the comments:

-	// goal of percent bonded atoms
+	// Goal of percent bonded atoms.
	GoalBonded string `protobuf:"bytes,5,opt,name=goal_bonded,json=goalBonded,proto3" json:"goal_bonded,omitempty"`

-	// expected blocks per year
+	// Expected blocks per year.
	BlocksPerYear uint64 `protobuf:"varint,6,opt,name=blocks_per_year,json=blocksPerYear,proto3" json:"blocks_per_year,omitempty"`

-	// maximum supply for the token
+	// Maximum supply for the token.
	MaxSupply string `protobuf:"bytes,7,opt,name=max_supply,json=maxSupply,proto3" json:"max_supply,omitempty"`
simapp/v2/sim_test_utils.go (5)

34-38: Simplify the mismatch logging loop

The loop in lines 34-37 logs only the first mismatch due to the break statement. If the intention is to log all mismatches, consider removing the break; otherwise, if only the first mismatch should be logged, the loop may be unnecessary.


40-40: Clarify the log message to reflect actual comparison results

The log message on line 40 uses len(failedKVAs), which represents the number of mismatched key/value pairs, but states "compared %d different key/value pairs". Consider adjusting the message to indicate the number of differences found or logging the total number of key/value pairs compared for clarity.


44-77: Use more descriptive variable names for readability

Variables a and b in DiffKVStores and kvAs, kvBs can be renamed to storeA, storeB, kvsA, and kvsB respectively. This will enhance code clarity and maintainability, aligning with the Uber Go Style Guide's emphasis on explicit naming.


54-70: Ensure safe concurrent assignment to shared variables

Assigning to kvAs and kvBs within goroutines may lead to data races if accessed concurrently. Although currently safe due to the WaitGroup, consider declaring kvAs and kvBs within the goroutines and returning them to avoid potential concurrency issues and adhere to best practices.


96-140: Improve variable naming in getDiffFromKVPair

In the getDiffFromKVPair function, variables kvAs and kvBs could be renamed to kvsA and kvsB or kvPairsA and kvPairsB to enhance readability, following the Uber Go Style Guide's recommendation for clear and descriptive variable names.

simapp/v2/sim_test.go (2)

122-173: Enhance test coverage for specific staking export/import fixes

While the TestAppImportExport function verifies overall store equality after export and import, it would be beneficial to include explicit assertions on OldToNewConsAddrMap and ConsAddrToValidatorIdentifierMap. This ensures that the specific staking issues addressed in the PR are thoroughly tested.


158-165: Rename the decodeable interface to follow Go conventions

Per Go naming conventions, interface names should end with "er". Consider renaming the decodeable interface to storeDecoder for clarity and consistency with established best practices.

runtime/v2/manager.go (1)

87-100: LGTM! Clean implementation with proper store key management.

The implementation correctly handles default naming, overrides, and skipped keys. Consider pre-allocating the map with the exact capacity needed.

-storeKeys := make(map[string]string, len(m.modules))
+moduleKeys := maps.Keys(m.modules)
+storeKeys := make(map[string]string, len(moduleKeys)-len(m.config.SkipStoreKeys))
types/simulation/collections.go (1)

40-49: Refactor to reduce code duplication when handling vA and vB.

The nil checks and stringification logic for vA and vB are similar. Extracting this logic into a helper function can improve maintainability and readability.

For example:

 func NewStoreDecoderFuncFromCollectionsSchema(schema collections.Schema) func(kvA, kvB kv.Pair) string {
     // existing code...
     return func(kvA, kvB kv.Pair) string {
         // existing code...
-        vAString, vBString := "<nil>", "<nil>"
-        if vA != nil {
-            if vAString, err = vc.Stringify(vA); err != nil {
-                panic(err)
-            }
-        }
-        if vB != nil {
-            if vBString, err = vc.Stringify(vB); err != nil {
-                panic(err)
-            }
-        }
+        vAString := stringifyValue(vA, vc)
+        vBString := stringifyValue(vB, vc)
         return vAString + "\n" + vBString
     }
 }
+
+func stringifyValue(value any, vc collcodec.UntypedValueCodec) string {
+    if value == nil {
+        return "<nil>"
+    }
+    strValue, err := vc.Stringify(value)
+    if err != nil {
+        panic(err)
+    }
+    return strValue
+}
x/staking/proto/cosmos/staking/v1beta1/genesis.proto (1)

Line range hint 95-99: Consider adding validation rules for RotationQueueRecord

While the message structure is correct, consider adding comments to describe any validation rules or constraints for the val_addrs field.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f9bb180 and b9f4fef.

⛔ Files ignored due to path filters (5)
  • x/accounts/defaults/lockup/v1/lockup.pb.go is excluded by !**/*.pb.go
  • x/accounts/v1/tx.pb.go is excluded by !**/*.pb.go
  • x/mint/types/mint.pb.go is excluded by !**/*.pb.go
  • x/protocolpool/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/staking/types/genesis.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (22)
  • api/cosmos/accounts/defaults/lockup/v1/lockup.pulsar.go (1 hunks)
  • api/cosmos/accounts/v1/tx.pulsar.go (1 hunks)
  • api/cosmos/mint/v1beta1/mint.pulsar.go (1 hunks)
  • api/cosmos/protocolpool/v1/genesis.pulsar.go (2 hunks)
  • api/cosmos/staking/v1beta1/genesis.pulsar.go (48 hunks)
  • runtime/v2/manager.go (1 hunks)
  • scripts/build/simulations.mk (1 hunks)
  • simapp/v2/app_config.go (1 hunks)
  • simapp/v2/sim_runner.go (1 hunks)
  • simapp/v2/sim_test.go (2 hunks)
  • simapp/v2/sim_test_utils.go (1 hunks)
  • types/simulation/collections.go (1 hunks)
  • x/accounts/proto/cosmos/accounts/defaults/lockup/v1/lockup.proto (1 hunks)
  • x/accounts/proto/cosmos/accounts/v1/tx.proto (0 hunks)
  • x/mint/proto/cosmos/mint/v1beta1/mint.proto (0 hunks)
  • x/protocolpool/proto/cosmos/protocolpool/v1/genesis.proto (1 hunks)
  • x/staking/CHANGELOG.md (1 hunks)
  • x/staking/depinject.go (1 hunks)
  • x/staking/keeper/genesis.go (3 hunks)
  • x/staking/proto/cosmos/staking/v1beta1/genesis.proto (2 hunks)
  • x/staking/simulation/decoder.go (0 hunks)
  • x/staking/simulation/decoder_test.go (0 hunks)
💤 Files with no reviewable changes (4)
  • x/mint/proto/cosmos/mint/v1beta1/mint.proto
  • x/staking/simulation/decoder.go
  • x/staking/simulation/decoder_test.go
  • x/accounts/proto/cosmos/accounts/v1/tx.proto
🧰 Additional context used
📓 Path-based instructions (14)
simapp/v2/app_config.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

types/simulation/collections.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

simapp/v2/sim_runner.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/staking/depinject.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

runtime/v2/manager.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

api/cosmos/accounts/defaults/lockup/v1/lockup.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/staking/keeper/genesis.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

api/cosmos/mint/v1beta1/mint.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

api/cosmos/protocolpool/v1/genesis.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/staking/CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

api/cosmos/accounts/v1/tx.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

simapp/v2/sim_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

simapp/v2/sim_test_utils.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

api/cosmos/staking/v1beta1/genesis.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

🪛 golangci-lint (1.62.2)
x/staking/keeper/genesis.go

364-364: File is not gofumpt-ed with -extra

(gofumpt)


376-376: File is not gofumpt-ed with -extra

(gofumpt)

🪛 GitHub Actions: Lint
x/staking/keeper/genesis.go

[warning] 364-364: File is not gofumpt-ed with -extra


[warning] 376-376: File is not gofumpt-ed with -extra

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (28)
scripts/build/simulations.mk (1)

31-33: LGTM! Enabled the test-sim-import-export target correctly

The uncommented lines properly enable the test-sim-import-export target, allowing the import/export simulation to run as intended.

simapp/v2/app_config.go (1)

191-193: LGTM! Appropriate modules added to SkipStoreKeys.

The addition of genutiltypes, runtime, and vesting modules to SkipStoreKeys is correct as these modules don't require persistent storage keys.

simapp/v2/sim_runner.go (1)

87-87: LGTM! Well-defined interface addition.

The StoreKeys() method is a clean addition to the ModuleManager interface, providing a way to access module store keys.

api/cosmos/staking/v1beta1/genesis.pulsar.go (12)

427-476: New list types for RotatedConsensusAddresses are correctly implemented

The addition of _GenesisState_12_list and _GenesisState_13_list to handle slices of RotatedConsensusAddresses follows the existing patterns in the codebase and is correctly implemented.


Line range hint 542-561: Field descriptors for new GenesisState fields are properly initialized

The new field descriptors fd_GenesisState_rotated_cons_addresses and fd_GenesisState_initial_cons_addresses are correctly added and initialized in the init() function, ensuring proper reflection.


695-706: Updates to Range() method include new fields appropriately

The Range() method in fastReflection_GenesisState is correctly updated to include the new fields RotatedConsAddresses and InitialConsAddresses, allowing iteration over these fields.


744-747: Proper implementation of Has() method for new fields

The Has() method properly checks for the presence of the new fields RotatedConsAddresses and InitialConsAddresses.


786-789: Clear() method correctly handles new fields

The Clear() method is updated to clear the new fields RotatedConsAddresses and InitialConsAddresses, ensuring they can be reset appropriately.


933-940: Updates to Set() method include new fields

The Set() method correctly handles setting the values of RotatedConsAddresses and InitialConsAddresses.


1014-1025: Mutable() method adjusted for new fields

The Mutable() method correctly provides mutable access for the new fields in GenesisState.


1074-1079: NewField() method appropriately initializes new fields

The NewField() method returns appropriate default values for the new list fields, ensuring consistency.


Line range hint 1208-1280: Serialization methods updated for new fields

The size and marshal functions in ProtoMethods() are appropriately updated to handle serialization of the new fields, ensuring that the new data is correctly serialized and deserialized.


1852-1935: Unmarshal function correctly parses new fields

The unmarshal function is updated to correctly parse the new fields RotatedConsAddresses and InitialConsAddresses during deserialization.


Line range hint 2423-2491: Definition of RotatedConsensusAddresses is well-structured

The new struct RotatedConsensusAddresses and its associated methods are correctly implemented, providing the necessary functionality for handling rotated consensus addresses.


Line range hint 3960-4077: New fields added to GenesisState struct are properly defined

The addition of RotatedConsAddresses and InitialConsAddresses to the GenesisState struct is correctly implemented, with appropriate protobuf annotations and JSON tags.

api/cosmos/accounts/v1/tx.pulsar.go (1)

4720-4826: LGTM!

The changes in the protobuf message definitions appear to be generated code and conform to the expected structure.

x/staking/depinject.go (1)

136-136: Use the default collection-based store decoder.

This update replaces the legacy store decoder with NewStoreDecoderFuncFromCollectionsSchema, ensuring better support for all fields and preventing potential panics.

x/staking/keeper/genesis.go (4)

198-211: LGTM! Proper error handling for consensus address rotation.

The implementation correctly decodes and stores old-to-new consensus address mappings with appropriate error handling.


212-225: LGTM! Proper error handling for initial consensus addresses.

The implementation correctly decodes and stores initial-to-current consensus address mappings with appropriate error handling.


363-388: LGTM! Proper error handling in export logic.

The implementation correctly exports both mappings with appropriate error handling and clear error messages.

🧰 Tools
🪛 golangci-lint (1.62.2)

364-364: File is not gofumpt-ed with -extra

(gofumpt)


376-376: File is not gofumpt-ed with -extra

(gofumpt)

🪛 GitHub Actions: Lint

[warning] 364-364: File is not gofumpt-ed with -extra


[warning] 376-376: File is not gofumpt-ed with -extra


401-402: LGTM! Proper inclusion in genesis state.

The exported mappings are correctly included in the genesis state.

api/cosmos/protocolpool/v1/genesis.pulsar.go (1)

Line range hint 1549-1656: LGTM! Generated code matches protobuf definition.

The generated code correctly implements the Distribution message type with all required fields and methods.

api/cosmos/accounts/defaults/lockup/v1/lockup.pulsar.go (1)

Line range hint 1772-2000: LGTM! Generated code matches protobuf definition.

The generated code correctly implements the UnbondingEntries message type with all required fields and methods.

x/accounts/proto/cosmos/accounts/defaults/lockup/v1/lockup.proto (1)

26-29: LGTM! Clear and concise message definition.

The UnbondingEntries message type is well-defined and follows protobuf best practices.

x/protocolpool/proto/cosmos/protocolpool/v1/genesis.proto (1)

Line range hint 31-39: Well-structured message definition!

The Distribution message is well-defined with clear field names, appropriate types, and helpful comments explaining the purpose of each field. The use of gogoproto annotations is correct.

x/staking/proto/cosmos/staking/v1beta1/genesis.proto (2)

50-59: Well-structured additions to GenesisState!

The new fields for handling consensus address rotation are well-organized with appropriate annotations and clear comments.


74-84: Well-defined RotatedConsensusAddresses message!

The message structure clearly represents the old and new consensus addresses with appropriate scalar annotations for address fields.

x/staking/CHANGELOG.md (1)

30-31: Changelog entry is well-formatted!

The entry follows the changelog format guidelines and clearly describes the purpose of the changes.

@julienrbrt julienrbrt added this pull request to the merge queue Jan 20, 2025
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: 1

🧹 Nitpick comments (10)
api/cosmos/staking/v1beta1/genesis.pulsar.go (1)

4065-4077: Getter methods for RotatedConsAddresses and InitialConsAddresses
These accessors match the typical proto-generated code style.

Consider returning an empty slice instead of nil, but this is a minor style preference in some projects.

api/cosmos/accounts/v1/tx.pulsar.go (1)

4720-4826: Function and variable naming conventions in auto-generated code.

The auto-generated code includes function and variable names with underscores (e.g., fastReflection_MsgInit), which deviates from the Uber Golang style guide that recommends using camelCase for naming. While auto-generated code is typically exempt from manual style corrections, consider configuring the code generator protoc-gen-go-pulsar to adhere to Go naming conventions to improve code consistency.

scripts/build/simulations.mk (1)

33-33: Use SIM_NUM_BLOCKS variable for consistency.

To maintain consistency with other simulation targets and allow for easier configuration, consider using the SIM_NUM_BLOCKS variable instead of hardcoding the number of blocks.

Apply this diff to use the variable:

 	 	-NumBlocks=50
+	 	-NumBlocks=$(SIM_NUM_BLOCKS)
simapp/v2/sim_test_utils.go (1)

96-140: Improve code readability with early returns.

The function getDiffFromKVPair has nested conditions that could be simplified with early returns. The deferred swap logic also makes the flow harder to follow.

Consider restructuring for better readability:

 func getDiffFromKVPair(kvAs, kvBs []kv.Pair) (diffA, diffB []kv.Pair) {
-	// we assume that kvBs is equal or larger than kvAs
-	// if not, we swap the two
-	if len(kvAs) > len(kvBs) {
-		kvAs, kvBs = kvBs, kvAs
-		// we need to swap the diffA and diffB as well
-		defer func() {
-			diffA, diffB = diffB, diffA
-		}()
-	}
+	// Handle the case where kvAs is larger
+	if len(kvAs) > len(kvBs) {
+		diffB, diffA = getDiffFromKVPair(kvBs, kvAs)
+		return
+	}

-	// in case kvAs is empty we can return early
-	// since there is nothing to compare
-	// if kvAs == kvBs, then diffA and diffB will be empty
-	if len(kvAs) == 0 {
-		return []kv.Pair{}, kvBs
-	}
+	// Handle empty kvAs case
+	if len(kvAs) == 0 {
+		return []kv.Pair{}, kvBs
+	}
x/staking/keeper/genesis.go (2)

363-388: Fix gofumpt formatting issues.

The code has formatting issues reported by the linter.

Run gofumpt -w -extra . to fix the formatting:

  • Add a blank line before line 364
  • Add a blank line before line 376
🧰 Tools
🪛 golangci-lint (1.62.2)

364-364: File is not gofumpt-ed with -extra

(gofumpt)


376-376: File is not gofumpt-ed with -extra

(gofumpt)

🪛 GitHub Actions: Lint

[warning] 364-364: File is not gofumpt-ed with -extra


[warning] 376-376: File is not gofumpt-ed with -extra


363-388: Consider adding validation for duplicate addresses.

The code should validate that there are no duplicate addresses in the maps to prevent potential conflicts.

Consider adding validation:

 	var initConsAddrs, rotatedConsAddrs []types.RotatedConsensusAddresses
+	seen := make(map[string]bool)
 	err = k.ConsAddrToValidatorIdentifierMap.Walk(ctx, nil, func(newBz []byte, initBz []byte) (stop bool, err error) {
 		oldAddr, err2 := k.consensusAddressCodec.BytesToString(initBz)
 		if err2 != nil {
 			return true, fmt.Errorf("decode initial address %X: %w", initBz, err2)
 		}
 		newAddr, err2 := k.consensusAddressCodec.BytesToString(newBz)
 		if err2 != nil {
 			return true, fmt.Errorf("decode new address %X: %w", newBz, err2)
 		}
+		if seen[oldAddr] || seen[newAddr] {
+			return true, fmt.Errorf("duplicate address found: old=%s new=%s", oldAddr, newAddr)
+		}
+		seen[oldAddr] = true
+		seen[newAddr] = true
 		initConsAddrs = append(initConsAddrs, types.RotatedConsensusAddresses{OldAddress: oldAddr, NewAddress: newAddr})
 		return false, nil
 	})
🧰 Tools
🪛 golangci-lint (1.62.2)

364-364: File is not gofumpt-ed with -extra

(gofumpt)


376-376: File is not gofumpt-ed with -extra

(gofumpt)

🪛 GitHub Actions: Lint

[warning] 364-364: File is not gofumpt-ed with -extra


[warning] 376-376: File is not gofumpt-ed with -extra

x/staking/proto/cosmos/staking/v1beta1/genesis.proto (3)

50-52: Consider adding a more descriptive comment for the rotation_queue field.

The current comment "RotationQueue with address and time tuples" could be more descriptive about the purpose and significance of this queue in the context of consensus key rotation.


53-59: Ensure consistent naming convention for address-related fields.

The field names use inconsistent casing:

  • rotated_cons_addresses uses snake_case
  • RotatedConsAddresses in the comment uses PascalCase

Line range hint 95-99: Add field descriptions for RotationQueueRecord.

While the message structure is correct, it would benefit from having descriptions for both fields to clarify their purpose and usage.

x/staking/CHANGELOG.md (1)

Line range hint 30-34: Add more details about the genesis import/export fix.

The changelog entry for PR #23462 could be more descriptive about what specific data was missing and how it affects users.

Consider expanding the entry to:

-* [#23462](https://github.com/cosmos/cosmos-sdk/pull/23462) fixes missing data for genesis ex-/import on key rotation 
+* [#23462](https://github.com/cosmos/cosmos-sdk/pull/23462) Fix missing consensus address mappings during genesis export/import when validators have rotated their consensus keys
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f9bb180 and b9f4fef.

⛔ Files ignored due to path filters (5)
  • x/accounts/defaults/lockup/v1/lockup.pb.go is excluded by !**/*.pb.go
  • x/accounts/v1/tx.pb.go is excluded by !**/*.pb.go
  • x/mint/types/mint.pb.go is excluded by !**/*.pb.go
  • x/protocolpool/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/staking/types/genesis.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (22)
  • api/cosmos/accounts/defaults/lockup/v1/lockup.pulsar.go (1 hunks)
  • api/cosmos/accounts/v1/tx.pulsar.go (1 hunks)
  • api/cosmos/mint/v1beta1/mint.pulsar.go (1 hunks)
  • api/cosmos/protocolpool/v1/genesis.pulsar.go (2 hunks)
  • api/cosmos/staking/v1beta1/genesis.pulsar.go (48 hunks)
  • runtime/v2/manager.go (1 hunks)
  • scripts/build/simulations.mk (1 hunks)
  • simapp/v2/app_config.go (1 hunks)
  • simapp/v2/sim_runner.go (1 hunks)
  • simapp/v2/sim_test.go (2 hunks)
  • simapp/v2/sim_test_utils.go (1 hunks)
  • types/simulation/collections.go (1 hunks)
  • x/accounts/proto/cosmos/accounts/defaults/lockup/v1/lockup.proto (1 hunks)
  • x/accounts/proto/cosmos/accounts/v1/tx.proto (0 hunks)
  • x/mint/proto/cosmos/mint/v1beta1/mint.proto (0 hunks)
  • x/protocolpool/proto/cosmos/protocolpool/v1/genesis.proto (1 hunks)
  • x/staking/CHANGELOG.md (1 hunks)
  • x/staking/depinject.go (1 hunks)
  • x/staking/keeper/genesis.go (3 hunks)
  • x/staking/proto/cosmos/staking/v1beta1/genesis.proto (2 hunks)
  • x/staking/simulation/decoder.go (0 hunks)
  • x/staking/simulation/decoder_test.go (0 hunks)
💤 Files with no reviewable changes (4)
  • x/mint/proto/cosmos/mint/v1beta1/mint.proto
  • x/staking/simulation/decoder.go
  • x/accounts/proto/cosmos/accounts/v1/tx.proto
  • x/staking/simulation/decoder_test.go
🧰 Additional context used
📓 Path-based instructions (14)
types/simulation/collections.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

simapp/v2/sim_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/staking/CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

simapp/v2/app_config.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

api/cosmos/protocolpool/v1/genesis.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/staking/depinject.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

simapp/v2/sim_runner.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

simapp/v2/sim_test_utils.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

api/cosmos/accounts/defaults/lockup/v1/lockup.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

api/cosmos/accounts/v1/tx.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/staking/keeper/genesis.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

runtime/v2/manager.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

api/cosmos/mint/v1beta1/mint.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

api/cosmos/staking/v1beta1/genesis.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

🪛 golangci-lint (1.62.2)
x/staking/keeper/genesis.go

364-364: File is not gofumpt-ed with -extra

(gofumpt)


376-376: File is not gofumpt-ed with -extra

(gofumpt)

🪛 GitHub Actions: Lint
x/staking/keeper/genesis.go

[warning] 364-364: File is not gofumpt-ed with -extra


[warning] 376-376: File is not gofumpt-ed with -extra

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (27)
api/cosmos/mint/v1beta1/mint.pulsar.go (1)

1526-1588: Auto-generated protobuf descriptor changes
These lines appear to be part of the compiled raw descriptor. The additions don't present functional or syntactical issues.

api/cosmos/staking/v1beta1/genesis.pulsar.go (13)

427-476: Introduction of _GenesisState_12_list for RotatedConsensusAddresses
This auto-generated code segment correctly follows the existing pattern for repeated fields.


478-527: Introduction of _GenesisState_13_list for InitialConsAddresses
Similarly, this segment properly implements a repeated field list structure.


542-543: Field descriptors for rotated and initial consensus addresses
Defines descriptors for the new repeated fields, adhering to the standard approach.


560-561: Initialization of new field descriptors
Ensures proper registration of new fields in the init function.


695-706: Range logic for new repeated fields
Correctly enumerates the new repeated fields in the Range invocation.


744-747: Has method for new repeated fields
Follows the same logic as existing repeated fields. No concerns.


786-789: Clear method for new repeated fields
Properly resets the new repeated fields to nil.


933-940: Set method for new repeated fields
Implementation is consistent with proto reflection patterns.


1014-1025: Mutable method for new repeated fields
Allows for correct creation or extension of repeated fields.


1208-1219: Size calculation for the new repeated fields
Properly accounts for lengths of both message slices.


1249-1280: Marshaling the newly introduced repeated fields
Implements the standard approach by iterating backward and writing each element.


1852-1885: Unmarshal logic for rotated_cons_addresses
Decodes each entry and appends to the slice, following standard patterns.


1886-1919: Unmarshal logic for initial_cons_addresses
Mirrors the approach used for rotated_cons_addresses.

x/staking/depinject.go (1)

136-136: LGTM – updated store decoder registration.

The change to use simtypes.NewStoreDecoderFuncFromCollectionsSchema(am.keeper.Schema) improves the store decoder by utilizing the collections schema, aligning with the latest best practices. Good work on updating the store decoder function.

simapp/v2/sim_test_utils.go (1)

36-36: Remove TODO comment or create an issue.

The TODO comment break // todo: remove should either be removed or tracked in an issue for future follow-up.

Would you like me to help create an issue to track this TODO?

simapp/v2/sim_test.go (1)

121-173: LGTM! Well-structured test with comprehensive store comparison.

The test function is well-implemented with:

  • Clear separation of export and import steps
  • Proper handling of store comparisons with skip prefixes
  • Comprehensive logging for debugging
simapp/v2/app_config.go (1)

191-193: LGTM! Appropriate additions to SkipStoreKeys.

The new entries are correctly added to skip store construction for modules that don't require a store key.

x/staking/keeper/genesis.go (1)

198-225: LGTM! Well-implemented consensus address handling.

The implementation correctly:

  • Handles address decoding with proper error messages
  • Maintains clear mapping between old and new consensus addresses
  • Provides informative error context with entry indices
simapp/v2/sim_runner.go (1)

87-87: Verify implementations of the ModuleManager interface.

The addition of StoreKeys() method is a breaking change that requires all implementations of the ModuleManager interface to provide store key mappings.

Run this script to find all implementations that need updating:

✅ Verification successful

No breaking changes detected in ModuleManager implementations

The only implementation of the ModuleManager interface found in the codebase (MM struct in runtime/v2/manager.go) already implements the StoreKeys() method with the correct signature. No updates are required for existing implementations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find all Go files that may contain ModuleManager implementations
ast-grep --pattern 'type $_ struct {
  $$$
}

func ($x $_) Modules() map[string]$_ {
  $$$
}'

Length of output: 95


Script:

#!/bin/bash
# First, find the ModuleManager interface definition
echo "=== Finding ModuleManager interface ==="
ast-grep --pattern 'type ModuleManager interface {
  $$$
}'

echo -e "\n=== Finding potential implementations ==="
# Look for struct types that implement methods matching the interface name
rg "func \(\w+ \w+\) (?:Modules|StoreKeys)" --type go

Length of output: 305


Script:

#!/bin/bash
echo "=== Finding interfaces with StoreKeys method ==="
ast-grep --pattern 'interface {
  $$$
  StoreKeys() $_
  $$$
}'

echo -e "\n=== Finding StoreKeys implementations ==="
rg "func.*StoreKeys\(\)" --type go -A 2

Length of output: 2026

runtime/v2/manager.go (1)

87-100: LGTM! Clean implementation of store key mapping.

The implementation:

  • Provides default store keys based on module names
  • Handles overrides via config
  • Supports skipping specific keys
  • Is thread-safe by creating a new map
api/cosmos/protocolpool/v1/genesis.pulsar.go (1)

Line range hint 1549-1656: Generated code looks good.

This is machine-generated protobuf code that follows the expected patterns.

api/cosmos/accounts/defaults/lockup/v1/lockup.pulsar.go (1)

Line range hint 1772-1784: Generated code looks good.

This is machine-generated protobuf code that follows the expected patterns.

x/staking/proto/cosmos/staking/v1beta1/genesis.proto (1)

74-84: LGTM! Well-structured message definition.

The RotatedConsensusAddresses message is well-defined with clear field descriptions and appropriate scalar type for address fields.

types/simulation/collections.go (1)

40-49: Good improvement in nil handling!

The changes properly handle nil values by setting default strings and checking for nil before stringification, preventing potential panics.

x/accounts/proto/cosmos/accounts/defaults/lockup/v1/lockup.proto (1)

26-28: LGTM! Clear and concise message definition.

The UnbondingEntries message is well-defined with a clear purpose of grouping multiple entries.

x/protocolpool/proto/cosmos/protocolpool/v1/genesis.proto (1)

Line range hint 31-38: LGTM! Well-documented message definition.

The Distribution message is well-structured with clear comments explaining the purpose of each field and appropriate use of protobuf options.

simapp/v2/sim_test_utils.go Show resolved Hide resolved
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

🧹 Nitpick comments (3)
x/protocolpool/proto/cosmos/protocolpool/v1/genesis.proto (1)

Line range hint 31-39: LGTM - Well-structured proto definition with clear documentation.

The Distribution message type is well-defined with appropriate field types and protobuf options. The documentation clearly explains the purpose of each field and the rationale behind tracking distribution time.

Consider adding examples in the documentation to illustrate typical usage scenarios, such as:

// Example:
// {
//   "time": "2024-01-20T15:00:00Z",
//   "amount": {
//     "coins": [
//       {"denom": "stake", "amount": "1000"}
//     ]
//   }
// }
simapp/v2/sim_test.go (2)

150-157: Consider extracting skipPrefixes to a constant.

The skipPrefixes map could be defined as a package-level constant to improve maintainability and reusability.


161-166: Optimize store decoder registration.

Consider these improvements:

  1. Pre-allocate the storeDecoders map with the expected size
  2. Add error handling for the type assertion
-       storeDecoders := make(simtypes.StoreDecoderRegistry)
+       storeDecoders := make(simtypes.StoreDecoderRegistry, len(ti.ModuleManager.Modules()))
        for _, m := range ti.ModuleManager.Modules() {
-           if v, ok := m.(decodeable); ok {
+           if v, ok := m.(decodeable); !ok {
+               tb.Logf("module %T does not implement decodeable interface", m)
+               continue
+           } else {
                v.RegisterStoreDecoder(storeDecoders)
            }
        }
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f9bb180 and b9f4fef.

⛔ Files ignored due to path filters (5)
  • x/accounts/defaults/lockup/v1/lockup.pb.go is excluded by !**/*.pb.go
  • x/accounts/v1/tx.pb.go is excluded by !**/*.pb.go
  • x/mint/types/mint.pb.go is excluded by !**/*.pb.go
  • x/protocolpool/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/staking/types/genesis.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (22)
  • api/cosmos/accounts/defaults/lockup/v1/lockup.pulsar.go (1 hunks)
  • api/cosmos/accounts/v1/tx.pulsar.go (1 hunks)
  • api/cosmos/mint/v1beta1/mint.pulsar.go (1 hunks)
  • api/cosmos/protocolpool/v1/genesis.pulsar.go (2 hunks)
  • api/cosmos/staking/v1beta1/genesis.pulsar.go (48 hunks)
  • runtime/v2/manager.go (1 hunks)
  • scripts/build/simulations.mk (1 hunks)
  • simapp/v2/app_config.go (1 hunks)
  • simapp/v2/sim_runner.go (1 hunks)
  • simapp/v2/sim_test.go (2 hunks)
  • simapp/v2/sim_test_utils.go (1 hunks)
  • types/simulation/collections.go (1 hunks)
  • x/accounts/proto/cosmos/accounts/defaults/lockup/v1/lockup.proto (1 hunks)
  • x/accounts/proto/cosmos/accounts/v1/tx.proto (0 hunks)
  • x/mint/proto/cosmos/mint/v1beta1/mint.proto (0 hunks)
  • x/protocolpool/proto/cosmos/protocolpool/v1/genesis.proto (1 hunks)
  • x/staking/CHANGELOG.md (1 hunks)
  • x/staking/depinject.go (1 hunks)
  • x/staking/keeper/genesis.go (3 hunks)
  • x/staking/proto/cosmos/staking/v1beta1/genesis.proto (2 hunks)
  • x/staking/simulation/decoder.go (0 hunks)
  • x/staking/simulation/decoder_test.go (0 hunks)
💤 Files with no reviewable changes (4)
  • x/accounts/proto/cosmos/accounts/v1/tx.proto
  • x/mint/proto/cosmos/mint/v1beta1/mint.proto
  • x/staking/simulation/decoder_test.go
  • x/staking/simulation/decoder.go
✅ Files skipped from review due to trivial changes (1)
  • api/cosmos/accounts/v1/tx.pulsar.go
🧰 Additional context used
📓 Path-based instructions (13)
simapp/v2/app_config.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

types/simulation/collections.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

simapp/v2/sim_runner.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

runtime/v2/manager.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/staking/keeper/genesis.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

simapp/v2/sim_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

api/cosmos/mint/v1beta1/mint.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

api/cosmos/accounts/defaults/lockup/v1/lockup.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/staking/CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

x/staking/depinject.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

api/cosmos/protocolpool/v1/genesis.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

simapp/v2/sim_test_utils.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

api/cosmos/staking/v1beta1/genesis.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

🪛 golangci-lint (1.62.2)
x/staking/keeper/genesis.go

364-364: File is not gofumpt-ed with -extra

(gofumpt)


376-376: File is not gofumpt-ed with -extra

(gofumpt)

🪛 GitHub Check: CodeQL
x/staking/keeper/genesis.go

[warning] 364-364: Useless assignment to local variable
This definition of err is never used.


[warning] 376-376: Useless assignment to local variable
This definition of err is never used.

api/cosmos/staking/v1beta1/genesis.pulsar.go

[warning] 2599-2599: Panic in BeginBock or EndBlock consensus methods
Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt


[warning] 2601-2601: Panic in BeginBock or EndBlock consensus methods
Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt

🪛 GitHub Actions: Lint
x/staking/keeper/genesis.go

[warning] 364-364: File is not gofumpt-ed with -extra


[warning] 376-376: File is not gofumpt-ed with -extra

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: main
  • GitHub Check: main
  • GitHub Check: assign-reviewers
  • GitHub Check: Summary
🔇 Additional comments (32)
api/cosmos/protocolpool/v1/genesis.pulsar.go (1)

Line range hint 1549-1656: LGTM - Generated code matches proto definitions.

The generated code correctly implements the Distribution message type with all its fields and metadata as defined in the proto file. Since this is an auto-generated file, no manual changes should be made here.

simapp/v2/sim_test_utils.go (2)

88-88: 🛠️ Refactor suggestion

Handle unexpected keys without panicking.

Using panic in library code can cause unexpected crashes in applications that use this library. Instead, consider returning an error or logging the issue to allow the calling function to handle it gracefully.

Apply this diff to avoid the panic:

-    		panic(fmt.Errorf("unexpected key %X (%s)", kvA.Key, kvA.Key))
+    		tb.Fatalf("unexpected key %X (%s)", kvA.Key, kvA.Key)

Likely invalid or redundant comment.


74-74: 🛠️ Refactor suggestion

Replace fmt.Printf with tb.Logf for consistent test logging.

Using fmt.Printf in test code is discouraged as it bypasses the test logging mechanisms provided by the testing framework. Switching to tb.Logf ensures that logs are properly captured and reported in test outputs.

Apply this diff to make the change:

-    		fmt.Printf("%q:: KV stores are different: %d key/value pairs in store A and %d key/value pairs in store B\n", storeKey, len(kvAs), len(kvBs))
+    		tb.Logf("%q:: KV stores are different: %d key/value pairs in store A and %d key/value pairs in store B", storeKey, len(kvAs), len(kvBs))

Likely invalid or redundant comment.

api/cosmos/staking/v1beta1/genesis.pulsar.go (14)

427-527: New generated code for RotatedConsensusAddresses is correctly implemented.

The addition of the RotatedConsensusAddresses type and its associated methods aligns with the updated protobuf definitions. The methods properly implement the required interfaces, ensuring seamless serialization and deserialization.


560-561: GenesisState struct updated to include new fields appropriately.

The fields RotatedConsAddresses and InitialConsAddresses are correctly added to the GenesisState struct. This ensures that the genesis state can accurately represent the rotated consensus addresses during initialization and export.


695-706: Extended Range method to include new fields in iteration.

The Range method of fastReflection_GenesisState now includes the new fields RotatedConsAddresses and InitialConsAddresses. This change ensures that these fields are considered during reflection operations.


744-747: Updated Has method to support new fields.

The Has method correctly checks for the presence of the new fields RotatedConsAddresses and InitialConsAddresses, maintaining consistency in field population checks.


786-789: Enhanced Clear method to handle new fields appropriately.

The Clear method now includes cases to clear RotatedConsAddresses and InitialConsAddresses, ensuring that these fields can be reset when necessary.


863-874: Adjusted Get method to retrieve new fields properly.

The Get method is updated to return the values of RotatedConsAddresses and InitialConsAddresses fields, enabling accurate data retrieval.


933-940: Modified Set method to assign values to new fields.

The Set method allows assignment to RotatedConsAddresses and InitialConsAddresses, facilitating correct data storage in the GenesisState.


1014-1025: Implemented Mutable method support for new fields.

The Mutable method now can initialize and return mutable references to the new fields, ensuring they can be modified as needed.


1074-1079: Provided NewField method implementations for new list fields.

The NewField method correctly creates new list instances for RotatedConsAddresses and InitialConsAddresses, maintaining consistency in object creation.


1208-1219: Adjusted marshaling size calculation to include new fields.

The size calculation in the ProtoMethods now accounts for RotatedConsAddresses and InitialConsAddresses, ensuring accurate buffer allocation during marshaling.


1249-1280: Updated marshaling logic to serialize new fields properly.

The marshaling function includes serialization of RotatedConsAddresses and InitialConsAddresses, guaranteeing that these fields are correctly written to the buffer.


1775-1942: Enhanced unmarshaling logic to deserialize new fields correctly.

The unmarshaling function now handles RotatedConsAddresses and InitialConsAddresses, allowing for accurate reconstruction of the GenesisState from serialized data.


Line range hint 2423-2759: Added new message type RotatedConsensusAddresses with necessary methods.

The RotatedConsensusAddresses type includes all required methods for protobuf message handling, ensuring compatibility and proper functioning within the protocol buffers framework.


Line range hint 3960-4069: Protobuf definitions and generated code updated to include new fields and types.

The GenesisState message in the protobuf file now contains rotated_cons_addresses and initial_cons_addresses, and the generated Go code reflects these additions accurately.

types/simulation/collections.go (1)

40-51: Prevent potential panics by checking for nil before stringification.

The added nil checks before stringifying vA and vB ensure that the function handles nil values gracefully, preventing potential panics during simulation store decoding.

scripts/build/simulations.mk (1)

31-33: LGTM! Test configuration is well structured.

The test command is properly configured with appropriate timeout and block count parameters.

x/staking/depinject.go (1)

136-136: Improved store decoder implementation.

The switch to Collection based store decoder is a good improvement as it provides better support for all fields and prevents panics.

simapp/v2/app_config.go (1)

191-193: LGTM! Appropriate modules added to SkipStoreKeys.

The added modules (genutil, runtime, vesting) correctly belong in SkipStoreKeys as they don't require their own store keys.

x/staking/keeper/genesis.go (3)

198-211: LGTM! Well-structured error handling for rotated consensus addresses.

The implementation properly decodes and stores old-to-new consensus address mappings with clear error messages that include the index of the failing entry.


212-225: LGTM! Well-structured error handling for initial consensus addresses.

The implementation properly decodes and stores initial-to-current consensus address mappings with clear error messages that include the index of the failing entry.


401-402: LGTM! Proper inclusion of new fields in genesis state.

The new fields RotatedConsAddresses and InitialConsAddresses are correctly added to the genesis state.

simapp/v2/sim_runner.go (1)

87-87: LGTM! Clean interface extension.

The addition of StoreKeys() method to the ModuleManager interface is well-defined and follows the interface design pattern.

runtime/v2/manager.go (1)

87-100: LGTM! Clean and efficient implementation of store keys mapping.

The implementation properly handles:

  • Default store key naming convention
  • Store key overrides from config
  • Store key exclusions from config
api/cosmos/mint/v1beta1/mint.pulsar.go (1)

Line range hint 1-1588: Skip review of generated protobuf code.

This is an auto-generated protobuf file. Any changes should be made to the source .proto files instead.

api/cosmos/accounts/defaults/lockup/v1/lockup.pulsar.go (1)

1772-1772: Generated code looks good!

The generated protobuf code correctly implements the UnbondingEntries message with all necessary methods and follows protobuf generation standards.

x/accounts/proto/cosmos/accounts/defaults/lockup/v1/lockup.proto (1)

26-29: Well-structured protobuf definition!

The UnbondingEntries message is well-defined with:

  • Clear documentation
  • Proper field numbering
  • Appropriate use of repeated field for entries
x/staking/proto/cosmos/staking/v1beta1/genesis.proto (2)

50-59: Well-structured genesis state additions!

The new fields in GenesisState are properly defined with:

  • Clear field numbering (11, 12, 13)
  • Appropriate protobuf options for nullable and empty value handling
  • Good documentation comments explaining the purpose of each field

74-84: Well-designed address rotation message!

The RotatedConsensusAddresses message is well-structured with:

  • Clear field naming (old_address, new_address)
  • Proper use of cosmos.AddressString scalar type
  • Good documentation for each field
x/staking/CHANGELOG.md (1)

30-31: Clear and well-placed changelog entry!

The changelog entry correctly documents the fix for missing data during genesis export/import on key rotation, following the changelog guidelines.

simapp/v2/sim_test_utils.go Show resolved Hide resolved
x/staking/keeper/genesis.go Show resolved Hide resolved
Merged via the queue into main with commit 5359c8f Jan 20, 2025
86 of 88 checks passed
@julienrbrt julienrbrt deleted the alex/simsv2_moretests branch January 20, 2025 10:04
mergify bot pushed a commit that referenced this pull request Jan 20, 2025
(cherry picked from commit 5359c8f)

# Conflicts:
#	api/cosmos/accounts/defaults/lockup/v1/lockup.pulsar.go
#	api/cosmos/accounts/v1/tx.pulsar.go
#	api/cosmos/mint/v1beta1/mint.pulsar.go
#	api/cosmos/protocolpool/v1/genesis.pulsar.go
#	api/cosmos/staking/v1beta1/genesis.pulsar.go
#	runtime/v2/manager.go
#	scripts/build/simulations.mk
#	simapp/sim_test_utils.go
#	simapp/v2/sim_runner.go
#	simapp/v2/sim_test.go
#	x/staking/CHANGELOG.md
@alpe alpe mentioned this pull request Jan 20, 2025
12 tasks
julienrbrt added a commit that referenced this pull request Jan 20, 2025
@mergify mergify bot mentioned this pull request Jan 20, 2025
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants