Skip to content

Commit

Permalink
Merge pull request bnb-chain#7 from Loverush/develop
Browse files Browse the repository at this point in the history
Update vote broadcast routine
  • Loading branch information
pythonberg1997 authored Mar 8, 2022
2 parents db60920 + 60a25f3 commit 649930c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ import (
const (
// txChanSize is the size of channel listening to NewTxsEvent.
// The number is referenced from the size of tx pool.
txChanSize = 256
voteChanSize = 4096
txChanSize = 4096

// voteChanSize is the size of channel listening to NewVotesEvent.
voteChanSize = 256

deltaTdThreshold = 20
)

var (
Expand Down Expand Up @@ -99,7 +103,7 @@ type handlerConfig struct {
Chain *core.BlockChain // Blockchain to serve data from
TxPool txPool // Transaction pool to propagate from
VotePool votePool // Votes pool to propagate from
Network uint64 // Network identifier to adfvertise
Network uint64 // Network identifier to advertise
Sync downloader.SyncMode // Whether to fast or full sync
DiffSync bool // Whether to diff sync
BloomCache uint64 // Megabytes to alloc for fast sync bloom
Expand Down Expand Up @@ -273,7 +277,7 @@ func newHandler(config *handlerConfig) (*handler, error) {
}

// runEthPeer registers an eth peer into the joint eth/snap peerset, adds it to
// various subsistems and starts handling messages.
// various subsystems and starts handling messages.
func (h *handler) runEthPeer(peer *eth.Peer, handler eth.Handler) error {
// If the peer has a `snap` extension, wait for it to connect so we can have
// a uniform initialization/teardown mechanism
Expand Down Expand Up @@ -619,7 +623,10 @@ func (h *handler) BroadcastVotes(votes types.VoteEnvelopes) {
for _, vote := range votes {
peers := h.peers.peersWithoutVote(vote.Hash())
for _, peer := range peers {
voteset[peer] = append(voteset[peer], vote)
_, peerTD := peer.Head()
if deltaTD := new(big.Int).Abs(new(big.Int).Sub(h.chain.CurrentBlock().Difficulty(), peerTD)); deltaTD.Cmp(big.NewInt(deltaTdThreshold)) < 1 {
voteset[peer] = append(voteset[peer], vote)
}
}
}

Expand Down

0 comments on commit 649930c

Please sign in to comment.