Skip to content

Commit 3de1bc8

Browse files
qdm12ARR4N
andcommitted
chore(core/types): Header libevm PostCopy hook
- Implement `PostCopy` header hook - Remove `CopyHeader` and use imported one from libevm See original PR ava-labs/coreth#759 Signed-off-by: Quentin McGaw <[email protected]> Co-authored-by: Arran Schlosberg <[email protected]>
1 parent 722d13c commit 3de1bc8

File tree

4 files changed

+8
-43
lines changed

4 files changed

+8
-43
lines changed

core/types/block.go

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -118,48 +118,6 @@ func NewBlock(
118118
return b
119119
}
120120

121-
// CopyHeader creates a deep copy of a block header.
122-
func CopyHeader(h *Header) *Header {
123-
cpy := *h
124-
hExtra := GetHeaderExtra(h)
125-
cpyExtra := &HeaderExtra{}
126-
SetHeaderExtra(&cpy, cpyExtra)
127-
128-
if cpy.Difficulty = new(big.Int); h.Difficulty != nil {
129-
cpy.Difficulty.Set(h.Difficulty)
130-
}
131-
if cpy.Number = new(big.Int); h.Number != nil {
132-
cpy.Number.Set(h.Number)
133-
}
134-
if h.BaseFee != nil {
135-
cpy.BaseFee = new(big.Int).Set(h.BaseFee)
136-
}
137-
if hExtra.BlockGasCost != nil {
138-
cpyExtra.BlockGasCost = new(big.Int).Set(hExtra.BlockGasCost)
139-
}
140-
if len(h.Extra) > 0 {
141-
cpy.Extra = make([]byte, len(h.Extra))
142-
copy(cpy.Extra, h.Extra)
143-
}
144-
if h.WithdrawalsHash != nil {
145-
cpy.WithdrawalsHash = new(common.Hash)
146-
*cpy.WithdrawalsHash = *h.WithdrawalsHash
147-
}
148-
if h.ExcessBlobGas != nil {
149-
cpy.ExcessBlobGas = new(uint64)
150-
*cpy.ExcessBlobGas = *h.ExcessBlobGas
151-
}
152-
if h.BlobGasUsed != nil {
153-
cpy.BlobGasUsed = new(uint64)
154-
*cpy.BlobGasUsed = *h.BlobGasUsed
155-
}
156-
if h.ParentBeaconRoot != nil {
157-
cpy.ParentBeaconRoot = new(common.Hash)
158-
*cpy.ParentBeaconRoot = *h.ParentBeaconRoot
159-
}
160-
return &cpy
161-
}
162-
163121
// DecodeRLP decodes a block from RLP.
164122
func (b *Block) DecodeRLP(s *rlp.Stream) error {
165123
var eb extblock

core/types/header_ext.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ func (h *HeaderExtra) DecodeJSON(eth *ethtypes.Header, input []byte) error {
8282
}
8383

8484
func (h *HeaderExtra) PostCopy(dst *ethtypes.Header) {
85-
panic("not implemented")
85+
cp := &HeaderExtra{}
86+
if h.BlockGasCost != nil {
87+
cp.BlockGasCost = new(big.Int).Set(h.BlockGasCost)
88+
}
89+
SetHeaderExtra(dst, cp)
8690
}
8791

8892
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
@@ -177,4 +177,6 @@ func assertNonZero[T interface {
177177
}
178178
}
179179

180+
// Note [TestCopyHeader] tests the [HeaderExtra.PostCopy] method.
181+
180182
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
@@ -52,6 +52,7 @@ const (
5252
var (
5353
BloomLookup = ethtypes.BloomLookup
5454
BytesToBloom = ethtypes.BytesToBloom
55+
CopyHeader = ethtypes.CopyHeader
5556
CreateBloom = ethtypes.CreateBloom
5657
EncodeNonce = ethtypes.EncodeNonce
5758
FullAccount = ethtypes.FullAccount

0 commit comments

Comments
 (0)