Skip to content

lnrpc: add incoming/outgoing channel ids filter to forwarding history request #9356

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

Merged
merged 1 commit into from
Jun 14, 2025

Conversation

funyug
Copy link
Contributor

@funyug funyug commented Dec 13, 2024

fixes #5932

Change Description

This PR adds incoming channel ids and outgoing channel ids filter to forwarding history rpc call by introducing incoming_channel_ids and outgoing_channel_ids parameters to filter the events.

Steps to Test

Steps for reviewers to follow to test the change.

  • Start LND
  • Run lncli fwdinghistory --incoming_chan_ids=m where m is a channel id

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

🏷️ Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this 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.

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.

@saubyk saubyk added this to the 0.20.0 milestone Dec 13, 2024
@Abdulkbk
Copy link
Contributor

Abdulkbk commented Apr 1, 2025

Some CI are failing and the logs have expired. Could you rebase and push?

@funyug funyug force-pushed the add-filters-fwdhistory branch from 21b7c97 to 12f979a Compare April 2, 2025 19:01
@funyug
Copy link
Contributor Author

funyug commented Apr 2, 2025

Rebased and pushed

@Abdulkbk
Copy link
Contributor

Abdulkbk commented Apr 2, 2025

Rebased and pushed

Great.

I will drop a review tomorrow. In the meantime I think the lint CI is failing; I think all you need to do is add an empty line after the statement here

@funyug
Copy link
Contributor Author

funyug commented Apr 3, 2025

Fixed the linting issue

Copy link
Contributor

@Abdulkbk Abdulkbk left a comment

Choose a reason for hiding this comment

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

This PR looks very neat. I just left a few nits and suggestions. Also don't forget to add a release-note.

I also tested this with a cluster of 3 nodes alice -> bob -> hank, made some transactions and the lncli fwdinghistory --incoming_chan_ids=<...> --outgoing_chan_ids=<...> works as expected, works correctly with the other existing params --max_events, --index_offset, ...

Good job!

@@ -1597,6 +1611,21 @@ func forwardingHistory(ctx *cli.Context) error {
NumMaxEvents: maxEvents,
PeerAliasLookup: lookupPeerAlias,
}
outChan := ctx.Int64Slice("outgoing_chan_ids")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could use outgoingChanIDs (and incomingChanIDs down) makes it immediately clear that these variables hold channel identifiers


require.Equal(t, expectedEvents, timeSlice.ForwardingEvents,
"unexpected events returned")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should also test for when IncomingChanIDs and OutgoingChanIDs are specified simultaneously.

Copy link
Collaborator

Choose a reason for hiding this comment

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

agreed

Copy link
Collaborator

Choose a reason for hiding this comment

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

@funyug - i think instead of having 2 verbose tests, you can just have 1 table driven tests with the various scenarios and expected results.

@funyug funyug force-pushed the add-filters-fwdhistory branch from 1040e23 to 9ae99da Compare April 6, 2025 13:27
@funyug
Copy link
Contributor Author

funyug commented Apr 6, 2025

Thanks. Did the changes requested above, added the release note and rebased and squashed the commits.

Copy link
Contributor

@Abdulkbk Abdulkbk left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

Left one more nit.

Also consider splitting your future PRs into structured commits to ease the review process.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe add your name under the contributors' section like it's done here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@guggero guggero self-requested a review April 7, 2025 08:16
@funyug funyug force-pushed the add-filters-fwdhistory branch from 9ae99da to ad4b755 Compare April 7, 2025 10:12
@funyug
Copy link
Contributor Author

funyug commented Apr 7, 2025

Thanks. Will split the PR into multiple commits in future.

Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Thanks for the feature. Looks pretty good, have a few simplifications to suggest.


