diff --git a/core/types/withdrawal.go b/core/types/withdrawal.go index 7671fd60df..6f99e53b56 100644 --- a/core/types/withdrawal.go +++ b/core/types/withdrawal.go @@ -43,18 +43,18 @@ type withdrawalMarshaling struct { Amount hexutil.Uint64 } -var withdrawalSize = common.StorageSize(reflect.TypeOf(Withdrawal{}).Size()) - -func (w Withdrawal) Size() common.StorageSize { - return common.StorageSize(withdrawalSize) -} - // Withdrawals implements DerivableList for withdrawals. 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 8346d40232..5441ad1187 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -385,9 +385,7 @@ func (q *queue) Results(block bool) []*fetchResult { for _, tx := range result.Transactions { size += common.StorageSize(tx.Size()) } - for _, withdrawal := range result.Withdrawals { - size += withdrawal.Size() - } + size += common.StorageSize(result.Withdrawals.Size()) q.resultSize = common.StorageSize(blockCacheSizeWeight)*size + (1-common.StorageSize(blockCacheSizeWeight))*q.resultSize }