diff --git a/channeldb/graph.go b/channeldb/graph.go index 68d5b87c..fef94919 100644 --- a/channeldb/graph.go +++ b/channeldb/graph.go @@ -1636,9 +1636,11 @@ func (c *ChannelGraph) FilterChannelRange(startHeight, endHeight uint32) ([]uint return chanIDs, nil } -// FetchChanInfos returns the set of channel edges that correspond to the -// passed channel ID's. This can be used to respond to peer queries that are -// seeking to fill in gaps in their view of the channel graph. +// FetchChanInfos returns the set of channel edges that correspond to the passed +// channel ID's. If an edge is the query is unknown to the database, it will +// skipped and the result will contain only those edges that exist at the time +// of the query. This can be used to respond to peer queries that are seeking to +// fill in gaps in their view of the channel graph. func (c *ChannelGraph) FetchChanInfos(chanIDs []uint64) ([]ChannelEdge, error) { // TODO(roasbeef): sort cids? @@ -1664,11 +1666,16 @@ func (c *ChannelGraph) FetchChanInfos(chanIDs []uint64) ([]ChannelEdge, error) { for _, cid := range chanIDs { byteOrder.PutUint64(cidBytes[:], cid) - // First, we'll fetch the static edge information. + // First, we'll fetch the static edge information. If + // the edge is unknown, we will skip the edge and + // continue gathering all known edges. edgeInfo, err := fetchChanEdgeInfo( edgeIndex, cidBytes[:], ) - if err != nil { + switch { + case err == ErrEdgeNotFound: + continue + case err != nil: return err } edgeInfo.db = c.db diff --git a/channeldb/graph_test.go b/channeldb/graph_test.go index c2ae2ab2..12ff6a1b 100644 --- a/channeldb/graph_test.go +++ b/channeldb/graph_test.go @@ -2006,6 +2006,24 @@ func TestFetchChanInfos(t *testing.T) { edgeQuery = append(edgeQuery, chanID.ToUint64()) } + // Add an additional edge that does not exist. The query should skip + // this channel and return only infos for the edges that exist. + edgeQuery = append(edgeQuery, 500) + + // Add an another edge to the query that has been marked as a zombie + // edge. The query should also skip this channel. + zombieChan, zombieChanID := createEdge( + 666, 0, 0, 0, node1, node2, + ) + if err := graph.AddChannelEdge(&zombieChan); err != nil { + t.Fatalf("unable to create channel edge: %v", err) + } + err = graph.DeleteChannelEdge(&zombieChan.ChannelPoint) + if err != nil { + t.Fatalf("unable to delete and mark edge zombie: %v", err) + } + edgeQuery = append(edgeQuery, zombieChanID.ToUint64()) + // We'll now attempt to query for the range of channel ID's we just // inserted into the database. We should get the exact same set of // edges back.