@@ -1651,19 +1651,39 @@ func (s *server) establishPersistentConnections() error {
1651
1651
if err != nil {
1652
1652
return err
1653
1653
}
1654
+
1654
1655
// TODO(roasbeef): instead iterate over link nodes and query graph for
1655
1656
// each of the nodes.
1657
+ selfPub := s .identityPriv .PubKey ().SerializeCompressed ()
1656
1658
err = sourceNode .ForEachChannel (nil , func (
1657
- _ * bbolt.Tx ,
1658
- _ * channeldb.ChannelEdgeInfo ,
1659
+ tx * bbolt.Tx ,
1660
+ chanInfo * channeldb.ChannelEdgeInfo ,
1659
1661
policy , _ * channeldb.ChannelEdgePolicy ) error {
1660
1662
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 [:])
1662
1681
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.
1665
1685
addrSet := make (map [string ]net.Addr )
1666
- for _ , addr := range policy . Node .Addresses {
1686
+ for _ , addr := range channelPeer .Addresses {
1667
1687
switch addr .(type ) {
1668
1688
case * net.TCPAddr :
1669
1689
addrSet [addr .String ()] = addr
@@ -1705,7 +1725,7 @@ func (s *server) establishPersistentConnections() error {
1705
1725
n := & nodeAddresses {
1706
1726
addresses : addrs ,
1707
1727
}
1708
- n .pubKey , err = policy . Node .PubKey ()
1728
+ n .pubKey , err = channelPeer .PubKey ()
1709
1729
if err != nil {
1710
1730
return err
1711
1731
}
0 commit comments