diff --git a/core/types/block.go b/core/types/block.go index 404edca818..01c723c475 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -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 diff --git a/core/types/header_ext.go b/core/types/header_ext.go index 1e6ebd5bf8..ad83f8ec4b 100644 --- a/core/types/header_ext.go +++ b/core/types/header_ext.go @@ -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) { diff --git a/core/types/header_ext_test.go b/core/types/header_ext_test.go index 97b22237b3..769052a552 100644 --- a/core/types/header_ext_test.go +++ b/core/types/header_ext_test.go @@ -168,4 +168,6 @@ func assertNonZero[T interface { } } +// Note [TestCopyHeader] tests the [HeaderExtra.PostCopy] method. + func ptrTo[T any](x T) *T { return &x } diff --git a/core/types/imports.go b/core/types/imports.go index cc25fa9a8e..e630ea5366 100644 --- a/core/types/imports.go +++ b/core/types/imports.go @@ -51,6 +51,7 @@ const ( var ( BloomLookup = ethtypes.BloomLookup BytesToBloom = ethtypes.BytesToBloom + CopyHeader = ethtypes.CopyHeader CreateBloom = ethtypes.CreateBloom EncodeNonce = ethtypes.EncodeNonce FullAccount = ethtypes.FullAccount