From c5dbb223d2103f0eb6b697ce141935ba43f65651 Mon Sep 17 00:00:00 2001 From: NathanBSC Date: Mon, 24 Jul 2023 17:56:27 +0800 Subject: [PATCH] log: reduce logs when receiving too much votes from a peer --- eth/handler_bsc.go | 1 - eth/protocols/bsc/peer.go | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/eth/handler_bsc.go b/eth/handler_bsc.go index d01a475ed0..4fb1824f27 100644 --- a/eth/handler_bsc.go +++ b/eth/handler_bsc.go @@ -62,7 +62,6 @@ func (h *bscHandler) Handle(peer *bsc.Peer, packet bsc.Packet) error { // votes broadcast for the local node to process. func (h *bscHandler) handleVotesBroadcast(peer *bsc.Peer, votes []*types.VoteEnvelope) error { if peer.IsOverLimitAfterReceiving() { - peer.Log().Warn("peer sending votes too much, votes dropped; it may be a ddos attack, please check!") return nil } // Here we only put the first vote, to avoid ddos attack by sending a large batch of votes. diff --git a/eth/protocols/bsc/peer.go b/eth/protocols/bsc/peer.go index 77ac11599f..242864fdbb 100644 --- a/eth/protocols/bsc/peer.go +++ b/eth/protocols/bsc/peer.go @@ -26,7 +26,7 @@ const ( receiveRateLimitPerSecond = 10 // the time span of one period - secondsPerPeriod = float64(10) + secondsPerPeriod = float64(30) ) // max is a helper function which returns the larger of the two given integers. @@ -133,6 +133,9 @@ func (p *Peer) AsyncSendVotes(votes []*types.VoteEnvelope) { // Otherwise, check whether the number of received votes extra (secondsPerPeriod * receiveRateLimitPerSecond) func (p *Peer) IsOverLimitAfterReceiving() bool { if timeInterval := time.Since(p.periodBegin).Seconds(); timeInterval >= secondsPerPeriod { + if p.periodCounter > uint(secondsPerPeriod*receiveRateLimitPerSecond) { + p.Log().Debug("sending votes too much", "secondsPerPeriod", secondsPerPeriod, "count ", p.periodCounter) + } p.periodBegin = time.Now() p.periodCounter = 0 return false