diff --git a/lnwallet/channel.go b/lnwallet/channel.go index 1e9ba5842..0000026c2 100644 --- a/lnwallet/channel.go +++ b/lnwallet/channel.go @@ -234,11 +234,11 @@ type commitment struct { // outgoingHTLCs is a slice of all the outgoing HTLC's (from our PoV) // on this commitment transaction. - outgoingHTLCs []PaymentDescriptor + outgoingHTLCs []paymentDescriptor // incomingHTLCs is a slice of all the incoming HTLC's (from our PoV) // on this commitment transaction. - incomingHTLCs []PaymentDescriptor + incomingHTLCs []paymentDescriptor // customBlob stores opaque bytes that may be used by custom channels // to store extra data for a given commitment state. @@ -254,8 +254,8 @@ type commitment struct { // this map in order to locate the details needed to validate an HTLC // signature while iterating of the outputs in the local commitment // view. - outgoingHTLCIndex map[int32]*PaymentDescriptor - incomingHTLCIndex map[int32]*PaymentDescriptor + outgoingHTLCIndex map[int32]*paymentDescriptor + incomingHTLCIndex map[int32]*paymentDescriptor } // locateOutputIndex is a small helper function to locate the output index of a @@ -263,7 +263,7 @@ type commitment struct { // 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 // 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, cltvs []uint32) (int32, error) { @@ -303,7 +303,7 @@ func locateOutputIndex(p *PaymentDescriptor, tx *wire.MsgTx, // populateHtlcIndexes modifies the set of HTLCs locked-into the target view // to have full indexing information populated. This information is required as // we need to keep track of the indexes of each HTLC in order to properly write -// the current state to disk, and also to locate the PaymentDescriptor +// the current state to disk, and also to locate the paymentDescriptor // corresponding to HTLC outputs in the commitment transaction. func (c *commitment) populateHtlcIndexes(chanType channeldb.ChannelType, cltvs []uint32) error { @@ -313,12 +313,12 @@ func (c *commitment) populateHtlcIndexes(chanType channeldb.ChannelType, // must keep this index so we can validate the HTLC signatures sent to // us. dups := make(map[PaymentHash][]int32) - c.outgoingHTLCIndex = make(map[int32]*PaymentDescriptor) - c.incomingHTLCIndex = make(map[int32]*PaymentDescriptor) + c.outgoingHTLCIndex = make(map[int32]*paymentDescriptor) + c.incomingHTLCIndex = make(map[int32]*paymentDescriptor) // populateIndex is a helper function that populates the necessary // indexes within the commitment view for a particular HTLC. - populateIndex := func(htlc *PaymentDescriptor, incoming bool) error { + populateIndex := func(htlc *paymentDescriptor, incoming bool) error { isDust := HtlcIsDust( chanType, incoming, c.whoseCommit, c.feePerKw, htlc.Amount.ToSatoshis(), c.dustLimit, @@ -482,15 +482,15 @@ func (c *commitment) toDiskCommit( func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight, htlc *channeldb.HTLC, commitKeys lntypes.Dual[*CommitmentKeyRing], whoseCommit lntypes.ChannelParty, - auxLeaf input.AuxTapLeaf) (PaymentDescriptor, error) { + auxLeaf input.AuxTapLeaf) (paymentDescriptor, error) { - // The proper pkScripts for this PaymentDescriptor must be + // The proper pkScripts for this paymentDescriptor must be // generated so we can easily locate them within the commitment // transaction in the future. var ( ourP2WSH, theirP2WSH []byte ourWitnessScript, theirWitnessScript []byte - pd PaymentDescriptor + pd paymentDescriptor chanType = lc.channelState.ChanType ) @@ -550,7 +550,7 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight, // With the scripts reconstructed (depending on if this is our commit // vs theirs or a pending commit for the remote party), we can now // re-create the original payment descriptor. - return PaymentDescriptor{ + return paymentDescriptor{ ChanID: lc.ChannelID(), RHash: htlc.RHash, Timeout: htlc.RefundTimeout, @@ -577,16 +577,16 @@ func (lc *LightningChannel) diskHtlcToPayDesc(feeRate chainfee.SatPerKWeight, func (lc *LightningChannel) extractPayDescs(feeRate chainfee.SatPerKWeight, htlcs []channeldb.HTLC, commitKeys lntypes.Dual[*CommitmentKeyRing], whoseCommit lntypes.ChannelParty, - auxLeaves fn.Option[CommitAuxLeaves]) ([]PaymentDescriptor, - []PaymentDescriptor, error) { + auxLeaves fn.Option[CommitAuxLeaves]) ([]paymentDescriptor, + []paymentDescriptor, error) { var ( - incomingHtlcs []PaymentDescriptor - outgoingHtlcs []PaymentDescriptor + incomingHtlcs []paymentDescriptor + outgoingHtlcs []paymentDescriptor ) // For each included HTLC within this commitment state, we'll convert - // the disk format into our in memory PaymentDescriptor format, + // the disk format into our in memory paymentDescriptor format, // partitioning based on if we offered or received the HTLC. for _, htlc := range htlcs { // TODO(roasbeef): set isForwarded to false for all? need to @@ -668,7 +668,7 @@ func (lc *LightningChannel) diskCommitToMemCommit( } // With the key rings re-created, we'll now convert all the on-disk - // 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. incomingHtlcs, outgoingHtlcs, err := lc.extractPayDescs( chainfee.SatPerKWeight(diskCommit.FeePerKw), @@ -1024,7 +1024,7 @@ func (lc *LightningChannel) ResetState() { lc.Unlock() } -// logUpdateToPayDesc converts a LogUpdate into a matching PaymentDescriptor +// logUpdateToPayDesc converts a LogUpdate into a matching paymentDescriptor // entry that can be re-inserted into the update log. This method is used when // we extended a state to the remote party, but the connection was obstructed // before we could finish the commitment dance. In this case, we need to @@ -1034,25 +1034,25 @@ func (lc *LightningChannel) logUpdateToPayDesc(logUpdate *channeldb.LogUpdate, remoteUpdateLog *updateLog, commitHeight uint64, feeRate chainfee.SatPerKWeight, remoteCommitKeys *CommitmentKeyRing, remoteDustLimit btcutil.Amount, - auxLeaves fn.Option[CommitAuxLeaves]) (*PaymentDescriptor, error) { + auxLeaves fn.Option[CommitAuxLeaves]) (*paymentDescriptor, error) { // Depending on the type of update message we'll map that to a distinct - // PaymentDescriptor instance. - var pd *PaymentDescriptor + // paymentDescriptor instance. + var pd *paymentDescriptor switch wireMsg := logUpdate.UpdateMsg.(type) { - // For offered HTLC's, we'll map that to a PaymentDescriptor with the + // For offered HTLC's, we'll map that to a paymentDescriptor with the // type Add, ensuring we restore the necessary fields. From the PoV of // the commitment chain, this HTLC was included in the remote chain, // but not the local chain. case *lnwire.UpdateAddHTLC: // First, we'll map all the relevant fields in the // UpdateAddHTLC message to their corresponding fields in the - // PaymentDescriptor struct. We also set addCommitHeightRemote + // paymentDescriptor struct. We also set addCommitHeightRemote // as we've included this HTLC in our local commitment chain // for the remote party. - pd = &PaymentDescriptor{ + pd = &paymentDescriptor{ ChanID: wireMsg.ChanID, RHash: wireMsg.PaymentHash, Timeout: wireMsg.Expiry, @@ -1093,11 +1093,11 @@ func (lc *LightningChannel) logUpdateToPayDesc(logUpdate *channeldb.LogUpdate, // For HTLC's we're offered we'll fetch the original offered HTLC // from the remote party's update log so we can retrieve the same - // PaymentDescriptor that SettleHTLC would produce. + // paymentDescriptor that SettleHTLC would produce. case *lnwire.UpdateFulfillHTLC: ogHTLC := remoteUpdateLog.lookupHtlc(wireMsg.ID) - pd = &PaymentDescriptor{ + pd = &paymentDescriptor{ ChanID: wireMsg.ChanID, Amount: ogHTLC.Amount, RHash: ogHTLC.RHash, @@ -1115,7 +1115,7 @@ func (lc *LightningChannel) logUpdateToPayDesc(logUpdate *channeldb.LogUpdate, case *lnwire.UpdateFailHTLC: ogHTLC := remoteUpdateLog.lookupHtlc(wireMsg.ID) - pd = &PaymentDescriptor{ + pd = &paymentDescriptor{ ChanID: wireMsg.ChanID, Amount: ogHTLC.Amount, RHash: ogHTLC.RHash, @@ -1132,7 +1132,7 @@ func (lc *LightningChannel) logUpdateToPayDesc(logUpdate *channeldb.LogUpdate, ogHTLC := remoteUpdateLog.lookupHtlc(wireMsg.ID) // TODO(roasbeef): err if nil? - pd = &PaymentDescriptor{ + pd = &paymentDescriptor{ ChanID: wireMsg.ChanID, Amount: ogHTLC.Amount, RHash: ogHTLC.RHash, @@ -1151,7 +1151,7 @@ func (lc *LightningChannel) logUpdateToPayDesc(logUpdate *channeldb.LogUpdate, // height to the same value, as we consider the fee update locked in by // adding and removing it at the same height. case *lnwire.UpdateFee: - pd = &PaymentDescriptor{ + pd = &paymentDescriptor{ ChanID: wireMsg.ChanID, LogIndex: logUpdate.LogIndex, Amount: lnwire.NewMSatFromSatoshis( @@ -1166,29 +1166,29 @@ func (lc *LightningChannel) logUpdateToPayDesc(logUpdate *channeldb.LogUpdate, return pd, nil } -// localLogUpdateToPayDesc converts a LogUpdate into a matching PaymentDescriptor -// entry that can be re-inserted into the local update log. This method is used -// when we sent an update+sig, receive a revocation, but drop right before the -// counterparty can sign for the update we just sent. In this case, we need to -// re-insert the original entries back into the update log so we'll be expecting -// the peer to sign them. The height of the remote commitment is expected to be -// provided and we restore all log update entries with this height, even though -// the real height may be lower. In the way these fields are used elsewhere, this -// doesn't change anything. +// localLogUpdateToPayDesc converts a LogUpdate into a matching +// paymentDescriptor entry that can be re-inserted into the local update log. +// This method is used when we sent an update+sig, receive a revocation, but +// drop right before the counterparty can sign for the update we just sent. In +// this case, we need to re-insert the original entries back into the update +// log so we'll be expecting the peer to sign them. The height of the remote +// commitment is expected to be provided and we restore all log update entries +// with this height, even though the real height may be lower. In the way these +// fields are used elsewhere, this doesn't change anything. func (lc *LightningChannel) localLogUpdateToPayDesc(logUpdate *channeldb.LogUpdate, - remoteUpdateLog *updateLog, commitHeight uint64) (*PaymentDescriptor, + remoteUpdateLog *updateLog, commitHeight uint64) (*paymentDescriptor, error) { // Since Add updates aren't saved to disk under this key, the update will // never be an Add. switch wireMsg := logUpdate.UpdateMsg.(type) { // For HTLCs that we settled, we'll fetch the original offered HTLC from - // the remote update log so we can retrieve the same PaymentDescriptor that - // ReceiveHTLCSettle would produce. + // the remote update log so we can retrieve the same paymentDescriptor + // that ReceiveHTLCSettle would produce. case *lnwire.UpdateFulfillHTLC: ogHTLC := remoteUpdateLog.lookupHtlc(wireMsg.ID) - return &PaymentDescriptor{ + return &paymentDescriptor{ ChanID: wireMsg.ChanID, Amount: ogHTLC.Amount, RHash: ogHTLC.RHash, @@ -1205,7 +1205,7 @@ func (lc *LightningChannel) localLogUpdateToPayDesc(logUpdate *channeldb.LogUpda case *lnwire.UpdateFailHTLC: ogHTLC := remoteUpdateLog.lookupHtlc(wireMsg.ID) - return &PaymentDescriptor{ + return &paymentDescriptor{ ChanID: wireMsg.ChanID, Amount: ogHTLC.Amount, RHash: ogHTLC.RHash, @@ -1221,7 +1221,7 @@ func (lc *LightningChannel) localLogUpdateToPayDesc(logUpdate *channeldb.LogUpda case *lnwire.UpdateFailMalformedHTLC: ogHTLC := remoteUpdateLog.lookupHtlc(wireMsg.ID) - return &PaymentDescriptor{ + return &paymentDescriptor{ ChanID: wireMsg.ChanID, Amount: ogHTLC.Amount, RHash: ogHTLC.RHash, @@ -1234,7 +1234,7 @@ func (lc *LightningChannel) localLogUpdateToPayDesc(logUpdate *channeldb.LogUpda }, nil case *lnwire.UpdateFee: - return &PaymentDescriptor{ + return &paymentDescriptor{ ChanID: wireMsg.ChanID, LogIndex: logUpdate.LogIndex, Amount: lnwire.NewMSatFromSatoshis( @@ -1251,7 +1251,7 @@ func (lc *LightningChannel) localLogUpdateToPayDesc(logUpdate *channeldb.LogUpda } // remoteLogUpdateToPayDesc converts a LogUpdate into a matching -// PaymentDescriptor entry that can be re-inserted into the update log. This +// paymentDescriptor entry that can be re-inserted into the update log. This // method is used when we revoked a local commitment, but the connection was // obstructed before we could sign a remote commitment that contains these // updates. In this case, we need to re-insert the original entries back into @@ -1261,12 +1261,12 @@ func (lc *LightningChannel) localLogUpdateToPayDesc(logUpdate *channeldb.LogUpda // may be lower. In the way these fields are used elsewhere, this doesn't change // anything. func (lc *LightningChannel) remoteLogUpdateToPayDesc(logUpdate *channeldb.LogUpdate, - localUpdateLog *updateLog, commitHeight uint64) (*PaymentDescriptor, + localUpdateLog *updateLog, commitHeight uint64) (*paymentDescriptor, error) { switch wireMsg := logUpdate.UpdateMsg.(type) { case *lnwire.UpdateAddHTLC: - pd := &PaymentDescriptor{ + pd := &paymentDescriptor{ ChanID: wireMsg.ChanID, RHash: wireMsg.PaymentHash, Timeout: wireMsg.Expiry, @@ -1287,11 +1287,11 @@ func (lc *LightningChannel) remoteLogUpdateToPayDesc(logUpdate *channeldb.LogUpd // For HTLCs that the remote party settled, we'll fetch the original // offered HTLC from the local update log so we can retrieve the same - // PaymentDescriptor that ReceiveHTLCSettle would produce. + // paymentDescriptor that ReceiveHTLCSettle would produce. case *lnwire.UpdateFulfillHTLC: ogHTLC := localUpdateLog.lookupHtlc(wireMsg.ID) - return &PaymentDescriptor{ + return &paymentDescriptor{ ChanID: wireMsg.ChanID, Amount: ogHTLC.Amount, RHash: ogHTLC.RHash, @@ -1308,7 +1308,7 @@ func (lc *LightningChannel) remoteLogUpdateToPayDesc(logUpdate *channeldb.LogUpd case *lnwire.UpdateFailHTLC: ogHTLC := localUpdateLog.lookupHtlc(wireMsg.ID) - return &PaymentDescriptor{ + return &paymentDescriptor{ ChanID: wireMsg.ChanID, Amount: ogHTLC.Amount, RHash: ogHTLC.RHash, @@ -1324,7 +1324,7 @@ func (lc *LightningChannel) remoteLogUpdateToPayDesc(logUpdate *channeldb.LogUpd case *lnwire.UpdateFailMalformedHTLC: ogHTLC := localUpdateLog.lookupHtlc(wireMsg.ID) - return &PaymentDescriptor{ + return &paymentDescriptor{ ChanID: wireMsg.ChanID, Amount: ogHTLC.Amount, RHash: ogHTLC.RHash, @@ -1343,7 +1343,7 @@ func (lc *LightningChannel) remoteLogUpdateToPayDesc(logUpdate *channeldb.LogUpd // height to the same value, as we consider the fee update locked in by // adding and removing it at the same height. case *lnwire.UpdateFee: - return &PaymentDescriptor{ + return &paymentDescriptor{ ChanID: wireMsg.ChanID, LogIndex: logUpdate.LogIndex, Amount: lnwire.NewMSatFromSatoshis( @@ -2536,10 +2536,10 @@ type HtlcView struct { NextHeight uint64 // OurUpdates are our outgoing HTLCs. - OurUpdates []*PaymentDescriptor + OurUpdates []*paymentDescriptor // TheirUpdates are their incoming HTLCs. - TheirUpdates []*PaymentDescriptor + TheirUpdates []*paymentDescriptor // FeePerKw is the fee rate in sat/kw of the commitment transaction. FeePerKw chainfee.SatPerKWeight @@ -2551,7 +2551,7 @@ type HtlcView struct { func (lc *LightningChannel) fetchHTLCView(theirLogIndex, ourLogIndex uint64) *HtlcView { - var ourHTLCs []*PaymentDescriptor + var ourHTLCs []*paymentDescriptor for e := lc.updateLogs.Local.Front(); e != nil; e = e.Next() { htlc := e.Value @@ -2563,7 +2563,7 @@ func (lc *LightningChannel) fetchHTLCView(theirLogIndex, } } - var theirHTLCs []*PaymentDescriptor + var theirHTLCs []*paymentDescriptor for e := lc.updateLogs.Remote.Front(); e != nil; e = e.Next() { htlc := e.Value @@ -2701,13 +2701,13 @@ func (lc *LightningChannel) fetchCommitmentView( // commitment are mutated, we'll manually copy over each HTLC to its // respective slice. c.outgoingHTLCs = make( - []PaymentDescriptor, len(filteredHTLCView.OurUpdates), + []paymentDescriptor, len(filteredHTLCView.OurUpdates), ) for i, htlc := range filteredHTLCView.OurUpdates { c.outgoingHTLCs[i] = *htlc } c.incomingHTLCs = make( - []PaymentDescriptor, len(filteredHTLCView.TheirUpdates), + []paymentDescriptor, len(filteredHTLCView.TheirUpdates), ) for i, htlc := range filteredHTLCView.TheirUpdates { c.incomingHTLCs[i] = *htlc @@ -2882,9 +2882,9 @@ func (lc *LightningChannel) evaluateHTLCView(view *HtlcView, ourBalance, // fetchParent is a helper that looks up update log parent entries in the // appropriate log. -func (lc *LightningChannel) fetchParent(entry *PaymentDescriptor, +func (lc *LightningChannel) fetchParent(entry *paymentDescriptor, whoseCommitChain, whoseUpdateLog lntypes.ChannelParty, -) (*PaymentDescriptor, error) { +) (*paymentDescriptor, error) { var ( updateLog *updateLog @@ -2937,7 +2937,7 @@ func (lc *LightningChannel) fetchParent(entry *PaymentDescriptor, // If the HTLC hasn't yet been committed in either chain, then the height it // was committed is updated. Keeping track of this inclusion height allows us to // later compact the log once the change is fully committed in both chains. -func processAddEntry(htlc *PaymentDescriptor, ourBalance, +func processAddEntry(htlc *paymentDescriptor, ourBalance, theirBalance *lnwire.MilliSatoshi, nextHeight uint64, whoseCommitChain lntypes.ChannelParty, isIncoming, mutateState bool) { @@ -2975,7 +2975,7 @@ func processAddEntry(htlc *PaymentDescriptor, ourBalance, // processRemoveEntry processes a log entry which settles or times out a // previously added HTLC. If the removal entry has already been processed, it // is skipped. -func processRemoveEntry(htlc *PaymentDescriptor, ourBalance, +func processRemoveEntry(htlc *paymentDescriptor, ourBalance, theirBalance *lnwire.MilliSatoshi, nextHeight uint64, whoseCommitChain lntypes.ChannelParty, isIncoming, mutateState bool) { @@ -3024,7 +3024,7 @@ func processRemoveEntry(htlc *PaymentDescriptor, ourBalance, // processFeeUpdate processes a log update that updates the current commitment // fee. -func processFeeUpdate(feeUpdate *PaymentDescriptor, nextHeight uint64, +func processFeeUpdate(feeUpdate *paymentDescriptor, nextHeight uint64, whoseCommitChain lntypes.ChannelParty, mutateState bool, view *HtlcView) { @@ -3298,7 +3298,7 @@ func (lc *LightningChannel) createCommitDiff(newCommit *commitment, continue } - // We'll map the type of the PaymentDescriptor to one of the + // We'll map the type of the paymentDescriptor to one of the // four messages that it corresponds to. With this set of // messages obtained, we can simply read from disk and re-send // them in the case of a needed channel sync. @@ -3333,7 +3333,7 @@ func (lc *LightningChannel) createCommitDiff(newCommit *commitment, // Nothing special to do. } - logUpdates = append(logUpdates, pd.ToLogUpdate()) + logUpdates = append(logUpdates, pd.toLogUpdate()) } // With the set of log updates mapped into wire messages, we'll now @@ -3391,7 +3391,7 @@ func (lc *LightningChannel) getUnsignedAckedUpdates() []channeldb.LogUpdate { continue } - logUpdates = append(logUpdates, pd.ToLogUpdate()) + logUpdates = append(logUpdates, pd.toLogUpdate()) } return logUpdates @@ -3535,11 +3535,11 @@ func (lc *LightningChannel) applyCommitFee( // commitment transaction in terms of the ChannelConstraints that we and our // remote peer agreed upon during the funding workflow. The // predict[Our|Their]Add should parameters should be set to a valid -// PaymentDescriptor if we are validating in the state when adding a new HTLC, +// paymentDescriptor if we are validating in the state when adding a new HTLC, // or nil otherwise. func (lc *LightningChannel) validateCommitmentSanity(theirLogCounter, ourLogCounter uint64, whoseCommitChain lntypes.ChannelParty, - buffer BufferType, predictOurAdd, predictTheirAdd *PaymentDescriptor, + buffer BufferType, predictOurAdd, predictTheirAdd *paymentDescriptor, ) error { // First fetch the initial balance before applying any updates. @@ -3666,7 +3666,7 @@ func (lc *LightningChannel) validateCommitmentSanity(theirLogCounter, // validateUpdates take a set of updates, and validates them against // the passed channel constraints. - validateUpdates := func(updates []*PaymentDescriptor, + validateUpdates := func(updates []*paymentDescriptor, constraints *channeldb.ChannelConfig) error { // We keep track of the number of HTLCs in flight for the @@ -5390,7 +5390,7 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) ( // updates that we will eventually put into the // FwdPkg at this height. addUpdatesToForward = append( - addUpdatesToForward, pd.ToLogUpdate(), + addUpdatesToForward, pd.toLogUpdate(), ) case pd.EntryType != Add && committedRmv && shouldFwdRmv: @@ -5410,10 +5410,12 @@ func (lc *LightningChannel) ReceiveRevocation(revMsg *lnwire.RevokeAndAck) ( // updates that we will eventually put into the // FwdPkg at this height. settleFailUpdatesToForward = append( - settleFailUpdatesToForward, pd.ToLogUpdate(), + settleFailUpdatesToForward, pd.toLogUpdate(), ) default: + // The update was not "freshly locked in" so we will + // ignore it as we construct the forwarding package. continue } } @@ -5720,9 +5722,9 @@ func (lc *LightningChannel) MayAddOutgoingHtlc(amt lnwire.MilliSatoshi) error { // htlcAddDescriptor returns a payment descriptor for the htlc and open key // provided to add to our local update log. func (lc *LightningChannel) htlcAddDescriptor(htlc *lnwire.UpdateAddHTLC, - openKey *models.CircuitKey) *PaymentDescriptor { + openKey *models.CircuitKey) *paymentDescriptor { - return &PaymentDescriptor{ + return &paymentDescriptor{ ChanID: htlc.ChanID, EntryType: Add, RHash: PaymentHash(htlc.PaymentHash), @@ -5739,7 +5741,7 @@ func (lc *LightningChannel) htlcAddDescriptor(htlc *lnwire.UpdateAddHTLC, // validateAddHtlc validates the addition of an outgoing htlc to our local and // remote commitments. -func (lc *LightningChannel) validateAddHtlc(pd *PaymentDescriptor, +func (lc *LightningChannel) validateAddHtlc(pd *paymentDescriptor, buffer BufferType) error { // Make sure adding this HTLC won't violate any of the constraints we // must keep on the commitment transactions. @@ -5785,7 +5787,7 @@ func (lc *LightningChannel) ReceiveHTLC(htlc *lnwire.UpdateAddHTLC) (uint64, "ID %d", htlc.ID, lc.updateLogs.Remote.htlcCounter) } - pd := &PaymentDescriptor{ + pd := &paymentDescriptor{ ChanID: htlc.ChanID, EntryType: Add, RHash: PaymentHash(htlc.PaymentHash), @@ -5866,7 +5868,7 @@ func (lc *LightningChannel) SettleHTLC(preimage [32]byte, return ErrInvalidSettlePreimage{preimage[:], htlc.RHash[:]} } - pd := &PaymentDescriptor{ + pd := &paymentDescriptor{ ChanID: lc.ChannelID(), Amount: htlc.Amount, RPreimage: preimage, @@ -5912,7 +5914,7 @@ func (lc *LightningChannel) ReceiveHTLCSettle(preimage [32]byte, htlcIndex uint6 return ErrInvalidSettlePreimage{preimage[:], htlc.RHash[:]} } - pd := &PaymentDescriptor{ + pd := &paymentDescriptor{ ChanID: lc.ChannelID(), Amount: htlc.Amount, RPreimage: preimage, @@ -5974,7 +5976,7 @@ func (lc *LightningChannel) FailHTLC(htlcIndex uint64, reason []byte, return ErrHtlcIndexAlreadyFailed(htlcIndex) } - pd := &PaymentDescriptor{ + pd := &paymentDescriptor{ ChanID: lc.ChannelID(), Amount: htlc.Amount, RHash: htlc.RHash, @@ -6025,7 +6027,7 @@ func (lc *LightningChannel) MalformedFailHTLC(htlcIndex uint64, return ErrHtlcIndexAlreadyFailed(htlcIndex) } - pd := &PaymentDescriptor{ + pd := &paymentDescriptor{ ChanID: lc.ChannelID(), Amount: htlc.Amount, RHash: htlc.RHash, @@ -6068,7 +6070,7 @@ func (lc *LightningChannel) ReceiveFailHTLC(htlcIndex uint64, reason []byte, return ErrHtlcIndexAlreadyFailed(htlcIndex) } - pd := &PaymentDescriptor{ + pd := &paymentDescriptor{ ChanID: lc.ChannelID(), Amount: htlc.Amount, RHash: htlc.RHash, @@ -8188,7 +8190,7 @@ func (lc *LightningChannel) UpdateFee(feePerKw chainfee.SatPerKWeight) error { return err } - pd := &PaymentDescriptor{ + pd := &paymentDescriptor{ ChanID: lc.ChannelID(), LogIndex: lc.updateLogs.Local.logIndex, Amount: lnwire.NewMSatFromSatoshis(btcutil.Amount(feePerKw)), @@ -8261,7 +8263,7 @@ func (lc *LightningChannel) ReceiveUpdateFee(feePerKw chainfee.SatPerKWeight) er } // TODO(roasbeef): or just modify to use the other balance? - pd := &PaymentDescriptor{ + pd := &paymentDescriptor{ ChanID: lc.ChannelID(), LogIndex: lc.updateLogs.Remote.logIndex, Amount: lnwire.NewMSatFromSatoshis(btcutil.Amount(feePerKw)), @@ -8752,7 +8754,7 @@ func (lc *LightningChannel) unsignedLocalUpdates(remoteMessageIndex, // sends. if pd.LogIndex < remoteMessageIndex && pd.LogIndex >= localMessageIndex { localPeerUpdates = append( - localPeerUpdates, pd.ToLogUpdate(), + localPeerUpdates, pd.toLogUpdate(), ) } } diff --git a/lnwallet/channel_test.go b/lnwallet/channel_test.go index 0af74dd1d..744be3ae5 100644 --- a/lnwallet/channel_test.go +++ b/lnwallet/channel_test.go @@ -6934,8 +6934,8 @@ func TestNewBreachRetributionSkipsDustHtlcs(t *testing.T) { } } -// compareHtlcs compares two PaymentDescriptors. -func compareHtlcs(htlc1, htlc2 *PaymentDescriptor) error { +// compareHtlcs compares two paymentDescriptors. +func compareHtlcs(htlc1, htlc2 *paymentDescriptor) error { if htlc1.LogIndex != htlc2.LogIndex { return fmt.Errorf("htlc log index did not match") } @@ -6953,7 +6953,7 @@ func compareHtlcs(htlc1, htlc2 *PaymentDescriptor) error { } // compareIndexes is a helper method to compare two index maps. -func compareIndexes(a, b map[uint64]*fn.Node[*PaymentDescriptor]) error { +func compareIndexes(a, b map[uint64]*fn.Node[*paymentDescriptor]) error { for k1, e1 := range a { e2, ok := b[k1] if !ok { @@ -7422,7 +7422,7 @@ func TestChannelRestoreCommitHeight(t *testing.T) { t.Fatalf("unable to create new channel: %v", err) } - var pd *PaymentDescriptor + var pd *paymentDescriptor if remoteLog { h := newChannel.updateLogs.Local.lookupHtlc(htlcIndex) if h != nil { @@ -8191,8 +8191,8 @@ func TestFetchParent(t *testing.T) { name string whoseCommitChain lntypes.ChannelParty whoseUpdateLog lntypes.ChannelParty - localEntries []*PaymentDescriptor - remoteEntries []*PaymentDescriptor + localEntries []*paymentDescriptor + remoteEntries []*paymentDescriptor // parentIndex is the parent index of the entry that we will // lookup with fetch parent. @@ -8226,7 +8226,7 @@ func TestFetchParent(t *testing.T) { { name: "remote log + chain, remote add height 0", localEntries: nil, - remoteEntries: []*PaymentDescriptor{ + remoteEntries: []*paymentDescriptor{ // This entry will be added at log index =0. { HtlcIndex: 1, @@ -8248,7 +8248,7 @@ func TestFetchParent(t *testing.T) { }, { name: "remote log, local chain, local add height 0", - remoteEntries: []*PaymentDescriptor{ + remoteEntries: []*paymentDescriptor{ // This entry will be added at log index =0. { HtlcIndex: 1, @@ -8271,7 +8271,7 @@ func TestFetchParent(t *testing.T) { }, { name: "local log + chain, local add height 0", - localEntries: []*PaymentDescriptor{ + localEntries: []*paymentDescriptor{ // This entry will be added at log index =0. { HtlcIndex: 1, @@ -8295,7 +8295,7 @@ func TestFetchParent(t *testing.T) { { name: "local log + remote chain, remote add height 0", - localEntries: []*PaymentDescriptor{ + localEntries: []*paymentDescriptor{ // This entry will be added at log index =0. { HtlcIndex: 1, @@ -8319,7 +8319,7 @@ func TestFetchParent(t *testing.T) { { name: "remote log found", localEntries: nil, - remoteEntries: []*PaymentDescriptor{ + remoteEntries: []*paymentDescriptor{ // This entry will be added at log index =0. { HtlcIndex: 1, @@ -8342,7 +8342,7 @@ func TestFetchParent(t *testing.T) { }, { name: "local log found", - localEntries: []*PaymentDescriptor{ + localEntries: []*paymentDescriptor{ // This entry will be added at log index =0. { HtlcIndex: 1, @@ -8388,7 +8388,7 @@ func TestFetchParent(t *testing.T) { } parent, err := lc.fetchParent( - &PaymentDescriptor{ + &paymentDescriptor{ ParentIndex: test.parentIndex, }, test.whoseCommitChain, @@ -8451,8 +8451,8 @@ func TestEvaluateView(t *testing.T) { tests := []struct { name string - ourHtlcs []*PaymentDescriptor - theirHtlcs []*PaymentDescriptor + ourHtlcs []*paymentDescriptor + theirHtlcs []*paymentDescriptor whoseCommitChain lntypes.ChannelParty mutateState bool @@ -8484,7 +8484,7 @@ func TestEvaluateView(t *testing.T) { name: "our fee update is applied", whoseCommitChain: lntypes.Local, mutateState: false, - ourHtlcs: []*PaymentDescriptor{ + ourHtlcs: []*paymentDescriptor{ { Amount: ourFeeUpdateAmt, EntryType: FeeUpdate, @@ -8501,8 +8501,8 @@ func TestEvaluateView(t *testing.T) { name: "their fee update is applied", whoseCommitChain: lntypes.Local, mutateState: false, - ourHtlcs: []*PaymentDescriptor{}, - theirHtlcs: []*PaymentDescriptor{ + ourHtlcs: []*paymentDescriptor{}, + theirHtlcs: []*paymentDescriptor{ { Amount: theirFeeUpdateAmt, EntryType: FeeUpdate, @@ -8519,14 +8519,14 @@ func TestEvaluateView(t *testing.T) { name: "htlcs adds without settles", whoseCommitChain: lntypes.Local, mutateState: false, - ourHtlcs: []*PaymentDescriptor{ + ourHtlcs: []*paymentDescriptor{ { HtlcIndex: 0, Amount: htlcAddAmount, EntryType: Add, }, }, - theirHtlcs: []*PaymentDescriptor{ + theirHtlcs: []*paymentDescriptor{ { HtlcIndex: 0, Amount: htlcAddAmount, @@ -8553,7 +8553,7 @@ func TestEvaluateView(t *testing.T) { name: "our htlc settled, state mutated", whoseCommitChain: lntypes.Local, mutateState: true, - ourHtlcs: []*PaymentDescriptor{ + ourHtlcs: []*paymentDescriptor{ { HtlcIndex: 0, Amount: htlcAddAmount, @@ -8561,7 +8561,7 @@ func TestEvaluateView(t *testing.T) { addCommitHeightLocal: addHeight, }, }, - theirHtlcs: []*PaymentDescriptor{ + theirHtlcs: []*paymentDescriptor{ { HtlcIndex: 0, Amount: htlcAddAmount, @@ -8588,7 +8588,7 @@ func TestEvaluateView(t *testing.T) { name: "our htlc settled, state not mutated", whoseCommitChain: lntypes.Local, mutateState: false, - ourHtlcs: []*PaymentDescriptor{ + ourHtlcs: []*paymentDescriptor{ { HtlcIndex: 0, Amount: htlcAddAmount, @@ -8596,7 +8596,7 @@ func TestEvaluateView(t *testing.T) { addCommitHeightLocal: addHeight, }, }, - theirHtlcs: []*PaymentDescriptor{ + theirHtlcs: []*paymentDescriptor{ { HtlcIndex: 0, Amount: htlcAddAmount, @@ -8623,7 +8623,7 @@ func TestEvaluateView(t *testing.T) { name: "their htlc settled, state mutated", whoseCommitChain: lntypes.Local, mutateState: true, - ourHtlcs: []*PaymentDescriptor{ + ourHtlcs: []*paymentDescriptor{ { HtlcIndex: 0, Amount: htlcAddAmount, @@ -8638,7 +8638,7 @@ func TestEvaluateView(t *testing.T) { ParentIndex: 1, }, }, - theirHtlcs: []*PaymentDescriptor{ + theirHtlcs: []*paymentDescriptor{ { HtlcIndex: 0, Amount: htlcAddAmount, @@ -8667,7 +8667,7 @@ func TestEvaluateView(t *testing.T) { whoseCommitChain: lntypes.Local, mutateState: false, - ourHtlcs: []*PaymentDescriptor{ + ourHtlcs: []*paymentDescriptor{ { HtlcIndex: 0, Amount: htlcAddAmount, @@ -8682,7 +8682,7 @@ func TestEvaluateView(t *testing.T) { ParentIndex: 0, }, }, - theirHtlcs: []*PaymentDescriptor{ + theirHtlcs: []*paymentDescriptor{ { HtlcIndex: 0, Amount: htlcAddAmount, @@ -8789,7 +8789,7 @@ func TestEvaluateView(t *testing.T) { // checkExpectedHtlcs checks that a set of htlcs that we have contains all the // htlcs we expect. -func checkExpectedHtlcs(t *testing.T, actual []*PaymentDescriptor, +func checkExpectedHtlcs(t *testing.T, actual []*paymentDescriptor, expected map[uint64]bool) { if len(expected) != len(actual) { @@ -8981,7 +8981,7 @@ func TestProcessFeeUpdate(t *testing.T) { // Create a fee update with add and remove heights as // set in the test. heights := test.startHeights - update := &PaymentDescriptor{ + update := &paymentDescriptor{ Amount: ourFeeUpdateAmt, addCommitHeightRemote: heights.remoteAdd, addCommitHeightLocal: heights.localAdd, @@ -9008,7 +9008,7 @@ func TestProcessFeeUpdate(t *testing.T) { } } -func checkHeights(t *testing.T, update *PaymentDescriptor, expected heights) { +func checkHeights(t *testing.T, update *paymentDescriptor, expected heights) { updateHeights := heights{ localAdd: update.addCommitHeightLocal, localRemove: update.removeCommitHeightLocal, @@ -9377,7 +9377,7 @@ func TestProcessAddRemoveEntry(t *testing.T) { t.Parallel() heights := test.startHeights - update := &PaymentDescriptor{ + update := &paymentDescriptor{ Amount: updateAmount, addCommitHeightLocal: heights.localAdd, addCommitHeightRemote: heights.remoteAdd, @@ -10572,7 +10572,7 @@ func testNewBreachRetribution(t *testing.T, chanType channeldb.ChannelType) { } // TestExtractPayDescs asserts that `extractPayDescs` can correctly turn a -// slice of htlcs into two slices of PaymentDescriptors. +// slice of htlcs into two slices of paymentDescriptors. func TestExtractPayDescs(t *testing.T) { t.Parallel() @@ -10609,22 +10609,22 @@ func TestExtractPayDescs(t *testing.T) { ) require.NoError(t, err) - // Assert the incoming PaymentDescriptors are matched. + // Assert the incoming paymentDescriptors are matched. for i, pd := range incomingPDs { htlc := incomings[i] assertPayDescMatchHTLC(t, pd, htlc) } - // Assert the outgoing PaymentDescriptors are matched. + // Assert the outgoing paymentDescriptors are matched. for i, pd := range outgoingPDs { htlc := outgoings[i] assertPayDescMatchHTLC(t, pd, htlc) } } -// assertPayDescMatchHTLC compares a PaymentDescriptor to a channeldb.HTLC and +// assertPayDescMatchHTLC compares a paymentDescriptor to a channeldb.HTLC and // asserts that the fields are matched. -func assertPayDescMatchHTLC(t *testing.T, pd PaymentDescriptor, +func assertPayDescMatchHTLC(t *testing.T, pd paymentDescriptor, htlc channeldb.HTLC) { require := require.New(t) diff --git a/lnwallet/commitment.go b/lnwallet/commitment.go index 2ff23ab63..73565ea18 100644 --- a/lnwallet/commitment.go +++ b/lnwallet/commitment.go @@ -1229,10 +1229,10 @@ func genHtlcScript(chanType channeldb.ChannelType, isIncoming bool, // is incoming and if it's being applied to our commitment transaction or that // of the remote node's. Additionally, in order to be able to efficiently // locate the added HTLC on the commitment transaction from the -// PaymentDescriptor that generated it, the generated script is stored within +// paymentDescriptor that generated it, the generated script is stored within // the descriptor itself. func addHTLC(commitTx *wire.MsgTx, whoseCommit lntypes.ChannelParty, - isIncoming bool, paymentDesc *PaymentDescriptor, + isIncoming bool, paymentDesc *paymentDescriptor, keyRing *CommitmentKeyRing, chanType channeldb.ChannelType, auxLeaf input.AuxTapLeaf) error { @@ -1253,7 +1253,7 @@ func addHTLC(commitTx *wire.MsgTx, whoseCommit lntypes.ChannelParty, amountPending := int64(paymentDesc.Amount.ToSatoshis()) commitTx.AddTxOut(wire.NewTxOut(amountPending, pkScript)) - // Store the pkScript of this particular PaymentDescriptor so we can + // Store the pkScript of this particular paymentDescriptor so we can // quickly locate it within the commitment transaction later. if whoseCommit.IsLocal() { paymentDesc.ourPkScript = pkScript diff --git a/lnwallet/payment_descriptor.go b/lnwallet/payment_descriptor.go index 2d6c158cd..5a51f29ce 100644 --- a/lnwallet/payment_descriptor.go +++ b/lnwallet/payment_descriptor.go @@ -62,17 +62,17 @@ func (u updateType) String() string { } } -// PaymentDescriptor represents a commitment state update which either adds, -// settles, or removes an HTLC. PaymentDescriptors encapsulate all necessary +// paymentDescriptor represents a commitment state update which either adds, +// settles, or removes an HTLC. paymentDescriptors encapsulate all necessary // metadata w.r.t to an HTLC, and additional data pairing a settle message to // the original added HTLC. // // TODO(roasbeef): LogEntry interface?? // - need to separate attrs for cancel/add/settle/feeupdate -type PaymentDescriptor struct { +type paymentDescriptor struct { // ChanID is the ChannelID of the LightningChannel that this - // PaymentDescriptor belongs to. We track this here so we can - // reconstruct the Messages that this PaymentDescriptor is built from. + // paymentDescriptor belongs to. We track this here so we can + // reconstruct the Messages that this paymentDescriptor is built from. ChanID lnwire.ChannelID // RHash is the payment hash for this HTLC. The HTLC can be settled iff @@ -170,7 +170,7 @@ type PaymentDescriptor struct { // removeCommitHeight[Remote|Local] encodes the height of the // commitment which removed the parent pointer of this - // PaymentDescriptor either due to a timeout or a settle. Once both + // paymentDescriptor either due to a timeout or a settle. Once both // these heights are below the tail of both chains, the log entries can // safely be removed. removeCommitHeightRemote uint64 @@ -199,7 +199,7 @@ type PaymentDescriptor struct { // [our|their|]PkScript are the raw public key scripts that encodes the // redemption rules for this particular HTLC. These fields will only be - // populated iff the EntryType of this PaymentDescriptor is Add. + // populated iff the EntryType of this paymentDescriptor is Add. // ourPkScript is the ourPkScript from the context of our local // commitment chain. theirPkScript is the latest pkScript from the // context of the remote commitment chain. @@ -212,7 +212,7 @@ type PaymentDescriptor struct { theirPkScript []byte theirWitnessScript []byte - // EntryType denotes the exact type of the PaymentDescriptor. In the + // EntryType denotes the exact type of the paymentDescriptor. In the // case of a Timeout, or Settle type, then the Parent field will point // into the log to the HTLC being modified. EntryType updateType @@ -232,11 +232,11 @@ type PaymentDescriptor struct { CustomRecords lnwire.CustomRecords } -// ToLogUpdate recovers the underlying LogUpdate from the paymentDescriptor. +// toLogUpdate recovers the underlying LogUpdate from the paymentDescriptor. // This operation is lossy and will forget some extra information tracked by the // paymentDescriptor but the function is total in that all paymentDescriptors // can be converted back to LogUpdates. -func (pd *PaymentDescriptor) ToLogUpdate() channeldb.LogUpdate { +func (pd *paymentDescriptor) toLogUpdate() channeldb.LogUpdate { var msg lnwire.Message switch pd.EntryType { case Add: diff --git a/lnwallet/update_log.go b/lnwallet/update_log.go index 5b9d6c565..42e5373a2 100644 --- a/lnwallet/update_log.go +++ b/lnwallet/update_log.go @@ -29,16 +29,16 @@ type updateLog struct { // List is the updatelog itself, we embed this value so updateLog has // access to all the method of a list.List. - *fn.List[*PaymentDescriptor] + *fn.List[*paymentDescriptor] // updateIndex maps a `logIndex` to a particular update entry. It // deals with the four update types: // `Fail|MalformedFail|Settle|FeeUpdate` - updateIndex map[uint64]*fn.Node[*PaymentDescriptor] + updateIndex map[uint64]*fn.Node[*paymentDescriptor] // htlcIndex maps a `htlcCounter` to an offered HTLC entry, hence the // `Add` update. - htlcIndex map[uint64]*fn.Node[*PaymentDescriptor] + htlcIndex map[uint64]*fn.Node[*paymentDescriptor] // modifiedHtlcs is a set that keeps track of all the current modified // htlcs, hence update types `Fail|MalformedFail|Settle`. A modified @@ -50,9 +50,9 @@ type updateLog struct { // newUpdateLog creates a new updateLog instance. func newUpdateLog(logIndex, htlcCounter uint64) *updateLog { return &updateLog{ - List: fn.NewList[*PaymentDescriptor](), - updateIndex: make(map[uint64]*fn.Node[*PaymentDescriptor]), - htlcIndex: make(map[uint64]*fn.Node[*PaymentDescriptor]), + List: fn.NewList[*paymentDescriptor](), + updateIndex: make(map[uint64]*fn.Node[*paymentDescriptor]), + htlcIndex: make(map[uint64]*fn.Node[*paymentDescriptor]), logIndex: logIndex, htlcCounter: htlcCounter, modifiedHtlcs: fn.NewSet[uint64](), @@ -64,7 +64,7 @@ func newUpdateLog(logIndex, htlcCounter uint64) *updateLog { // state. This function differs from appendHtlc in that it won't increment // either of log's counters. If the HTLC is already present, then it is // ignored. -func (u *updateLog) restoreHtlc(pd *PaymentDescriptor) { +func (u *updateLog) restoreHtlc(pd *paymentDescriptor) { if _, ok := u.htlcIndex[pd.HtlcIndex]; ok { return } @@ -74,7 +74,7 @@ func (u *updateLog) restoreHtlc(pd *PaymentDescriptor) { // appendUpdate appends a new update to the tip of the updateLog. The entry is // also added to index accordingly. -func (u *updateLog) appendUpdate(pd *PaymentDescriptor) { +func (u *updateLog) appendUpdate(pd *paymentDescriptor) { u.updateIndex[u.logIndex] = u.PushBack(pd) u.logIndex++ } @@ -82,13 +82,13 @@ func (u *updateLog) appendUpdate(pd *PaymentDescriptor) { // restoreUpdate appends a new update to the tip of the updateLog. The entry is // also added to index accordingly. This function differs from appendUpdate in // that it won't increment the log index counter. -func (u *updateLog) restoreUpdate(pd *PaymentDescriptor) { +func (u *updateLog) restoreUpdate(pd *paymentDescriptor) { u.updateIndex[pd.LogIndex] = u.PushBack(pd) } // appendHtlc appends a new HTLC offer to the tip of the update log. The entry // is also added to the offer index accordingly. -func (u *updateLog) appendHtlc(pd *PaymentDescriptor) { +func (u *updateLog) appendHtlc(pd *paymentDescriptor) { u.htlcIndex[u.htlcCounter] = u.PushBack(pd) u.htlcCounter++ @@ -97,7 +97,7 @@ func (u *updateLog) appendHtlc(pd *PaymentDescriptor) { // lookupHtlc attempts to look up an offered HTLC according to its offer // index. If the entry isn't found, then a nil pointer is returned. -func (u *updateLog) lookupHtlc(i uint64) *PaymentDescriptor { +func (u *updateLog) lookupHtlc(i uint64) *paymentDescriptor { htlc, ok := u.htlcIndex[i] if !ok { return nil @@ -145,7 +145,7 @@ func compactLogs(ourLog, theirLog *updateLog, localChainTail, remoteChainTail uint64) { compactLog := func(logA, logB *updateLog) { - var nextA *fn.Node[*PaymentDescriptor] + var nextA *fn.Node[*paymentDescriptor] for e := logA.Front(); e != nil; e = nextA { // Assign next iteration element at top of loop because // we may remove the current element from the list,