Skip to content

Commit 0a85fe1

Browse files
committed
Header Copy hooks
1 parent 8e7cc54 commit 0a85fe1

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

core/types/block.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,7 @@ func NewBlockWithWithdrawals(header *Header, txs []*Transaction, uncles []*Heade
281281
return b.WithWithdrawals(withdrawals)
282282
}
283283

284-
// CopyHeader creates a deep copy of a block header.
285-
func CopyHeader(h *Header) *Header {
284+
func copyHeader(h *Header) *Header {
286285
cpy := *h
287286
if cpy.Difficulty = new(big.Int); h.Difficulty != nil {
288287
cpy.Difficulty.Set(h.Difficulty)
@@ -313,9 +312,6 @@ func CopyHeader(h *Header) *Header {
313312
cpy.ParentBeaconRoot = new(common.Hash)
314313
*cpy.ParentBeaconRoot = *h.ParentBeaconRoot
315314
}
316-
if h.extra != nil {
317-
cpy.extra = h.extra
318-
}
319315
return &cpy
320316
}
321317

core/types/block.libevm.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type HeaderHooks interface {
3232
UnmarshalJSON(*Header, []byte) error //nolint:govet
3333
EncodeRLP(*Header, io.Writer) error
3434
DecodeRLP(*Header, *rlp.Stream) error
35+
Copy(*Header) *Header
3536
}
3637

3738
// hooks returns the Header's registered HeaderHooks, if any, otherwise a
@@ -109,6 +110,15 @@ func (*NOOPHeaderHooks) DecodeRLP(h *Header, s *rlp.Stream) error {
109110
return s.Decode((*withoutMethods)(h))
110111
}
111112

113+
func (n *NOOPHeaderHooks) Copy(h *Header) *Header {
114+
return copyHeader(h)
115+
}
116+
117+
// CopyHeader creates a deep copy of a block header.
118+
func CopyHeader(h *Header) *Header {
119+
return h.hooks().Copy(h)
120+
}
121+
112122
// BlockHooks are required for all types registered with [RegisterExtras] for
113123
// [Block] payloads.
114124
type BlockHooks interface {

core/types/block.libevm_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ func (hh *stubHeaderHooks) DecodeRLP(h *Header, s *rlp.Stream) error {
7575
return hh.errDecode
7676
}
7777

78+
func (hh *stubHeaderHooks) Copy(*Header) *Header {
79+
return nil
80+
}
81+
7882
type stubBlockHooks struct {
7983
suffix []byte
8084
gotRawRLPToDecode []byte

0 commit comments

Comments
 (0)