multi: let chan and graph db implement AddrSource

Then use both to construct a multiAddrSource AddrSource and use that
around the code-base.
This commit is contained in:
Elle Mouton
2024-10-22 14:35:37 +02:00
parent 51c2f709e1
commit 2c083bc017
4 changed files with 55 additions and 70 deletions

View File

@@ -414,6 +414,32 @@ func (c *ChannelGraph) NewPathFindTx() (kvdb.RTx, error) {
return c.db.BeginReadTx()
}
// AddrsForNode returns all known addresses for the target node public key that
// the graph DB is aware of. The returned boolean indicates if the given node is
// unknown to the graph DB or not.
//
// NOTE: this is part of the channeldb.AddrSource interface.
func (c *ChannelGraph) AddrsForNode(nodePub *btcec.PublicKey) (bool, []net.Addr,
error) {
pubKey, err := route.NewVertexFromBytes(nodePub.SerializeCompressed())
if err != nil {
return false, nil, err
}
node, err := c.FetchLightningNode(pubKey)
// We don't consider it an error if the graph is unaware of the node.
switch {
case err != nil && !errors.Is(err, ErrGraphNodeNotFound):
return false, nil, err
case errors.Is(err, ErrGraphNodeNotFound):
return false, nil, nil
}
return true, node.Addresses, nil
}
// ForEachChannel iterates through all the channel edges stored within the
// graph and invokes the passed callback for each edge. The callback takes two
// edges as since this is a directed graph, both the in/out edges are visited.