Skip to content

Commit

Permalink
Move to a PostCopy hook 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Jan 31, 2025
1 parent b9e5186 commit f8a0ea3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
6 changes: 3 additions & 3 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,8 @@ func NewBlockWithWithdrawals(header *Header, txs []*Transaction, uncles []*Heade
return b.WithWithdrawals(withdrawals)
}

// CopyEthHeader creates a deep copy of an Ethereum block header.
// Use [CopyHeader] instead if your header has any registered extra.
func CopyEthHeader(h *Header) *Header {
// CopyHeader creates a deep copy of a block header.
func CopyHeader(h *Header) *Header {
cpy := *h
if cpy.Difficulty = new(big.Int); h.Difficulty != nil {
cpy.Difficulty.Set(h.Difficulty)
Expand Down Expand Up @@ -310,6 +309,7 @@ func CopyEthHeader(h *Header) *Header {
cpy.ParentBeaconRoot = new(common.Hash)
*cpy.ParentBeaconRoot = *h.ParentBeaconRoot
}
h.hooks().PostCopy(&cpy, h)
return &cpy
}

Expand Down
11 changes: 2 additions & 9 deletions core/types/block.libevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type HeaderHooks interface {
UnmarshalJSON(*Header, []byte) error //nolint:govet
EncodeRLP(*Header, io.Writer) error
DecodeRLP(*Header, *rlp.Stream) error
Copy(*Header) *Header
PostCopy(dst, src *Header)
}

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

func (n *NOOPHeaderHooks) Copy(h *Header) *Header {
return CopyEthHeader(h)
}

// CopyHeader creates a deep copy of a block header.
func CopyHeader(h *Header) *Header {
return h.hooks().Copy(h)
}
func (n *NOOPHeaderHooks) PostCopy(dst, src *Header) {}
4 changes: 1 addition & 3 deletions core/types/block.libevm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ func (hh *stubHeaderHooks) DecodeRLP(h *Header, s *rlp.Stream) error {
return hh.errDecode
}

func (hh *stubHeaderHooks) Copy(h *Header) *Header {
return h
}
func (hh *stubHeaderHooks) PostCopy(dst, src *Header) {}

func TestHeaderHooks(t *testing.T) {
TestOnlyClearRegisteredExtras()
Expand Down

0 comments on commit f8a0ea3

Please sign in to comment.