fuzz pool

This commit is contained in:
alex.sharov 2021-07-30 10:28:03 +07:00
parent 1f46e8166b
commit 04ed6f7f70
3 changed files with 44 additions and 15 deletions

View File

@ -185,7 +185,7 @@ func PromoteStep(pending, baseFee, queued *SubPool) {
baseFee.Add(pending.PopWorst())
continue
}
if worst.SubPool >= 0b11000 {
if worst.SubPool >= 0b10000 {
queued.Add(pending.PopWorst())
continue
}
@ -194,7 +194,7 @@ func PromoteStep(pending, baseFee, queued *SubPool) {
//2. If top element in the worst green queue has SubPool == 0b1111, but there is not enough room in the pool, discard.
for worst := pending.Worst(); pending.Len() > PendingSubPoolLimit; worst = pending.Worst() {
if worst.SubPool >= 0b11110 { // TODO: here must 'SubPool == 0b1111' or 'SubPool <= 0b1111' ?
if worst.SubPool >= 0b11111 { // TODO: here must 'SubPool == 0b1111' or 'SubPool <= 0b1111' ?
break
}
pending.PopWorst()
@ -214,7 +214,7 @@ func PromoteStep(pending, baseFee, queued *SubPool) {
if worst.SubPool >= 0b11100 {
break
}
if worst.SubPool >= 0b11000 {
if worst.SubPool >= 0b10000 {
queued.Add(baseFee.PopWorst())
continue
}
@ -223,7 +223,7 @@ func PromoteStep(pending, baseFee, queued *SubPool) {
//5. If the top element in the worst yellow queue has SubPool == 0x1110, but there is not enough room in the pool, discard.
for worst := baseFee.Worst(); baseFee.Len() > BaseFeeSubPoolLimit; worst = baseFee.Worst() {
if worst.SubPool >= 0b11110 {
if worst.SubPool >= 0b11101 {
break
}
baseFee.PopWorst()
@ -252,11 +252,7 @@ func PromoteStep(pending, baseFee, queued *SubPool) {
}
//8. If the top element in the worst red queue has SubPool >= 0b100, but there is not enough room in the pool, discard.
for worst := queued.Worst(); queued.Len() > QueuedSubPoolLimit; worst = queued.Worst() {
if worst.SubPool >= 0b10000 {
break
}
for _ = queued.Worst(); queued.Len() > QueuedSubPoolLimit; _ = queued.Worst() {
queued.PopWorst()
}
}

View File

@ -17,6 +17,7 @@ import (
func FuzzPromoteStep(f *testing.F) {
f.Add([]uint8{0b11111, 0b10001, 0b10101, 0b00001, 0b00000}, []uint8{0b11111, 0b10001, 0b10101, 0b00001, 0b00000}, []uint8{0b11111, 0b10001, 0b10101, 0b00001, 0b00000})
f.Add([]uint8{0b11111}, []uint8{0b11111}, []uint8{0b11110, 0b0, 0b1010})
f.Fuzz(func(t *testing.T, s1, s2, s3 []uint8) {
t.Parallel()
pending := NewSubPool()
@ -38,11 +39,21 @@ func FuzzPromoteStep(f *testing.F) {
best, worst := pending.Best(), pending.Worst()
_ = best
//if best != nil && best.SubPool < 0b11110 {
// t.Fatalf("Pending best too small %b", best.SubPool)
//}
if worst != nil && worst.SubPool < 0b11000 {
t.Fatalf("Pending worst too small %b, input: %b", worst.SubPool, s1)
if worst != nil && worst.SubPool < 0b01111 {
t.Fatalf("Pending worst too small %b, input: %b,%b,%b", worst.SubPool, s1, s2, s3)
}
best, worst = baseFee.Best(), baseFee.Worst()
_ = best
if worst != nil && worst.SubPool < 0b01111 {
t.Fatalf("Pending worst too small %b, input: %b,%b,%b", worst.SubPool, s1, s2, s3)
}
best, worst = queue.Best(), queue.Worst()
_ = best
if worst != nil && worst.SubPool < 0b01111 {
t.Fatalf("Pending worst too small %b, input: %b,%b,%b", worst.SubPool, s1, s2, s3)
}
})
}

View File

@ -50,7 +50,7 @@ func TestSubPoolMarkerOrder(t *testing.T) {
)
}
func TestSubPool(t *testing.T) {
func TestSubPoolOrder(t *testing.T) {
sub := NewSubPool()
sub.Add(&MetaTx{SubPool: 0b10101})
sub.Add(&MetaTx{SubPool: 0b11110})
@ -67,3 +67,25 @@ func TestSubPool(t *testing.T) {
require.Equal(t, uint8(0b00001), uint8(sub.Worst().SubPool))
require.Equal(t, uint8(0b01110), uint8(sub.Best().SubPool))
}
func TestSubPoolsPromote(t *testing.T) {
pending, baseFee, queued := NewSubPool(), NewSubPool(), NewSubPool()
pending.Add(&MetaTx{SubPool: SubPoolMarker(0b11111)})
baseFee.Add(&MetaTx{SubPool: SubPoolMarker(0b11111)})
queued.Add(&MetaTx{SubPool: SubPoolMarker(0b11110)})
queued.Add(&MetaTx{SubPool: SubPoolMarker(0b0)})
queued.Add(&MetaTx{SubPool: SubPoolMarker(0b01010)})
PromoteStep(pending, baseFee, queued)
if pending.Worst() != nil {
require.Less(t, uint8(0b01111), uint8(pending.Worst().SubPool))
}
if baseFee.Worst() != nil {
require.Less(t, uint8(0b01111), uint8(baseFee.Worst().SubPool))
}
if queued.Worst() != nil {
require.Less(t, uint8(0b01111), uint8(queued.Worst().SubPool))
}
// if limit reached, worst must be greater than X
}