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(x/staking,genutil)!: use validatorUpdates #19754

Merged
merged 7 commits into from
Mar 19, 2024

Conversation

chixiaowen
Copy link
Contributor

@chixiaowen chixiaowen commented Mar 14, 2024

Description

ref: #19736


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
  • 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.

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

  • Refactor
    • Updated code to use module.ValidatorUpdate instead of abci.ValidatorUpdate across various files, enhancing consistency and compatibility with newer standards.
    • Simplified handling of public key types and validator updates, improving code efficiency and maintainability.
  • New Features
    • Introduced methods for generating module.ValidatorUpdate instances based on validator information, facilitating easier updates and management of validator states.
  • Tests
    • Adjusted integration tests to align with the updated import paths and function signatures, ensuring reliability and correctness of the changes.

@chixiaowen chixiaowen requested a review from a team as a code owner March 14, 2024 07:04
@github-actions github-actions bot added C:x/staking C:x/genutil genutil module issues labels Mar 14, 2024
Copy link
Contributor

coderabbitai bot commented Mar 14, 2024

Walkthrough

Walkthrough

The update involves transitioning the Cosmos SDK to utilize module.ValidatorUpdate instead of abci.ValidatorUpdate in key modules like x/staking and x/genutil. This enhancement simplifies validator update handling by directly returning module.ValidatorUpdate instances from keeper functions, streamlining processes and enhancing integration with Cosmos SDK types.

Changes

Files Change Summary
x/genutil/genesis.go, x/staking/keeper/genesis.go Updated imports, replaced abci.ValidatorUpdate with module.ValidatorUpdate, and simplified public key handling.
x/genutil/gentx.go, x/genutil/module.go, x/staking/module.go Adjusted function signatures to use module.ValidatorUpdate and removed redundant code.
x/genutil/.../expected_keepers_mocks.go, x/genutil/types/expected_keepers.go, x/staking/keeper/abci.go, x/staking/keeper/val_state_change.go, tests/integration/staking/keeper/validator_test.go Modified imports and types to utilize module.ValidatorUpdate.
x/staking/types/validator.go, types/module/module.go Introduced functionality for generating module.ValidatorUpdate instances and conversion between validator update types.

Assessment against linked issues

Objective Addressed Explanation
Use ValidatorUpdates in x/staking and x/gentutil (#19736)

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>.
    • Generate unit-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@chixiaowen chixiaowen changed the title use validatorUpdates refactor(x/staking,genutil)!: use validatorUpdates Mar 14, 2024
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.

Review Status

Actionable comments generated: 2

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 5424b55 and 3fe4097.
Files selected for processing (6)
  • tests/integration/staking/keeper/genesis_test.go (3 hunks)
  • x/genutil/genesis.go (2 hunks)
  • x/genutil/module.go (1 hunks)
  • x/staking/keeper/abci.go (2 hunks)
  • x/staking/keeper/genesis.go (4 hunks)
  • x/staking/module.go (2 hunks)
Additional comments: 8
x/genutil/genesis.go (1)
  • 5-6: The import statements have been updated to include fmt and module from cosmos/cosmos-sdk/types, which aligns with the changes made in the InitGenesis function to use module.ValidatorUpdate instead of abci.ValidatorUpdate. This change is consistent with the PR's objective to streamline the process of generating validator updates.
x/genutil/module.go (1)
  • 81-81: The InitGenesis function in x/genutil/module.go has been simplified by directly returning the result of InitGenesis without intermediate processing. This change is consistent with the PR's objective to streamline the process of generating validator updates by leveraging the new module.ValidatorUpdate type directly within the modules. The simplification enhances the maintainability and readability of the code.
x/staking/module.go (2)
  • 151-151: The InitGenesis function in x/staking/module.go has been simplified by removing unnecessary code for handling different types of public keys, now directly returning results from the keeper functions. This change aligns with the PR's objective and improves code maintainability.
  • 177-177: The EndBlock function has also been simplified in a similar manner to InitGenesis, directly returning results from the keeper functions without unnecessary intermediate processing. This simplification is consistent with the PR's objectives and enhances code readability and maintainability.
tests/integration/staking/keeper/genesis_test.go (3)
  • 5-5: The import statement for github.com/cosmos/cosmos-sdk/types/module has been added, which is necessary for the updated tests to use module.ValidatorUpdate instead of abci.ValidatorUpdate. This change is consistent with the modifications made in the x/staking and x/genutil modules and is necessary for the tests to reflect these changes.
  • 132-149: The tests have been updated to use module.ValidatorUpdate and to modify validator updates based on key types. This change ensures that the tests are aligned with the modifications made in the x/staking and x/genutil modules, thereby maintaining test accuracy and relevance.
  • 246-265: Similar updates have been made in another test within the same file, replacing abcivals with validatorUpdates and using module.ValidatorUpdate. These changes are consistent with the PR's objectives and ensure that the integration tests accurately reflect the updated logic in the x/staking and x/genutil modules.
x/staking/keeper/genesis.go (1)
  • 197-233: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [22-230]

The InitGenesis function in the keeper package of the staking module has been updated to return a slice of module.ValidatorUpdate instead of abci.ValidatorUpdate. This change aligns with the PR's objective to directly return ValidatorUpdates, enhancing the efficiency and clarity of the Cosmos SDK's handling of validator updates. The function now handles CometBFT updates differently based on the Exported field in the GenesisState, which is a thoughtful addition to accommodate different scenarios.

Similar to previous files, the error handling for unexpected public key types could be enhanced by providing more context in the error message.

Consider enhancing the error message for unexpected validator public key types to include more context, such as the validator's address or name, to aid in debugging.

- return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey)
+ return nil, fmt.Errorf("unexpected validator pubkey type: %T for validator with address: %s", v.PubKey, validatorAddress)

