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

Commit 39d3c84

Browse files
committed
chore(core/types): header PostCopy hook
1 parent 22d5be0 commit 39d3c84

File tree

3 files changed

+16
-48
lines changed

3 files changed

+16
-48
lines changed

core/types/block.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -126,53 +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.WithdrawalsHash != nil {
158-
cpy.WithdrawalsHash = new(common.Hash)
159-
*cpy.WithdrawalsHash = *h.WithdrawalsHash
160-
}
161-
if h.ExcessBlobGas != nil {
162-
cpy.ExcessBlobGas = new(uint64)
163-
*cpy.ExcessBlobGas = *h.ExcessBlobGas
164-
}
165-
if h.BlobGasUsed != nil {
166-
cpy.BlobGasUsed = new(uint64)
167-
*cpy.BlobGasUsed = *h.BlobGasUsed
168-
}
169-
if h.ParentBeaconRoot != nil {
170-
cpy.ParentBeaconRoot = new(common.Hash)
171-
*cpy.ParentBeaconRoot = *h.ParentBeaconRoot
172-
}
173-
return &cpy
174-
}
175-
176129
// DecodeRLP decodes a block from RLP.
177130
func (b *Block) DecodeRLP(s *rlp.Stream) error {
178131
var eb extblock

core/types/header_ext.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,21 @@ func (h *HeaderExtra) DecodeJSON(eth *ethtypes.Header, input []byte) error {
8686
}
8787

8888
func (h *HeaderExtra) PostCopy(dst *ethtypes.Header) {
89-
panic("not implemented")
89+
extraCopy := &HeaderExtra{
90+
ExtDataHash: h.ExtDataHash,
91+
}
92+
93+
if h.BlockGasCost != nil {
94+
extraCopy.BlockGasCost = big.NewInt(0)
95+
extraCopy.BlockGasCost.SetBytes(h.BlockGasCost.Bytes())
96+
}
97+
98+
if h.ExtDataGasUsed != nil {
99+
extraCopy.ExtDataGasUsed = big.NewInt(0)
100+
extraCopy.ExtDataGasUsed.SetBytes(h.ExtDataGasUsed.Bytes())
101+
}
102+
103+
_ = WithHeaderExtra(dst, extraCopy)
90104
}
91105

92106
func (h *HeaderSerializable) updateFromEth(eth *ethtypes.Header) {

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)