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/evidence): accept address codec in constructor #21859

Merged
merged 11 commits into from
Sep 25, 2024

Conversation

tac0turtle
Copy link
Member

@tac0turtle tac0turtle commented Sep 23, 2024

Description

this pr moves towards evidence accepting consensus codec to be consistent with how address codec is passed around


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

  • New Features

    • Introduced a consensus address codec to enhance address handling in the evidence module.
    • Updated the NewKeeper function to accept a consensus codec, improving address decoding.
  • Bug Fixes

    • Adjusted evidence processing to utilize the new consensus address codec, enhancing reliability in handling light client attacks and duplicate votes.
  • Documentation

    • Updated changelog to reflect new functionality and changes in the evidence module.
  • Tests

    • Expanded test setup to include additional codec for validator consensus addresses.

@tac0turtle tac0turtle marked this pull request as ready for review September 23, 2024 14:50
Copy link
Contributor

coderabbitai bot commented Sep 23, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes involve enhancements to the evidenceKeeper within the simapp framework, specifically by introducing a new consensus address codec parameter. This adjustment affects several components, including the NewKeeper function, module input structures, and evidence processing methods, thereby streamlining the handling of consensus addresses and reducing dependency on the stakingKeeper.

Changes

File Path Change Summary
simapp/app.go Modified NewSimApp to include app.StakingKeeper.ConsensusAddressCodec() in the evidenceKeeper instantiation.
x/evidence/CHANGELOG.md Updated to reflect that NewKeeper now accepts a consensus codec as an argument, eliminating reliance on staking for address decoding.
x/evidence/depinject.go Added ConsensusAddressCodec field to ModuleInputs struct and updated ProvideModule function to include this new parameter.
x/evidence/keeper/abci.go Altered BeginBlocker to use k.consensusAddressCodec instead of k.stakingKeeper.ConsensusAddressCodec() for processing evidence.
x/evidence/keeper/infraction.go Updated handleEquivocationEvidence to retrieve consensus address using k.consensusAddressCodec instead of k.stakingKeeper.ConsensusAddressCodec().
x/evidence/keeper/keeper.go Introduced consensusAddressCodec field to Keeper struct and updated NewKeeper function signature to include this new parameter.
x/evidence/keeper/keeper_test.go Added a new instance of address.NewBech32Codec for validator consensus in the SetupTest function.
x/evidence/testutil/expected_keepers_mocks.go Removed ConsensusAddressCodec method and associated mock recorder from MockStakingKeeper.
x/evidence/types/expected_keepers.go Removed ConsensusAddressCodec method from StakingKeeper interface, eliminating the need for implementations to provide a consensus address codec.

Suggested labels

C:server/v2, C:x/accounts, C:Store, C:server/v2 cometbft


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@julienrbrt julienrbrt changed the title refactor: accept address codec in constructor refactor(x/evidence): accept address codec in constructor Sep 23, 2024
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.

ACK.

Can we get api breaking changelog in x/evidence?

@@ -23,7 +23,7 @@
// It's still ongoing discussion how should we treat and slash attacks with
// premeditation. So for now we agree to treat them in the same way.
case comet.LightClientAttack, comet.DuplicateVote:
evidence := types.FromABCIEvidence(evidence, k.stakingKeeper.ConsensusAddressCodec())
evidence := types.FromABCIEvidence(evidence, k.consensusAddressCodec)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

path flow from Begin/EndBlock to a panic call
Base automatically changed from marko/mint_staking to main September 24, 2024 19:58
@github-actions github-actions bot removed the C:x/mint label Sep 25, 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.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (4)
x/evidence/keeper/abci.go (1)

26-26: LGTM! Consider enhancing error handling.

The change aligns well with the PR objective of accepting the address codec in the constructor, improving consistency in how the address codec is used throughout the codebase. The overall logic of the function remains intact, and the modification doesn't introduce new panic scenarios.

Consider wrapping the FromABCIEvidence call in a separate function that includes error handling. This would improve the robustness of the code:

func (k Keeper) convertABCIEvidence(evidence comet.Evidence) (types.Evidence, error) {
    converted, err := types.FromABCIEvidence(evidence, k.consensusAddressCodec)
    if err != nil {
        return nil, fmt.Errorf("failed to convert ABCI evidence: %w", err)
    }
    return converted, nil
}

Then, you can use this function in the BeginBlocker:

evidence, err := k.convertABCIEvidence(evidence)
if err != nil {
    return err
}
err = k.handleEquivocationEvidence(ctx, evidence)
if err != nil {
    return err
}

This approach would provide more detailed error information and make the code more maintainable.

x/evidence/depinject.go (1)

36-40: LGTM! Consider adding a comment for the new field.

The addition of ConsensusAddressCodec aligns with the PR objective and follows the existing naming conventions. To improve clarity, consider adding a brief comment explaining the purpose of this new field, similar to other fields in the struct.

 	AddressCodec          address.Codec