Note: validatorAddress should be replaced with the actual variable holding the validator's address, which might require additional changes to include this information in the error context.

Comment on lines 19 to 43
) (validatorUpdates []module.ValidatorUpdate, err error) {
if len(genesisState.GenTxs) > 0 {
validators, err = DeliverGenTxs(ctx, genesisState.GenTxs, stakingKeeper, deliverTx, txEncodingConfig)
cometValidatorUpdates, err := DeliverGenTxs(ctx, genesisState.GenTxs, stakingKeeper, deliverTx, txEncodingConfig)
if err != nil {
return nil, err
}
validatorUpdates = make([]module.ValidatorUpdate, len(cometValidatorUpdates))
for i, v := range cometValidatorUpdates {
if ed25519 := v.PubKey.GetEd25519(); len(ed25519) > 0 {
validatorUpdates[i] = module.ValidatorUpdate{
PubKey: ed25519,
PubKeyType: "ed25519",
Power: v.Power,
}
} else if secp256k1 := v.PubKey.GetSecp256K1(); len(secp256k1) > 0 {
validatorUpdates[i] = module.ValidatorUpdate{
PubKey: secp256k1,
PubKeyType: "secp256k1",
Power: v.Power,
}
} else {
return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey)
}
}
return validatorUpdates, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

The InitGenesis function has been updated to return validatorUpdates of type module.ValidatorUpdate instead of abci.ValidatorUpdate. This change is part of the PR's objective to directly return ValidatorUpdates in keeper functions, eliminating the need for intermediary conversion logic. The function now handles different types of public keys (ed25519 and secp256k1) and returns the appropriate ValidatorUpdate for each. This simplification enhances the maintainability and readability of the code.

However, there's a potential issue with the error handling for unexpected public key types. The error message uses %T to print the type of v.PubKey, which is correct, but it might be beneficial to include more context in the error message to aid in debugging, such as the validator's address or name if available.

Consider enhancing the error message in the case of an unexpected validator public key type to include more context, such as the validator's address or name, to aid in debugging.

- return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey)
+ return nil, fmt.Errorf("unexpected validator pubkey type: %T for validator with address: %s", v.PubKey, validatorAddress)

Note: validatorAddress should be replaced with the actual variable holding the validator's address, which might require additional changes to include this information in the error context.


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.

