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