-	ConsensusAddressCodec address.Codec
+	ConsensusAddressCodec address.Codec // Codec for encoding/decoding consensus addresses
x/evidence/keeper/keeper.go (1)

26-32: LGTM! Consider adding a comment for the new field.

The addition of consensusAddressCodec to the Keeper struct is consistent with the PR objectives. The field is properly typed and follows the existing naming convention.

Consider adding a brief comment explaining the purpose of the consensusAddressCodec field, similar to other fields in the struct. This would improve code readability and maintainability.

x/evidence/keeper/keeper_test.go (1)

114-114: LGTM! Consider adding a comment for clarity.

The addition of address.NewBech32Codec("cosmosvalcons") aligns with the PR objective of accepting an address codec in the constructor. This change enhances the test setup to include a consensus address codec.

Consider adding a brief comment to explain the purpose of this new codec:

// Add consensus address codec for validator consensus addresses
address.NewBech32Codec("cosmosvalcons"),
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c971f75 and ae2002c.

📒 Files selected for processing (9)
  • simapp/app.go (1 hunks)
  • x/evidence/CHANGELOG.md (1 hunks)
  • x/evidence/depinject.go (2 hunks)
  • x/evidence/keeper/abci.go (1 hunks)
  • x/evidence/keeper/infraction.go (1 hunks)
  • x/evidence/keeper/keeper.go (2 hunks)
  • x/evidence/keeper/keeper_test.go (1 hunks)
  • x/evidence/testutil/expected_keepers_mocks.go (0 hunks)
  • x/evidence/types/expected_keepers.go (0 hunks)
💤 Files not reviewed due to no reviewable changes (2)
  • x/evidence/testutil/expected_keepers_mocks.go
  • x/evidence/types/expected_keepers.go
🧰 Additional context used
📓 Path-based instructions (7)
simapp/app.go (1)

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

x/evidence/CHANGELOG.md (1)

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

x/evidence/depinject.go (1)

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

x/evidence/keeper/abci.go (1)

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

x/evidence/keeper/infraction.go (1)

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

x/evidence/keeper/keeper.go (1)

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

x/evidence/keeper/keeper_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"

🔇 Additional comments not posted (7)
x/evidence/depinject.go (2)

Line range hint 36-51: Summary: Changes align well with PR objectives

The modifications in this file successfully implement the PR's objective of accepting an address codec in the constructor. The changes are minimal and focused, enhancing the evidence module's functionality without introducing unnecessary complexity. The new ConsensusAddressCodec field in ModuleInputs and its usage in ProvideModule function are consistent with the existing code structure and naming conventions.


51-51: LGTM! Verify keeper.NewKeeper signature.

The update to include in.ConsensusAddressCodec in the keeper.NewKeeper call aligns with the PR objective and corresponds to the new field in ModuleInputs. The change is focused and minimal.

To ensure consistency, please verify that the keeper.NewKeeper function signature in the keeper package has been updated to accept this new parameter. Run the following script to check:

✅ Verification successful

LGTM! The keeper.NewKeeper function signature includes in.ConsensusAddressCodec as expected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the keeper.NewKeeper function signature

# Test: Search for the NewKeeper function definition
ast-grep --lang go --pattern 'func NewKeeper($$$) $_ {
  $$$
}'

Length of output: 56664

x/evidence/CHANGELOG.md (1)

35-35: LGTM: Changelog entry is accurate and well-formatted.

The new changelog entry correctly follows the guidelines, accurately reflects the changes described in the PR objectives, and is placed in the appropriate "Api Breaking Changes" section. It clearly explains that NewKeeper now accepts a consensus codec and the purpose of this change.

x/evidence/keeper/keeper.go (3)

42-42: LGTM! Function signature updated correctly.

The NewKeeper function signature has been properly updated to include the new consensusAddressCodec parameter. This change is consistent with the PR objectives and maintains the existing function structure and naming conventions.


46-53: LGTM! Keeper initialization updated correctly.

The NewKeeper function body has been properly updated to initialize the new consensusAddressCodec field in the Keeper struct. This change is consistent with the PR objectives and maintains the existing structure of the function.


Line range hint 26-53: Overall changes look good and align with PR objectives.

The changes to the Keeper struct and NewKeeper function successfully integrate the new consensusAddressCodec field, allowing the evidence module to accept a consensus codec in its constructor. This enhancement should improve consistency in how the address codec is utilized throughout the codebase.

Key points:

  1. New consensusAddressCodec field added to Keeper struct.
  2. NewKeeper function signature updated to accept the new parameter.
  3. Proper initialization of the new field in the NewKeeper function.

These changes are well-implemented and maintain the existing code structure and conventions.

simapp/app.go (1)

445-451: LGTM: EvidenceKeeper initialization looks correct.