Suggested change
) (validatorUpdates []module.ValidatorUpdate, err error) {
if len(genesisState.GenTxs) > 0 {
validators, err = DeliverGenTxs(ctx, genesisState.GenTxs, stakingKeeper, deliverTx, txEncodingConfig)
cometValidatorUpdates, err := DeliverGenTxs(ctx, genesisState.GenTxs, stakingKeeper, deliverTx, txEncodingConfig)
if err != nil {
return nil, err
}
validatorUpdates = make([]module.ValidatorUpdate, len(cometValidatorUpdates))
for i, v := range cometValidatorUpdates {
if ed25519 := v.PubKey.GetEd25519(); len(ed25519) > 0 {
validatorUpdates[i] = module.ValidatorUpdate{
PubKey: ed25519,
PubKeyType: "ed25519",
Power: v.Power,
}
} else if secp256k1 := v.PubKey.GetSecp256K1(); len(secp256k1) > 0 {
validatorUpdates[i] = module.ValidatorUpdate{
PubKey: secp256k1,
PubKeyType: "secp256k1",
Power: v.Power,
}
} else {
return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey)
}
}
return validatorUpdates, nil
) (validatorUpdates []module.ValidatorUpdate, err error) {
if len(genesisState.GenTxs) > 0 {
cometValidatorUpdates, err := DeliverGenTxs(ctx, genesisState.GenTxs, stakingKeeper, deliverTx, txEncodingConfig)
if err != nil {
return nil, err
}
validatorUpdates = make([]module.ValidatorUpdate, len(cometValidatorUpdates))
for i, v := range cometValidatorUpdates {
if ed25519 := v.PubKey.GetEd25519(); len(ed25519) > 0 {
validatorUpdates[i] = module.ValidatorUpdate{
PubKey: ed25519,
PubKeyType: "ed25519",
Power: v.Power,
}
} else if secp256k1 := v.PubKey.GetSecp256K1(); len(secp256k1) > 0 {
validatorUpdates[i] = module.ValidatorUpdate{
PubKey: secp256k1,
PubKeyType: "secp256k1",
Power: v.Power,
}
} else {
return nil, fmt.Errorf("unexpected validator pubkey type: %T for validator with address: %s", v.PubKey, validatorAddress)
}
}
return validatorUpdates, nil

Comment on lines 22 to 46
func (k *Keeper) EndBlocker(ctx context.Context) ([]module.ValidatorUpdate, error) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)
return k.BlockValidatorUpdates(ctx)
cometValidatorUpdates, err := k.BlockValidatorUpdates(ctx)
if err != nil {
return nil, err
}
validatorUpdates := make([]module.ValidatorUpdate, len(cometValidatorUpdates))
for i, v := range cometValidatorUpdates {
if ed25519 := v.PubKey.GetEd25519(); len(ed25519) > 0 {
validatorUpdates[i] = module.ValidatorUpdate{
PubKey: ed25519,
PubKeyType: "ed25519",
Power: v.Power,
}
} else if secp256k1 := v.PubKey.GetSecp256K1(); len(secp256k1) > 0 {
validatorUpdates[i] = module.ValidatorUpdate{
PubKey: secp256k1,
PubKeyType: "secp256k1",
Power: v.Power,
}
} else {
return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey)
}
}
return validatorUpdates, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

The EndBlocker function has been updated to return an array of module.ValidatorUpdate instead of abci.ValidatorUpdate, aligning with the PR's objective. The function now handles conversion of validator updates to the new type, which simplifies the process and eliminates the need for intermediary conversion logic. This change improves the maintainability and readability of the code.

Similar to the previous file, the error handling for unexpected public key types could be enhanced by providing more context in the error message.

Consider enhancing the error message for unexpected validator public key types to include more context, such as the validator's address or name, to aid in debugging.

- return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey)
+ return nil, fmt.Errorf("unexpected validator pubkey type: %T for validator with address: %s", v.PubKey, validatorAddress)

Note: validatorAddress should be replaced with the actual variable holding the validator's address, which might require additional changes to include this information in the error context.


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.

Suggested change
func (k *Keeper) EndBlocker(ctx context.Context) ([]module.ValidatorUpdate, error) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)
return k.BlockValidatorUpdates(ctx)
cometValidatorUpdates, err := k.BlockValidatorUpdates(ctx)
if err != nil {
return nil, err
}
validatorUpdates := make([]module.ValidatorUpdate, len(cometValidatorUpdates))
for i, v := range cometValidatorUpdates {
if ed25519 := v.PubKey.GetEd25519(); len(ed25519) > 0 {
validatorUpdates[i] = module.ValidatorUpdate{
PubKey: ed25519,
PubKeyType: "ed25519",
Power: v.Power,
}
} else if secp256k1 := v.PubKey.GetSecp256K1(); len(secp256k1) > 0 {
validatorUpdates[i] = module.ValidatorUpdate{
PubKey: secp256k1,
PubKeyType: "secp256k1",
Power: v.Power,
}
} else {
return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey)
}
}
return validatorUpdates, nil
} else {
return nil, fmt.Errorf("unexpected validator pubkey type: %T for validator with address: %s", v.PubKey, validatorAddress)
}

