Skip to content

Commit

Permalink
fix: avoid to block the chain when failed to send votes (#1734)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanBSC authored Jun 27, 2023
1 parent 69fd672 commit 598c36b
Showing 1 changed file with 7 additions and 2 deletions.
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

0 comments on commit 598c36b

Please sign in to comment.