Merge pull request #8517 from ProofOfKeags/cleanup/link-weeds
htlcswitch+peer+lnwire: pull weeds
This commit is contained in:
11 files changed
+437
-334
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.
|
||||||
|
|||||||
+4
-15
@@ -92,13 +92,6 @@ type ChannelLinkConfig struct {
|
|||||||
// allowing the link to open and close circuits.
|
// allowing the link to open and close circuits.
|
||||||
Circuits CircuitModifier
|
Circuits CircuitModifier
|
||||||
|
|
||||||
// Switch provides a reference to the HTLC switch, we only use this in
|
|
||||||
// testing to access circuit operations not typically exposed by the
|
|
||||||
// CircuitModifier.
|
|
||||||
//
|
|
||||||
// TODO(conner): remove after refactoring htlcswitch testing framework.
|
|
||||||
Switch *Switch
|
|
||||||
|
|
||||||
// BestHeight returns the best known height.
|
// BestHeight returns the best known height.
|
||||||
BestHeight func() uint32
|
BestHeight func() uint32
|
||||||
|
|
||||||
@@ -320,9 +313,6 @@ type channelLink struct {
|
|||||||
// updates.
|
// updates.
|
||||||
channel *lnwallet.LightningChannel
|
channel *lnwallet.LightningChannel
|
||||||
|
|
||||||
// shortChanID is the most up to date short channel ID for the link.
|
|
||||||
shortChanID lnwire.ShortChannelID
|
|
||||||
|
|
||||||
// cfg is a structure which carries all dependable fields/handlers
|
// cfg is a structure which carries all dependable fields/handlers
|
||||||
// which may affect behaviour of the service.
|
// which may affect behaviour of the service.
|
||||||
cfg ChannelLinkConfig
|
cfg ChannelLinkConfig
|
||||||
@@ -455,7 +445,6 @@ func NewChannelLink(cfg ChannelLinkConfig,
|
|||||||
return &channelLink{
|
return &channelLink{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
channel: channel,
|
channel: channel,
|
||||||
shortChanID: channel.ShortChanID(),
|
|
||||||
hodlMap: make(map[models.CircuitKey]hodlHtlc),
|
hodlMap: make(map[models.CircuitKey]hodlHtlc),
|
||||||
hodlQueue: queue.NewConcurrentQueue(10),
|
hodlQueue: queue.NewConcurrentQueue(10),
|
||||||
log: build.NewPrefixLog(logPrefix, log),
|
log: build.NewPrefixLog(logPrefix, log),
|
||||||
@@ -2202,7 +2191,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
|
|||||||
for id, settled := range finalHTLCs {
|
for id, settled := range finalHTLCs {
|
||||||
l.cfg.HtlcNotifier.NotifyFinalHtlcEvent(
|
l.cfg.HtlcNotifier.NotifyFinalHtlcEvent(
|
||||||
models.CircuitKey{
|
models.CircuitKey{
|
||||||
ChanID: l.shortChanID,
|
ChanID: l.ShortChanID(),
|
||||||
HtlcID: id,
|
HtlcID: id,
|
||||||
},
|
},
|
||||||
channeldb.FinalHtlcInfo{
|
channeldb.FinalHtlcInfo{
|
||||||
@@ -2563,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.
|
||||||
@@ -2582,7 +2571,7 @@ func (l *channelLink) ShortChanID() lnwire.ShortChannelID {
|
|||||||
l.RLock()
|
l.RLock()
|
||||||
defer l.RUnlock()
|
defer l.RUnlock()
|
||||||
|
|
||||||
return l.shortChanID
|
return l.channel.ShortChanID()
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateShortChanID updates the short channel ID for a link. This may be
|
// UpdateShortChanID updates the short channel ID for a link. This may be
|
||||||
|
|||||||
@@ -13,9 +13,10 @@ import (
|
|||||||
type linkTestContext struct {
|
type linkTestContext struct {
|
||||||
t *testing.T
|
t *testing.T
|
||||||
|
|
||||||
aliceLink ChannelLink
|
aliceSwitch *Switch
|
||||||
bobChannel *lnwallet.LightningChannel
|
aliceLink ChannelLink
|
||||||
aliceMsgs <-chan lnwire.Message
|
bobChannel *lnwallet.LightningChannel
|
||||||
|
aliceMsgs <-chan lnwire.Message
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendHtlcBobToAlice sends an HTLC from Bob to Alice, that pays to a preimage
|
// sendHtlcBobToAlice sends an HTLC from Bob to Alice, that pays to a preimage
|
||||||
@@ -39,7 +40,7 @@ func (l *linkTestContext) sendHtlcAliceToBob(htlcID int,
|
|||||||
|
|
||||||
l.t.Helper()
|
l.t.Helper()
|
||||||
|
|
||||||
circuitMap := l.aliceLink.(*channelLink).cfg.Switch.circuits
|
circuitMap := l.aliceSwitch.circuits
|
||||||
fwdActions, err := circuitMap.CommitCircuits(
|
fwdActions, err := circuitMap.CommitCircuits(
|
||||||
&PaymentCircuit{
|
&PaymentCircuit{
|
||||||
Incoming: CircuitKey{
|
Incoming: CircuitKey{
|
||||||
|
|||||||
+387
-290
File diff suppressed because it is too large.
Load diff
+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())
|
||||||
|
|
||||||
|
|||||||
@@ -5263,10 +5263,12 @@ func testSwitchHandlePacketForward(t *testing.T, zeroConf, private,
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
// Create a link for Alice that we'll add to the switch.
|
// Create a link for Alice that we'll add to the switch.
|
||||||
aliceLink, _, _, _, _, err :=
|
harness, err :=
|
||||||
newSingleLinkTestHarness(t, btcutil.SatoshiPerBitcoin, 0)
|
newSingleLinkTestHarness(t, btcutil.SatoshiPerBitcoin, 0)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
aliceLink := harness.aliceLink
|
||||||
|
|
||||||
s, err := initSwitchWithTempDB(t, testStartingHeight)
|
s, err := initSwitchWithTempDB(t, testStartingHeight)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to init switch: %v", err)
|
t.Fatalf("unable to init switch: %v", err)
|
||||||
@@ -5313,7 +5315,6 @@ func testSwitchHandlePacketForward(t *testing.T, zeroConf, private,
|
|||||||
if zeroConf {
|
if zeroConf {
|
||||||
// Store the alias in the shortChanID field and mark the real
|
// Store the alias in the shortChanID field and mark the real
|
||||||
// scid in the database.
|
// scid in the database.
|
||||||
aliceChannelLink.shortChanID = aliceAlias
|
|
||||||
err = aliceChannelState.MarkRealScid(aliceScid)
|
err = aliceChannelState.MarkRealScid(aliceScid)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|||||||
@@ -1129,7 +1129,6 @@ func (h *hopNetwork) createChannelLink(server, peer *mockServer,
|
|||||||
|
|
||||||
link := NewChannelLink(
|
link := NewChannelLink(
|
||||||
ChannelLinkConfig{
|
ChannelLinkConfig{
|
||||||
Switch: server.htlcSwitch,
|
|
||||||
BestHeight: server.htlcSwitch.BestHeight,
|
BestHeight: server.htlcSwitch.BestHeight,
|
||||||
FwrdingPolicy: h.globalPolicy,
|
FwrdingPolicy: h.globalPolicy,
|
||||||
Peer: peer,
|
Peer: peer,
|
||||||
|
|||||||
@@ -190,6 +190,19 @@ type Message interface {
|
|||||||
MsgType() MessageType
|
MsgType() MessageType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LinkUpdater is an interface implemented by most messages in BOLT 2 that are
|
||||||
|
// allowed to update the channel state.
|
||||||
|
type LinkUpdater interface {
|
||||||
|
// All LinkUpdater messages are messages and so we embed the interface
|
||||||
|
// so that we can treat it as a message if all we know about it is that
|
||||||
|
// it is a LinkUpdater message.
|
||||||
|
Message
|
||||||
|
|
||||||
|
// TargetChanID returns the channel id of the link for which this
|
||||||
|
// message is intended.
|
||||||
|
TargetChanID() ChannelID
|
||||||
|
}
|
||||||
|
|
||||||
// makeEmptyMessage creates a new empty message of the proper concrete type
|
// makeEmptyMessage creates a new empty message of the proper concrete type
|
||||||
// based on the passed message type.
|
// based on the passed message type.
|
||||||
func makeEmptyMessage(msgType MessageType) (Message, error) {
|
func makeEmptyMessage(msgType MessageType) (Message, error) {
|
||||||
|
|||||||
+1
-1
@@ -1750,7 +1750,7 @@ out:
|
|||||||
// will consider them as link updates and send them to
|
// will consider them as link updates and send them to
|
||||||
// chanStream. These messages will be queued inside chanStream
|
// chanStream. These messages will be queued inside chanStream
|
||||||
// if the channel is not active yet.
|
// if the channel is not active yet.
|
||||||
case LinkUpdater:
|
case lnwire.LinkUpdater:
|
||||||
targetChan = msg.TargetChanID()
|
targetChan = msg.TargetChanID()
|
||||||
isLinkUpdate = p.hasChannel(targetChan)
|
isLinkUpdate = p.hasChannel(targetChan)
|
||||||
|
|
||||||
|
|||||||
@@ -34,14 +34,6 @@ type messageSwitch interface {
|
|||||||
error)
|
error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LinkUpdater is an interface implemented by most messages in BOLT 2 that are
|
|
||||||
// allowed to update the channel state.
|
|
||||||
type LinkUpdater interface {
|
|
||||||
// TargetChanID returns the channel id of the link for which this message
|
|
||||||
// is intended.
|
|
||||||
TargetChanID() lnwire.ChannelID
|
|
||||||
}
|
|
||||||
|
|
||||||
// MessageConn is an interface implemented by anything that delivers
|
// MessageConn is an interface implemented by anything that delivers
|
||||||
// an lnwire.Message using a net.Conn interface.
|
// an lnwire.Message using a net.Conn interface.
|
||||||
type MessageConn interface {
|
type MessageConn interface {
|
||||||
|
|||||||
Reference in new issue
Block a user