Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R4R]reorganize the logic of reannouncing transactions #620

Merged
merged 1 commit into from
Dec 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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