Skip to content

Commit

Permalink
core/types: improve accuracy of header.Size() (ethereum#25859)
Browse files Browse the repository at this point in the history
The header.Size() method did not take the basefee into account.
  • Loading branch information
zhiqiangxu authored and blakehhuynh committed Oct 3, 2022
1 parent 4fa8ee6 commit 36636b3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/types/block.go
Expand Up @@ -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
Expand Down

0 comments on commit 36636b3

Please sign in to comment.