multi: don't leak underlying pointer to LightningChannel.ChannelPoint()

This commit is contained in:
Keagan McClelland committed 2024-03-08 15:27:19 -08:00
1 parent e9b3808c29
commit fd1cd315ce
11 files changed
+53 -42

No files matched your search

+17 -17
View File
@@ -1016,7 +1016,7 @@ func TestBreachHandoffSuccess(t *testing.T) {
// observer to exit. // observer to exit.
processACK := make(chan error) processACK := make(chan error)
breach := &ContractBreachEvent{ breach := &ContractBreachEvent{
ChanPoint: *chanPoint, ChanPoint: chanPoint,
ProcessACK: func(brarErr error) { ProcessACK: func(brarErr error) {
processACK <- brarErr processACK <- brarErr
}, },
@@ -1044,13 +1044,13 @@ func TestBreachHandoffSuccess(t *testing.T) {
// After exiting, the breach arbiter should have persisted the // After exiting, the breach arbiter should have persisted the
// retribution information and the channel should be shown as pending // retribution information and the channel should be shown as pending
// force closed. // force closed.
assertArbiterBreach(t, brar, chanPoint) assertArbiterBreach(t, brar, &chanPoint)
// Send another breach event. Since the handoff for this channel was // Send another breach event. Since the handoff for this channel was
// already ACKed, the breach arbiter should immediately ACK and ignore // already ACKed, the breach arbiter should immediately ACK and ignore
// this event. // this event.
breach = &ContractBreachEvent{ breach = &ContractBreachEvent{
ChanPoint: *chanPoint, ChanPoint: chanPoint,
ProcessACK: func(brarErr error) { ProcessACK: func(brarErr error) {
processACK <- brarErr processACK <- brarErr
}, },
@@ -1077,7 +1077,7 @@ func TestBreachHandoffSuccess(t *testing.T) {
} }
// State should not have changed. // State should not have changed.
assertArbiterBreach(t, brar, chanPoint) assertArbiterBreach(t, brar, &chanPoint)
} }
// TestBreachHandoffFail tests that a channel's close observer properly // TestBreachHandoffFail tests that a channel's close observer properly
@@ -1099,7 +1099,7 @@ func TestBreachHandoffFail(t *testing.T) {
chanPoint := alice.ChannelPoint() chanPoint := alice.ChannelPoint()
processACK := make(chan error) processACK := make(chan error)
breach := &ContractBreachEvent{ breach := &ContractBreachEvent{
ChanPoint: *chanPoint, ChanPoint: chanPoint,
ProcessACK: func(brarErr error) { ProcessACK: func(brarErr error) {
processACK <- brarErr processACK <- brarErr
}, },
@@ -1127,7 +1127,7 @@ func TestBreachHandoffFail(t *testing.T) {
// Since the handoff failed, the breach arbiter should not show the // Since the handoff failed, the breach arbiter should not show the
// channel as breached, and the channel should also not have been marked // channel as breached, and the channel should also not have been marked
// pending closed. // pending closed.
assertNoArbiterBreach(t, brar, chanPoint) assertNoArbiterBreach(t, brar, &chanPoint)
assertNotPendingClosed(t, alice) assertNotPendingClosed(t, alice)
brar, err := createTestArbiter( brar, err := createTestArbiter(
@@ -1138,7 +1138,7 @@ func TestBreachHandoffFail(t *testing.T) {
// Signal a spend of the funding transaction and wait for the close // Signal a spend of the funding transaction and wait for the close
// observer to exit. This time we are allowing the handoff to succeed. // observer to exit. This time we are allowing the handoff to succeed.
breach = &ContractBreachEvent{ breach = &ContractBreachEvent{
ChanPoint: *chanPoint, ChanPoint: chanPoint,
ProcessACK: func(brarErr error) { ProcessACK: func(brarErr error) {
processACK <- brarErr processACK <- brarErr
}, },
@@ -1166,7 +1166,7 @@ func TestBreachHandoffFail(t *testing.T) {
// Check that the breach was properly recorded in the breach arbiter, // Check that the breach was properly recorded in the breach arbiter,
// and that the close observer marked the channel as pending closed // and that the close observer marked the channel as pending closed
// before exiting. // before exiting.
assertArbiterBreach(t, brar, chanPoint) assertArbiterBreach(t, brar, &chanPoint)
} }
// TestBreachCreateJusticeTx tests that we create three different variants of // TestBreachCreateJusticeTx tests that we create three different variants of
@@ -1590,7 +1590,7 @@ func testBreachSpends(t *testing.T, test breachTest) {
processACK := make(chan error) processACK := make(chan error)
breach := &ContractBreachEvent{ breach := &ContractBreachEvent{
ChanPoint: *chanPoint, ChanPoint: chanPoint,
ProcessACK: func(brarErr error) { ProcessACK: func(brarErr error) {
processACK <- brarErr processACK <- brarErr
}, },
@@ -1630,7 +1630,7 @@ func testBreachSpends(t *testing.T, test breachTest) {
// After exiting, the breach arbiter should have persisted the // After exiting, the breach arbiter should have persisted the
// retribution information and the channel should be shown as pending // retribution information and the channel should be shown as pending
// force closed. // force closed.
assertArbiterBreach(t, brar, chanPoint) assertArbiterBreach(t, brar, &chanPoint)
// Assert that the database sees the channel as pending close, otherwise // Assert that the database sees the channel as pending close, otherwise
// the breach arbiter won't be able to fully close it. // the breach arbiter won't be able to fully close it.
@@ -1669,7 +1669,7 @@ func testBreachSpends(t *testing.T, test breachTest) {
htlcOutpoint := retribution.HtlcRetributions[0].OutPoint htlcOutpoint := retribution.HtlcRetributions[0].OutPoint
spendTxs, err := getSpendTransactions( spendTxs, err := getSpendTransactions(
brar.cfg.Signer, chanPoint, retribution, brar.cfg.Signer, &chanPoint, retribution,
) )
require.NoError(t, err) require.NoError(t, err)
@@ -1764,7 +1764,7 @@ func testBreachSpends(t *testing.T, test breachTest) {
} }
// Assert that the channel is fully resolved. // Assert that the channel is fully resolved.
assertBrarCleanup(t, brar, alice.ChannelPoint(), alice.State().Db) assertBrarCleanup(t, brar, &chanPoint, alice.State().Db)
} }
// TestBreachDelayedJusticeConfirmation tests that the breach arbiter will // TestBreachDelayedJusticeConfirmation tests that the breach arbiter will
@@ -1799,7 +1799,7 @@ func TestBreachDelayedJusticeConfirmation(t *testing.T) {
processACK := make(chan error, 1) processACK := make(chan error, 1)
breach := &ContractBreachEvent{ breach := &ContractBreachEvent{
ChanPoint: *chanPoint, ChanPoint: chanPoint,
ProcessACK: func(brarErr error) { ProcessACK: func(brarErr error) {
processACK <- brarErr processACK <- brarErr
}, },
@@ -1840,7 +1840,7 @@ func TestBreachDelayedJusticeConfirmation(t *testing.T) {
// After exiting, the breach arbiter should have persisted the // After exiting, the breach arbiter should have persisted the
// retribution information and the channel should be shown as pending // retribution information and the channel should be shown as pending
// force closed. // force closed.
assertArbiterBreach(t, brar, chanPoint) assertArbiterBreach(t, brar, &chanPoint)
// Assert that the database sees the channel as pending close, otherwise // Assert that the database sees the channel as pending close, otherwise
// the breach arbiter won't be able to fully close it. // the breach arbiter won't be able to fully close it.
@@ -1965,7 +1965,7 @@ func TestBreachDelayedJusticeConfirmation(t *testing.T) {
} }
// Assert that the channel is fully resolved. // Assert that the channel is fully resolved.
assertBrarCleanup(t, brar, alice.ChannelPoint(), alice.State().Db) assertBrarCleanup(t, brar, &chanPoint, alice.State().Db)
} }
// findInputIndex returns the index of the input that spends from the given // findInputIndex returns the index of the input that spends from the given
@@ -2081,7 +2081,7 @@ func assertPendingClosed(t *testing.T, c *lnwallet.LightningChannel) {
require.NoError(t, err, "unable to load pending closed channels") require.NoError(t, err, "unable to load pending closed channels")
for _, chanSummary := range closedChans { for _, chanSummary := range closedChans {
if chanSummary.ChanPoint == *c.ChannelPoint() { if chanSummary.ChanPoint == c.ChannelPoint() {
return return
} }
} }
@@ -2098,7 +2098,7 @@ func assertNotPendingClosed(t *testing.T, c *lnwallet.LightningChannel) {
require.NoError(t, err, "unable to load pending closed channels") require.NoError(t, err, "unable to load pending closed channels")
for _, chanSummary := range closedChans { for _, chanSummary := range closedChans {
if chanSummary.ChanPoint == *c.ChannelPoint() { if chanSummary.ChanPoint == c.ChannelPoint() {
t.Fatalf("channel %v was marked pending closed", t.Fatalf("channel %v was marked pending closed",
c.ChannelPoint()) c.ChannelPoint())
} }
+5 -3
View File
@@ -1371,7 +1371,7 @@ func (l *channelLink) htlcManager() {
// TODO(roasbeef): remove all together // TODO(roasbeef): remove all together
go func() { go func() {
chanPoint := l.channel.ChannelPoint() chanPoint := l.channel.ChannelPoint()
l.cfg.Peer.WipeChannel(chanPoint) l.cfg.Peer.WipeChannel(&chanPoint)
}() }()
return return
@@ -2559,7 +2559,8 @@ func (l *channelLink) PeerPubKey() [33]byte {
// ChannelPoint returns the channel outpoint for the channel link. // ChannelPoint returns the channel outpoint for the channel link.
// NOTE: Part of the ChannelLink interface. // NOTE: Part of the ChannelLink interface.
func (l *channelLink) ChannelPoint() *wire.OutPoint { func (l *channelLink) ChannelPoint() *wire.OutPoint {
return l.channel.ChannelPoint() chanPoint := l.channel.ChannelPoint()
return &chanPoint
} }
// ShortChanID returns the short channel ID for the channel link. The short // ShortChanID returns the short channel ID for the channel link. The short
@@ -2601,7 +2602,8 @@ func (l *channelLink) UpdateShortChanID() (lnwire.ShortChannelID, error) {
// //
// NOTE: Part of the ChannelLink interface. // NOTE: Part of the ChannelLink interface.
func (l *channelLink) ChanID() lnwire.ChannelID { func (l *channelLink) ChanID() lnwire.ChannelID {
return lnwire.NewChanIDFromOutPoint(l.channel.ChannelPoint()) chanPoint := l.channel.ChannelPoint()
return lnwire.NewChanIDFromOutPoint(&chanPoint)
} }
// Bandwidth returns the total amount that can flow through the channel link at // Bandwidth returns the total amount that can flow through the channel link at
+2 -1
View File
@@ -3762,7 +3762,8 @@ func TestChannelRetransmission(t *testing.T) {
t.Fatalf("unable to create channel: %v", err) t.Fatalf("unable to create channel: %v", err)
} }
chanID := lnwire.NewChanIDFromOutPoint(channels.aliceToBob.ChannelPoint()) chanPoint := channels.aliceToBob.ChannelPoint()
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
serverErr := make(chan error, 4) serverErr := make(chan error, 4)
aliceInterceptor := createInterceptorFunc("[alice] <-- [bob]", aliceInterceptor := createInterceptorFunc("[alice] <-- [bob]",
+3 -2
View File
@@ -268,11 +268,12 @@ func NewChanCloser(cfg ChanCloseCfg, deliveryScript []byte,
idealFeePerKw chainfee.SatPerKWeight, negotiationHeight uint32, idealFeePerKw chainfee.SatPerKWeight, negotiationHeight uint32,
closeReq *htlcswitch.ChanClose, locallyInitiated bool) *ChanCloser { closeReq *htlcswitch.ChanClose, locallyInitiated bool) *ChanCloser {
cid := lnwire.NewChanIDFromOutPoint(cfg.Channel.ChannelPoint()) chanPoint := cfg.Channel.ChannelPoint()
cid := lnwire.NewChanIDFromOutPoint(&chanPoint)
return &ChanCloser{ return &ChanCloser{
closeReq: closeReq, closeReq: closeReq,
state: closeIdle, state: closeIdle,
chanPoint: *cfg.Channel.ChannelPoint(), chanPoint: chanPoint,
cid: cid, cid: cid,
cfg: cfg, cfg: cfg,
negotiationHeight: negotiationHeight, negotiationHeight: negotiationHeight,
+2 -2
View File
@@ -146,8 +146,8 @@ type mockChannel struct {
remoteKey keychain.KeyDescriptor remoteKey keychain.KeyDescriptor
} }
func (m *mockChannel) ChannelPoint() *wire.OutPoint { func (m *mockChannel) ChannelPoint() wire.OutPoint {
return &m.chanPoint return m.chanPoint
} }
func (m *mockChannel) MarkCoopBroadcasted(*wire.MsgTx, bool) error { func (m *mockChannel) MarkCoopBroadcasted(*wire.MsgTx, bool) error {
+1 -1
View File
@@ -29,7 +29,7 @@ type CoopFeeEstimator interface {
// closing process. // closing process.
type Channel interface { //nolint:interfacebloat type Channel interface { //nolint:interfacebloat
// ChannelPoint returns the channel point of the target channel. // ChannelPoint returns the channel point of the target channel.
ChannelPoint() *wire.OutPoint ChannelPoint() wire.OutPoint
// MarkCoopBroadcasted persistently marks that the channel close // MarkCoopBroadcasted persistently marks that the channel close
// transaction has been broadcast. // transaction has been broadcast.
+2 -2
View File
@@ -6426,8 +6426,8 @@ func (lc *LightningChannel) ReceiveFailHTLC(htlcIndex uint64, reason []byte,
// ChannelPoint returns the outpoint of the original funding transaction which // ChannelPoint returns the outpoint of the original funding transaction which
// created this active channel. This outpoint is used throughout various // created this active channel. This outpoint is used throughout various
// subsystems to uniquely identify an open channel. // subsystems to uniquely identify an open channel.
func (lc *LightningChannel) ChannelPoint() *wire.OutPoint { func (lc *LightningChannel) ChannelPoint() wire.OutPoint {
return &lc.channelState.FundingOutpoint return lc.channelState.FundingOutpoint
} }
// ShortChanID returns the short channel ID for the channel. The short channel // ShortChanID returns the short channel ID for the channel. The short channel
+2 -1
View File
@@ -269,7 +269,8 @@ func addTestHtlcs(t *testing.T, remote, local *LightningChannel,
hash160map[hash160] = preimage hash160map[hash160] = preimage
// Add htlc to the channel. // Add htlc to the channel.
chanID := lnwire.NewChanIDFromOutPoint(remote.ChannelPoint()) chanPoint := remote.ChannelPoint()
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
msg := &lnwire.UpdateAddHTLC{ msg := &lnwire.UpdateAddHTLC{
Amount: htlc.amount, Amount: htlc.amount,
+3 -3
View File
@@ -3209,10 +3209,10 @@ func (p *Brontide) finalizeChanClosure(chanCloser *chancloser.ChanCloser) {
// First, we'll clear all indexes related to the channel in question. // First, we'll clear all indexes related to the channel in question.
chanPoint := chanCloser.Channel().ChannelPoint() chanPoint := chanCloser.Channel().ChannelPoint()
p.WipeChannel(chanPoint) p.WipeChannel(&chanPoint)
// Also clear the activeChanCloses map of this channel. // Also clear the activeChanCloses map of this channel.
cid := lnwire.NewChanIDFromOutPoint(chanPoint) cid := lnwire.NewChanIDFromOutPoint(&chanPoint)
delete(p.activeChanCloses, cid) delete(p.activeChanCloses, cid)
// Next, we'll launch a goroutine which will request to be notified by // Next, we'll launch a goroutine which will request to be notified by
@@ -3247,7 +3247,7 @@ func (p *Brontide) finalizeChanClosure(chanCloser *chancloser.ChanCloser) {
} }
go WaitForChanToClose(chanCloser.NegotiationHeight(), notifier, errChan, go WaitForChanToClose(chanCloser.NegotiationHeight(), notifier, errChan,
chanPoint, &closingTxid, closingTx.TxOut[0].PkScript, func() { &chanPoint, &closingTxid, closingTx.TxOut[0].PkScript, func() {
// Respond to the local subsystem which requested the // Respond to the local subsystem which requested the
// channel closure. // channel closure.
if closeReq != nil { if closeReq != nil {
+14 -9
View File
@@ -53,7 +53,8 @@ func TestPeerChannelClosureShutdownResponseLinkRemoved(t *testing.T) {
) )
require.NoError(t, err, "unable to create test channels") require.NoError(t, err, "unable to create test channels")
chanID := lnwire.NewChanIDFromOutPoint(bobChan.ChannelPoint()) chanPoint := bobChan.ChannelPoint()
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
dummyDeliveryScript := genScript(t, p2wshAddress) dummyDeliveryScript := genScript(t, p2wshAddress)
@@ -100,7 +101,8 @@ func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) {
) )
require.NoError(t, err, "unable to create test channels") require.NoError(t, err, "unable to create test channels")
chanID := lnwire.NewChanIDFromOutPoint(bobChan.ChannelPoint()) chanPoint := bobChan.ChannelPoint()
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
mockLink := newMockUpdateHandler(chanID) mockLink := newMockUpdateHandler(chanID)
mockSwitch.links = append(mockSwitch.links, mockLink) mockSwitch.links = append(mockSwitch.links, mockLink)
@@ -204,7 +206,8 @@ func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) {
) )
require.NoError(t, err, "unable to create test channels") require.NoError(t, err, "unable to create test channels")
chanID := lnwire.NewChanIDFromOutPoint(bobChan.ChannelPoint()) chanPoint := bobChan.ChannelPoint()
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
mockLink := newMockUpdateHandler(chanID) mockLink := newMockUpdateHandler(chanID)
mockSwitch.links = append(mockSwitch.links, mockLink) mockSwitch.links = append(mockSwitch.links, mockLink)
@@ -215,7 +218,7 @@ func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) {
errChan := make(chan error, 1) errChan := make(chan error, 1)
closeCommand := &htlcswitch.ChanClose{ closeCommand := &htlcswitch.ChanClose{
CloseType: contractcourt.CloseRegular, CloseType: contractcourt.CloseRegular,
ChanPoint: bobChan.ChannelPoint(), ChanPoint: &chanPoint,
Updates: updateChan, Updates: updateChan,
TargetFeePerKw: 12500, TargetFeePerKw: 12500,
Err: errChan, Err: errChan,
@@ -327,7 +330,8 @@ func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
) )
require.NoError(t, err, "unable to create test channels") require.NoError(t, err, "unable to create test channels")
chanID := lnwire.NewChanIDFromOutPoint(bobChan.ChannelPoint()) chanPoint := bobChan.ChannelPoint()
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
mockLink := newMockUpdateHandler(chanID) mockLink := newMockUpdateHandler(chanID)
mockSwitch.links = append(mockSwitch.links, mockLink) mockSwitch.links = append(mockSwitch.links, mockLink)
@@ -513,7 +517,8 @@ func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
) )
require.NoError(t, err, "unable to create test channels") require.NoError(t, err, "unable to create test channels")
chanID := lnwire.NewChanIDFromOutPoint(bobChan.ChannelPoint()) chanPoint := bobChan.ChannelPoint()
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
mockLink := newMockUpdateHandler(chanID) mockLink := newMockUpdateHandler(chanID)
mockSwitch.links = append(mockSwitch.links, mockLink) mockSwitch.links = append(mockSwitch.links, mockLink)
@@ -522,7 +527,7 @@ func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
errChan := make(chan error, 1) errChan := make(chan error, 1)
closeCommand := &htlcswitch.ChanClose{ closeCommand := &htlcswitch.ChanClose{
CloseType: contractcourt.CloseRegular, CloseType: contractcourt.CloseRegular,
ChanPoint: bobChan.ChannelPoint(), ChanPoint: &chanPoint,
Updates: updateChan, Updates: updateChan,
TargetFeePerKw: 12500, TargetFeePerKw: 12500,
Err: errChan, Err: errChan,
@@ -844,7 +849,7 @@ func TestCustomShutdownScript(t *testing.T) {
} }
chanPoint := bobChan.ChannelPoint() chanPoint := bobChan.ChannelPoint()
chanID := lnwire.NewChanIDFromOutPoint(chanPoint) chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
mockLink := newMockUpdateHandler(chanID) mockLink := newMockUpdateHandler(chanID)
mockSwitch.links = append(mockSwitch.links, mockLink) mockSwitch.links = append(mockSwitch.links, mockLink)
@@ -854,7 +859,7 @@ func TestCustomShutdownScript(t *testing.T) {
errChan := make(chan error, 1) errChan := make(chan error, 1)
closeCommand := htlcswitch.ChanClose{ closeCommand := htlcswitch.ChanClose{
CloseType: contractcourt.CloseRegular, CloseType: contractcourt.CloseRegular,
ChanPoint: chanPoint, ChanPoint: &chanPoint,
Updates: updateChan, Updates: updateChan,
TargetFeePerKw: 12500, TargetFeePerKw: 12500,
DeliveryScript: test.userCloseScript, DeliveryScript: test.userCloseScript,
+2 -1
View File
@@ -412,7 +412,8 @@ func createTestPeer(t *testing.T, notifier chainntnfs.ChainNotifier,
alicePeer := NewBrontide(*cfg) alicePeer := NewBrontide(*cfg)
alicePeer.remoteFeatures = lnwire.NewFeatureVector(nil, lnwire.Features) alicePeer.remoteFeatures = lnwire.NewFeatureVector(nil, lnwire.Features)
chanID := lnwire.NewChanIDFromOutPoint(channelAlice.ChannelPoint()) chanPoint := channelAlice.ChannelPoint()
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
alicePeer.activeChannels.Store(chanID, channelAlice) alicePeer.activeChannels.Store(chanID, channelAlice)
alicePeer.wg.Add(1) alicePeer.wg.Add(1)