Skip to content

Commit 56f17af

Browse files
authored
Merge pull request #8517 from ProofOfKeags/cleanup/link-weeds
htlcswitch+peer+lnwire: pull weeds
2 parents 5f89a8b + 5970089 commit 56f17af

File tree

11 files changed

+437
-334
lines changed

11 files changed

+437
-334
lines changed

htlcswitch/interfaces.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/lightningnetwork/lnd/channeldb"
88
"github.com/lightningnetwork/lnd/channeldb/models"
99
"github.com/lightningnetwork/lnd/invoices"
10-
"github.com/lightningnetwork/lnd/lnpeer"
1110
"github.com/lightningnetwork/lnd/lntypes"
1211
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
1312
"github.com/lightningnetwork/lnd/lnwire"
@@ -262,9 +261,9 @@ type ChannelLink interface {
262261
// total sent/received milli-satoshis.
263262
Stats() (uint64, lnwire.MilliSatoshi, lnwire.MilliSatoshi)
264263

265-
// Peer returns the representation of remote peer with which we have
266-
// the channel link opened.
267-
Peer() lnpeer.Peer
264+
// Peer returns the serialized public key of remote peer with which we
265+
// have the channel link opened.
266+
PeerPubKey() [33]byte
268267

269268
// AttachMailBox delivers an active MailBox to the link. The MailBox may
270269
// have buffered messages.

htlcswitch/link.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,6 @@ type ChannelLinkConfig struct {
9292
// allowing the link to open and close circuits.
9393
Circuits CircuitModifier
9494

95-
// Switch provides a reference to the HTLC switch, we only use this in
96-
// testing to access circuit operations not typically exposed by the
97-
// CircuitModifier.
98-
//
99-
// TODO(conner): remove after refactoring htlcswitch testing framework.
100-
Switch *Switch
101-
10295
// BestHeight returns the best known height.
10396
BestHeight func() uint32
10497

@@ -320,9 +313,6 @@ type channelLink struct {
320313
// updates.
321314
channel *lnwallet.LightningChannel
322315

323-
// shortChanID is the most up to date short channel ID for the link.
324-
shortChanID lnwire.ShortChannelID
325-
326316
// cfg is a structure which carries all dependable fields/handlers
327317
// which may affect behaviour of the service.
328318
cfg ChannelLinkConfig
@@ -455,7 +445,6 @@ func NewChannelLink(cfg ChannelLinkConfig,
455445
return &channelLink{
456446
cfg: cfg,
457447
channel: channel,
458-
shortChanID: channel.ShortChanID(),
459448
hodlMap: make(map[models.CircuitKey]hodlHtlc),
460449
hodlQueue: queue.NewConcurrentQueue(10),
461450
log: build.NewPrefixLog(logPrefix, log),
@@ -2202,7 +2191,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
22022191
for id, settled := range finalHTLCs {
22032192
l.cfg.HtlcNotifier.NotifyFinalHtlcEvent(
22042193
models.CircuitKey{
2205-
ChanID: l.shortChanID,
2194+
ChanID: l.ShortChanID(),
22062195
HtlcID: id,
22072196
},
22082197
channeldb.FinalHtlcInfo{
@@ -2563,8 +2552,8 @@ func (l *channelLink) updateCommitTx() error {
25632552
// channel link opened.
25642553
//
25652554
// NOTE: Part of the ChannelLink interface.
2566-
func (l *channelLink) Peer() lnpeer.Peer {
2567-
return l.cfg.Peer
2555+
func (l *channelLink) PeerPubKey() [33]byte {
2556+
return l.cfg.Peer.PubKey()
25682557
}
25692558

25702559
// ChannelPoint returns the channel outpoint for the channel link.
@@ -2582,7 +2571,7 @@ func (l *channelLink) ShortChanID() lnwire.ShortChannelID {
25822571
l.RLock()
25832572
defer l.RUnlock()
25842573

2585-
return l.shortChanID
2574+
return l.channel.ShortChanID()
25862575
}
25872576

25882577
// UpdateShortChanID updates the short channel ID for a link. This may be

htlcswitch/link_isolated_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import (
1313
type linkTestContext struct {
1414
t *testing.T
1515

16-
aliceLink ChannelLink
17-
bobChannel *lnwallet.LightningChannel
18-
aliceMsgs <-chan lnwire.Message
16+
aliceSwitch *Switch
17+
aliceLink ChannelLink
18+
bobChannel *lnwallet.LightningChannel
19+
aliceMsgs <-chan lnwire.Message
1920
}
2021

2122
// sendHtlcBobToAlice sends an HTLC from Bob to Alice, that pays to a preimage
@@ -39,7 +40,7 @@ func (l *linkTestContext) sendHtlcAliceToBob(htlcID int,
3940

4041
l.t.Helper()
4142

42-
circuitMap := l.aliceLink.(*channelLink).cfg.Switch.circuits
43+
circuitMap := l.aliceSwitch.circuits
4344
fwdActions, err := circuitMap.CommitCircuits(
4445
&PaymentCircuit{
4546
Incoming: CircuitKey{

0 commit comments

Comments
 (0)