From 4b3fe05fe77ccf0583fd7f8058da5fea39c38b25 Mon Sep 17 00:00:00 2001 From: Gus Date: Tue, 11 Sep 2018 13:01:57 -0600 Subject: [PATCH] Removes unsafe package in exchange for binary.Size({} interface) to get the size of Header interface --- core/types/block.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/types/block.go b/core/types/block.go index 8a21bba1e7..9ea3c9f128 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -24,7 +24,6 @@ import ( "sort" "sync/atomic" "time" - "unsafe" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -105,7 +104,8 @@ func (h *Header) Hash() common.Hash { // 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 common.StorageSize(unsafe.Sizeof(*h)) + common.StorageSize(len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen()+h.Time.BitLen())/8) + size := binary.Size(h) + return common.StorageSize(size) + common.StorageSize(len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen()+h.Time.BitLen())/8) } func rlpHash(x interface{}) (h common.Hash) {