channeldb: return proper error in ChannelGraph.ForEachChannel()

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.
This commit is contained in:
Olaoluwa Osuntokun 2016-12-24 18:29:49 -06:00
parent 4a0a657eb0
commit 42c90794ac
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

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