htlcswitch+lnwallet: quarantine paymentDescriptor to lnwallet
The objective of this commit is to make paymentDescriptor a private data structure so we can quarantine it to the lnwallet package. To accomplish this we had to prevent it from leaking out via the arguments or return values of the public functions in lnwallet. This naturally had consequences for the htlcswitch package as we choose other mechanisms for tracking the data that paymentDescriptor was responsible for. Astoundingly, this was highly successful and allowed us to remove a ton of redundant code. The diff for this commit represents a substantial reduction in total lines of code as well as extraneous arguments and return values from key functions. This also sets the stage for future commits where we actually will be attempting to rid lnwallet of paymentDescriptor completely.
This commit is contained in:
5 files changed
+150
-148
No files matched your search
+88
-86
@@ -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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user