-
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
Open
funyug
wants to merge
2
commits into
lightningnetwork:master
Choose a base branch
from
funyug:add-filters-fwdhistory
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"time" | ||
|
||
"github.com/davecgh/go-spew/spew" | ||
"github.com/lightningnetwork/lnd/fn/v2" | ||
"github.com/lightningnetwork/lnd/lnwire" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
@@ -360,3 +361,201 @@ func TestForwardingLogStoreEvent(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: missing godocs |
||
// TestForwardingLogQueryIncomingOrOutgoingChanIDs tests that querying the | ||
// forwarding log using only incoming channel IDs or outgoing channel IDs | ||
// returns the correct subset of events. | ||
func TestForwardingLogQueryIncomingOrOutgoingChanIDs(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Set up a test database. | ||
db, err := MakeTestDB(t) | ||
require.NoError(t, err, "unable to make test db") | ||
|
||
log := ForwardingLog{ | ||
db: db, | ||
} | ||
|
||
initialTime := time.Unix(1234, 0) | ||
endTime := time.Unix(1234, 0) | ||
|
||
// Create 10 random events with varying incoming and outgoing ChanIDs. | ||
numEvents := 10 | ||
events := make([]ForwardingEvent, numEvents) | ||
incomingChanIDs := []lnwire.ShortChannelID{ | ||
lnwire.NewShortChanIDFromInt(2001), | ||
lnwire.NewShortChanIDFromInt(2002), | ||
lnwire.NewShortChanIDFromInt(2003), | ||
} | ||
|
||
outgoingChanIDs := []lnwire.ShortChannelID{ | ||
lnwire.NewShortChanIDFromInt(3001), | ||
lnwire.NewShortChanIDFromInt(3002), | ||
lnwire.NewShortChanIDFromInt(3003), | ||
} | ||
|
||
for i := 0; i < numEvents; i++ { | ||
events[i] = ForwardingEvent{ | ||
Timestamp: endTime, | ||
IncomingChanID: incomingChanIDs[i%len(incomingChanIDs)], | ||
OutgoingChanID: outgoingChanIDs[i%len(outgoingChanIDs)], | ||
AmtIn: lnwire.MilliSatoshi(rand.Int63()), | ||
AmtOut: lnwire.MilliSatoshi(rand.Int63()), | ||
} | ||
endTime = endTime.Add(time.Minute * 10) | ||
} | ||
|
||
// Add events to the database. | ||
require.NoError( | ||
t, | ||
log.AddForwardingEvents(events), | ||
"unable to add events", | ||
) | ||
|
||
// Query with multiple incoming channel IDs. | ||
incomingEventQuery := ForwardingEventQuery{ | ||
StartTime: initialTime, | ||
EndTime: endTime, | ||
IncomingChanIDs: fn.NewSet( | ||
incomingChanIDs[0].ToUint64(), | ||
incomingChanIDs[1].ToUint64(), | ||
), | ||
IndexOffset: 0, | ||
NumMaxEvents: 10, | ||
} | ||
incomingEventsTimeSlice, err := log.Query(incomingEventQuery) | ||
require.NoError(t, err, "unable to query for events") | ||
|
||
// Verify that only events with the specified incomingChanIDs are | ||
// returned. | ||
expectedIncomingEvents := []ForwardingEvent{} | ||
for _, e := range events { | ||
if e.IncomingChanID == incomingChanIDs[0] || | ||
e.IncomingChanID == incomingChanIDs[1] { | ||
|
||
expectedIncomingEvents = append( | ||
expectedIncomingEvents, e, | ||
) | ||
} | ||
} | ||
|
||
require.Equal( | ||
t, | ||
expectedIncomingEvents, | ||
incomingEventsTimeSlice.ForwardingEvents, | ||
) | ||
|
||
// Query with multiple outgoing channel IDs. | ||
outgoingEventQuery := ForwardingEventQuery{ | ||
StartTime: initialTime, | ||
EndTime: endTime, | ||
OutgoingChanIDs: fn.NewSet( | ||
outgoingChanIDs[0].ToUint64(), | ||
outgoingChanIDs[1].ToUint64(), | ||
), | ||
IndexOffset: 0, | ||
NumMaxEvents: 10, | ||
} | ||
outgoingEventsTimeSlice, err := log.Query(outgoingEventQuery) | ||
require.NoError(t, err, "unable to query for events") | ||
|
||
// Verify that only events with the specified outgoingChanIDs are | ||
// returned. | ||
expectedOutgoingEvents := []ForwardingEvent{} | ||
for _, e := range events { | ||
if e.OutgoingChanID == outgoingChanIDs[0] || | ||
e.OutgoingChanID == outgoingChanIDs[1] { | ||
|
||
expectedOutgoingEvents = append( | ||
expectedOutgoingEvents, e, | ||
) | ||
} | ||
} | ||
|
||
require.Equal( | ||
t, | ||
expectedOutgoingEvents, | ||
outgoingEventsTimeSlice.ForwardingEvents, | ||
) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should also test for when |
||
|
||
// TestForwardingLogQueryIncomingAndOutgoingChanIDs tests that querying the | ||
// forwarding log using both incoming and outgoing channel IDs returns events | ||
// that match either of the specified criteria. | ||
func TestForwardingLogQueryIncomingAndOutgoingChanIDs(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Set up a test database. | ||
db, err := MakeTestDB(t) | ||
require.NoError(t, err, "unable to make test db") | ||
|
||
log := ForwardingLog{ | ||
db: db, | ||
} | ||
|
||
initialTime := time.Unix(1234, 0) | ||
endTime := time.Unix(1234, 0) | ||
|
||
// Create 10 random events with varying incoming and outgoing ChanIDs. | ||
numEvents := 10 | ||
events := make([]ForwardingEvent, numEvents) | ||
outgoingChanIDs := []lnwire.ShortChannelID{ | ||
lnwire.NewShortChanIDFromInt(2001), | ||
lnwire.NewShortChanIDFromInt(2002), | ||
lnwire.NewShortChanIDFromInt(2003), | ||
} | ||
|
||
incomingChanIDs := []lnwire.ShortChannelID{ | ||
lnwire.NewShortChanIDFromInt(3001), | ||
lnwire.NewShortChanIDFromInt(3002), | ||
lnwire.NewShortChanIDFromInt(3003), | ||
} | ||
|
||
for i := 0; i < numEvents; i++ { | ||
events[i] = ForwardingEvent{ | ||
Timestamp: endTime, | ||
OutgoingChanID: outgoingChanIDs[i%len(outgoingChanIDs)], | ||
IncomingChanID: incomingChanIDs[i%len(incomingChanIDs)], | ||
AmtIn: lnwire.MilliSatoshi(rand.Int63()), | ||
AmtOut: lnwire.MilliSatoshi(rand.Int63()), | ||
} | ||
endTime = endTime.Add(time.Minute * 10) | ||
} | ||
|
||
// Add events to the database. | ||
require.NoError(t, log.AddForwardingEvents(events), | ||
"unable to add events") | ||
|
||
// Query with multiple outgoing channel IDs. | ||
eventQuery := ForwardingEventQuery{ | ||
StartTime: initialTime, | ||
EndTime: endTime, | ||
OutgoingChanIDs: fn.NewSet( | ||
outgoingChanIDs[0].ToUint64(), | ||
outgoingChanIDs[1].ToUint64(), | ||
), | ||
IncomingChanIDs: fn.NewSet( | ||
incomingChanIDs[0].ToUint64(), | ||
incomingChanIDs[1].ToUint64(), | ||
), | ||
IndexOffset: 0, | ||
NumMaxEvents: 10, | ||
} | ||
timeSlice, err := log.Query(eventQuery) | ||
require.NoError(t, err, "unable to query for events") | ||
|
||
// Verify that only events with the specified outgoingChanIDs are | ||
// returned. | ||
expectedEvents := []ForwardingEvent{} | ||
for _, e := range events { | ||
if e.OutgoingChanID == outgoingChanIDs[0] || | ||
e.OutgoingChanID == outgoingChanIDs[1] || | ||
e.IncomingChanID == incomingChanIDs[0] || | ||
e.IncomingChanID == incomingChanIDs[1] { | ||
|
||
expectedEvents = append(expectedEvents, e) | ||
} | ||
} | ||
|
||
require.Equal(t, expectedEvents, timeSlice.ForwardingEvents) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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