Skip to content

Commit db39a90

Browse files
committed
multi: make NewChanIDFromOutpoint accept value instead of pointer
1 parent fd1cd31 commit db39a90

27 files changed

+108
-106
lines changed

channeldb/channel.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ func (c *OpenChannel) fullSync(tx kvdb.RwTx) error {
11691169
return ErrChanAlreadyExists
11701170
}
11711171

1172-
cid := lnwire.NewChanIDFromOutPoint(&c.FundingOutpoint)
1172+
cid := lnwire.NewChanIDFromOutPoint(c.FundingOutpoint)
11731173
if cidBucket.Get(cid[:]) != nil {
11741174
return ErrChanAlreadyExists
11751175
}
@@ -1574,7 +1574,7 @@ func (c *OpenChannel) ChanSyncMsg() (*lnwire.ChannelReestablish, error) {
15741574

15751575
return &lnwire.ChannelReestablish{
15761576
ChanID: lnwire.NewChanIDFromOutPoint(
1577-
&c.FundingOutpoint,
1577+
c.FundingOutpoint,
15781578
),
15791579
NextLocalCommitHeight: nextLocalCommitHeight,
15801580
RemoteCommitTailHeight: remoteChainTipHeight,

channeldb/db.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ func (c *ChannelStateDB) FetchChannelByID(tx kvdb.RTx, id lnwire.ChannelID) (
704704
return err
705705
}
706706

707-
chanID := lnwire.NewChanIDFromOutPoint(&outPoint)
707+
chanID := lnwire.NewChanIDFromOutPoint(outPoint)
708708
if chanID != id {
709709
return nil
710710
}

channeldb/db_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func TestFetchClosedChannelForID(t *testing.T) {
140140
state.FundingOutpoint.Index = i
141141

142142
// We calculate the ChannelID and use it to fetch the summary.
143-
cid := lnwire.NewChanIDFromOutPoint(&state.FundingOutpoint)
143+
cid := lnwire.NewChanIDFromOutPoint(state.FundingOutpoint)
144144
fetchedSummary, err := cdb.FetchClosedChannelForID(cid)
145145
if err != nil {
146146
t.Fatalf("unable to fetch close summary: %v", err)
@@ -158,7 +158,7 @@ func TestFetchClosedChannelForID(t *testing.T) {
158158
// As a final test we make sure that we get ErrClosedChannelNotFound
159159
// for a ChannelID we didn't add to the DB.
160160
state.FundingOutpoint.Index++
161-
cid := lnwire.NewChanIDFromOutPoint(&state.FundingOutpoint)
161+
cid := lnwire.NewChanIDFromOutPoint(state.FundingOutpoint)
162162
_, err = cdb.FetchClosedChannelForID(cid)
163163
if err != ErrClosedChannelNotFound {
164164
t.Fatalf("expected ErrClosedChannelNotFound, instead got: %v", err)
@@ -240,7 +240,7 @@ func TestFetchChannel(t *testing.T) {
240240
require.Equal(t, channelState, dbChannel)
241241

242242
// Next, attempt to fetch the channel by its channel ID.
243-
chanID := lnwire.NewChanIDFromOutPoint(&channelState.FundingOutpoint)
243+
chanID := lnwire.NewChanIDFromOutPoint(channelState.FundingOutpoint)
244244
dbChannel, err = cdb.FetchChannelByID(nil, chanID)
245245
require.NoError(t, err, "unable to fetch channel")
246246

@@ -259,7 +259,7 @@ func TestFetchChannel(t *testing.T) {
259259
_, err = cdb.FetchChannel(nil, channelState2.FundingOutpoint)
260260
require.ErrorIs(t, err, ErrChannelNotFound)
261261

262-
chanID2 := lnwire.NewChanIDFromOutPoint(&channelState2.FundingOutpoint)
262+
chanID2 := lnwire.NewChanIDFromOutPoint(channelState2.FundingOutpoint)
263263
_, err = cdb.FetchChannelByID(nil, chanID2)
264264
require.ErrorIs(t, err, ErrChannelNotFound)
265265
}

channeldb/forwarding_package_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func checkPkgFilterEncodeDecode(t *testing.T, i uint16, f *channeldb.PkgFilter)
141141
}
142142

143143
var (
144-
chanID = lnwire.NewChanIDFromOutPoint(&wire.OutPoint{})
144+
chanID = lnwire.NewChanIDFromOutPoint(wire.OutPoint{})
145145

146146
adds = []channeldb.LogUpdate{
147147
{

discovery/gossiper.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,8 +1748,9 @@ func (d *AuthenticatedGossiper) processChanPolicyUpdate(
17481748
// update with the peer's alias. We do this after
17491749
// updateChannel so that the alias isn't persisted to
17501750
// the database.
1751-
op := &edgeInfo.Info.ChannelPoint
1752-
chanID := lnwire.NewChanIDFromOutPoint(op)
1751+
chanID := lnwire.NewChanIDFromOutPoint(
1752+
edgeInfo.Info.ChannelPoint,
1753+
)
17531754

17541755
var defaultAlias lnwire.ShortChannelID
17551756
foundAlias, _ := d.cfg.GetAlias(chanID)

funding/manager.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ func (f *Manager) start() error {
698698
}
699699

700700
for _, channel := range allChannels {
701-
chanID := lnwire.NewChanIDFromOutPoint(&channel.FundingOutpoint)
701+
chanID := lnwire.NewChanIDFromOutPoint(channel.FundingOutpoint)
702702

703703
// For any channels that were in a pending state when the
704704
// daemon was last connected, the Funding Manager will
@@ -1113,7 +1113,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel,
11131113
channelState channelOpeningState,
11141114
updateChan chan<- *lnrpc.OpenStatusUpdate) error {
11151115

1116-
chanID := lnwire.NewChanIDFromOutPoint(&channel.FundingOutpoint)
1116+
chanID := lnwire.NewChanIDFromOutPoint(channel.FundingOutpoint)
11171117
log.Debugf("Channel(%v) with ShortChanID %v has opening state %v",
11181118
chanID, shortChanID, channelState)
11191119

@@ -1273,7 +1273,7 @@ func (f *Manager) advancePendingChannelState(
12731273

12741274
// Find and close the discoverySignal for this channel such
12751275
// that ChannelReady messages will be processed.
1276-
chanID := lnwire.NewChanIDFromOutPoint(&channel.FundingOutpoint)
1276+
chanID := lnwire.NewChanIDFromOutPoint(channel.FundingOutpoint)
12771277
discoverySignal, ok := f.localDiscoverySignals.Load(chanID)
12781278
if ok {
12791279
close(discoverySignal)
@@ -1339,7 +1339,7 @@ func (f *Manager) advancePendingChannelState(
13391339
}
13401340

13411341
// Success, funding transaction was confirmed.
1342-
chanID := lnwire.NewChanIDFromOutPoint(&channel.FundingOutpoint)
1342+
chanID := lnwire.NewChanIDFromOutPoint(channel.FundingOutpoint)
13431343
log.Debugf("ChannelID(%v) is now fully confirmed! "+
13441344
"(shortChanID=%v)", chanID, confChannel.shortChanID)
13451345

@@ -2246,7 +2246,7 @@ func (f *Manager) continueFundingAccept(resCtx *reservationWithCtx,
22462246
// properly synchronize with the writeHandler goroutine, we add a new
22472247
// channel to the barriers map which will be closed once the channel is
22482248
// fully open.
2249-
channelID := lnwire.NewChanIDFromOutPoint(outPoint)
2249+
channelID := lnwire.NewChanIDFromOutPoint(*outPoint)
22502250
log.Debugf("Creating chan barrier for ChanID(%v)", channelID)
22512251

22522252
// The next message that advances the funding flow will reference the
@@ -2421,7 +2421,7 @@ func (f *Manager) fundeeProcessFundingCreated(peer lnpeer.Peer,
24212421
// properly synchronize with the writeHandler goroutine, we add a new
24222422
// channel to the barriers map which will be closed once the channel is
24232423
// fully open.
2424-
channelID := lnwire.NewChanIDFromOutPoint(&fundingOut)
2424+
channelID := lnwire.NewChanIDFromOutPoint(fundingOut)
24252425
log.Debugf("Creating chan barrier for ChanID(%v)", channelID)
24262426

24272427
fundingSigned := &lnwire.FundingSigned{}
@@ -2582,7 +2582,7 @@ func (f *Manager) funderProcessFundingSigned(peer lnpeer.Peer,
25822582
// process the channel confirmation fully before we receive a
25832583
// channel_ready message.
25842584
fundingPoint := resCtx.reservation.FundingOutpoint()
2585-
permChanID := lnwire.NewChanIDFromOutPoint(fundingPoint)
2585+
permChanID := lnwire.NewChanIDFromOutPoint(*fundingPoint)
25862586
f.localDiscoverySignals.Store(permChanID, make(chan struct{}))
25872587

25882588
// We have to store the forwardingPolicy before the reservation context
@@ -2788,7 +2788,7 @@ func (f *Manager) fundingTimeout(c *channeldb.OpenChannel,
27882788

27892789
// Create channel identifier and set the channel ID.
27902790
cid := newChanIdentifier(pendingID)
2791-
cid.setChanID(lnwire.NewChanIDFromOutPoint(&c.FundingOutpoint))
2791+
cid.setChanID(lnwire.NewChanIDFromOutPoint(c.FundingOutpoint))
27922792

27932793
// TODO(halseth): should this send be made
27942794
// reliable?
@@ -2953,7 +2953,7 @@ func (f *Manager) waitForFundingConfirmation(
29532953

29542954
fundingPoint := completeChan.FundingOutpoint
29552955
log.Infof("ChannelPoint(%v) is now active: ChannelID(%v)",
2956-
fundingPoint, lnwire.NewChanIDFromOutPoint(&fundingPoint))
2956+
fundingPoint, lnwire.NewChanIDFromOutPoint(fundingPoint))
29572957

29582958
// With the block height and the transaction index known, we can
29592959
// construct the compact chanID which is used on the network to unique
@@ -3071,7 +3071,7 @@ func (f *Manager) handleFundingConfirmation(
30713071
confChannel *confirmedChannel) error {
30723072

30733073
fundingPoint := completeChan.FundingOutpoint
3074-
chanID := lnwire.NewChanIDFromOutPoint(&fundingPoint)
3074+
chanID := lnwire.NewChanIDFromOutPoint(fundingPoint)
30753075

30763076
// TODO(roasbeef): ideally persistent state update for chan above
30773077
// should be abstracted
@@ -3147,7 +3147,7 @@ func (f *Manager) handleFundingConfirmation(
31473147
func (f *Manager) sendChannelReady(completeChan *channeldb.OpenChannel,
31483148
channel *lnwallet.LightningChannel) error {
31493149

3150-
chanID := lnwire.NewChanIDFromOutPoint(&completeChan.FundingOutpoint)
3150+
chanID := lnwire.NewChanIDFromOutPoint(completeChan.FundingOutpoint)
31513151

31523152
var peerKey [33]byte
31533153
copy(peerKey[:], completeChan.IdentityPub.SerializeCompressed())
@@ -3374,7 +3374,7 @@ func (f *Manager) addToRouterGraph(completeChan *channeldb.OpenChannel,
33743374
peerAlias *lnwire.ShortChannelID,
33753375
ourPolicy *models.ChannelEdgePolicy) error {
33763376

3377-
chanID := lnwire.NewChanIDFromOutPoint(&completeChan.FundingOutpoint)
3377+
chanID := lnwire.NewChanIDFromOutPoint(completeChan.FundingOutpoint)
33783378

33793379
fwdMinHTLC, fwdMaxHTLC := f.extractAnnounceParams(completeChan)
33803380

@@ -3465,7 +3465,7 @@ func (f *Manager) annAfterSixConfs(completeChan *channeldb.OpenChannel,
34653465
}
34663466

34673467
chanID := lnwire.NewChanIDFromOutPoint(
3468-
&completeChan.FundingOutpoint,
3468+
completeChan.FundingOutpoint,
34693469
)
34703470
pubKey := peer.PubKey()
34713471
log.Debugf("Sending our NodeAnnouncement for "+
@@ -3530,7 +3530,7 @@ func (f *Manager) annAfterSixConfs(completeChan *channeldb.OpenChannel,
35303530
}
35313531

35323532
fundingPoint := completeChan.FundingOutpoint
3533-
chanID := lnwire.NewChanIDFromOutPoint(&fundingPoint)
3533+
chanID := lnwire.NewChanIDFromOutPoint(fundingPoint)
35343534

35353535
log.Infof("Announcing ChannelPoint(%v), short_chan_id=%v",
35363536
&fundingPoint, shortChanID)
@@ -3964,7 +3964,7 @@ func (f *Manager) handleChannelReadyReceived(channel *channeldb.OpenChannel,
39643964
scid *lnwire.ShortChannelID, pendingChanID [32]byte,
39653965
updateChan chan<- *lnrpc.OpenStatusUpdate) error {
39663966

3967-
chanID := lnwire.NewChanIDFromOutPoint(&channel.FundingOutpoint)
3967+
chanID := lnwire.NewChanIDFromOutPoint(channel.FundingOutpoint)
39683968

39693969
// Since we've sent+received funding locked at this point, we
39703970
// can clean up the pending musig2 nonce state.
@@ -3981,7 +3981,7 @@ func (f *Manager) handleChannelReadyReceived(channel *channeldb.OpenChannel,
39813981
// we'll just return, letting the next iteration of the loop
39823982
// check again.
39833983
var defaultAlias lnwire.ShortChannelID
3984-
chanID := lnwire.NewChanIDFromOutPoint(&channel.FundingOutpoint)
3984+
chanID := lnwire.NewChanIDFromOutPoint(channel.FundingOutpoint)
39853985
foundAlias, _ := f.cfg.AliasManager.GetPeerAlias(chanID)
39863986
if foundAlias == defaultAlias {
39873987
return nil
@@ -4876,7 +4876,7 @@ func (f *Manager) pruneZombieReservations() {
48764876
log.Warnf(err.Error())
48774877

48784878
chanID := lnwire.NewChanIDFromOutPoint(
4879-
resCtx.reservation.FundingOutpoint(),
4879+
*resCtx.reservation.FundingOutpoint(),
48804880
)
48814881

48824882
// Create channel identifier and set the channel ID.

funding/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3365,7 +3365,7 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
33653365
t, alice, bob, func(node *testNode, msg *newChannelMsg) bool {
33663366
aliceDB := alice.fundingMgr.cfg.ChannelDB
33673367
chanID := lnwire.NewChanIDFromOutPoint(
3368-
&msg.channel.FundingOutpoint,
3368+
msg.channel.FundingOutpoint,
33693369
)
33703370

33713371
if node == alice {

htlcswitch/link.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,8 +2602,7 @@ func (l *channelLink) UpdateShortChanID() (lnwire.ShortChannelID, error) {
26022602
//
26032603
// NOTE: Part of the ChannelLink interface.
26042604
func (l *channelLink) ChanID() lnwire.ChannelID {
2605-
chanPoint := l.channel.ChannelPoint()
2606-
return lnwire.NewChanIDFromOutPoint(&chanPoint)
2605+
return lnwire.NewChanIDFromOutPoint(l.channel.ChannelPoint())
26072606
}
26082607

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

htlcswitch/link_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ func TestChannelLinkMultiHopUnknownNextHop(t *testing.T) {
14971497
// back the payment to Alice since he is unaware of Carol when the
14981498
// payment comes across.
14991499
bobChanID := lnwire.NewChanIDFromOutPoint(
1500-
&channels.bobToCarol.State().FundingOutpoint,
1500+
channels.bobToCarol.ChannelPoint(),
15011501
)
15021502
n.bobServer.htlcSwitch.RemoveLink(bobChanID)
15031503

@@ -3763,7 +3763,7 @@ func TestChannelRetransmission(t *testing.T) {
37633763
}
37643764

37653765
chanPoint := channels.aliceToBob.ChannelPoint()
3766-
chanID := lnwire.NewChanIDFromOutPoint(&chanPoint)
3766+
chanID := lnwire.NewChanIDFromOutPoint(chanPoint)
37673767
serverErr := make(chan error, 4)
37683768

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

htlcswitch/switch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ func (s *Switch) UpdateForwardingPolicies(
621621

622622
// Update each link in chanPolicies.
623623
for targetLink, policy := range chanPolicies {
624-
cid := lnwire.NewChanIDFromOutPoint(&targetLink)
624+
cid := lnwire.NewChanIDFromOutPoint(targetLink)
625625

626626
link, ok := s.linkIndex[cid]
627627
if !ok {
@@ -1797,7 +1797,7 @@ out:
17971797
// relevant link (if it exists) so the channel can be
17981798
// cooperatively closed (if possible).
17991799
case req := <-s.chanCloseRequests:
1800-
chanID := lnwire.NewChanIDFromOutPoint(req.ChanPoint)
1800+
chanID := lnwire.NewChanIDFromOutPoint(*req.ChanPoint)
18011801

18021802
s.indexMtx.RLock()
18031803
link, ok := s.linkIndex[chanID]

0 commit comments

Comments
 (0)