Skip to content

Commit

Permalink
Merge pull request ethereum#64 from mdehoog/roberto-dev
Browse files Browse the repository at this point in the history
update header sanity check & storage size estimates to consider new fields
  • Loading branch information
roberto-bayardo authored Nov 28, 2022
2 parents 536fa4b + d4a5151 commit 210ecb7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,18 @@ 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 {
var baseFeeBits int
var feeBits int
if h.BaseFee != nil {
baseFeeBits = h.BaseFee.BitLen()
feeBits = h.BaseFee.BitLen()
}
return headerSize + common.StorageSize(len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen()+baseFeeBits)/8)
if h.ExcessDataGas != nil {
feeBits += h.ExcessDataGas.BitLen()
}
var withdrawalBytes int
if h.WithdrawalsHash != nil {
withdrawalBytes = common.HashLength
}
return headerSize + common.StorageSize(len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen()+feeBits)/8+withdrawalBytes)
}

// SanityCheck checks a few basic things -- these checks are way beyond what
Expand All @@ -166,6 +173,11 @@ func (h *Header) SanityCheck() error {
return fmt.Errorf("too large base fee: bitlen %d", bfLen)
}
}
if h.ExcessDataGas != nil {
if bfLen := h.ExcessDataGas.BitLen(); bfLen > 256 {
return fmt.Errorf("too large excess data gas: bitlen %d", bfLen)
}
}
return nil
}

Expand Down

0 comments on commit 210ecb7

Please sign in to comment.