eth/handler, broadcast: optimize tx broadcast mechanism (#22176)
This PR optimizes the broadcast loop. Instead of iterating twice through a given set of transactions to weed out which peers have and which do not have a tx, to send/announce transactions, we do it only once.
This commit is contained in:
committed by
GitHub
parent
1489c3f494
commit
e01096f531
@ -142,18 +142,18 @@ func (p *Peer) announceTransactions() {
|
||||
if done == nil && len(queue) > 0 {
|
||||
// Pile transaction hashes until we reach our allowed network limit
|
||||
var (
|
||||
hashes []common.Hash
|
||||
count int
|
||||
pending []common.Hash
|
||||
size common.StorageSize
|
||||
)
|
||||
for i := 0; i < len(queue) && size < maxTxPacketSize; i++ {
|
||||
if p.txpool.Get(queue[i]) != nil {
|
||||
pending = append(pending, queue[i])
|
||||
for count = 0; count < len(queue) && size < maxTxPacketSize; count++ {
|
||||
if p.txpool.Get(queue[count]) != nil {
|
||||
pending = append(pending, queue[count])
|
||||
size += common.HashLength
|
||||
}
|
||||
hashes = append(hashes, queue[i])
|
||||
}
|
||||
queue = queue[:copy(queue, queue[len(hashes):])]
|
||||
// Shift and trim queue
|
||||
queue = queue[:copy(queue, queue[count:])]
|
||||
|
||||
// If there's anything available to transfer, fire up an async writer
|
||||
if len(pending) > 0 {
|
||||
|
Reference in New Issue
Block a user