// If both conditions are met, then we'll add
// the event to our return payload.
if incomingMatch && outgoingMatch {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could invert this condition and do a continue. Then the rest of the code could continue without an additional level of indentation.

eventQuery := ForwardingEventQuery{
StartTime: initialTime,
EndTime: endTime,
IncomingChanIDs: fn.NewSet(incomingChanIDs[0].ToUint64(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: format these fn.NewSet() calls like other multi-line function calls.

Technically, the require.NoError() calls also fall under that rule, since they don't use string formatting templates (e.g. the function name doesn't end in an f to indicate formatting).

}
}

require.Equal(t, expectedEvents, timeSlice.ForwardingEvents,
Copy link
Collaborator

Choose a reason for hiding this comment

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

See my comment above. IMO those additional context strings can just be omitted to make things tidier. The generated error message if this fails is pretty clear where things fail and what expectation failed. So often no additional context is needed in the first place.


// TestForwardingLogQueryOutgoingChanIDs tests that querying the forwarding log
// using only outgoing channel IDs returns the correct subset of events.
func TestForwardingLogQueryOutgoingChanIDs(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this test be combined with the above? Creating events with both incoming and outgoing IDs, then do two different queries and compare the results?

rpcserver.go Outdated
Comment on lines 7982 to 7997
incomingChanIDs = make(fn.Set[uint64], len(req.IncomingChanIds))
outgoingChanIDs = make(fn.Set[uint64], len(req.OutgoingChanIds))
for _, chanID := range req.IncomingChanIds {
incomingChanIDs.Add(chanID)
}

for _, chanID := range req.OutgoingChanIds {
outgoingChanIDs.Add(chanID)
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can just be:

	incomingChanIDs := fn.NewSet(req.IncomingChanIds...)
	outgoingChanIDs := fn.NewSet(req.OutgoingChanIds...)

@funyug funyug force-pushed the add-filters-fwdhistory branch from ad4b755 to ab53876 Compare April 17, 2025 08:16
@funyug
Copy link
Contributor Author

funyug commented Apr 17, 2025

Did the changes mentioned above. Created a fixup commit and rebased the branch.

@guggero guggero requested review from guggero and removed request for guggero April 17, 2025 12:34
@guggero
Copy link
Collaborator

guggero commented Apr 24, 2025

Will take a look once v0.19.0-beta (non-RC) is out and the feature freeze is over.

@funyug
Copy link
Contributor Author

funyug commented May 22, 2025

@guggero I see 0.19.0-beta is out. Should i rebase it for review now?

@guggero
Copy link
Collaborator

guggero commented May 22, 2025

@guggero I see 0.19.0-beta is out. Should i rebase it for review now?

Yes please.

@funyug funyug force-pushed the add-filters-fwdhistory branch from ab53876 to 0e70bf1 Compare May 23, 2025 14:21
@funyug
Copy link
Contributor Author

funyug commented May 23, 2025

rebased

@guggero guggero self-requested a review May 26, 2025 07:22
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

There are some unresolved comments from my last review. Can you please address those? This is quite close otherwise.

@funyug
Copy link
Contributor Author

funyug commented May 27, 2025

Can you point me to the ones that are unresolved. I think I did fix them all in the last commit.

@lightninglabs-deploy
Copy link

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

@funyug
Copy link
Contributor Author

funyug commented Jun 3, 2025

@guggero waiting for further instructions

@guggero
Copy link
Collaborator

guggero commented Jun 3, 2025

Can you point me to the ones that are unresolved. I think I did fix them all in the last commit.

Hmm, I must've looked at an old version by accident. Looks good now, thanks.

@guggero guggero requested a review from ellemouton June 3, 2025 11:06
Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

logic LGTM! I'll Approve it once the fixup commits have been squashed.

It's fine for this PR since it is relatively small, but I'd suggest that for future you try to structure your commits as follows:

  1. first make the internal server changes (ie all your changes to channeldb and the unit test there. Ie, at this step the server can do the new thing but hasnt exposed the functionality yet.
  2. Add the new proto fields (ie, expose the new server functionality)
  3. Finally, update the client (lncli) to make use of the new server functionality.

This type of structure makes it way easier for a reviewer to "read" the PR


require.Equal(t, expectedEvents, timeSlice.ForwardingEvents,
"unexpected events returned")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

agreed


require.Equal(t, expectedEvents, timeSlice.ForwardingEvents,
"unexpected events returned")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@funyug - i think instead of having 2 verbose tests, you can just have 1 table driven tests with the various scenarios and expected results.

@ellemouton
Copy link
Collaborator

@funyug - some changes were made to an area touched by this PR recently - so you'll need to please fix the merge conflicts 🙏

@funyug funyug force-pushed the add-filters-fwdhistory branch from 587e4ef to b1cb0bc Compare June 10, 2025 11:26
Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

thanks @funyug 🙏

Please re-request review from me once you have squashed the fixup commits and addressed the test related comment 🙏

@funyug funyug force-pushed the add-filters-fwdhistory branch from 74c846e to 6440b25 Compare June 10, 2025 13:54
@funyug
Copy link
Contributor Author

funyug commented Jun 10, 2025

@ellemouton updated the tests as requested. Also fixed the linting issue, conflicts and squashed.

This commit adds incoming and outgoing channel ids filter to forwarding history request to filter events received/forwarded from/to a particular channel
@funyug funyug force-pushed the add-filters-fwdhistory branch from 6440b25 to bfe1edf Compare June 11, 2025 03:40
@funyug funyug requested a review from ellemouton June 11, 2025 04:08
Copy link
Collaborator

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

thanks! LGTM! 🚀

@yyforyongyu yyforyongyu merged commit fe40542 into lightningnetwork:master Jun 14, 2025
37 of 38 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.

Add Channel ID parametre to ForwardingHistoryRequest
7 participants