From a62e0270025a17facc64ce416c5901e0a298ab9c Mon Sep 17 00:00:00 2001 From: gammazero Date: Wed, 9 Feb 2022 10:29:49 -0800 Subject: [PATCH] review changes --- chain/sub/incoming.go | 5 ++--- chain/sub/ratelimit/queue.go | 4 ++-- chain/sub/ratelimit/window_test.go | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/chain/sub/incoming.go b/chain/sub/incoming.go index e39d0177f..222ad3dea 100644 --- a/chain/sub/incoming.go +++ b/chain/sub/incoming.go @@ -6,7 +6,6 @@ import ( "time" address "github.com/filecoin-project/go-address" - //"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain" "github.com/filecoin-project/lotus/chain/consensus" @@ -465,7 +464,7 @@ type IndexerMessageValidator struct { } func NewIndexerMessageValidator(self peer.ID, chainApi full.ChainModuleAPI, stateApi full.StateModuleAPI) *IndexerMessageValidator { - peerCache, _ := lru.New2Q(1024) + peerCache, _ := lru.New2Q(8192) return &IndexerMessageValidator{ self: self, @@ -498,7 +497,7 @@ func (v *IndexerMessageValidator) Validate(ctx context.Context, pid peer.ID, msg } if minerID == "" { - log.Warnw("ignoring messsage missing miner id", "peer", originPeer) + log.Debugw("ignoring messsage missing miner id", "peer", originPeer) return pubsub.ValidationIgnore } diff --git a/chain/sub/ratelimit/queue.go b/chain/sub/ratelimit/queue.go index d5ed001fd..49f9bef66 100644 --- a/chain/sub/ratelimit/queue.go +++ b/chain/sub/ratelimit/queue.go @@ -2,7 +2,7 @@ package ratelimit import "errors" -var ErrRate = errors.New("rate exceeded") +var ErrRateLimitExceeded = errors.New("rate limit exceeded") type queue struct { buf []int64 @@ -24,7 +24,7 @@ func (q *queue) len() int { // push adds an element to the end of the queue. func (q *queue) push(elem int64) error { if q.count == len(q.buf) { - return ErrRate + return ErrRateLimitExceeded } q.buf[q.tail] = elem diff --git a/chain/sub/ratelimit/window_test.go b/chain/sub/ratelimit/window_test.go index f656d6a0b..c86b65ef7 100644 --- a/chain/sub/ratelimit/window_test.go +++ b/chain/sub/ratelimit/window_test.go @@ -37,8 +37,8 @@ func TestWindow(t *testing.T) { if w.Len() != maxEvents { t.Fatalf("q.Len() is %d, expected %d", w.Len(), maxEvents) } - if err = w.Add(); err == nil { - t.Fatalf("add event %d within time limit should have failed", maxEvents+1) + if err = w.Add(); err != ErrRateLimitExceeded { + t.Fatalf("add event %d within time limit should have failed with err: %s", maxEvents+1, ErrRateLimitExceeded) } time.Sleep(timeLimit)