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

fix: avoid to block the chain when failed to send votes #1734

Merged
Merged
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
9 changes: 7 additions & 2 deletions eth/protocols/bsc/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const (
// maxKnownVotes is the maximum vote hashes to keep in the known list
// before starting to randomly evict them.
maxKnownVotes = 5376

// voteBufferSize is the maximum number of batch votes can be hold before sending
voteBufferSize = 21 * 2
)

// max is a helper function which returns the larger of the two given integers.
Expand Down Expand Up @@ -43,7 +46,7 @@ func NewPeer(version uint, p *p2p.Peer, rw p2p.MsgReadWriter) *Peer {
peer := &Peer{
id: id,
knownVotes: newKnownCache(maxKnownVotes),
voteBroadcast: make(chan []*types.VoteEnvelope),
voteBroadcast: make(chan []*types.VoteEnvelope, voteBufferSize),
Peer: p,
rw: rw,
version: version,
Expand Down Expand Up @@ -105,7 +108,9 @@ func (p *Peer) AsyncSendVotes(votes []*types.VoteEnvelope) {
select {
case p.voteBroadcast <- votes:
case <-p.term:
p.Log().Debug("Dropping vote propagation", "count", len(votes))
p.Log().Debug("Dropping vote propagation for closed peer", "count", len(votes))
default:
p.Log().Debug("Dropping vote propagation for abnormal peer", "count", len(votes))
}
}

Expand Down