eth/downloader: remove TODO and condense surrounding code.

This commit is contained in:
Jared Wasinger 2025-04-15 16:46:58 +08:00
parent cca407b2a1
commit 29435f8f31

View file

@ -123,10 +123,11 @@ func (r *resultStore) isThrottled(index int) bool {
// retrievals that can be allowed until the cumulative block size hits a
// predetermined threshold (1 gb).
func (r *resultStore) throttleThreshold() int {
index := r.itemsCount - 1
avgGasUsed := r.itemsGasUsed / (uint64(index) + 1)
var avgGasUsed uint64
if r.itemsCount > 0 {
avgGasUsed = r.itemsGasUsed / uint64(r.itemsCount)
}
blockSize := max(estWorstCaseBlockSize(avgGasUsed), headerSize)
throttleThreshold := min(uint64(len(r.items)), uint64(blockCacheMemory)/blockSize+1)
return int(throttleThreshold)
}