diff --git a/contractcourt/channel_arbitrator.go b/contractcourt/channel_arbitrator.go index 740e3de6..517221d0 100644 --- a/contractcourt/channel_arbitrator.go +++ b/contractcourt/channel_arbitrator.go @@ -1084,33 +1084,11 @@ func (c *ChannelArbitrator) prepContractResolutions(htlcActions ChainActionMap, inResolutionMap := make(map[wire.OutPoint]lnwallet.IncomingHtlcResolution) for i := 0; i < len(incomingResolutions); i++ { inRes := incomingResolutions[i] - - // If we have a success transaction, then the htlc's outpoint - // is the transaction's only input. Otherwise, it's the claim - // point. - var htlcPoint wire.OutPoint - if inRes.SignedSuccessTx != nil { - htlcPoint = inRes.SignedSuccessTx.TxIn[0].PreviousOutPoint - } else { - htlcPoint = inRes.ClaimOutpoint - } - - inResolutionMap[htlcPoint] = inRes + inResolutionMap[inRes.HtlcPoint()] = inRes } for i := 0; i < len(outgoingResolutions); i++ { outRes := outgoingResolutions[i] - - // If we have a timeout transaction, then the htlc's outpoint - // is the transaction's only input. Otherwise, it's the claim - // point. - var htlcPoint wire.OutPoint - if outRes.SignedTimeoutTx != nil { - htlcPoint = outRes.SignedTimeoutTx.TxIn[0].PreviousOutPoint - } else { - htlcPoint = outRes.ClaimOutpoint - } - - outResolutionMap[htlcPoint] = outRes + outResolutionMap[outRes.HtlcPoint()] = outRes } // We'll create the resolver kit that we'll be cloning for each diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 8572ed62..f10f20a7 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -5499,6 +5499,30 @@ func newIncomingHtlcResolution(signer Signer, localChanCfg *channeldb.ChannelCon }, nil } +// HtlcPoint returns the htlc's outpoint on the commitment tx. +func (r *IncomingHtlcResolution) HtlcPoint() wire.OutPoint { + // If we have a success transaction, then the htlc's outpoint + // is the transaction's only input. Otherwise, it's the claim + // point. + if r.SignedSuccessTx != nil { + return r.SignedSuccessTx.TxIn[0].PreviousOutPoint + } + + return r.ClaimOutpoint +} + +// HtlcPoint returns the htlc's outpoint on the commitment tx. +func (r *OutgoingHtlcResolution) HtlcPoint() wire.OutPoint { + // If we have a timeout transaction, then the htlc's outpoint + // is the transaction's only input. Otherwise, it's the claim + // point. + if r.SignedTimeoutTx != nil { + return r.SignedTimeoutTx.TxIn[0].PreviousOutPoint + } + + return r.ClaimOutpoint +} + // extractHtlcResolutions creates a series of outgoing HTLC resolutions, and // the local key used when generating the HTLC scrips. This function is to be // used in two cases: force close, or a unilateral close.