htlcswitch: re-write link's packet overflow queue for readability+extensibility
This commit completes a full re-write of the link’s packet overflow queue with the goals of the making the code itself more understandable and also allowing it to be more extensible in the future with various algorithms for handling HTLC congestion avoidance and persistent queue back pressure. The new design is simpler and consumes much less coroutines (no longer a new goroutine for each active HLTC). We now implement a simple synchronized queue using a standard condition variable.
This commit is contained in:
3 files changed
+219
-99
No files matched your search
@@ -9,28 +9,29 @@ import (
|
||||
)
|
||||
|
||||
// TestWaitingQueueThreadSafety test the thread safety properties of the
|
||||
// waiting queue, by executing methods in seprate goroutines which operates
|
||||
// waiting queue, by executing methods in separate goroutines which operates
|
||||
// with the same data.
|
||||
func TestWaitingQueueThreadSafety(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
q := newWaitingQueue()
|
||||
q := newPacketQueue()
|
||||
q.Start()
|
||||
defer q.Stop()
|
||||
|
||||
a := make([]lnwire.MilliSatoshi, 1000)
|
||||
for i := 0; i < len(a); i++ {
|
||||
const numPkts = 1000
|
||||
a := make([]lnwire.MilliSatoshi, numPkts)
|
||||
for i := 0; i < numPkts; i++ {
|
||||
a[i] = lnwire.MilliSatoshi(i)
|
||||
q.consume(&htlcPacket{
|
||||
q.AddPkt(&htlcPacket{
|
||||
amount: lnwire.MilliSatoshi(i),
|
||||
htlc: &lnwire.UpdateAddHTLC{},
|
||||
})
|
||||
}
|
||||
|
||||
var b []lnwire.MilliSatoshi
|
||||
for i := 0; i < len(a); i++ {
|
||||
q.release()
|
||||
|
||||
for i := 0; i < numPkts; i++ {
|
||||
select {
|
||||
case packet := <-q.pending:
|
||||
case packet := <-q.outgoingPkts:
|
||||
b = append(b, packet.amount)
|
||||
|
||||
case <-time.After(2 * time.Second):
|
||||
|
||||
Reference in new issue
Block a user