Copy link
Contributor

@likhita-809 likhita-809 left a comment

Choose a reason for hiding this comment

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

need to fix lint issues, otherwise lgtm

x/staking/keeper/abci.go Outdated Show resolved Hide resolved
x/staking/keeper/abci.go Show resolved Hide resolved
x/staking/keeper/genesis.go Outdated 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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 3fe4097 and ce30686.
Files selected for processing (4)
  • tests/integration/staking/keeper/genesis_test.go (3 hunks)
  • x/genutil/genesis.go (2 hunks)
  • x/staking/keeper/abci.go (2 hunks)
  • x/staking/keeper/genesis.go (3 hunks)
Files skipped from review as they are similar to previous changes (4)
  • tests/integration/staking/keeper/genesis_test.go
  • x/genutil/genesis.go
  • x/staking/keeper/abci.go
  • x/staking/keeper/genesis.go

x/staking/module.go Dismissed Show dismissed Hide dismissed
x/staking/keeper/abci.go Fixed Show fixed Hide fixed
x/genutil/genesis.go Outdated 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.

Review Status

Actionable comments generated: 1

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between ce30686 and b66ab4f.
Files selected for processing (4)
  • types/module/module.go (2 hunks)
  • x/genutil/genesis.go (2 hunks)
  • x/staking/keeper/abci.go (2 hunks)
  • x/staking/keeper/genesis.go (3 hunks)
Files skipped from review as they are similar to previous changes (3)
  • x/genutil/genesis.go
  • x/staking/keeper/abci.go
  • x/staking/keeper/genesis.go
Additional comments: 1
types/module/module.go (1)
  • 30-31: The addition of tmed25519 and tmsecp256k1 imports is appropriate for handling cryptographic operations in the new Parse2ModuleValidatorUpdate function.

Comment on lines 902 to 924

// Parse2ModuleValidatorUpdate parses a slice of comet ValidatorUpdate to a slice of Module ValidatorUpdate
func Parse2ModuleValidatorUpdate(cometValidatorUpdates []abci.ValidatorUpdate) ([]ValidatorUpdate, error) {
validatorUpdates := make([]ValidatorUpdate, len(cometValidatorUpdates))
for i, v := range cometValidatorUpdates {
if ed25519 := v.PubKey.GetEd25519(); len(ed25519) > 0 {
validatorUpdates[i] = ValidatorUpdate{
PubKey: ed25519,
PubKeyType: tmed25519.KeyType,
Power: v.Power,
}
} else if secp256k1 := v.PubKey.GetSecp256K1(); len(secp256k1) > 0 {
validatorUpdates[i] = ValidatorUpdate{
PubKey: secp256k1,
PubKeyType: tmsecp256k1.KeyType,
Power: v.Power,
}
} else {
return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey)
}
}
return validatorUpdates, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation of Parse2ModuleValidatorUpdate is correct and efficiently handles the conversion of validator updates from Comet to Module types. However, the error message in line 920 could be improved for clarity by including the actual type found.

- return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey)
+ return nil, fmt.Errorf("unexpected validator pubkey type: %T, expected ed25519 or secp256k1", v.PubKey.Sum)

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.

