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:
1 parent
be69b022d9
commit
3761912680
4 files changed
+26
-15
No files matched your search
@@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/channeldb/models"
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/invoices"
|
"github.com/lightningnetwork/lnd/invoices"
|
||||||
"github.com/lightningnetwork/lnd/lnpeer"
|
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@@ -262,9 +261,9 @@ type ChannelLink interface {
|
|||||||
// total sent/received milli-satoshis.
|
// total sent/received milli-satoshis.
|
||||||
Stats() (uint64, lnwire.MilliSatoshi, lnwire.MilliSatoshi)
|
Stats() (uint64, lnwire.MilliSatoshi, lnwire.MilliSatoshi)
|
||||||
|
|
||||||
// Peer returns the representation of remote peer with which we have
|
// Peer returns the serialized public key of remote peer with which we
|
||||||
// the channel link opened.
|
// have the channel link opened.
|
||||||
Peer() lnpeer.Peer
|
PeerPubKey() [33]byte
|
||||||
|
|
||||||
// AttachMailBox delivers an active MailBox to the link. The MailBox may
|
// AttachMailBox delivers an active MailBox to the link. The MailBox may
|
||||||
// have buffered messages.
|
// have buffered messages.
|
||||||
|
|||||||
+2
-2
@@ -2552,8 +2552,8 @@ func (l *channelLink) updateCommitTx() error {
|
|||||||
// channel link opened.
|
// channel link opened.
|
||||||
//
|
//
|
||||||
// NOTE: Part of the ChannelLink interface.
|
// NOTE: Part of the ChannelLink interface.
|
||||||
func (l *channelLink) Peer() lnpeer.Peer {
|
func (l *channelLink) PeerPubKey() [33]byte {
|
||||||
return l.cfg.Peer
|
return l.cfg.Peer.PubKey()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChannelPoint returns the channel outpoint for the channel link.
|
// ChannelPoint returns the channel outpoint for the channel link.
|
||||||
|
|||||||
+16
-4
@@ -891,10 +891,22 @@ func (f *mockChannelLink) Start() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *mockChannelLink) ChanID() lnwire.ChannelID { return f.chanID }
|
func (f *mockChannelLink) ChanID() lnwire.ChannelID {
|
||||||
func (f *mockChannelLink) ShortChanID() lnwire.ShortChannelID { return f.shortChanID }
|
return f.chanID
|
||||||
func (f *mockChannelLink) Bandwidth() lnwire.MilliSatoshi { return 99999999 }
|
}
|
||||||
func (f *mockChannelLink) Peer() lnpeer.Peer { return f.peer }
|
|
||||||
|
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) ChannelPoint() *wire.OutPoint { return &wire.OutPoint{} }
|
||||||
func (f *mockChannelLink) Stop() {}
|
func (f *mockChannelLink) Stop() {}
|
||||||
func (f *mockChannelLink) EligibleToForward() bool { return f.eligible }
|
func (f *mockChannelLink) EligibleToForward() bool { return f.eligible }
|
||||||
|
|||||||
@@ -1147,7 +1147,7 @@ func (s *Switch) handlePacketForward(packet *htlcPacket) error {
|
|||||||
|
|
||||||
return s.failAddPacket(packet, linkError)
|
return s.failAddPacket(packet, linkError)
|
||||||
}
|
}
|
||||||
targetPeerKey := targetLink.Peer().PubKey()
|
targetPeerKey := targetLink.PeerPubKey()
|
||||||
interfaceLinks, _ := s.getLinks(targetPeerKey)
|
interfaceLinks, _ := s.getLinks(targetPeerKey)
|
||||||
s.indexMtx.RUnlock()
|
s.indexMtx.RUnlock()
|
||||||
|
|
||||||
@@ -1810,9 +1810,9 @@ out:
|
|||||||
}
|
}
|
||||||
s.indexMtx.RUnlock()
|
s.indexMtx.RUnlock()
|
||||||
|
|
||||||
peerPub := link.Peer().PubKey()
|
peerPub := link.PeerPubKey()
|
||||||
log.Debugf("Requesting local channel close: peer=%v, "+
|
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)
|
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
|
// Next we'll add the link to the interface index so we can
|
||||||
// quickly look up all the channels for a particular node.
|
// quickly look up all the channels for a particular node.
|
||||||
peerPub := link.Peer().PubKey()
|
peerPub := link.PeerPubKey()
|
||||||
if _, ok := s.interfaceIndex[peerPub]; !ok {
|
if _, ok := s.interfaceIndex[peerPub]; !ok {
|
||||||
s.interfaceIndex[peerPub] = make(map[lnwire.ChannelID]ChannelLink)
|
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
|
// If the link has been added to the peer index, then we'll move to
|
||||||
// delete the entry within the index.
|
// delete the entry within the index.
|
||||||
peerPub := link.Peer().PubKey()
|
peerPub := link.PeerPubKey()
|
||||||
if peerIndex, ok := s.interfaceIndex[peerPub]; ok {
|
if peerIndex, ok := s.interfaceIndex[peerPub]; ok {
|
||||||
delete(peerIndex, link.ChanID())
|
delete(peerIndex, link.ChanID())
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user