Skip to content

Commit 44a2447

Browse files
qdm12ARR4N
andauthored
chore(core/types): Header libevm PostCopy hook (5) (#759)
- Implement `PostCopy` header hook - Remove `CopyHeader` and use imported one from libevm Signed-off-by: Quentin McGaw <[email protected]> Co-authored-by: Arran Schlosberg <[email protected]>
1 parent 0657877 commit 44a2447

File tree

4 files changed

+13
-48
lines changed

4 files changed

+13
-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-
SetHeaderExtra(&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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,16 @@ func (h *HeaderExtra) DecodeJSON(eth *ethtypes.Header, input []byte) error {
8484
}
8585

8686
func (h *HeaderExtra) PostCopy(dst *ethtypes.Header) {
87-
panic("not implemented")
87+
cp := &HeaderExtra{
88+
ExtDataHash: h.ExtDataHash,
89+
}
90+
if h.BlockGasCost != nil {
91+
cp.BlockGasCost = new(big.Int).Set(h.BlockGasCost)
92+
}
93+
if h.ExtDataGasUsed != nil {
94+
cp.ExtDataGasUsed = new(big.Int).Set(h.ExtDataGasUsed)
95+
}
96+
SetHeaderExtra(dst, cp)
8897
}
8998

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

core/types/header_ext_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,6 @@ func assertNonZero[T interface {
168168
}
169169
}
170170

171+
// Note [TestCopyHeader] tests the [HeaderExtra.PostCopy] method.
172+
171173
func ptrTo[T any](x T) *T { return &x }

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)