Skip to content

Commit

Permalink
reorganize the logic of reannouncing transactions (bnb-chain#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
keefel committed Dec 20, 2021
1 parent 74f6b61 commit ebf6372
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,26 +565,19 @@ func (h *handler) BroadcastTransactions(txs types.Transactions) {
// ReannounceTransactions will announce a batch of local pending transactions
// to a square root of all peers.
func (h *handler) ReannounceTransactions(txs types.Transactions) {
var (
annoCount int // Count of announcements made
annos = make(map[*ethPeer][]common.Hash) // Set peer->hash to announce
)
hashes := make([]common.Hash, 0, txs.Len())
for _, tx := range txs {
hashes = append(hashes, tx.Hash())
}

// Announce transactions hash to a batch of peers
peersCount := uint(math.Sqrt(float64(h.peers.len())))
peers := h.peers.headPeers(peersCount)
for _, tx := range txs {
for _, peer := range peers {
annos[peer] = append(annos[peer], tx.Hash())
}
}

for peer, hashes := range annos {
annoCount += len(hashes)
for _, peer := range peers {
peer.AsyncSendPooledTransactionHashes(hashes)
}
log.Debug("Transaction reannounce", "txs", len(txs),
"announce packs", peersCount, "announced hashes", annoCount)
"announce packs", peersCount, "announced hashes", peersCount*uint(len(hashes)))
}

// minedBroadcastLoop sends mined blocks to connected peers.
Expand Down

0 comments on commit ebf6372

Please sign in to comment.