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

feat(schema): update event index definitions #21565

Merged
merged 5 commits into from
Sep 9, 2024

Conversation

aaronc
Copy link
Member

@aaronc aaronc commented Sep 5, 2024

Description

This updates the appdata.Event TxIndex, MsgIndex a EventIndex documentation to precisely specify their use and to handle the case where we do not know the index, making these indexes 1-based. Special tx index constants for pre-block, begin-block and end-block processing are also added.


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 new BlockStage field in event data for better clarity on block processing stages.
    • Added a structured enumeration for various block stages, enhancing type safety and readability.
  • Documentation

    • Updated documentation for indices to clarify their 1-based nature and conditions for being zero.

Copy link
Contributor

coderabbitai bot commented Sep 5, 2024

Walkthrough

Walkthrough

The changes introduce a new field, BlockStage, to the Event struct in the schema/appdata/data.go file, replacing comments related to TxIndex. This update includes the definition of a new type, BlockStage, with constants for different block processing stages. Documentation for indices has been clarified to indicate they are now 1-based, enhancing the structure and clarity of event data representation.

Changes

Files Change Summary
schema/appdata/data.go Added BlockStage field to Event struct; defined BlockStage type with constants; updated documentation for indices to clarify 1-based indexing.

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

@aaronc aaronc marked this pull request as ready for review September 5, 2024 13:23
@aaronc aaronc requested review from testinginprod and a team as code owners September 5, 2024 13:23
Copy link
Contributor

github-actions bot commented Sep 5, 2024

@aaronc your pull request is missing a changelog!

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.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a57b254 and a1c067b.

Files selected for processing (1)
  • schema/appdata/data.go (2 hunks)
Additional context used
Path-based instructions (1)
schema/appdata/data.go (1)

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

Additional comments not posted (2)
schema/appdata/data.go (2)

52-68: Review of the Event struct changes:

The changes to the Event struct introduce a new field BlockStage and redefine TxIndex, MsgIndex, and EventIndex to be 1-based, with zero indicating unknown values. This aligns with the PR objectives to enhance clarity and functionality.

  • BlockStage Field: The addition of the BlockStage field (lines 52-54) is well-documented and clearly specifies its purpose and default value. This is a positive change that enhances the semantic understanding of the event's context within the block processing lifecycle.
  • Index Fields: The changes to the index fields (lines 56-68) are crucial as they now clearly define the starting index as 1, and zero as an indicator of unknown values. This is a significant improvement in clarity for developers interacting with these fields.

Overall, these changes are well-aligned with the PR objectives and should improve the usability and understanding of the Event struct.


81-99: Review of the BlockStage type and constants:

The introduction of the BlockStage type (lines 81-82) and its associated constants (lines 84-99) is a structured approach to defining various stages of block processing. This addition is beneficial for several reasons:

  • Clear Definitions: Each stage of block processing is clearly defined with its own constant, making it easier for developers to reference and understand the specific stages of an event within the block lifecycle.
  • Use of iota: The use of iota for initializing constants ensures that these values are unique and incremented correctly, which is a good practice in Go for defining related constants.

This enhancement aids in the clarity and functionality of event indexing within the SDK, as outlined in the PR objectives.

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.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a57b254 and a1c067b.

Files selected for processing (1)
  • schema/appdata/data.go (2 hunks)
Additional context used
Path-based instructions (1)
schema/appdata/data.go (1)

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

Additional comments not posted (2)
schema/appdata/data.go (2)

52-68: Review of the Event struct modifications:

The addition of the BlockStage field and the updates to the index fields (TxIndex, MsgIndex, EventIndex) are well-documented and align with the PR objectives to enhance clarity and functionality. The comments clearly specify the 1-based indexing and conditions for unknown indices, which improves the semantic understanding of these fields.

  • BlockStage Field: The addition of this field with a clear comment about its purpose and the default value (UnknownBlockStage) is a good practice. It helps in understanding the context of the event within the block processing stages.
  • Index Fields: The clarification that these indices are 1-based unless explicitly set to zero (indicating unknown) is crucial for avoiding off-by-one errors and makes the data structure more intuitive.

Overall, these changes are well-aligned with the PR's goals and should enhance the usability and maintenance of the event indexing system.


81-99: Review of the BlockStage type and constants:

The definition of the BlockStage type and its associated constants (UnknownBlockStage, PreBlockStage, BeginBlockStage, TxProcessingStage, EndBlockStage) is a significant improvement in terms of type safety and code readability. Using an enumerated type (int32) for these constants ensures that they are lightweight and efficient for comparisons, which is ideal for performance-sensitive applications like blockchain technologies.

  • Type Safety: Defining BlockStage as a distinct type rather than using a generic integer enhances type safety, making the code less prone to errors.
  • Readability and Maintenance: The use of enumerated constants makes the code more readable and easier to maintain. It clearly delineates the stages of block processing, which is crucial for developers working with this part of the Cosmos SDK.

This approach follows best practices in Go programming and aligns well with the Uber Golang style guide by promoting clear type definitions and the use of constants for known values.

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.

👍🏾

@tac0turtle tac0turtle added this pull request to the merge queue Sep 9, 2024
Merged via the queue into main with commit 561840f Sep 9, 2024
76 of 77 checks passed
@tac0turtle tac0turtle deleted the aaronc/aaronc-schema-event-updates branch September 9, 2024 07:38
@aaronc
Copy link
Member Author

aaronc commented Sep 9, 2024

Thanks for the reviews @julienrbrt and @tac0turtle. @cool-develope does this look good enough for you or is there anything you would change or add?

@julienrbrt
Copy link
Member

Thanks for the reviews @julienrbrt and @tac0turtle. @cool-develope does this look good enough for you or is there anything you would change or add?

I still think we should add attributes for those: https://github.com/cosmos/cosmos-sdk/blob/v0.50.9/baseapp/baseapp.go#L1075-L1100 (Which I believe was going to be done in a follow-up already).
I know the proposal was to add the Sender attribute and have it match the module name, but I think it is confusing and makes more sense to have the signer 🤷🏾‍♂️.

@aaronc
Copy link
Member Author

aaronc commented Sep 9, 2024

Thanks for the reviews @julienrbrt and @tac0turtle. @cool-develope does this look good enough for you or is there anything you would change or add?

I still think we should add attributes for those: https://github.com/cosmos/cosmos-sdk/blob/v0.50.9/baseapp/baseapp.go#L1075-L1100 (Which I believe was going to be done in a follow-up already).

I know the proposal was to add the Sender attribute and have it match the module name, but I think it is confusing and makes more sense to have the signer 🤷🏾‍♂️.

So this code from BaseApp is just adding a new event for a message. There is nothing that prevents such an event from being created using this event model. It's basically the same as far as event producers are concerned and we don't need new attributes here. But in appdata we could also add an OnMessage callback specifically for that.

I think sender attribute will make more sense in the context of RFC 003 and x/accounts when that model is more first class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants