-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
base: master
Are you sure you want to change the base?
Conversation
Important Review skippedAuto reviews are limited to specific labels. 🏷️ Labels to auto review (1)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Some CI are failing and the logs have expired. Could you rebase and push? |
21b7c97
to
12f979a
Compare
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 |
Fixed the linting issue |
There was a problem hiding this 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!
cmd/commands/cmd_payments.go
Outdated
@@ -1597,6 +1611,21 @@ func forwardingHistory(ctx *cli.Context) error { | |||
NumMaxEvents: maxEvents, | |||
PeerAliasLookup: lookupPeerAlias, | |||
} | |||
outChan := ctx.Int64Slice("outgoing_chan_ids") |
There was a problem hiding this comment.
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) { | |||
} | |||
} | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing godocs
channeldb/forwarding_log_test.go
Outdated
require.Equal(t, expectedEvents, timeSlice.ForwardingEvents, | ||
"unexpected events returned") | ||
} | ||
|
There was a problem hiding this comment.
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") | ||
} |
There was a problem hiding this comment.
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() { | |||
|
There was a problem hiding this comment.
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
1040e23
to
9ae99da
Compare
Thanks. Did the changes requested above, added the release note and rebased and squashed the commits. |
There was a problem hiding this 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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
9ae99da
to
ad4b755
Compare
Thanks. Will split the PR into multiple commits in future. |
There was a problem hiding this 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.
channeldb/forwarding_log.go
Outdated
|
||
// If both conditions are met, then we'll add | ||
// the event to our return payload. | ||
if incomingMatch && outgoingMatch { |
There was a problem hiding this comment.
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.
channeldb/forwarding_log_test.go
Outdated
eventQuery := ForwardingEventQuery{ | ||
StartTime: initialTime, | ||
EndTime: endTime, | ||
IncomingChanIDs: fn.NewSet(incomingChanIDs[0].ToUint64(), |
There was a problem hiding this comment.
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).
channeldb/forwarding_log_test.go
Outdated
} | ||
} | ||
|
||
require.Equal(t, expectedEvents, timeSlice.ForwardingEvents, |
There was a problem hiding this comment.
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.
channeldb/forwarding_log_test.go
Outdated
|
||
// TestForwardingLogQueryOutgoingChanIDs tests that querying the forwarding log | ||
// using only outgoing channel IDs returns the correct subset of events. | ||
func TestForwardingLogQueryOutgoingChanIDs(t *testing.T) { |
There was a problem hiding this comment.
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?
cmd/commands/cmd_payments.go
Outdated
@@ -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 " + |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
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
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) | ||
} | ||
|
There was a problem hiding this comment.
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...)
This commit adds incoming and outgoing channel ids filter to forwarding history request to filter events received/forwarded from/to a particular channel
ad4b755
to
ab53876
Compare
Did the changes mentioned above. Created a fixup commit and rebased the branch. |
Will take a look once |
@funyug, remember to re-request review from reviewers when ready |
@guggero I see 0.19.0-beta is out. Should i rebase it for review now? |
Yes please. |
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.
Pull Request Checklist
Testing
Code Style and Documentation
[skip ci]
in the commit message for small changes.📝 Please see our Contribution Guidelines for further guidance.