Skip to content

chanevents: add channel event pruning#245

Merged
bitromortac merged 4 commits into
lightninglabs:masterfrom
bitromortac:2606-fwd-prep-14
Jun 25, 2026
Merged

chanevents: add channel event pruning#245
bitromortac merged 4 commits into
lightninglabs:masterfrom
bitromortac:2606-fwd-prep-14

Conversation

@bitromortac

@bitromortac bitromortac commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Bounds the channel_events table, which otherwise grows without bound on high-frequency channels. Pruning is on by default with two independent limits:

  • --chanevents.max-events=7000000 (~1GB of storage)
  • --chanevents.retention=1440h (60 days)

Both parameters can be used independently and the pruning interval is about an hour.

Add a PruneChannelEvents query that bounds the channel_events table by both
size and age in a single statement: an id-keyset offset enforces a maximum
event count and a timestamp filter enforces a retention window, OR-joined so
each limit applies independently. The query returns the number of rows deleted
so callers can surface pruning activity.

Add a standalone timestamp index so the global age-based prune does not scan
the full table. The existing composite index leads with channel_id and cannot
serve a channel-agnostic timestamp filter.
@bitromortac
bitromortac requested a review from ViktorT-11 June 23, 2026 08:24
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a safety mechanism to prune the channel_events database table, which can grow indefinitely. By introducing configurable size and age limits, the system ensures that disk usage remains predictable and manageable. The changes include new configuration parameters, a database migration for optimized query performance, and a background monitoring loop to enforce these retention policies automatically.

Highlights

  • Channel Event Pruning: Introduced automatic pruning for the channel_events table to prevent unbounded growth on high-frequency channels.
  • Configurable Limits: Added --chanevents.max-events (default 7,000,000) and --chanevents.retention (default 60 days) to allow operators to control storage usage.
  • Database Optimization: Added a new migration to include a standalone timestamp index on the channel_events table, significantly improving the performance of age-based pruning.
  • Background Monitoring: Implemented a background ticker in the channel event monitor that periodically enforces storage limits.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a channel event pruning mechanism to Faraday to bound database growth by size and age. It adds configuration options, a background monitor loop, a database migration for a timestamp index, and tests. The reviewer's feedback identifies several improvement opportunities: enforcing a minimum interval for the background pruning ticker to prevent CPU starvation, validating that retention is not negative, removing an unnecessary transaction wrapper for a single query to reduce overhead, and softening a strict assertion in the integration test to avoid CI/CD flakes.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread chanevents/monitor.go Outdated
Comment thread config.go Outdated
Comment thread chanevents/store.go Outdated
Comment thread itest/channel_events_test.go Outdated

@ViktorT-11 ViktorT-11 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good! Just leaving a few suggestions which are non-blocking

Comment thread db/sqlc/queries/chanevents.sql Outdated
Comment thread itest/channel_events_test.go
Comment thread chanevents/monitor.go

for {
select {
case event, ok := <-eventChan:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could maybe also activate pruning once a number of events of a threshold limit has been handled, which resets the ticker. Just to avoid that we'd get a lot of events in one hour which makes the db much larger than the intended max size.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't address this, I think we can get to that later if we really need such high-fidelity

@bitromortac

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a channel event pruning mechanism to prevent unbounded database growth by adding size-based (max-events) and age-based (retention) limits. The review feedback highlights a critical integer overflow risk during type casting that could lead to unintended data loss, a potential nil pointer dereference when initializing the monitor, and an optimization opportunity to avoid running a background ticker when pruning is disabled.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread chanevents/store.go
Comment thread faraday.go
Comment thread chanevents/monitor.go Outdated
Comment thread chanevents/monitor.go Outdated
Comment thread chanevents/monitor.go Outdated
Comment thread chanevents/monitor.go Outdated
We add regular channel event pruning, as otherwise the database may get
filled quickly. We add two mechanisms, a retention time and a max events
number. Both can be turned on individually.
Add an integration test to verify the safety pruning behavior under various
conditions.
Document the new configuration flags in the README, providing rough storage
estimation metrics (~100 bytes per event) to guide database sizing.
@bitromortac
bitromortac merged commit f99e4a3 into lightninglabs:master Jun 25, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants