eth/downloader: make block body download throttle heuristic based on worst-case block size at the current gas limit

This commit is contained in:
Jared Wasinger 2025-03-27 18:26:00 +01:00
parent 83cc2cda25
commit bfeffc573c

View file

@ -373,26 +373,16 @@ func (q *queue) Results(block bool) []*fetchResult {
q.lock.Unlock() q.lock.Unlock()
} }
// Regardless if closed or not, we can still deliver whatever we have // Regardless if closed or not, we can still deliver whatever we have
results := q.resultCache.GetCompleted(maxResultsProcess) results := q.resultCache.GetCompleted(maxResultsProcess)
for _, result := range results {
// Recalculate the result item weights to prevent memory exhaustion // set a throttle threshhold based on estimated worst-sized block that can be created for a given gas limit.
size := result.Header.Size() targetSize := uint64(256_000_000)
for _, uncle := range result.Uncles { gasLimit := results[0].Header.GasLimit
size += uncle.Size() if gasLimit == 0 {
} gasLimit = 1
for _, receipt := range result.Receipts {
size += receipt.Size()
}
for _, tx := range result.Transactions {
size += common.StorageSize(tx.Size())
}
size += common.StorageSize(result.Withdrawals.Size())
q.resultSize = common.StorageSize(blockCacheSizeWeight)*size +
(1-common.StorageSize(blockCacheSizeWeight))*q.resultSize
} }
// Using the newly calibrated resultsize, figure out the new throttle limit throttleThreshold := min(targetSize/(gasLimit/10), 2048)
// on the result cache
throttleThreshold := uint64((common.StorageSize(blockCacheMemory) + q.resultSize - 1) / q.resultSize)
throttleThreshold = q.resultCache.SetThrottleThreshold(throttleThreshold) throttleThreshold = q.resultCache.SetThrottleThreshold(throttleThreshold)
// With results removed from the cache, wake throttled fetchers // With results removed from the cache, wake throttled fetchers