Skip to content

Commit fd1cd31

Browse files
committed
multi: don't leak underlying pointer to LightningChannel.ChannelPoint()
1 parent e9b3808 commit fd1cd31

File tree

11 files changed

+53
-42
lines changed

11 files changed

+53
-42
lines changed

contractcourt/breach_arbitrator_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ func TestBreachHandoffSuccess(t *testing.T) {
10161016
// observer to exit.
10171017
processACK := make(chan error)
10181018
breach := &ContractBreachEvent{
1019-
ChanPoint: *chanPoint,
1019+
ChanPoint: chanPoint,
10201020
ProcessACK: func(brarErr error) {
10211021
processACK <- brarErr
10221022
},
@@ -1044,13 +1044,13 @@ func TestBreachHandoffSuccess(t *testing.T) {
10441044
// After exiting, the breach arbiter should have persisted the
10451045
// retribution information and the channel should be shown as pending
10461046
// force closed.
1047-
assertArbiterBreach(t, brar, chanPoint)
1047+
assertArbiterBreach(t, brar, &chanPoint)
10481048

10491049
// Send another breach event. Since the handoff for this channel was
10501050
// already ACKed, the breach arbiter should immediately ACK and ignore
10511051
// this event.
10521052
breach = &ContractBreachEvent{
1053-
ChanPoint: *chanPoint,
1053+
ChanPoint: chanPoint,
10541054
ProcessACK: func(brarErr error) {
10551055
processACK <- brarErr
10561056
},
@@ -1077,7 +1077,7 @@ func TestBreachHandoffSuccess(t *testing.T) {
10771077
}
10781078

10791079
// State should not have changed.
1080-
assertArbiterBreach(t, brar, chanPoint)
1080+
assertArbiterBreach(t, brar, &chanPoint)
10811081
}
10821082

10831083
// TestBreachHandoffFail tests that a channel's close observer properly
@@ -1099,7 +1099,7 @@ func TestBreachHandoffFail(t *testing.T) {
10991099
chanPoint := alice.ChannelPoint()
11001100
processACK := make(chan error)
11011101
breach := &ContractBreachEvent{
1102-
ChanPoint: *chanPoint,
1102+
ChanPoint: chanPoint,
11031103
ProcessACK: func(brarErr error) {
11041104
processACK <- brarErr
11051105
},
@@ -1127,7 +1127,7 @@ func TestBreachHandoffFail(t *testing.T) {
11271127
// Since the handoff failed, the breach arbiter should not show the
11281128
// channel as breached, and the channel should also not have been marked
11291129
// pending closed.
1130-
assertNoArbiterBreach(t, brar, chanPoint)
1130+
assertNoArbiterBreach(t, brar, &chanPoint)
11311131
assertNotPendingClosed(t, alice)
11321132

11331133
brar, err := createTestArbiter(
@@ -1138,7 +1138,7 @@ func TestBreachHandoffFail(t *testing.T) {
11381138
// Signal a spend of the funding transaction and wait for the close
11391139
// observer to exit. This time we are allowing the handoff to succeed.
11401140
breach = &ContractBreachEvent{
1141-
ChanPoint: *chanPoint,
1141+
ChanPoint: chanPoint,
11421142
ProcessACK: func(brarErr error) {
11431143
processACK <- brarErr
11441144
},
@@ -1166,7 +1166,7 @@ func TestBreachHandoffFail(t *testing.T) {
11661166
// Check that the breach was properly recorded in the breach arbiter,
11671167
// and that the close observer marked the channel as pending closed
11681168
// before exiting.
1169-
assertArbiterBreach(t, brar, chanPoint)
1169+
assertArbiterBreach(t, brar, &chanPoint)
11701170
}
11711171

11721172
// TestBreachCreateJusticeTx tests that we create three different variants of
@@ -1590,7 +1590,7 @@ func testBreachSpends(t *testing.T, test breachTest) {
15901590

15911591
processACK := make(chan error)
15921592
breach := &ContractBreachEvent{
1593-
ChanPoint: *chanPoint,
1593+
ChanPoint: chanPoint,
15941594
ProcessACK: func(brarErr error) {
15951595
processACK <- brarErr
15961596
},
@@ -1630,7 +1630,7 @@ func testBreachSpends(t *testing.T, test breachTest) {
16301630
// After exiting, the breach arbiter should have persisted the
16311631
// retribution information and the channel should be shown as pending
16321632
// force closed.
1633-
assertArbiterBreach(t, brar, chanPoint)
1633+
assertArbiterBreach(t, brar, &chanPoint)
16341634

16351635
// Assert that the database sees the channel as pending close, otherwise
16361636
// the breach arbiter won't be able to fully close it.
@@ -1669,7 +1669,7 @@ func testBreachSpends(t *testing.T, test breachTest) {
16691669
htlcOutpoint := retribution.HtlcRetributions[0].OutPoint
16701670

16711671
spendTxs, err := getSpendTransactions(
1672-
brar.cfg.Signer, chanPoint, retribution,
1672+
brar.cfg.Signer, &chanPoint, retribution,
16731673
)
16741674
require.NoError(t, err)
16751675

@@ -1764,7 +1764,7 @@ func testBreachSpends(t *testing.T, test breachTest) {
17641764
}
17651765

17661766
// Assert that the channel is fully resolved.
1767-
assertBrarCleanup(t, brar, alice.ChannelPoint(), alice.State().Db)
1767+
assertBrarCleanup(t, brar, &chanPoint, alice.State().Db)
17681768
}
17691769

17701770
// TestBreachDelayedJusticeConfirmation tests that the breach arbiter will
@@ -1799,7 +1799,7 @@ func TestBreachDelayedJusticeConfirmation(t *testing.T) {
17991799

18001800
processACK := make(chan error, 1)
18011801
breach := &ContractBreachEvent{
1802-
ChanPoint: *chanPoint,
1802+
ChanPoint: chanPoint,
18031803
ProcessACK: func(brarErr error) {
18041804
processACK <- brarErr
18051805
},
@@ -1840,7 +1840,7 @@ func TestBreachDelayedJusticeConfirmation(t *testing.T) {
18401840
// After exiting, the breach arbiter should have persisted the
18411841
// retribution information and the channel should be shown as pending
18421842
// force closed.
1843-
assertArbiterBreach(t, brar, chanPoint)
1843+
assertArbiterBreach(t, brar, &chanPoint)
18441844

18451845
// Assert that the database sees the channel as pending close, otherwise
18461846
// the breach arbiter won't be able to fully close it.
@@ -1965,7 +1965,7 @@ func TestBreachDelayedJusticeConfirmation(t *testing.T) {
19651965
}
19661966

19671967
// Assert that the channel is fully resolved.
1968-
assertBrarCleanup(t, brar, alice.ChannelPoint(), alice.State().Db)
1968+
assertBrarCleanup(t, brar, &chanPoint, alice.State().Db)
19691969
}
19701970

19711971
// findInputIndex returns the index of the input that spends from the given
@@ -2081,7 +2081,7 @@ func assertPendingClosed(t *testing.T, c *lnwallet.LightningChannel) {
20812081
require.NoError(t, err, "unable to load pending closed channels")
20822082

20832083
for _, chanSummary := range closedChans {
2084-
if chanSummary.ChanPoint == *c.ChannelPoint() {
2084+
if chanSummary.ChanPoint == c.ChannelPoint() {
20852085
return
20862086
}
20872087
}
@@ -2098,7 +2098,7 @@ func assertNotPendingClosed(t *testing.T, c *lnwallet.LightningChannel) {
20982098
require.NoError(t, err, "unable to load pending closed channels")
20992099

21002100
for _, chanSummary := range closedChans {
2101-
if chanSummary.ChanPoint == *c.ChannelPoint() {
2101+
if chanSummary.ChanPoint == c.ChannelPoint() {
21022102
t.Fatalf("channel %v was marked pending closed",
21032103
c.ChannelPoint())
21042104
}

htlcswitch/link.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ func (l *channelLink) htlcManager() {
13711371
// TODO(roasbeef): remove all together
13721372
go func() {
13731373
chanPoint := l.channel.ChannelPoint()
1374-
l.cfg.Peer.WipeChannel(chanPoint)
1374+
l.cfg.Peer.WipeChannel(&chanPoint)
13751375
}()
13761376

13771377
return
@@ -2559,7 +2559,8 @@ func (l *channelLink) PeerPubKey() [33]byte {
25592559
// ChannelPoint returns the channel outpoint for the channel link.
25602560
// NOTE: Part of the ChannelLink interface.
25612561
func (l *channelLink) ChannelPoint() *wire.OutPoint {
2562-
return l.channel.ChannelPoint()
2562+
chanPoint := l.channel.ChannelPoint()
2563+
return &chanPoint
25632564
}
25642565

25652566
// ShortChanID returns the short channel ID for the channel link. The short
@@ -2601,7 +2602,8 @@ func (l *channelLink) UpdateShortChanID() (lnwire.ShortChannelID, error) {
26012602
//
26022603
// NOTE: Part of the ChannelLink interface.
26032604
func (l *channelLink) ChanID() lnwire.ChannelID {
2604-
return lnwire.NewChanIDFromOutPoint(l.channel.ChannelPoint())
2605+
chanPoint := l.channel.ChannelPoint()
2606+
return lnwire.NewChanIDFromOutPoint(&chanPoint)
26052607
}
26062608

26072609
// Bandwidth returns the total amount that can flow through the channel link at

htlcswitch/link_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3762,7 +3762,8 @@ func TestChannelRetransmission(t *testing.T) {
37623762
t.Fatalf("unable to create channel: %v", err)
37633763
}
37643764

3765-
chanID := lnwire.NewChanIDFromOutPoint(channels.aliceToBob.ChannelPoint())
3765+
chanPoint := channels.aliceToBob.ChannelPoint()
3766+
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
37663767
serverErr := make(chan error, 4)
37673768

37683769
aliceInterceptor := createInterceptorFunc("[alice] <-- [bob]",

lnwallet/chancloser/chancloser.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,12 @@ func NewChanCloser(cfg ChanCloseCfg, deliveryScript []byte,
268268
idealFeePerKw chainfee.SatPerKWeight, negotiationHeight uint32,
269269
closeReq *htlcswitch.ChanClose, locallyInitiated bool) *ChanCloser {
270270

271-
cid := lnwire.NewChanIDFromOutPoint(cfg.Channel.ChannelPoint())
271+
chanPoint := cfg.Channel.ChannelPoint()
272+
cid := lnwire.NewChanIDFromOutPoint(&chanPoint)
272273
return &ChanCloser{
273274
closeReq: closeReq,
274275
state: closeIdle,
275-
chanPoint: *cfg.Channel.ChannelPoint(),
276+
chanPoint: chanPoint,
276277
cid: cid,
277278
cfg: cfg,
278279
negotiationHeight: negotiationHeight,

lnwallet/chancloser/chancloser_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ type mockChannel struct {
146146
remoteKey keychain.KeyDescriptor
147147
}
148148

149-
func (m *mockChannel) ChannelPoint() *wire.OutPoint {
150-
return &m.chanPoint
149+
func (m *mockChannel) ChannelPoint() wire.OutPoint {
150+
return m.chanPoint
151151
}
152152

153153
func (m *mockChannel) MarkCoopBroadcasted(*wire.MsgTx, bool) error {

lnwallet/chancloser/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type CoopFeeEstimator interface {
2929
// closing process.
3030
type Channel interface { //nolint:interfacebloat
3131
// ChannelPoint returns the channel point of the target channel.
32-
ChannelPoint() *wire.OutPoint
32+
ChannelPoint() wire.OutPoint
3333

3434
// MarkCoopBroadcasted persistently marks that the channel close
3535
// transaction has been broadcast.

lnwallet/channel.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6426,8 +6426,8 @@ func (lc *LightningChannel) ReceiveFailHTLC(htlcIndex uint64, reason []byte,
64266426
// ChannelPoint returns the outpoint of the original funding transaction which
64276427
// created this active channel. This outpoint is used throughout various
64286428
// subsystems to uniquely identify an open channel.
6429-
func (lc *LightningChannel) ChannelPoint() *wire.OutPoint {
6430-
return &lc.channelState.FundingOutpoint
6429+
func (lc *LightningChannel) ChannelPoint() wire.OutPoint {
6430+
return lc.channelState.FundingOutpoint
64316431
}
64326432

64336433
// ShortChanID returns the short channel ID for the channel. The short channel

lnwallet/transactions_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ func addTestHtlcs(t *testing.T, remote, local *LightningChannel,
269269
hash160map[hash160] = preimage
270270

271271
// Add htlc to the channel.
272-
chanID := lnwire.NewChanIDFromOutPoint(remote.ChannelPoint())
272+
chanPoint := remote.ChannelPoint()
273+
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
273274

274275
msg := &lnwire.UpdateAddHTLC{
275276
Amount: htlc.amount,

peer/brontide.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3209,10 +3209,10 @@ func (p *Brontide) finalizeChanClosure(chanCloser *chancloser.ChanCloser) {
32093209

32103210
// First, we'll clear all indexes related to the channel in question.
32113211
chanPoint := chanCloser.Channel().ChannelPoint()
3212-
p.WipeChannel(chanPoint)
3212+
p.WipeChannel(&chanPoint)
32133213

32143214
// Also clear the activeChanCloses map of this channel.
3215-
cid := lnwire.NewChanIDFromOutPoint(chanPoint)
3215+
cid := lnwire.NewChanIDFromOutPoint(&chanPoint)
32163216
delete(p.activeChanCloses, cid)
32173217

32183218
// Next, we'll launch a goroutine which will request to be notified by
@@ -3247,7 +3247,7 @@ func (p *Brontide) finalizeChanClosure(chanCloser *chancloser.ChanCloser) {
32473247
}
32483248

32493249
go WaitForChanToClose(chanCloser.NegotiationHeight(), notifier, errChan,
3250-
chanPoint, &closingTxid, closingTx.TxOut[0].PkScript, func() {
3250+
&chanPoint, &closingTxid, closingTx.TxOut[0].PkScript, func() {
32513251
// Respond to the local subsystem which requested the
32523252
// channel closure.
32533253
if closeReq != nil {

peer/brontide_test.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ func TestPeerChannelClosureShutdownResponseLinkRemoved(t *testing.T) {
5353
)
5454
require.NoError(t, err, "unable to create test channels")
5555

56-
chanID := lnwire.NewChanIDFromOutPoint(bobChan.ChannelPoint())
56+
chanPoint := bobChan.ChannelPoint()
57+
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
5758

5859
dummyDeliveryScript := genScript(t, p2wshAddress)
5960

@@ -100,7 +101,8 @@ func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) {
100101
)
101102
require.NoError(t, err, "unable to create test channels")
102103

103-
chanID := lnwire.NewChanIDFromOutPoint(bobChan.ChannelPoint())
104+
chanPoint := bobChan.ChannelPoint()
105+
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
104106

105107
mockLink := newMockUpdateHandler(chanID)
106108
mockSwitch.links = append(mockSwitch.links, mockLink)
@@ -204,7 +206,8 @@ func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) {
204206
)
205207
require.NoError(t, err, "unable to create test channels")
206208

207-
chanID := lnwire.NewChanIDFromOutPoint(bobChan.ChannelPoint())
209+
chanPoint := bobChan.ChannelPoint()
210+
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
208211
mockLink := newMockUpdateHandler(chanID)
209212
mockSwitch.links = append(mockSwitch.links, mockLink)
210213

@@ -215,7 +218,7 @@ func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) {
215218
errChan := make(chan error, 1)
216219
closeCommand := &htlcswitch.ChanClose{
217220
CloseType: contractcourt.CloseRegular,
218-
ChanPoint: bobChan.ChannelPoint(),
221+
ChanPoint: &chanPoint,
219222
Updates: updateChan,
220223
TargetFeePerKw: 12500,
221224
Err: errChan,
@@ -327,7 +330,8 @@ func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
327330
)
328331
require.NoError(t, err, "unable to create test channels")
329332

330-
chanID := lnwire.NewChanIDFromOutPoint(bobChan.ChannelPoint())
333+
chanPoint := bobChan.ChannelPoint()
334+
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
331335

332336
mockLink := newMockUpdateHandler(chanID)
333337
mockSwitch.links = append(mockSwitch.links, mockLink)
@@ -513,7 +517,8 @@ func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
513517
)
514518
require.NoError(t, err, "unable to create test channels")
515519

516-
chanID := lnwire.NewChanIDFromOutPoint(bobChan.ChannelPoint())
520+
chanPoint := bobChan.ChannelPoint()
521+
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
517522
mockLink := newMockUpdateHandler(chanID)
518523
mockSwitch.links = append(mockSwitch.links, mockLink)
519524

@@ -522,7 +527,7 @@ func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
522527
errChan := make(chan error, 1)
523528
closeCommand := &htlcswitch.ChanClose{
524529
CloseType: contractcourt.CloseRegular,
525-
ChanPoint: bobChan.ChannelPoint(),
530+
ChanPoint: &chanPoint,
526531
Updates: updateChan,
527532
TargetFeePerKw: 12500,
528533
Err: errChan,
@@ -844,7 +849,7 @@ func TestCustomShutdownScript(t *testing.T) {
844849
}
845850

846851
chanPoint := bobChan.ChannelPoint()
847-
chanID := lnwire.NewChanIDFromOutPoint(chanPoint)
852+
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
848853
mockLink := newMockUpdateHandler(chanID)
849854
mockSwitch.links = append(mockSwitch.links, mockLink)
850855

@@ -854,7 +859,7 @@ func TestCustomShutdownScript(t *testing.T) {
854859
errChan := make(chan error, 1)
855860
closeCommand := htlcswitch.ChanClose{
856861
CloseType: contractcourt.CloseRegular,
857-
ChanPoint: chanPoint,
862+
ChanPoint: &chanPoint,
858863
Updates: updateChan,
859864
TargetFeePerKw: 12500,
860865
DeliveryScript: test.userCloseScript,

0 commit comments

Comments
 (0)