channeldb: return true for HasChannelEdge unconditionally if edge exists

This commit modifies the HasChannelEdge function to _always_ return
true if we know of the channel edge, meaning that it was previously
added on announce.

This change fixes a minor bug present in the code which would result in
extraneous re-transmissions of updates received by the new routing
package.
This commit is contained in:
Olaoluwa Osuntokun 2016-12-26 22:00:35 -06:00
parent 1103e252be
commit e0d94b545c
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

View File

@ -439,7 +439,7 @@ func (c *ChannelGraph) HasChannelEdge(chanID uint64) (time.Time, time.Time, bool
exists bool
)
err := c.db.View(func(tx *bolt.Tx) error {
if err := c.db.View(func(tx *bolt.Tx) error {
edges := tx.Bucket(edgeBucket)
if edges == nil {
return ErrGraphNoEdgesFound
@ -456,6 +456,8 @@ func (c *ChannelGraph) HasChannelEdge(chanID uint64) (time.Time, time.Time, bool
return nil
}
exists = true
// If the channel has been found in the graph, then retrieve
// the edges itself so we can return the last updated
// timestmaps.
@ -469,21 +471,18 @@ func (c *ChannelGraph) HasChannelEdge(chanID uint64) (time.Time, time.Time, bool
if err != nil {
// TODO(roasbeef): hack fix to return false until both
// edges are populated
exists = false
return nil
}
node1UpdateTime = e1.LastUpdate
node2UpdateTime = e2.LastUpdate
exists = true
return nil
})
if err != nil {
}); err != nil {
return time.Time{}, time.Time{}, exists, err
}
return node1UpdateTime, node2UpdateTime, exists, err
return node1UpdateTime, node2UpdateTime, exists, nil
}
const (
@ -889,6 +888,8 @@ func (c *ChannelGraph) HasLightningNode(pub *btcec.PublicKey) (time.Time, bool,
// Otherwise the first argument should be nil and a fresh transaction will be
// created to execute the graph traversal.
func (l *LightningNode) ForEachChannel(tx *bolt.Tx, cb func(*ChannelEdge) error) error {
// TODO(roasbeef): remove the option to pass in a transaction after
// all?
nodePub := l.PubKey.SerializeCompressed()
traversal := func(tx *bolt.Tx) error {