mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-05 17:05:50 +02:00
htlcswitch: avoid leaking peer interface from link
Here we notice that the only use of the Peer call on the link is to find out what the peer's pubkey is. To avoid leaking handles to IO actions outside the interface we reduce the surface area to just return the peer's public key.
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||
"github.com/lightningnetwork/lnd/invoices"
|
||||
"github.com/lightningnetwork/lnd/lnpeer"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
@@ -262,9 +261,9 @@ type ChannelLink interface {
|
||||
// total sent/received milli-satoshis.
|
||||
Stats() (uint64, lnwire.MilliSatoshi, lnwire.MilliSatoshi)
|
||||
|
||||
// Peer returns the representation of remote peer with which we have
|
||||
// the channel link opened.
|
||||
Peer() lnpeer.Peer
|
||||
// Peer returns the serialized public key of remote peer with which we
|
||||
// have the channel link opened.
|
||||
PeerPubKey() [33]byte
|
||||
|
||||
// AttachMailBox delivers an active MailBox to the link. The MailBox may
|
||||
// have buffered messages.
|
||||
|
@@ -2552,8 +2552,8 @@ func (l *channelLink) updateCommitTx() error {
|
||||
// channel link opened.
|
||||
//
|
||||
// NOTE: Part of the ChannelLink interface.
|
||||
func (l *channelLink) Peer() lnpeer.Peer {
|
||||
return l.cfg.Peer
|
||||
func (l *channelLink) PeerPubKey() [33]byte {
|
||||
return l.cfg.Peer.PubKey()
|
||||
}
|
||||
|
||||
// ChannelPoint returns the channel outpoint for the channel link.
|
||||
|
@@ -891,10 +891,22 @@ func (f *mockChannelLink) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *mockChannelLink) ChanID() lnwire.ChannelID { return f.chanID }
|
||||
func (f *mockChannelLink) ShortChanID() lnwire.ShortChannelID { return f.shortChanID }
|
||||
func (f *mockChannelLink) Bandwidth() lnwire.MilliSatoshi { return 99999999 }
|
||||
func (f *mockChannelLink) Peer() lnpeer.Peer { return f.peer }
|
||||
func (f *mockChannelLink) ChanID() lnwire.ChannelID {
|
||||
return f.chanID
|
||||
}
|
||||
|
||||
func (f *mockChannelLink) ShortChanID() lnwire.ShortChannelID {
|
||||
return f.shortChanID
|
||||
}
|
||||
|
||||
func (f *mockChannelLink) Bandwidth() lnwire.MilliSatoshi {
|
||||
return 99999999
|
||||
}
|
||||
|
||||
func (f *mockChannelLink) PeerPubKey() [33]byte {
|
||||
return f.peer.PubKey()
|
||||
}
|
||||
|
||||
func (f *mockChannelLink) ChannelPoint() *wire.OutPoint { return &wire.OutPoint{} }
|
||||
func (f *mockChannelLink) Stop() {}
|
||||
func (f *mockChannelLink) EligibleToForward() bool { return f.eligible }
|
||||
|
@@ -1147,7 +1147,7 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
|
||||
|
||||
return s.failAddPacket(packet, linkError)
|
||||
}
|
||||
targetPeerKey := targetLink.Peer().PubKey()
|
||||
targetPeerKey := targetLink.PeerPubKey()
|
||||
interfaceLinks, _ := s.getLinks(targetPeerKey)
|
||||
s.indexMtx.RUnlock()
|
||||
|
||||
@@ -1810,9 +1810,9 @@ out:
|
||||
}
|
||||
s.indexMtx.RUnlock()
|
||||
|
||||
peerPub := link.Peer().PubKey()
|
||||
peerPub := link.PeerPubKey()
|
||||
log.Debugf("Requesting local channel close: peer=%v, "+
|
||||
"chan_id=%x", link.Peer(), chanID[:])
|
||||
"chan_id=%x", link.PeerPubKey(), chanID[:])
|
||||
|
||||
go s.cfg.LocalChannelClose(peerPub[:], req)
|
||||
|
||||
@@ -2335,7 +2335,7 @@ func (s *Switch) addLiveLink(link ChannelLink) {
|
||||
|
||||
// Next we'll add the link to the interface index so we can
|
||||
// quickly look up all the channels for a particular node.
|
||||
peerPub := link.Peer().PubKey()
|
||||
peerPub := link.PeerPubKey()
|
||||
if _, ok := s.interfaceIndex[peerPub]; !ok {
|
||||
s.interfaceIndex[peerPub] = make(map[lnwire.ChannelID]ChannelLink)
|
||||
}
|
||||
@@ -2610,7 +2610,7 @@ func (s *Switch) removeLink(chanID lnwire.ChannelID) ChannelLink {
|
||||
|
||||
// If the link has been added to the peer index, then we'll move to
|
||||
// delete the entry within the index.
|
||||
peerPub := link.Peer().PubKey()
|
||||
peerPub := link.PeerPubKey()
|
||||
if peerIndex, ok := s.interfaceIndex[peerPub]; ok {
|
||||
delete(peerIndex, link.ChanID())
|
||||
|
||||
|
Reference in New Issue
Block a user