Merge pull request #8979 from ProofOfKeags/refactor/useless-args

[NANO]: Remove useless appendages from lnwallet/channel.go
This commit is contained in:
Oliver Gugger authored and GitHub committed 2024-08-07 01:37:56 -06:00
commit 75ec6da177
2 files changed
+7 -18

No files matched your search

+6 -17
View File
@@ -349,23 +349,13 @@ type commitment struct {
// locateOutputIndex is a small helper function to locate the output index of a // locateOutputIndex is a small helper function to locate the output index of a
// particular HTLC within the current commitment transaction. The duplicate map // particular HTLC within the current commitment transaction. The duplicate map
// massed in is to be retained for each output within the commitment // passed in is to be retained for each output within the commitment
// transition. This ensures that we don't assign multiple HTLCs to the same // transition. This ensures that we don't assign multiple HTLCs to the same
// index within the commitment transaction. // index within the commitment transaction.
func locateOutputIndex(p *PaymentDescriptor, tx *wire.MsgTx, func locateOutputIndex(p *PaymentDescriptor, tx *wire.MsgTx,
whoseCommit lntypes.ChannelParty, dups map[PaymentHash][]int32, whoseCommit lntypes.ChannelParty, dups map[PaymentHash][]int32,
cltvs []uint32) (int32, error) { cltvs []uint32) (int32, error) {
// Checks to see if element (e) exists in slice (s).
contains := func(s []int32, e int32) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
// If this is their commitment transaction, we'll be trying to locate // If this is their commitment transaction, we'll be trying to locate
// their pkScripts, otherwise we'll be looking for ours. This is // their pkScripts, otherwise we'll be looking for ours. This is
// required as the commitment states are asymmetric in order to ascribe // required as the commitment states are asymmetric in order to ascribe
@@ -385,7 +375,7 @@ func locateOutputIndex(p *PaymentDescriptor, tx *wire.MsgTx,
// If this payment hash and index has already been // If this payment hash and index has already been
// found, then we'll continue in order to avoid any // found, then we'll continue in order to avoid any
// duplicate indexes. // duplicate indexes.
if contains(dups[p.RHash], int32(i)) { if fn.Elem(int32(i), dups[p.RHash]) {
continue continue
} }
@@ -576,7 +566,7 @@ func (c *commitment) toDiskCommit(
// restore commitment state written to disk back into memory once we need to // restore commitment state written to disk back into memory once we need to
// restart a channel session. // restart a channel session.
func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight, func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
commitHeight uint64, htlc *channeldb.HTLC, localCommitKeys, htlc *channeldb.HTLC, localCommitKeys *CommitmentKeyRing,
remoteCommitKeys *CommitmentKeyRing, whoseCommit lntypes.ChannelParty, remoteCommitKeys *CommitmentKeyRing, whoseCommit lntypes.ChannelParty,
) (PaymentDescriptor, error) { ) (PaymentDescriptor, error) {
@@ -664,8 +654,8 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight,
// to a set of incoming and outgoing payment descriptors. Once reconstructed, // to a set of incoming and outgoing payment descriptors. Once reconstructed,
// these payment descriptors can be re-inserted into the in-memory updateLog // these payment descriptors can be re-inserted into the in-memory updateLog
// for each side. // for each side.
func (lc *LightningChannel) extractPayDescs(commitHeight uint64, func (lc *LightningChannel) extractPayDescs(feeRate chainfee.SatPerKWeight,
feeRate chainfee.SatPerKWeight, htlcs []channeldb.HTLC, localCommitKeys, htlcs []channeldb.HTLC, localCommitKeys *CommitmentKeyRing,
remoteCommitKeys *CommitmentKeyRing, whoseCommit lntypes.ChannelParty, remoteCommitKeys *CommitmentKeyRing, whoseCommit lntypes.ChannelParty,
) ([]PaymentDescriptor, []PaymentDescriptor, error) { ) ([]PaymentDescriptor, []PaymentDescriptor, error) {
@@ -685,7 +675,7 @@ func (lc *LightningChannel) extractPayDescs(commitHeight uint64,
htlc := htlc htlc := htlc
payDesc, err := lc.diskHtlcToPayDesc( payDesc, err := lc.diskHtlcToPayDesc(
feeRate, commitHeight, &htlc, feeRate, &htlc,
localCommitKeys, remoteCommitKeys, localCommitKeys, remoteCommitKeys,
whoseCommit, whoseCommit,
) )
@@ -738,7 +728,6 @@ func (lc *LightningChannel) diskCommitToMemCommit(
// HTLC"s into PaymentDescriptor's so we can re-insert them into our // HTLC"s into PaymentDescriptor's so we can re-insert them into our
// update log. // update log.
incomingHtlcs, outgoingHtlcs, err := lc.extractPayDescs( incomingHtlcs, outgoingHtlcs, err := lc.extractPayDescs(
diskCommit.CommitHeight,
chainfee.SatPerKWeight(diskCommit.FeePerKw), chainfee.SatPerKWeight(diskCommit.FeePerKw),
diskCommit.Htlcs, localCommitKeys, remoteCommitKeys, diskCommit.Htlcs, localCommitKeys, remoteCommitKeys,
whoseCommit, whoseCommit,
+1 -1
View File
@@ -10379,7 +10379,7 @@ func TestExtractPayDescs(t *testing.T) {
// NOTE: we use nil commitment key rings to avoid checking the htlc // NOTE: we use nil commitment key rings to avoid checking the htlc
// scripts(`genHtlcScript`) as it should be tested independently. // scripts(`genHtlcScript`) as it should be tested independently.
incomingPDs, outgoingPDs, err := lnChan.extractPayDescs( incomingPDs, outgoingPDs, err := lnChan.extractPayDescs(
0, 0, htlcs, nil, nil, lntypes.Local, 0, htlcs, nil, nil, lntypes.Local,
) )
require.NoError(t, err) require.NoError(t, err)