Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log: reduce logs when receiving too much votes from a peer #1780

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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