Skip to content

Commit 48e2b3c

Browse files
committed
Move to a PostCopy hook 🎉
1 parent 9c69d61 commit 48e2b3c

File tree

3 files changed

+6
-15
lines changed

3 files changed

+6
-15
lines changed

core/types/block.go

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

280-
// CopyEthHeader creates a deep copy of an Ethereum block header.
281-
// Use [CopyHeader] instead if your header has any registered extra.
282-
func CopyEthHeader(h *Header) *Header {
280+
// CopyHeader creates a deep copy of a block header.
281+
func CopyHeader(h *Header) *Header {
283282
cpy := *h
284283
if cpy.Difficulty = new(big.Int); h.Difficulty != nil {
285284
cpy.Difficulty.Set(h.Difficulty)
@@ -310,6 +309,7 @@ func CopyEthHeader(h *Header) *Header {
310309
cpy.ParentBeaconRoot = new(common.Hash)
311310
*cpy.ParentBeaconRoot = *h.ParentBeaconRoot
312311
}
312+
h.hooks().PostCopy(&cpy, h)
313313
return &cpy
314314
}
315315

core/types/block.libevm.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +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
35+
PostCopy(dst, src *Header)
3636
}
3737

3838
// hooks returns the Header's registered HeaderHooks, if any, otherwise a
@@ -110,11 +110,4 @@ func (*NOOPHeaderHooks) DecodeRLP(h *Header, s *rlp.Stream) error {
110110
return s.Decode((*withoutMethods)(h))
111111
}
112112

113-
func (n *NOOPHeaderHooks) Copy(h *Header) *Header {
114-
return CopyEthHeader(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-
}
113+
func (n *NOOPHeaderHooks) PostCopy(dst, src *Header) {}

core/types/block.libevm_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ 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-
}
78+
func (hh *stubHeaderHooks) PostCopy(dst, src *Header) {}
8179

8280
func TestHeaderHooks(t *testing.T) {
8381
TestOnlyClearRegisteredExtras()

0 commit comments

Comments
 (0)