Skip to content

Commit

Permalink
log: reduce logs when receiving too much votes from a peer (#1780)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanBSC authored Jul 31, 2023
1 parent 278608a commit f616c36
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 0 additions & 1 deletion eth/handler_bsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion eth/protocols/bsc/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f616c36

Please sign in to comment.