cap MaxNonceGap to 4, add delay between batch messages during republish

This commit is contained in:
vyzo
2020-09-03 15:28:44 +03:00
parent f53d2e3a46
commit 28f57667f0
3 changed files with 16 additions and 9 deletions
+1 -9
View File
@@ -7,7 +7,6 @@ import (
"fmt"
"math"
stdbig "math/big"
"runtime"
"sort"
"sync"
"time"
@@ -53,7 +52,7 @@ var minimumBaseFee = types.NewInt(uint64(build.MinimumBaseFee))
var MaxActorPendingMessages = 1000
var MaxNonceGap = uint64(16)
var MaxNonceGap = uint64(4)
var (
ErrMessageTooBig = errors.New("message too big")
@@ -82,13 +81,6 @@ const (
localUpdates = "update"
)
func init() {
numcpus := uint64(runtime.NumCPU())
if numcpus < MaxNonceGap {
MaxNonceGap = numcpus
}
}
type MessagePool struct {
lk sync.Mutex
+9
View File
@@ -3,6 +3,7 @@ package messagepool
import (
"context"
"sort"
"time"
"golang.org/x/xerrors"
@@ -15,6 +16,8 @@ import (
const repubMsgLimit = 30
var RepublishBatchDelay = 200 * time.Millisecond
func (mp *MessagePool) republishPendingMessages() error {
mp.curTsLk.Lock()
ts := mp.curTs
@@ -131,6 +134,12 @@ func (mp *MessagePool) republishPendingMessages() error {
}
count++
if count < len(msgs) {
// this delay is here to encourage the pubsub subsystem to process the messages serially
// and avoid creating nonce gaps because of concurrent validation.
time.Sleep(RepublishBatchDelay)
}
}
// track most recently republished messages
+6
View File
@@ -12,6 +12,12 @@ import (
)
func TestRepubMessages(t *testing.T) {
oldRepublishBatchDelay = RepublishBatchDelay
RepublishBatchDelay = time.Microsecond
defer func() {
RepublishBatchDelay = oldRepublishBatchDelay
}()
tma := newTestMpoolAPI()
ds := datastore.NewMapDatastore()