mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-30 23:53:41 +02:00
channeldb: let AddrsForNode indicate if the node was found or not
Before this commit, the `(channeldb.DB).AddrsForNode` method treats the results from the channel db and the graph db slightly differently. It errors out if the channel db is unaware of the node in question but does not error out if the graph is unaware of the node. So this commit changes the logic slightly so that a "node-unknown" error from either backing source is not seen as an error.
This commit is contained in:
@@ -34,10 +34,13 @@ func assembleChanBackup(addrSource channeldb.AddrSource,
|
||||
|
||||
// First, we'll query the channel source to obtain all the addresses
|
||||
// that are associated with the peer for this channel.
|
||||
nodeAddrs, err := addrSource.AddrsForNode(openChan.IdentityPub)
|
||||
known, nodeAddrs, err := addrSource.AddrsForNode(openChan.IdentityPub)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !known {
|
||||
return nil, fmt.Errorf("node unknown by address source")
|
||||
}
|
||||
|
||||
single := NewSingle(openChan, nodeAddrs)
|
||||
|
||||
|
@@ -62,20 +62,19 @@ func (m *mockChannelSource) addAddrsForNode(nodePub *btcec.PublicKey, addrs []ne
|
||||
m.addrs[nodeKey] = addrs
|
||||
}
|
||||
|
||||
func (m *mockChannelSource) AddrsForNode(nodePub *btcec.PublicKey) ([]net.Addr, error) {
|
||||
func (m *mockChannelSource) AddrsForNode(nodePub *btcec.PublicKey) (bool,
|
||||
[]net.Addr, error) {
|
||||
|
||||
if m.failQuery {
|
||||
return nil, fmt.Errorf("fail")
|
||||
return false, nil, fmt.Errorf("fail")
|
||||
}
|
||||
|
||||
var nodeKey [33]byte
|
||||
copy(nodeKey[:], nodePub.SerializeCompressed())
|
||||
|
||||
addrs, ok := m.addrs[nodeKey]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("can't find addr")
|
||||
}
|
||||
|
||||
return addrs, nil
|
||||
return ok, addrs, nil
|
||||
}
|
||||
|
||||
// TestFetchBackupForChan tests that we're able to construct a single channel
|
||||
|
Reference in New Issue
Block a user