Skip to content

Commit 36636b3

Browse files
zhiqiangxublakehhuynh
authored andcommitted
core/types: improve accuracy of header.Size() (ethereum#25859)
The header.Size() method did not take the basefee into account.
1 parent 4fa8ee6 commit 36636b3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

core/types/block.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ var headerSize = common.StorageSize(reflect.TypeOf(Header{}).Size())
117117
// Size returns the approximate memory used by all internal contents. It is used
118118
// to approximate and limit the memory consumption of various caches.
119119
func (h *Header) Size() common.StorageSize {
120-
return headerSize + common.StorageSize(len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen())/8)
120+
var baseFeeBits int
121+
if h.BaseFee != nil {
122+
baseFeeBits = h.BaseFee.BitLen()
123+
}
124+
return headerSize + common.StorageSize(len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen()+baseFeeBits)/8)
121125
}
122126

123127
// SanityCheck checks a few basic things -- these checks are way beyond what

0 commit comments

Comments
 (0)