Skip to content

Commit d5fab39

Browse files
committed
server: use chanInfo instead of chanPolicy to establish channel peer conns
In this commit, we modify the way we attempt to locate the our channel peer to establish a persistent connection on start up. Before this commit, we would use the channel policy pointing to the peer to locate the node as it's embedded in the struct. However, at times it's currently possible for the channel policy to not be found in the database if the remote nodes announces before we finalize the process on our end. This can at times lead to a panic as the pointer isn't checked before attempting to access it. To remedy this, we now instead use the channel info which will _always_ be there if the channel is known.
1 parent 6696ccc commit d5fab39

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

server.go

+27-7
Original file line numberDiff line numberDiff line change
@@ -1651,19 +1651,39 @@ func (s *server) establishPersistentConnections() error {
16511651
if err != nil {
16521652
return err
16531653
}
1654+
16541655
// TODO(roasbeef): instead iterate over link nodes and query graph for
16551656
// each of the nodes.
1657+
selfPub := s.identityPriv.PubKey().SerializeCompressed()
16561658
err = sourceNode.ForEachChannel(nil, func(
1657-
_ *bbolt.Tx,
1658-
_ *channeldb.ChannelEdgeInfo,
1659+
tx *bbolt.Tx,
1660+
chanInfo *channeldb.ChannelEdgeInfo,
16591661
policy, _ *channeldb.ChannelEdgePolicy) error {
16601662

1661-
pubStr := string(policy.Node.PubKeyBytes[:])
1663+
// If the remote party has announced the channel to us, but we
1664+
// haven't yet, then we won't have a policy. However, we don't
1665+
// need this to connect to the peer, so we'll log it and move on.
1666+
if policy == nil {
1667+
srvrLog.Warnf("No channel policy found for "+
1668+
"ChannelPoint(%v): ", chanInfo.ChannelPoint)
1669+
}
1670+
1671+
// We'll now fetch the peer opposite from us within this
1672+
// channel so we can queue up a direct connection to them.
1673+
channelPeer, err := chanInfo.FetchOtherNode(tx, selfPub)
1674+
if err != nil {
1675+
return fmt.Errorf("unable to fetch channel peer for "+
1676+
"ChannelPoint(%v): %v", chanInfo.ChannelPoint,
1677+
err)
1678+
}
1679+
1680+
pubStr := string(channelPeer.PubKeyBytes[:])
16621681

1663-
// Add all unique addresses from channel graph/NodeAnnouncements
1664-
// to the list of addresses we'll connect to for this peer.
1682+
// Add all unique addresses from channel
1683+
// graph/NodeAnnouncements to the list of addresses we'll
1684+
// connect to for this peer.
16651685
addrSet := make(map[string]net.Addr)
1666-
for _, addr := range policy.Node.Addresses {
1686+
for _, addr := range channelPeer.Addresses {
16671687
switch addr.(type) {
16681688
case *net.TCPAddr:
16691689
addrSet[addr.String()] = addr
@@ -1705,7 +1725,7 @@ func (s *server) establishPersistentConnections() error {
17051725
n := &nodeAddresses{
17061726
addresses: addrs,
17071727
}
1708-
n.pubKey, err = policy.Node.PubKey()
1728+
n.pubKey, err = channelPeer.PubKey()
17091729
if err != nil {
17101730
return err
17111731
}

0 commit comments

Comments
 (0)