Suggested change
// Parse2ModuleValidatorUpdate parses a slice of comet ValidatorUpdate to a slice of Module ValidatorUpdate
func Parse2ModuleValidatorUpdate(cometValidatorUpdates []abci.ValidatorUpdate) ([]ValidatorUpdate, error) {
validatorUpdates := make([]ValidatorUpdate, len(cometValidatorUpdates))
for i, v := range cometValidatorUpdates {
if ed25519 := v.PubKey.GetEd25519(); len(ed25519) > 0 {
validatorUpdates[i] = ValidatorUpdate{
PubKey: ed25519,
PubKeyType: tmed25519.KeyType,
Power: v.Power,
}
} else if secp256k1 := v.PubKey.GetSecp256K1(); len(secp256k1) > 0 {
validatorUpdates[i] = ValidatorUpdate{
PubKey: secp256k1,
PubKeyType: tmsecp256k1.KeyType,
Power: v.Power,
}
} else {
return nil, fmt.Errorf("unexpected validator pubkey type: %T", v.PubKey)
}
}
return validatorUpdates, nil
}
// Parse2ModuleValidatorUpdate parses a slice of comet ValidatorUpdate to a slice of Module ValidatorUpdate
func Parse2ModuleValidatorUpdate(cometValidatorUpdates []abci.ValidatorUpdate) ([]ValidatorUpdate, error) {
validatorUpdates := make([]ValidatorUpdate, len(cometValidatorUpdates))
for i, v := range cometValidatorUpdates {
if ed25519 := v.PubKey.GetEd25519(); len(ed25519) > 0 {
validatorUpdates[i] = ValidatorUpdate{
PubKey: ed25519,
PubKeyType: tmed25519.KeyType,
Power: v.Power,
}
} else if secp256k1 := v.PubKey.GetSecp256K1(); len(secp256k1) > 0 {
validatorUpdates[i] = ValidatorUpdate{
PubKey: secp256k1,
PubKeyType: tmsecp256k1.KeyType,
Power: v.Power,
}
} else {
return nil, fmt.Errorf("unexpected validator pubkey type: %T, expected ed25519 or secp256k1", v.PubKey.Sum)
}
}
return validatorUpdates, nil
}

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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 36981e6 and a980312.
Files selected for processing (7)
  • tests/integration/staking/keeper/genesis_test.go (3 hunks)
  • types/module/module.go (2 hunks)
  • x/genutil/genesis.go (2 hunks)
  • x/genutil/module.go (1 hunks)
  • x/staking/keeper/abci.go (2 hunks)
  • x/staking/keeper/genesis.go (3 hunks)
  • x/staking/module.go (2 hunks)
Files skipped from review as they are similar to previous changes (7)
  • tests/integration/staking/keeper/genesis_test.go
  • types/module/module.go
  • x/genutil/genesis.go
  • x/genutil/module.go
  • x/staking/keeper/abci.go
  • x/staking/keeper/genesis.go
  • x/staking/module.go

