From ebe31dfd5c8c053c098b65eac2ec3070b7f8e9a8 Mon Sep 17 00:00:00 2001 From: psogv0308 Date: Thu, 8 Aug 2024 22:14:00 +0900 Subject: [PATCH] eth/downloader, core/types: take withdrawals-size into account in downloader queue (#30276) Fixes a slight miscalculation in the downloader queue, which was not accurately taking block withdrawals into account when calculating the size of the items in the queue --- core/types/withdrawal.go | 7 +++++++ eth/downloader/queue.go | 1 + 2 files changed, 8 insertions(+) diff --git a/core/types/withdrawal.go b/core/types/withdrawal.go index d1ad918f98..6f99e53b56 100644 --- a/core/types/withdrawal.go +++ b/core/types/withdrawal.go @@ -18,6 +18,7 @@ package types import ( "bytes" + "reflect" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -48,6 +49,12 @@ type Withdrawals []*Withdrawal // Len returns the length of s. func (s Withdrawals) Len() int { return len(s) } +var withdrawalSize = int(reflect.TypeOf(Withdrawal{}).Size()) + +func (s Withdrawals) Size() int { + return withdrawalSize * len(s) +} + // EncodeIndex encodes the i'th withdrawal to w. Note that this does not check for errors // because we assume that *Withdrawal will only ever contain valid withdrawals that were either // constructed by decoding or via public API in this package. diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index 267c23407f..5441ad1187 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -385,6 +385,7 @@ func (q *queue) Results(block bool) []*fetchResult { 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 }