Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit 3593f92

Browse files
committed
chore(core/types): header PostCopy hook
1 parent ccca4fa commit 3593f92

File tree

3 files changed

+16
-46
lines changed

3 files changed

+16
-46
lines changed

core/types/block.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -126,49 +126,6 @@ func NewBlock(
126126
return b
127127
}
128128

129-
// CopyHeader creates a deep copy of a block header.
130-
func CopyHeader(h *Header) *Header {
131-
cpy := *h
132-
hExtra := GetHeaderExtra(h)
133-
cpyExtra := &HeaderExtra{
134-
ExtDataHash: hExtra.ExtDataHash,
135-
}
136-
cpy = *WithHeaderExtra(&cpy, cpyExtra)
137-
138-
if cpy.Difficulty = new(big.Int); h.Difficulty != nil {
139-
cpy.Difficulty.Set(h.Difficulty)
140-
}
141-
if cpy.Number = new(big.Int); h.Number != nil {
142-
cpy.Number.Set(h.Number)
143-
}
144-
if h.BaseFee != nil {
145-
cpy.BaseFee = new(big.Int).Set(h.BaseFee)
146-
}
147-
if hExtra.ExtDataGasUsed != nil {
148-
cpyExtra.ExtDataGasUsed = new(big.Int).Set(hExtra.ExtDataGasUsed)
149-
}
150-
if hExtra.BlockGasCost != nil {
151-
cpyExtra.BlockGasCost = new(big.Int).Set(hExtra.BlockGasCost)
152-
}
153-
if len(h.Extra) > 0 {
154-
cpy.Extra = make([]byte, len(h.Extra))
155-
copy(cpy.Extra, h.Extra)
156-
}
157-
if h.ExcessBlobGas != nil {
158-
cpy.ExcessBlobGas = new(uint64)
159-
*cpy.ExcessBlobGas = *h.ExcessBlobGas
160-
}
161-
if h.BlobGasUsed != nil {
162-
cpy.BlobGasUsed = new(uint64)
163-
*cpy.BlobGasUsed = *h.BlobGasUsed
164-
}
165-
if h.ParentBeaconRoot != nil {
166-
cpy.ParentBeaconRoot = new(common.Hash)
167-
*cpy.ParentBeaconRoot = *h.ParentBeaconRoot
168-
}
169-
return &cpy
170-
}
171-
172129
// DecodeRLP decodes a block from RLP.
173130
func (b *Block) DecodeRLP(s *rlp.Stream) error {
174131
var eb extblock

core/types/header_ext.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,21 @@ func (h *HeaderExtra) UnmarshalJSON(eth *ethtypes.Header, input []byte) error {
7575
}
7676

7777
func (h *HeaderExtra) PostCopy(dst *ethtypes.Header) {
78-
panic("not implemented")
78+
extraCopy := &HeaderExtra{
79+
ExtDataHash: h.ExtDataHash,
80+
}
81+
82+
if h.BlockGasCost != nil {
83+
extraCopy.BlockGasCost = big.NewInt(0)
84+
extraCopy.BlockGasCost.SetBytes(h.BlockGasCost.Bytes())
85+
}
86+
87+
if h.ExtDataGasUsed != nil {
88+
extraCopy.ExtDataGasUsed = big.NewInt(0)
89+
extraCopy.ExtDataGasUsed.SetBytes(h.ExtDataGasUsed.Bytes())
90+
}
91+
92+
_ = WithHeaderExtra(dst, extraCopy)
7993
}
8094

8195
func (h *HeaderSerializable) updateFromEth(eth *ethtypes.Header) {
@@ -134,7 +148,6 @@ func (h *HeaderSerializable) updateToExtras(extras *HeaderExtra) {
134148
extras.BlockGasCost = h.BlockGasCost
135149
}
136150

137-
138151
//go:generate go run github.com/fjl/gencodec -type HeaderSerializable -field-override headerMarshaling -out gen_header_json.go
139152
//go:generate go run github.com/ava-labs/libevm/rlp/rlpgen -type HeaderSerializable -out gen_header_rlp.go
140153

@@ -204,4 +217,3 @@ type headerMarshaling struct {
204217
func (h *HeaderSerializable) Hash() common.Hash {
205218
return rlpHash(h)
206219
}
207-

core/types/imports.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const (
5151
var (
5252
BloomLookup = ethtypes.BloomLookup
5353
BytesToBloom = ethtypes.BytesToBloom
54+
CopyHeader = ethtypes.CopyHeader
5455
CreateBloom = ethtypes.CreateBloom
5556
EncodeNonce = ethtypes.EncodeNonce
5657
FullAccount = ethtypes.FullAccount

0 commit comments

Comments
 (0)