@@ -385,6 +385,28 @@ type PaymentDescriptor struct {
385385 BlindingPoint lnwire.BlindingPointRecord
386386}
387387
388+ // AddHeight returns a pointer to the height at which the HTLC was added to the
389+ // commitment chain. The height is returned based on the chain the HTLC is
390+ // being added to (local or remote chain).
391+ func AddHeight (htlc * PaymentDescriptor , remoteChain bool ) * uint64 {
392+ if remoteChain {
393+ return & htlc .addCommitHeightRemote
394+ }
395+
396+ return & htlc .addCommitHeightLocal
397+ }
398+
399+ // RemoveHeight returns a pointer to the height at which the HTLC was removed
400+ // from the commitment chain. The height is returned based on the chain the HTLC
401+ // is being removed from (local or remote chain).
402+ func RemoveHeight (htlc * PaymentDescriptor , remoteChain bool ) * uint64 {
403+ if remoteChain {
404+ return & htlc .removeCommitHeightRemote
405+ }
406+
407+ return & htlc .removeCommitHeightLocal
408+ }
409+
388410// PayDescsFromRemoteLogUpdates converts a slice of LogUpdates received from the
389411// remote peer into PaymentDescriptors to inform a link's forwarding decisions.
390412//
@@ -3469,13 +3491,7 @@ func processAddEntry(htlc *PaymentDescriptor, ourBalance, theirBalance *lnwire.M
34693491 // a new commitment), then we'll may be updating the height this entry
34703492 // was added to the chain. Otherwise, we may be updating the entry's
34713493 // height w.r.t the local chain.
3472- var addHeight * uint64
3473- if remoteChain {
3474- addHeight = & htlc .addCommitHeightRemote
3475- } else {
3476- addHeight = & htlc .addCommitHeightLocal
3477- }
3478-
3494+ addHeight := AddHeight (htlc , remoteChain )
34793495 if * addHeight != 0 {
34803496 return
34813497 }
@@ -3506,14 +3522,8 @@ func processRemoveEntry(htlc *PaymentDescriptor, ourBalance,
35063522 theirBalance * lnwire.MilliSatoshi , nextHeight uint64 ,
35073523 remoteChain bool , isIncoming , mutateState bool ) {
35083524
3509- var removeHeight * uint64
3510- if remoteChain {
3511- removeHeight = & htlc .removeCommitHeightRemote
3512- } else {
3513- removeHeight = & htlc .removeCommitHeightLocal
3514- }
3515-
35163525 // Ignore any removal entries which have already been processed.
3526+ removeHeight := RemoveHeight (htlc , remoteChain )
35173527 if * removeHeight != 0 {
35183528 return
35193529 }
@@ -3557,15 +3567,8 @@ func processFeeUpdate(feeUpdate *PaymentDescriptor, nextHeight uint64,
35573567 // Fee updates are applied for all commitments after they are
35583568 // sent/received, so we consider them being added and removed at the
35593569 // same height.
3560- var addHeight * uint64
3561- var removeHeight * uint64
3562- if remoteChain {
3563- addHeight = & feeUpdate .addCommitHeightRemote
3564- removeHeight = & feeUpdate .removeCommitHeightRemote
3565- } else {
3566- addHeight = & feeUpdate .addCommitHeightLocal
3567- removeHeight = & feeUpdate .removeCommitHeightLocal
3568- }
3570+ addHeight := AddHeight (feeUpdate , remoteChain )
3571+ removeHeight := RemoveHeight (feeUpdate , remoteChain )
35693572
35703573 if * addHeight != 0 {
35713574 return
@@ -5041,10 +5044,12 @@ func (lc *LightningChannel) computeView(view *HtlcView, remoteChain bool,
50415044 // number of outstanding HTLCs has changed.
50425045 if lc .channelState .IsInitiator {
50435046 ourBalance += lnwire .NewMSatFromSatoshis (
5044- commitChain .tip ().fee )
5047+ commitChain .tip ().fee ,
5048+ )
50455049 } else if ! lc .channelState .IsInitiator {
50465050 theirBalance += lnwire .NewMSatFromSatoshis (
5047- commitChain .tip ().fee )
5051+ commitChain .tip ().fee ,
5052+ )
50485053 }
50495054 nextHeight := commitChain .tip ().height + 1
50505055
0 commit comments