From 42c90794ac614601429eed031bd6b56919ecbbdb Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 24 Dec 2016 18:29:49 -0600 Subject: [PATCH] channeldb: return proper error in ChannelGraph.ForEachChannel() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes a minor bug in the ForEachChannel method of the ChannelGraph struct. Rather than ErrGraphNoEdgesFound being returned if either of the edge related buckets hadn’t been created yet, ErrGraphNodesNotFound was being returned. To fix this bug, we now properly return ErrGraphNoEdgesFound. Additionally a mental note to roasbeef has been left as the current code currently assumes that eventually both directions of the channel edge will be advertised. However, this may not necessarily be the case in a live network, since a side chooses to preferentially advertise a channel or not. --- channeldb/graph.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/channeldb/graph.go b/channeldb/graph.go index 549edc0d..c567711d 100644 --- a/channeldb/graph.go +++ b/channeldb/graph.go @@ -131,11 +131,11 @@ func (c *ChannelGraph) ForEachChannel(cb func(*ChannelEdge, *ChannelEdge) error) // logically. edges := tx.Bucket(edgeBucket) if edges == nil { - return ErrGraphNodesNotFound + return ErrGraphNoEdgesFound } edgeIndex := edges.Bucket(edgeIndexBucket) if edgeIndex == nil { - return ErrGraphNodesNotFound + return ErrGraphNoEdgesFound } // For each edge pair within the edge index, we fetch each edge @@ -162,6 +162,10 @@ func (c *ChannelGraph) ForEachChannel(cb func(*ChannelEdge, *ChannelEdge) error) edge2.db = c.db edge2.Node.db = c.db + // TODO(roasbeef): second edge might not have + // propagated through network yet (or possibly never + // will be) + // With both edges read, execute the call back. IF this // function returns an error then the transaction will // be aborted.