Skip to content

Commit 2b686c4

Browse files
committed
feat(core/types): header copy hooks
1 parent e2b0abb commit 2b686c4

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

core/types/block.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ func NewBlockWithWithdrawals(header *Header, txs []*Transaction, uncles []*Heade
277277
return b.WithWithdrawals(withdrawals)
278278
}
279279

280-
// CopyHeader creates a deep copy of a block header.
281-
func CopyHeader(h *Header) *Header {
280+
func copyHeader(h *Header) *Header {
282281
cpy := *h
283282
if cpy.Difficulty = new(big.Int); h.Difficulty != nil {
284283
cpy.Difficulty.Set(h.Difficulty)

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
@@ -108,3 +109,12 @@ func (*NOOPHeaderHooks) DecodeRLP(h *Header, s *rlp.Stream) error {
108109
type withoutMethods Header
109110
return s.Decode((*withoutMethods)(h))
110111
}
112+
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+
}

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(h *Header) *Header {
79+
return h
80+
}
81+
7882
func TestHeaderHooks(t *testing.T) {
7983
TestOnlyClearRegisteredExtras()
8084
defer TestOnlyClearRegisteredExtras()

0 commit comments

Comments
 (0)