Skip to content

Commit ec8d46e

Browse files
authored
reorganize the logic of reannouncing transactions (#620)
1 parent a9ac317 commit ec8d46e

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

eth/handler.go

+6-13
Original file line numberDiff line numberDiff line change
@@ -565,26 +565,19 @@ func (h *handler) BroadcastTransactions(txs types.Transactions) {
565565
// ReannounceTransactions will announce a batch of local pending transactions
566566
// to a square root of all peers.
567567
func (h *handler) ReannounceTransactions(txs types.Transactions) {
568-
var (
569-
annoCount int // Count of announcements made
570-
annos = make(map[*ethPeer][]common.Hash) // Set peer->hash to announce
571-
)
568+
hashes := make([]common.Hash, 0, txs.Len())
569+
for _, tx := range txs {
570+
hashes = append(hashes, tx.Hash())
571+
}
572572

573573
// Announce transactions hash to a batch of peers
574574
peersCount := uint(math.Sqrt(float64(h.peers.len())))
575575
peers := h.peers.headPeers(peersCount)
576-
for _, tx := range txs {
577-
for _, peer := range peers {
578-
annos[peer] = append(annos[peer], tx.Hash())
579-
}
580-
}
581-
582-
for peer, hashes := range annos {
583-
annoCount += len(hashes)
576+
for _, peer := range peers {
584577
peer.AsyncSendPooledTransactionHashes(hashes)
585578
}
586579
log.Debug("Transaction reannounce", "txs", len(txs),
587-
"announce packs", peersCount, "announced hashes", annoCount)
580+
"announce packs", peersCount, "announced hashes", peersCount*uint(len(hashes)))
588581
}
589582

590583
// minedBroadcastLoop sends mined blocks to connected peers.

0 commit comments

Comments
 (0)