Thanks to visit codestin.com
Credit goes to github.com

Skip to content

lnrpc+channeldb: add reversed flag to ForwardingHistory#10603

Open
Janmesh23 wants to merge 1 commit intolightningnetwork:masterfrom
Janmesh23:forwarding-history-reversed-flag
Open

lnrpc+channeldb: add reversed flag to ForwardingHistory#10603
Janmesh23 wants to merge 1 commit intolightningnetwork:masterfrom
Janmesh23:forwarding-history-reversed-flag

Conversation

@Janmesh23
Copy link

@Janmesh23 Janmesh23 commented Feb 23, 2026

Summary of PR :

Added reversed flag to ForwardingHistory RPC.
Implemented reverse iteration in the database level (channeldb).
Added a comprehensive unit test verifying the new logic and pagination.
Manually updated the generated proto code to ensure the build stays green in this environment.

fixes #10555

@gemini-code-assist
Copy link

Summary of Changes

Hello @Janmesh23, 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 enhances the forwarding history functionality by introducing the ability to query events in reverse chronological order. This improvement provides greater flexibility for users who need to view the most recent forwarding events first, particularly useful for pagination and analysis of recent activity. The changes span the RPC layer down to the database, ensuring consistent behavior and robust testing.

Highlights

  • Reverse Chronological Querying: Introduced a Reversed flag to the ForwardingHistory RPC and the underlying channeldb query, enabling users to retrieve forwarding events in reverse chronological order (newest first).
  • Database Iteration Logic: Refactored the Query method in channeldb/forwarding_log.go to conditionally use logCursor.Prev() or logCursor.Next() based on the Reversed flag, allowing efficient backward iteration through stored events.
  • Comprehensive Unit Testing: Added a new unit test, TestForwardingLogQueryReversed, to thoroughly verify the correct functionality of reverse chronological querying, including pagination, ensuring data integrity and order.
  • RPC and Protocol Buffer Updates: Updated the ForwardingHistoryRequest message in lnrpc/lightning.proto and its generated Go code (lnrpc/lightning.pb.go) to include the new reversed boolean field, and integrated this into the rpcserver.

🧠 New Feature in Public Preview: You can now enable Memory 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.

Changelog
  • channeldb/forwarding_log.go
    • Added Reversed field to ForwardingEventQuery struct.
    • Refactored Query method to support reverse chronological iteration using conditional cursor movement and loop termination logic.
  • channeldb/forwarding_log_test.go
    • Added TestForwardingLogQueryReversed to validate reverse chronological querying and pagination for forwarding events.
  • lnrpc/lightning.pb.go
    • Added Reversed field and its getter to ForwardingHistoryRequest struct.
    • Reordered import statements.
  • lnrpc/lightning.proto
    • Added reversed field to ForwardingHistoryRequest message definition.
  • rpcserver.go
    • Mapped the Reversed flag from the RPC request to the database query.
Activity
  • Manually updated the generated proto code to ensure the build stays green in this environment.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link

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

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 reversed flag to the ForwardingHistory RPC, enabling users to fetch forwarding history in reverse chronological order. The implementation at the database level in channeldb/forwarding_log.go correctly handles both forward and reverse iteration, and a new unit test in channeldb/forwarding_log_test.go provides good coverage for this new functionality. The changes are well-contained and address the feature request effectively. I've included a couple of suggestions to improve code clarity and maintainability in channeldb/forwarding_log.go by addressing some code duplication.

Comment on lines 372 to 373
// If our current return payload exceeds the max number
// of events, then we'll exit now.

Choose a reason for hiding this comment

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

medium

This comment block is a duplicate of the one on lines 370-371. It can be removed to improve readability.

Comment on lines +387 to +391
if q.Reversed {
timestamp, eventBytes = logCursor.Prev()
} else {
timestamp, eventBytes = logCursor.Next()
}

Choose a reason for hiding this comment

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

medium

This block of code for advancing the cursor is repeated in three places within this loop (here, at lines 442-446, and 457-461). To improve maintainability and reduce redundancy, consider refactoring this logic into a helper closure.

For example:

advance := func() {
	if q.Reversed {
		timestamp, eventBytes = logCursor.Prev()
	} else {
		timestamp, eventBytes = logCursor.Next()
	}
}

You could then replace the repeated blocks with a call to advance().

@lightninglabs-deploy
Copy link
Collaborator

@Janmesh23, remember to re-request review from reviewers when ready

@Janmesh23
Copy link
Author

hi @ziggie1984 @Roasbeef !
it would be helpful if you guys review the PR and suggest the needful

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.

[feature]: reversed option in forwarding history endpoint

2 participants