Skip to content

feat(baseapp): add option to discard events #24440

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

aaronc
Copy link
Member

@aaronc aaronc commented Apr 8, 2025

Description

This adds a BaseApp option to totally disable event emission. A follow-up to this PR would be adding an app.toml setting to configure this.


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

    • Added a configurable option to disable event emission during block finalization and transaction processing, which can improve performance in high-throughput scenarios.
  • Refactor

    • Streamlined event management by updating the routing mechanism for handling events, ensuring consistent and configurable behavior across processing contexts.

Copy link

ironbird-prod bot commented Apr 8, 2025

Ironbird - launch a network To use Ironbird, you can use the following commands:
  • /ironbird start - Launch a testnet with the specified chain and load test configuration.
  • /ironbird chains - List of chain images that ironbird can use to spin-up testnet
  • /ironbird loadtests - List of load test modes that ironbird can run against testnet

@aaronc aaronc marked this pull request as ready for review April 8, 2025 21:08
@aaronc aaronc requested a review from a team April 8, 2025 21:08

This comment has been minimized.

Copy link
Contributor

coderabbitai bot commented Apr 8, 2025

📝 Walkthrough

Walkthrough

The pull request updates how event managers are instantiated and managed within the BaseApp framework. The BaseApp methods now invoke a new method from the message service router to create event managers instead of directly calling the default constructor. A new discarding event manager implementation has been added to handle cases when event emissions should be suppressed. Additionally, a boolean flag and a corresponding setter method allow toggling event emission behavior, ensuring that the appropriate event manager is used during transaction execution and block finalization.

Changes

Files Changes Summary
baseapp/baseapp.go Replaces sdk.NewEventManager() with app.msgServiceRouter.newEventManager() in the preBlock and runTx methods to change the source of event management.
baseapp/msg_service_router.go Adds a disableEventEmission flag and a new method newEventManager() that checks this flag; updates registerMsgServiceHandler to utilize the new event manager instantiation logic.
baseapp/discard_event_mgr.go Introduces a new discardingEventManager struct implementing sdk.EventManagerI; methods return empty events or nil, effectively discarding any emitted events.
baseapp/options.go Adds a new method SetDisableEventEmission(bool) to BaseApp that configures the disableEventEmission flag on the associated message service router.

Sequence Diagram(s)

sequenceDiagram
    participant BA as BaseApp
    participant MSR as MsgServiceRouter
    participant SEM as Standard EventManager
    participant DEM as DiscardingEventManager

    BA->>MSR: Call newEventManager()
    alt disableEventEmission = true
        MSR->>DEM: Return discardingEventManager instance
    else
        MSR->>SEM: Return standard sdk.NewEventManager instance
    end
    BA-->>MSR: Use returned event manager in context (preBlock/runTx)
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 29083cb and 0d2dd55.

📒 Files selected for processing (4)
  • baseapp/baseapp.go (2 hunks)
  • baseapp/discard_event_mgr.go (1 hunks)
  • baseapp/msg_service_router.go (3 hunks)
  • baseapp/options.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
baseapp/options.go (1)
baseapp/baseapp.go (1)
  • BaseApp (63-200)
baseapp/msg_service_router.go (2)
codec/types/interface_registry.go (1)
  • InterfaceRegistry (44-89)
types/events.go (1)
  • EventManagerI (18-25)
baseapp/discard_event_mgr.go (1)
types/events.go (3)
  • EmptyEvents (187-189)
  • Event (163-163)
  • EventManagerI (18-25)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (8)
baseapp/options.go (1)

407-411: Excellent addition that allows disabling event emission for performance optimization.

This new method provides a clean way to toggle event emission at the application level, which can be particularly beneficial for validator nodes where reduced processing overhead is critical. The implementation correctly sets the state on the message service router, which is then used throughout the codebase.

baseapp/baseapp.go (2)

714-714: Good refactoring to use the router's event manager factory method.

This change integrates well with the new event emission control feature by replacing the direct creation of event managers with the router's factory method. This ensures that the event emission setting is respected consistently throughout the application.


913-913: Good integration with the new event emission control system.

Similar to the change in the preBlock method, this modification ensures that event emission settings are consistently applied during transaction execution, maintaining coherent behavior across the codebase.

baseapp/msg_service_router.go (3)

34-34: Good addition of the disableEventEmission field.

This boolean field provides the foundation for the event emission control feature. Its placement in the MsgServiceRouter is appropriate since this router is responsible for message handling, which is where most events originate.


173-173: Excellent refactoring to use the newEventManager method.

This change ensures that the event emission setting is respected when creating event managers for message handling. The implementation correctly replaces the direct instantiation with the factory method.


219-224: Well-implemented factory method for event managers.

This concise method properly encapsulates the logic for creating either a regular or discarding event manager based on the disableEventEmission flag. The implementation follows good practices by:

  1. Checking the flag and returning the appropriate implementation
  2. Using the existing SDK method for normal event managers
  3. Using the new discarding event manager when events should be suppressed
baseapp/discard_event_mgr.go (2)

10-32: Well-designed discarding event manager implementation.

This implementation properly fulfills the EventManagerI interface with minimal, no-op methods that effectively discard all events. The code is clean, concise, and follows good practices:

  1. Returns empty collections for Events() and ABCIEvents()
  2. Returns nil for methods that require error returns
  3. Implements void methods with empty bodies
  4. Uses SDK's existing EmptyEvents() helper for consistency

33-33: Good practice to include interface compliance verification.

The type assertion ensures at compile time that the discardingEventManager struct fully implements the sdk.EventManagerI interface, preventing potential runtime errors if the interface definition changes in the future.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

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

@technicallyty
Copy link
Contributor

do we have an issue for the app.toml follow up?

routes map[string]MsgServiceHandler
hybridHandlers map[string]func(ctx context.Context, req, resp protoiface.MessageV1) error
circuitBreaker CircuitBreaker
interfaceRegistry codectypes.InterfaceRegistry
Copy link
Contributor

Choose a reason for hiding this comment

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

We write a test that demonstrates how this new option works:

  • events are emitted when the field is false
  • events are not emitted when true

by running some SDK message on the router

Copy link
Member Author

Choose a reason for hiding this comment

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

I adapted the existing FinalizeBlock test to check both cases: f130f81. Does that seem sufficient or should we aim to cover more possible cases?

@aaronc
Copy link
Member Author

aaronc commented Apr 9, 2025

@aljo242 I've addressed your comments and also handled a few cases for emit emission that I originally missed. Let me know if you see anything else that needs to be addressed!

@aaronc aaronc changed the title feat(baseapp): add option to disable event emission feat(baseapp): add option to discard events Apr 9, 2025
@aaronc
Copy link
Member Author

aaronc commented Apr 9, 2025

do we have an issue for the app.toml follow up?

Not yet. We should add one. I looked quickly and maybe I'm missing something, but I'm not seeing a straightforward way to do this without adding it specifically to each app.go.

@aljo242 aljo242 added T: Performance Performance improvements S:blocked Status: Blocked labels Apr 14, 2025
@aljo242
Copy link
Contributor

aljo242 commented Apr 14, 2025

Blocking until we can perform ironbird tests against this code

@aljo242 aljo242 added the Cryostasis PRs that we're not quite sure on yet, but don't want to close. label May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cryostasis PRs that we're not quite sure on yet, but don't want to close. needs-load-test S:blocked Status: Blocked T: Performance Performance improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants