Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,53 +126,6 @@ func NewBlock(
return b
}

// CopyHeader creates a deep copy of a block header.
func CopyHeader(h *Header) *Header {
cpy := *h
hExtra := GetHeaderExtra(h)
cpyExtra := &HeaderExtra{
ExtDataHash: hExtra.ExtDataHash,
}
SetHeaderExtra(&cpy, cpyExtra)

if cpy.Difficulty = new(big.Int); h.Difficulty != nil {
cpy.Difficulty.Set(h.Difficulty)
}
if cpy.Number = new(big.Int); h.Number != nil {
cpy.Number.Set(h.Number)
}
if h.BaseFee != nil {
cpy.BaseFee = new(big.Int).Set(h.BaseFee)
}
if hExtra.ExtDataGasUsed != nil {
cpyExtra.ExtDataGasUsed = new(big.Int).Set(hExtra.ExtDataGasUsed)
}
if hExtra.BlockGasCost != nil {
cpyExtra.BlockGasCost = new(big.Int).Set(hExtra.BlockGasCost)
}
if len(h.Extra) > 0 {
cpy.Extra = make([]byte, len(h.Extra))
copy(cpy.Extra, h.Extra)
}
if h.WithdrawalsHash != nil {
cpy.WithdrawalsHash = new(common.Hash)
*cpy.WithdrawalsHash = *h.WithdrawalsHash
}
if h.ExcessBlobGas != nil {
cpy.ExcessBlobGas = new(uint64)
*cpy.ExcessBlobGas = *h.ExcessBlobGas
}
if h.BlobGasUsed != nil {
cpy.BlobGasUsed = new(uint64)
*cpy.BlobGasUsed = *h.BlobGasUsed
}
if h.ParentBeaconRoot != nil {
cpy.ParentBeaconRoot = new(common.Hash)
*cpy.ParentBeaconRoot = *h.ParentBeaconRoot
}
return &cpy
}

// DecodeRLP decodes a block from RLP.
func (b *Block) DecodeRLP(s *rlp.Stream) error {
var eb extblock
Expand Down
11 changes: 10 additions & 1 deletion core/types/header_ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,16 @@ func (h *HeaderExtra) DecodeJSON(eth *ethtypes.Header, input []byte) error {
}

func (h *HeaderExtra) PostCopy(dst *ethtypes.Header) {
panic("not implemented")
cp := &HeaderExtra{
ExtDataHash: h.ExtDataHash,
}
if h.BlockGasCost != nil {
cp.BlockGasCost = new(big.Int).Set(h.BlockGasCost)
}
if h.ExtDataGasUsed != nil {
cp.ExtDataGasUsed = new(big.Int).Set(h.ExtDataGasUsed)
}
SetHeaderExtra(dst, cp)
}

func (h *HeaderSerializable) updateFromEth(eth *ethtypes.Header) {
Expand Down
2 changes: 2 additions & 0 deletions core/types/header_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,6 @@ func assertNonZero[T interface {
}
}

// Note [TestCopyHeader] tests the [HeaderExtra.PostCopy] method.

func ptrTo[T any](x T) *T { return &x }
1 change: 1 addition & 0 deletions core/types/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
var (
BloomLookup = ethtypes.BloomLookup
BytesToBloom = ethtypes.BytesToBloom
CopyHeader = ethtypes.CopyHeader
CreateBloom = ethtypes.CreateBloom
EncodeNonce = ethtypes.EncodeNonce
FullAccount = ethtypes.FullAccount
Expand Down
Loading