diff --git a/eth/fetcher/tx_fetcher.go b/eth/fetcher/tx_fetcher.go index 5817dfbcf5..2165b7f103 100644 --- a/eth/fetcher/tx_fetcher.go +++ b/eth/fetcher/tx_fetcher.go @@ -991,8 +991,10 @@ func (f *TxFetcher) scheduleFetches(timer *mclock.Timer, timeout chan struct{}, if len(f.announces[peer]) == 0 { return // continue in the for-each } + // hashes is allocated lazily: peers that collect no new hashes + // (all announces already being fetched) skip the 8KB allocation. var ( - hashes = make([]common.Hash, 0, maxTxRetrievals) + hashes []common.Hash bytes uint64 ) f.forEachAnnounce(f.announces[peer], func(hash common.Hash, meta txMetadata) bool { @@ -1009,6 +1011,9 @@ func (f *TxFetcher) scheduleFetches(timer *mclock.Timer, timeout chan struct{}, f.alternates[hash] = f.announced[hash] delete(f.announced, hash) + if hashes == nil { + hashes = make([]common.Hash, 0, maxTxRetrievals) + } // Accumulate the hash and stop if the limit was reached hashes = append(hashes, hash) if len(hashes) >= maxTxRetrievals {