From 3c8f560811a2e308a6a147e8de71c72fb302780e Mon Sep 17 00:00:00 2001 From: NathanBSC Date: Mon, 26 Jun 2023 17:46:05 +0800 Subject: [PATCH] fix: avoid to block the chain when failed to send votes --- eth/protocols/bsc/peer.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/eth/protocols/bsc/peer.go b/eth/protocols/bsc/peer.go index e66ab2a6b3..202502a4b8 100644 --- a/eth/protocols/bsc/peer.go +++ b/eth/protocols/bsc/peer.go @@ -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. @@ -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, @@ -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)) } }