mirror of
https://github.com/aljazceru/breez-lnd.git
synced 2025-12-19 07:04:25 +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:
@@ -14,11 +14,12 @@ import (
|
||||
func TestWaitingQueueThreadSafety(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
q := newPacketQueue()
|
||||
const numPkts = 1000
|
||||
|
||||
q := newPacketQueue(numPkts)
|
||||
q.Start()
|
||||
defer q.Stop()
|
||||
|
||||
const numPkts = 1000
|
||||
a := make([]lnwire.MilliSatoshi, numPkts)
|
||||
for i := 0; i < numPkts; i++ {
|
||||
a[i] = lnwire.MilliSatoshi(i)
|
||||
@@ -30,6 +31,8 @@ func TestWaitingQueueThreadSafety(t *testing.T) {
|
||||
|
||||
var b []lnwire.MilliSatoshi
|
||||
for i := 0; i < numPkts; i++ {
|
||||
q.SignalFreeSlot()
|
||||
|
||||
select {
|
||||
case packet := <-q.outgoingPkts:
|
||||
b = append(b, packet.amount)
|
||||
|
||||
Reference in New Issue
Block a user