From 367e60549af9b6551e0f7604b33a5b1c891f6b23 Mon Sep 17 00:00:00 2001 From: zhiqiangxu <652732310@qq.com> Date: Mon, 26 Sep 2022 15:10:39 +0800 Subject: [PATCH] core/types: improve accuracy of header.Size() (#25859) The header.Size() method did not take the basefee into account. --- core/types/block.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/types/block.go b/core/types/block.go index 7525a88f5a..8942082b6e 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -117,7 +117,11 @@ var headerSize = common.StorageSize(reflect.TypeOf(Header{}).Size()) // Size returns the approximate memory used by all internal contents. It is used // to approximate and limit the memory consumption of various caches. func (h *Header) Size() common.StorageSize { - return headerSize + common.StorageSize(len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen())/8) + var baseFeeBits int + if h.BaseFee != nil { + baseFeeBits = h.BaseFee.BitLen() + } + return headerSize + common.StorageSize(len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen()+baseFeeBits)/8) } // SanityCheck checks a few basic things -- these checks are way beyond what