mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-11 06:37:21 +01:00
htlcswitch: ensure the packetQueue can handle total+partial commitment overflows
In this commit, we’ve moved away from the internal queryHandler within
the packetQueue entirely. We now use an internal queueLen variable
internally to allow callers to sample the queue’s size, and also for
synchronization purposes internally.
This commit also introduces a chan struct{} (freeSlots) that is used
internally as a semaphore. The current value of freeSlots reflects the
number of available slots within the commitment transaction. Within the
link, after an HTLC has been removed/modified, then a “slot” is freed
up. The main packetConsumer then interprets these messages as a signal
to attempt to free up a new slot within the queue itself by dumping off
to the commitment transaction.
This commit is contained in:
@@ -240,13 +240,13 @@ func NewChannelLink(cfg ChannelLinkConfig, channel *lnwallet.LightningChannel,
|
||||
upstream: make(chan lnwire.Message),
|
||||
downstream: make(chan *htlcPacket),
|
||||
linkControl: make(chan interface{}),
|
||||
cancelReasons: make(map[uint64]lnwire.OpaqueReason),
|
||||
logCommitTimer: time.NewTimer(300 * time.Millisecond),
|
||||
overflowQueue: newPacketQueue(),
|
||||
bestHeight: currentHeight,
|
||||
quit: make(chan struct{}),
|
||||
// TODO(roasbeef): just do reserve here?
|
||||
availableBandwidth: uint64(channel.StateSnapshot().LocalBalance),
|
||||
cancelReasons: make(map[uint64]lnwire.OpaqueReason),
|
||||
logCommitTimer: time.NewTimer(300 * time.Millisecond),
|
||||
overflowQueue: newPacketQueue(lnwallet.MaxHTLCNumber / 2),
|
||||
bestHeight: currentHeight,
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1032,6 +1032,7 @@ func (l *channelLink) processLockedInHtlcs(
|
||||
// notify the overflow queue that a spare spot has been
|
||||
// freed up within the commitment state.
|
||||
packetsToForward = append(packetsToForward, settlePacket)
|
||||
l.overflowQueue.SignalFreeSlot()
|
||||
|
||||
// A failureCode message for a previously forwarded HTLC has been
|
||||
// received. As a result a new slot will be freed up in our
|
||||
@@ -1053,6 +1054,7 @@ func (l *channelLink) processLockedInHtlcs(
|
||||
// notify the overflow queue that a spare spot has been
|
||||
// freed up within the commitment state.
|
||||
packetsToForward = append(packetsToForward, failPacket)
|
||||
l.overflowQueue.SignalFreeSlot()
|
||||
|
||||
// An incoming HTLC add has been full-locked in. As a result we
|
||||
// can no examine the forwarding details of the HTLC, and the
|
||||
|
||||
Reference in New Issue
Block a user