x/staking/keeper/abci.go Fixed Show fixed Hide fixed
@@ -195,18 +197,18 @@ func (k Keeper) InitGenesis(ctx context.Context, data *types.GenesisState) (res

update := validator.ABCIValidatorUpdate(k.PowerReduction(ctx))
Copy link
Member

Choose a reason for hiding this comment

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

i think we can remove this section of code as well. seems we are going to a abciValidatorupdate in order to go back to a different type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not konw about this, who can helps me ? can I just delete it directly?

Copy link
Member

@julienrbrt julienrbrt Mar 15, 2024

Choose a reason for hiding this comment

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

basically you can call this directly in the struct:

tmProtoPk, err := v.CmtConsPublicKey()
if err != nil {
panic(err)
}
return abci.ValidatorUpdate{
PubKey: tmProtoPk,
Power: v.ConsensusPower(r),
}

Copy link
Member

Choose a reason for hiding this comment

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

copying that code which is mentioned. we may be able to drop the comet dependency in staking for validatorupdate entirely

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, i will do it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But this is another issue, can we open a separate issue for it? @julienrbrt @tac0turtle

Copy link
Member

@julienrbrt julienrbrt Mar 16, 2024

Choose a reason for hiding this comment

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

Imho, it's the same thing. Otherwise this PR only moves the logic a bit up which doesn't really have any advantage. We should use ValidatorUpdates as early as possible, and if it means not going via the abci struct we should do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👌, I will do it soon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok I will do 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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between a980312 and 02b82fb.
Files selected for processing (10)
  • tests/integration/staking/keeper/validator_test.go (3 hunks)
  • x/genutil/genesis.go (2 hunks)
  • x/genutil/gentx.go (2 hunks)
  • x/genutil/testutil/expected_keepers_mocks.go (5 hunks)
  • x/genutil/types/expected_keepers.go (1 hunks)
  • x/staking/keeper/abci.go (2 hunks)
  • x/staking/keeper/genesis.go (3 hunks)
  • x/staking/keeper/val_state_change.go (7 hunks)
  • x/staking/keeper/validator_test.go (2 hunks)
  • x/staking/types/validator.go (3 hunks)
Files skipped from review as they are similar to previous changes (3)
  • x/genutil/genesis.go
  • x/staking/keeper/abci.go
  • x/staking/keeper/genesis.go
Additional comments: 12
x/genutil/types/expected_keepers.go (1)
  • 16-16: The change from abci.ValidatorUpdate to module.ValidatorUpdate in the ApplyAndReturnValidatorSetUpdates method signature aligns with the PR's objectives to streamline validator updates handling. Ensure all implementations and usages of this interface are updated accordingly.
x/genutil/gentx.go (2)
  • 16-16: The addition of the module import is necessary for the updated return type of DeliverGenTxs and aligns with the PR's objectives.
  • 96-96: The update to the return type of DeliverGenTxs to []module.ValidatorUpdate is in line with the PR's objectives. Ensure the function's implementation and its callers are correctly updated to handle this new return type.
x/genutil/testutil/expected_keepers_mocks.go (2)
  • 14-15: The addition of the module import is necessary for the updated mock function signature and aligns with the changes in the interface definition.
  • 43-46: The update to the ApplyAndReturnValidatorSetUpdates mock function to return []module.ValidatorUpdate aligns with the interface changes. Ensure the mock's usage in tests is correctly updated to handle this new return type.
x/staking/types/validator.go (2)
  • 274-286: The addition of the ModuleValidatorUpdate method aligns with the PR's objectives, simplifying the generation of validator updates by directly utilizing the module.ValidatorUpdate type. Ensure the method is correctly used wherever validator updates are generated.
  • 303-315: The addition of the ModuleValidatorUpdateZero method is consistent with the PR's objectives, providing a straightforward way to generate validator updates with zero power using the module.ValidatorUpdate type. Ensure this method is used appropriately for the intended validator updates.
x/staking/keeper/val_state_change.go (2)
  • 27-27: The function BlockValidatorUpdates now returns []module.ValidatorUpdate instead of []abci.ValidatorUpdate. This change aligns with the PR's objective to use module.ValidatorUpdate directly, enhancing clarity and efficiency in handling validator updates.
  • 301-323: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [141-359]

In ApplyAndReturnValidatorSetUpdates, the transition from abci.ValidatorUpdate to module.ValidatorUpdate is evident. However, there are a few points to consider:

  • The variable updates of type []abci.ValidatorUpdate is still being used alongside the new moduleValidatorUpdates. This dual handling could potentially lead to confusion and errors. It's important to ensure that the transition to module.ValidatorUpdate is consistent and that any remnants of abci.ValidatorUpdate are intentional and well-justified.
  • The conversion process between abci.ValidatorUpdate and module.ValidatorUpdate should be scrutinized for efficiency and correctness. Ensure that all necessary fields are correctly mapped between these types.
  • The handling of moduleValidatorUpdates at the end of the function, where it's returned, aligns with the PR's goals. However, ensure that all callers of this function are updated to handle the new return type correctly.

Consider simplifying the handling of validator updates by fully transitioning to module.ValidatorUpdate where possible, reducing the complexity and potential for errors associated with managing two similar types.

x/staking/keeper/validator_test.go (1)
  • 20-20: The function applyValidatorSetUpdates now correctly returns []module.ValidatorUpdate, aligning with the changes made in the main code to use module.ValidatorUpdate directly. This ensures that the tests are consistent with the implementation and can accurately verify the behavior of the updated functions.
tests/integration/staking/keeper/validator_test.go (2)
  • 18-18: The import statement for "github.com/cosmos/cosmos-sdk/types/module" has been added. This change aligns with the PR's objective to utilize module.ValidatorUpdate instead of abci.ValidatorUpdate, ensuring the tests are updated to reflect the new type usage.
  • 879-879: The function applyValidatorSetUpdates now returns a slice of module.ValidatorUpdate instead of abci.ValidatorUpdate. This change is consistent with the PR's goal to directly use module.ValidatorUpdate across the x/staking and x/gentutil modules. It's crucial to ensure that all calls to this function within the test suite have been updated to handle the new return type correctly.

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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 02b82fb and 7d814b1.
Files selected for processing (3)
  • tests/integration/staking/keeper/validator_test.go (13 hunks)
  • x/staking/keeper/val_state_change.go (8 hunks)
  • x/staking/keeper/validator_test.go (6 hunks)
Files skipped from review as they are similar to previous changes (3)
  • tests/integration/staking/keeper/validator_test.go
  • x/staking/keeper/val_state_change.go
  • x/staking/keeper/validator_test.go

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.

One a about PowerReduction method

@@ -230,11 +243,24 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {
assert.NilError(t, err)

abcivals := make([]abci.ValidatorUpdate, 100)
validatorUpdates := make([]module.ValidatorUpdate, len(abcivals))
for i, val := range validators[:100] {
abcivals[i] = val.ABCIValidatorUpdate(f.stakingKeeper.PowerReduction(f.sdkCtx))
Copy link
Member

Choose a reason for hiding this comment

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

Do we have to go via the abci struct in PowerReduction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done! use ModuleValidatorUpdate

)

// StakingKeeper defines the expected staking keeper (noalias)
type StakingKeeper interface {
ApplyAndReturnValidatorSetUpdates(context.Context) (updates []abci.ValidatorUpdate, err error)
ApplyAndReturnValidatorSetUpdates(context.Context) (updates []module.ValidatorUpdate, err error)
Copy link
Member

Choose a reason for hiding this comment

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

Can we get a changelog under x/staking for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

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.

Review Status

Actionable comments generated: 1

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 7d814b1 and 63ff365.
Files selected for processing (2)
  • tests/integration/staking/keeper/genesis_test.go (3 hunks)
  • x/staking/CHANGELOG.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/integration/staking/keeper/genesis_test.go

@@ -89,6 +89,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#17335](https://github.com/cosmos/cosmos-sdk/pull/17335) Remove usage of `"cosmossdk.io/x/staking/types".Infraction_*` in favour of `"cosmossdk.io/api/cosmos/staking/v1beta1".Infraction_` in order to remove dependency between modules on staking
* [#17655](https://github.com/cosmos/cosmos-sdk/pull/17655) `QueryHistoricalInfo` was adjusted to return `HistoricalRecord` and marked `Hist` as deprecated.
* [#19414](https://github.com/cosmos/cosmos-sdk/pull/19414) Staking module takes an environment variable in `NewStakingKeeper` instead of individual services.
* [#19754](https://github.com/cosmos/cosmos-sdk/pull/19754) update to use `[]module.ValidatorUpdate` as return for `ApplyAndReturnValidatorSetUpdates`.
Copy link
Contributor

Choose a reason for hiding this comment

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

The changelog entry for PR #19754 correctly summarizes the change made to the ApplyAndReturnValidatorSetUpdates function. However, the entry starts with a lowercase "update" which should be capitalized to maintain consistency with the rest of the document.

- * [#19754](https://github.com/cosmos/cosmos-sdk/pull/19754) update to use `[]module.ValidatorUpdate` as return for `ApplyAndReturnValidatorSetUpdates`.
+ * [#19754](https://github.com/cosmos/cosmos-sdk/pull/19754) Update to use `[]module.ValidatorUpdate` as return for `ApplyAndReturnValidatorSetUpdates`.

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.

Suggested change
* [#19754](https://github.com/cosmos/cosmos-sdk/pull/19754) update to use `[]module.ValidatorUpdate` as return for `ApplyAndReturnValidatorSetUpdates`.
* [#19754](https://github.com/cosmos/cosmos-sdk/pull/19754) Update to use `[]module.ValidatorUpdate` as return for `ApplyAndReturnValidatorSetUpdates`.

func (v Validator) ModuleValidatorUpdate(r math.Int) module.ValidatorUpdate {
consPk, err := v.ConsPubKey()
if err != nil {
panic(err)

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
func (v Validator) ModuleValidatorUpdateZero() module.ValidatorUpdate {
consPk, err := v.ConsPubKey()
if err != nil {
panic(err)

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
Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

utACK, thank you for spending time on this

x/staking/types/validator.go Show resolved Hide resolved
@julienrbrt julienrbrt added this pull request to the merge queue Mar 19, 2024
Merged via the queue into cosmos:main with commit bfa734c Mar 19, 2024
60 of 62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/genutil genutil module issues C:x/staking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants