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(rollapp): trigger EventTypeStatusChange instead of EventTypeStateUpdate on state update finalization #913

Merged
merged 3 commits into from
Jun 5, 2024

Conversation

srene
Copy link
Contributor

@srene srene commented Jun 3, 2024

Description


Closes #875

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.

PR review checkboxes:

I have...

  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Targeted PR against the correct branch
  • included the correct type prefix in the PR title
  • Linked to the GitHub issue with discussion and accepted design
  • Targets only one GitHub issue
  • Wrote unit and integration tests
  • Wrote relevant migration scripts if necessary
  • All CI checks have passed
  • Added relevant godoc comments
  • Updated the scripts for local run, e.g genesis_config_commands.sh if the PR changes parameters
  • Add an issue in the e2e-tests repo if necessary

SDK Checklist

  • Import/Export Genesis
  • Registered Invariants
  • Registered Events
  • Updated openapi.yaml
  • No usage of go map
  • No usage of time.Now()
  • Used fixed point arithmetic and not float arithmetic
  • Avoid panicking in Begin/End block as much as possible
  • No unexpected math Overflow
  • Used sendCoin and not SendCoins
  • Out-of-block compute is bounded
  • No serialized ID at the end of store keys
  • UInt to byte conversion should use BigEndian

Full security checklist here

----;

For Reviewer:

  • Confirmed the correct type prefix in the PR title
  • Reviewers assigned
  • Confirmed all author checklist items have been addressed

---;

After reviewer approval:

  • In case the PR targets the main branch, PR should not be squash merge in order to keep meaningful git history.
  • In case the PR targets a release branch, PR must be rebased.

Summary by CodeRabbit

  • Bug Fixes

    • Updated event type from EventTypeStateUpdate to EventTypeStatusChange to ensure correct event handling.
  • Tests

    • Enhanced TestFinalize function to capture and validate events more accurately.
    • Introduced findEvent function to streamline event searching in test responses.

@srene srene self-assigned this Jun 3, 2024
@srene srene requested a review from a team as a code owner June 3, 2024 08:40
Comment on lines 131 to 139
func findEvent(response abci.ResponseEndBlock, eventType string) bool {
found := false
for _, event := range response.Events {
if event.Type == eventType {
found = true
}
}
return found
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func findEvent(response abci.ResponseEndBlock, eventType string) bool {
found := false
for _, event := range response.Events {
if event.Type == eventType {
found = true
}
}
return found
}
func findEvent(response abci.ResponseEndBlock, eventType string) bool {
for _, event := range response.Events {
if event.Type == eventType {
return true
}
}
return false
}

Copy link
Contributor

Choose a reason for hiding this comment

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

slices.ContainsFunc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

replaced by slices.ContainsFunc

@srene srene requested review from zale144 and danwt June 4, 2024 12:25
Copy link
Contributor

coderabbitai bot commented Jun 4, 2024

Walkthrough

The changes involve updating the event type emitted during the finalization process in the Keeper module from EventTypeStateUpdate to EventTypeStatusChange. Additionally, the test cases have been updated to capture and verify this new event type using a helper function.

Changes

File Path Change Summary
x/rollapp/keeper/block_height_to_finalization_queue.go Updated the event type in the finalizePending function from EventTypeStateUpdate to EventTypeStatusChange.
x/rollapp/keeper/block_height_to_finalization_queue_test.go Added import for "slices", modified TestFinalize function to capture response from EndBlocker, and introduced findEvent function to search for events.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant SDK
    participant Keeper
    participant EndBlocker
    participant Test

    Test->>EndBlocker: Call EndBlocker with RequestEndBlock
    EndBlocker->>Keeper: Invoke finalizePending
    Keeper->>SDK: Emit EventTypeStatusChange
    SDK->>Test: Return ResponseEndBlock with EventTypeStatusChange
    Test->>Test: Validate EventTypeStatusChange using findEvent
Loading

Assessment against linked issues

Objective (Issue #875) Addressed Explanation
Emit EventTypeStatusChange instead of EventTypeStateUpdate

Poem

In code's deep forest, changes bloom,
Events now dance to a different tune.
From state to status, they evolve,
A bug's mystery, at last, we solve.
Tests now seek what once was hidden,
In lines of code, precision's bidden.
🐇✨


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 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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

CodeRabbit Commands (invoked as PR comments)

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

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 35f5845 and d95515c.

Files selected for processing (2)
  • x/rollapp/keeper/block_height_to_finalization_queue.go (1 hunks)
  • x/rollapp/keeper/block_height_to_finalization_queue_test.go (3 hunks)
Additional comments not posted (3)
x/rollapp/keeper/block_height_to_finalization_queue_test.go (2)

132-134: The implementation of the findEvent function using slices.ContainsFunc is efficient and clean.


105-105: The modifications in TestFinalize function correctly capture the response from EndBlocker and use the findEvent function to verify the presence of the EventTypeStatusChange event.

Also applies to: 107-107, 111-111, 113-113, 117-117, 119-119

Verification successful

The findEvent function is correctly implemented and used in the test cases to verify the presence of specific event types in the response object.

  • x/rollapp/keeper/block_height_to_finalization_queue_test.go:
    • suite.False(findEvent(response, types.EventTypeStatusChange))
    • suite.True(findEvent(response, types.EventTypeStatusChange))
    • suite.True(findEvent(response, types.EventTypeStatusChange))
    • func findEvent(response abci.ResponseEndBlock, eventType string) bool
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct usage of the `findEvent` function in the test suite.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type go $'findEvent'

Length of output: 523

x/rollapp/keeper/block_height_to_finalization_queue.go (1)

54-54: The change to emit EventTypeStatusChange instead of EventTypeStateUpdate in the finalizePending function aligns with the PR objectives and correctly addresses the issue.

@mtsitrin mtsitrin merged commit 3e7dfc9 into main Jun 5, 2024
51 of 88 checks passed
@mtsitrin mtsitrin deleted the srene/875-finalize-event branch June 5, 2024 07:58
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.

wrong emitted event upon state update finalization
4 participants