diff --git a/core/types/block.go b/core/types/block.go index 8c136ef8a445..0706f5283814 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -281,8 +281,7 @@ func NewBlockWithWithdrawals(header *Header, txs []*Transaction, uncles []*Heade return b.WithWithdrawals(withdrawals) } -// CopyHeader creates a deep copy of a block header. -func CopyHeader(h *Header) *Header { +func copyHeader(h *Header) *Header { cpy := *h if cpy.Difficulty = new(big.Int); h.Difficulty != nil { cpy.Difficulty.Set(h.Difficulty) @@ -313,9 +312,6 @@ func CopyHeader(h *Header) *Header { cpy.ParentBeaconRoot = new(common.Hash) *cpy.ParentBeaconRoot = *h.ParentBeaconRoot } - if h.extra != nil { - cpy.extra = h.extra - } return &cpy } diff --git a/core/types/block.libevm.go b/core/types/block.libevm.go index 7ec55d708199..4d8f26cf0279 100644 --- a/core/types/block.libevm.go +++ b/core/types/block.libevm.go @@ -32,6 +32,7 @@ type HeaderHooks interface { UnmarshalJSON(*Header, []byte) error //nolint:govet EncodeRLP(*Header, io.Writer) error DecodeRLP(*Header, *rlp.Stream) error + Copy(*Header) *Header } // hooks returns the Header's registered HeaderHooks, if any, otherwise a @@ -109,6 +110,15 @@ func (*NOOPHeaderHooks) DecodeRLP(h *Header, s *rlp.Stream) error { return s.Decode((*withoutMethods)(h)) } +func (n *NOOPHeaderHooks) Copy(h *Header) *Header { + return copyHeader(h) +} + +// CopyHeader creates a deep copy of a block header. +func CopyHeader(h *Header) *Header { + return h.hooks().Copy(h) +} + // BlockHooks are required for all types registered with [RegisterExtras] for // [Block] payloads. type BlockHooks interface { diff --git a/core/types/block.libevm_test.go b/core/types/block.libevm_test.go index 5bb9ae6c4424..a011e9d7c459 100644 --- a/core/types/block.libevm_test.go +++ b/core/types/block.libevm_test.go @@ -75,6 +75,10 @@ func (hh *stubHeaderHooks) DecodeRLP(h *Header, s *rlp.Stream) error { return hh.errDecode } +func (hh *stubHeaderHooks) Copy(*Header) *Header { + return nil +} + type stubBlockHooks struct { suffix []byte gotRawRLPToDecode []byte