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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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

@@ -360,3 +361,131 @@ func TestForwardingLogStoreEvent(t *testing.T) {
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: missing godocs

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

Copy link
Contributor

@Abdulkbk Abdulkbk Apr 4, 2025

Choose a reason for hiding this comment

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

nit: missing godocs


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.

@@ -281,6 +281,7 @@ func (f *ForwardingLog) Query(q ForwardingEventQuery) (ForwardingLogTimeSlice, e
if recordsToSkip > 0 &&
q.IncomingChanIDs.IsEmpty() &&
q.OutgoingChanIDs.IsEmpty() {

Copy link
Contributor

Choose a reason for hiding this comment

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

This commit can be squashed into 12f979a

@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?

@@ -1517,6 +1521,16 @@ var forwardingHistoryCommand = cli.Command{
Usage: "skip the peer alias lookup per forwarding " +
"event in order to improve performance",
},
cli.Int64SliceFlag{
Name: "incoming_chan_ids",
Usage: "the short channel ids of the incoming " +
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should just say short channel id of the ... since each --incoming_chan_ids can only specify a single ID. But the flag can be specified multiple times in the same command (which we often add to the description with ... filter events by; can be specified multiple times in the same command.
Otherwise the user might think they need to comma separate the values.
Same for the flag below.

rpcserver.go Outdated
@@ -7954,7 +7954,8 @@ func (r *rpcServer) ForwardingHistory(ctx context.Context,
var (
startTime, endTime time.Time

numEvents uint32
numEvents uint32
incomingChanIDs, outgoingChanIDs fn.Set[uint64]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can remove these here and then use the := operator below.

rpcserver.go Outdated
Comment on lines 7982 to 7983
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 added 2 commits April 17, 2025 13:45
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 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.

@lightninglabs-deploy
Copy link

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

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

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
5 participants