Skip to content

Commit 75ec6da

Browse files
authored
Merge pull request #8979 from ProofOfKeags/refactor/useless-args
[NANO]: Remove useless appendages from lnwallet/channel.go
2 parents 9271b5e + 935e7f1 commit 75ec6da

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

lnwallet/channel.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -349,23 +349,13 @@ type commitment struct {
349349

350350
// locateOutputIndex is a small helper function to locate the output index of a
351351
// particular HTLC within the current commitment transaction. The duplicate map
352-
// massed in is to be retained for each output within the commitment
352+
// passed in is to be retained for each output within the commitment
353353
// transition. This ensures that we don't assign multiple HTLCs to the same
354354
// index within the commitment transaction.
355355
func locateOutputIndex(p *PaymentDescriptor, tx *wire.MsgTx,
356356
whoseCommit lntypes.ChannelParty, dups map[PaymentHash][]int32,
357357
cltvs []uint32) (int32, error) {
358358

359-
// Checks to see if element (e) exists in slice (s).
360-
contains := func(s []int32, e int32) bool {
361-
for _, a := range s {
362-
if a == e {
363-
return true
364-
}
365-
}
366-
return false
367-
}
368-
369359
// If this is their commitment transaction, we'll be trying to locate
370360
// their pkScripts, otherwise we'll be looking for ours. This is
371361
// required as the commitment states are asymmetric in order to ascribe
@@ -385,7 +375,7 @@ func locateOutputIndex(p *PaymentDescriptor, tx *wire.MsgTx,
385375
// If this payment hash and index has already been
386376
// found, then we'll continue in order to avoid any
387377
// duplicate indexes.
388-
if contains(dups[p.RHash], int32(i)) {
378+
if fn.Elem(int32(i), dups[p.RHash]) {
389379
continue
390380
}
391381

@@ -576,7 +566,7 @@ func (c *commitment) toDiskCommit(
576566
// restore commitment state written to disk back into memory once we need to
577567
// restart a channel session.
578568
func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
579-
commitHeight uint64, htlc *channeldb.HTLC, localCommitKeys,
569+
htlc *channeldb.HTLC, localCommitKeys *CommitmentKeyRing,
580570
remoteCommitKeys *CommitmentKeyRing, whoseCommit lntypes.ChannelParty,
581571
) (PaymentDescriptor, error) {
582572

@@ -664,8 +654,8 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
664654
// to a set of incoming and outgoing payment descriptors. Once reconstructed,
665655
// these payment descriptors can be re-inserted into the in-memory updateLog
666656
// for each side.
667-
func (lc *LightningChannel) extractPayDescs(commitHeight uint64,
668-
feeRate chainfee.SatPerKWeight, htlcs []channeldb.HTLC, localCommitKeys,
657+
func (lc *LightningChannel) extractPayDescs(feeRate chainfee.SatPerKWeight,
658+
htlcs []channeldb.HTLC, localCommitKeys *CommitmentKeyRing,
669659
remoteCommitKeys *CommitmentKeyRing, whoseCommit lntypes.ChannelParty,
670660
) ([]PaymentDescriptor, []PaymentDescriptor, error) {
671661

@@ -685,7 +675,7 @@ func (lc *LightningChannel) extractPayDescs(commitHeight uint64,
685675
htlc := htlc
686676

687677
payDesc, err := lc.diskHtlcToPayDesc(
688-
feeRate, commitHeight, &htlc,
678+
feeRate, &htlc,
689679
localCommitKeys, remoteCommitKeys,
690680
whoseCommit,
691681
)
@@ -738,7 +728,6 @@ func (lc *LightningChannel) diskCommitToMemCommit(
738728
// HTLC"s into PaymentDescriptor's so we can re-insert them into our
739729
// update log.
740730
incomingHtlcs, outgoingHtlcs, err := lc.extractPayDescs(
741-
diskCommit.CommitHeight,
742731
chainfee.SatPerKWeight(diskCommit.FeePerKw),
743732
diskCommit.Htlcs, localCommitKeys, remoteCommitKeys,
744733
whoseCommit,

lnwallet/channel_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10379,7 +10379,7 @@ func TestExtractPayDescs(t *testing.T) {
1037910379
// NOTE: we use nil commitment key rings to avoid checking the htlc
1038010380
// scripts(`genHtlcScript`) as it should be tested independently.
1038110381
incomingPDs, outgoingPDs, err := lnChan.extractPayDescs(
10382-
0, 0, htlcs, nil, nil, lntypes.Local,
10382+
0, htlcs, nil, nil, lntypes.Local,
1038310383
)
1038410384
require.NoError(t, err)
1038510385

0 commit comments

Comments
 (0)