Skip to content

Commit

Permalink
chore(core/types): header PostCopy hook
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Feb 12, 2025
1 parent e0537f8 commit 783edc9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 48 deletions.
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,
}
cpy = *WithHeaderExtra(&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
16 changes: 15 additions & 1 deletion core/types/header_ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,21 @@ func (h *HeaderExtra) DecodeJSON(eth *ethtypes.Header, input []byte) error {
}

func (h *HeaderExtra) PostCopy(dst *ethtypes.Header) {
panic("not implemented")
extraCopy := &HeaderExtra{
ExtDataHash: h.ExtDataHash,
}

if h.BlockGasCost != nil {
extraCopy.BlockGasCost = big.NewInt(0)
extraCopy.BlockGasCost.SetBytes(h.BlockGasCost.Bytes())
}

if h.ExtDataGasUsed != nil {
extraCopy.ExtDataGasUsed = big.NewInt(0)
extraCopy.ExtDataGasUsed.SetBytes(h.ExtDataGasUsed.Bytes())
}

_ = WithHeaderExtra(dst, extraCopy)
}

func (h *HeaderSerializable) updateFromEth(eth *ethtypes.Header) {
Expand Down
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

0 comments on commit 783edc9

Please sign in to comment.