The changes to the evidenceKeeper initialization look good. The new parameter app.StakingKeeper.ConsensusAddressCodec() has been added, which aligns with the PR objective of accepting an address codec in the constructor. This change ensures consistency in how the address codec is used throughout the codebase.

x/evidence/keeper/abci.go Show resolved Hide resolved
x/evidence/keeper/infraction.go Show resolved Hide resolved
simapp/app.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: 0

🧹 Outside diff range and nitpick comments (1)
tests/integration/evidence/keeper/infraction_test.go (1)

Line range hint 1-624: Consider adding a test case for the new address codec functionality.

While the existing tests provide good coverage for the evidence module, it might be beneficial to add a specific test case that verifies the correct usage of the newly added consensus address codec. This would ensure that the new parameter is being utilized as expected within the evidence keeper.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ae2002c and 4a3dfcc.

📒 Files selected for processing (6)
  • collections/naming_test.go (1 hunks)
  • schema/indexer/start.go (1 hunks)
  • schema/indexer/start_test.go (1 hunks)
  • tests/integration/evidence/keeper/infraction_test.go (1 hunks)
  • tools/hubl/internal/remote.go (0 hunks)
  • x/evidence/keeper/keeper.go (2 hunks)
💤 Files not reviewed due to no reviewable changes (1)
  • tools/hubl/internal/remote.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • x/evidence/keeper/keeper.go
🧰 Additional context used
📓 Path-based instructions (4)
collections/naming_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"

schema/indexer/start.go (1)

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

schema/indexer/start_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"

tests/integration/evidence/keeper/infraction_test.go (3)

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


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


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

🔇 Additional comments not posted (8)
collections/naming_test.go (4)

36-36: Excellent addition of t.Helper()

The addition of t.Helper() is a great improvement. This call marks the function as a test helper, which enhances the clarity of test failure messages by pointing to the calling test function rather than the helper itself. This change aligns with Go testing best practices and will make debugging failed tests easier.


44-44: Consistent improvement with t.Helper()

The addition of t.Helper() here is consistent with the change in expectKeyCodecName. This maintains a uniform approach across test helper functions, which is excellent for code readability and maintainability. Good job on applying this improvement consistently.


52-52: Completed set of t.Helper() improvements

The addition of t.Helper() to expectKeyCodecNames completes the set of improvements to all test helper functions in this file. This consistent application of t.Helper() across all helper functions demonstrates attention to detail and adherence to Go testing best practices. These changes will collectively enhance the debugging experience when tests fail by providing more accurate error locations.


36-52: Overall improvement in test helper functions

The changes made to this file consistently add t.Helper() to all test helper functions (expectKeyCodecName, expectValueCodecName, and expectKeyCodecNames). This improvement aligns with Go testing best practices and enhances the debugging experience by providing more accurate error locations in case of test failures.

These modifications do not alter the core functionality of the tests but significantly improve their usability and maintainability. The consistent application of this change across all helper functions demonstrates a thorough approach to code improvement.

Great job on enhancing the test suite's effectiveness!

schema/indexer/start_test.go (2)

83-83: Excellent addition of t.Helper()!

Adding t.Helper() to the callCommit function is a great improvement. This change aligns with Go best practices and the Uber Go Style Guide. It helps in providing more accurate line numbers in test failure reports, making it easier to identify the source of failures in the actual test function rather than in the helper.


Line range hint 1-236: Overall assessment: Positive improvement with no side effects

The addition of t.Helper() in the callCommit function is the only change in this file. It's a positive improvement that enhances the test output without altering the test logic or coverage. This change is in line with Go best practices and doesn't introduce any risks or require additional modifications.

schema/indexer/start.go (1)

199-199: LGTM: Improved function signature aligns with Uber Golang style guide.

The change to the unmarshalIndexerCustomConfig function signature is an improvement. By using the shorthand declaration for multiple parameters of the same type (cfg, expectedType interface{}), the code becomes more concise without sacrificing readability. This change aligns well with the Uber Golang style guide, which encourages clear and concise code.

The function's logic remains unchanged, ensuring that its behavior and functionality are preserved.

tests/integration/evidence/keeper/infraction_test.go (1)

157-157: LGTM! Verify impact on address handling.

The addition of stakingKeeper.ConsensusAddressCodec() as a parameter to NewKeeper aligns with the PR objective of accepting an address codec in the constructor. This change enhances the flexibility of the evidence keeper by allowing it to use the consensus address codec from the staking keeper.

To ensure this change doesn't introduce any inconsistencies, please run the following script to check for any other occurrences of NewKeeper that might need similar updates:

✅ Verification successful

Verification Complete: No additional NewKeeper instances require updates. The impact on address handling has been thoroughly checked.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other NewKeeper calls in the codebase
rg --type go 'NewKeeper\(' -A 10 -B 2

Length of output: 100498

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.

4 participants