all: rename BeaconRoot -> ParentBeaconRoot

This commit is contained in:
Felix Lange 2023-08-26 02:49:12 +02:00
parent d51660bcc9
commit 22adccb439
10 changed files with 83 additions and 83 deletions

View file

@ -226,7 +226,7 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash,
WithdrawalsHash: withdrawalsRoot, WithdrawalsHash: withdrawalsRoot,
ExcessBlobGas: params.ExcessBlobGas, ExcessBlobGas: params.ExcessBlobGas,
BlobGasUsed: params.BlobGasUsed, BlobGasUsed: params.BlobGasUsed,
BeaconRoot: beaconRoot, ParentBeaconRoot: beaconRoot,
} }
block := types.NewBlockWithHeader(header).WithBody(txs, nil /* uncles */).WithWithdrawals(params.Withdrawals) block := types.NewBlockWithHeader(header).WithBody(txs, nil /* uncles */).WithWithdrawals(params.Withdrawals)
if block.Hash() != params.BlockHash { if block.Hash() != params.BlockHash {

View file

@ -277,11 +277,11 @@ func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, pa
return fmt.Errorf("invalid excessBlobGas: have %d, expected nil", header.ExcessBlobGas) return fmt.Errorf("invalid excessBlobGas: have %d, expected nil", header.ExcessBlobGas)
case header.BlobGasUsed != nil: case header.BlobGasUsed != nil:
return fmt.Errorf("invalid blobGasUsed: have %d, expected nil", header.BlobGasUsed) return fmt.Errorf("invalid blobGasUsed: have %d, expected nil", header.BlobGasUsed)
case header.BeaconRoot != nil: case header.ParentBeaconRoot != nil:
return fmt.Errorf("invalid beaconRoot, have %#x, expected nil", header.BeaconRoot) return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected nil", header.ParentBeaconRoot)
} }
} else { } else {
if header.BeaconRoot == nil { if header.ParentBeaconRoot == nil {
return errors.New("header is missing beaconRoot") return errors.New("header is missing beaconRoot")
} }
if err := eip4844.VerifyEIP4844Header(parent, header); err != nil { if err := eip4844.VerifyEIP4844Header(parent, header); err != nil {

View file

@ -411,7 +411,7 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.S
excessBlobGas := eip4844.CalcExcessBlobGas(parentExcessBlobGas, parentBlobGasUsed) excessBlobGas := eip4844.CalcExcessBlobGas(parentExcessBlobGas, parentBlobGasUsed)
header.ExcessBlobGas = &excessBlobGas header.ExcessBlobGas = &excessBlobGas
header.BlobGasUsed = new(uint64) header.BlobGasUsed = new(uint64)
header.BeaconRoot = new(common.Hash) header.ParentBeaconRoot = new(common.Hash)
} }
return header return header
} }

View file

@ -486,7 +486,7 @@ func (g *Genesis) ToBlock() *types.Block {
// EIP-4788: The parentBeaconBlockRoot of the genesis block is always // EIP-4788: The parentBeaconBlockRoot of the genesis block is always
// the zero hash. This is because the genesis block does not have a parent // the zero hash. This is because the genesis block does not have a parent
// by definition. // by definition.
head.BeaconRoot = new(common.Hash) head.ParentBeaconRoot = new(common.Hash)
// EIP-4844 fields // EIP-4844 fields
head.ExcessBlobGas = g.ExcessBlobGas head.ExcessBlobGas = g.ExcessBlobGas
head.BlobGasUsed = g.BlobGasUsed head.BlobGasUsed = g.BlobGasUsed

View file

@ -412,7 +412,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
header.BlobGasUsed = &used header.BlobGasUsed = &used
beaconRoot := common.HexToHash("0xbeac00") beaconRoot := common.HexToHash("0xbeac00")
header.BeaconRoot = &beaconRoot header.ParentBeaconRoot = &beaconRoot
} }
// Assemble and return the final block for sealing // Assemble and return the final block for sealing
if config.IsShanghai(header.Number, header.Time) { if config.IsShanghai(header.Number, header.Time) {

View file

@ -91,8 +91,8 @@ type Header struct {
// ExcessBlobGas was added by EIP-4844 and is ignored in legacy headers. // ExcessBlobGas was added by EIP-4844 and is ignored in legacy headers.
ExcessBlobGas *uint64 `json:"excessBlobGas" rlp:"optional"` ExcessBlobGas *uint64 `json:"excessBlobGas" rlp:"optional"`
// BeaconRoot was added by EIP-4788 and is ignored in legacy headers. // ParentBeaconRoot was added by EIP-4788 and is ignored in legacy headers.
BeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"` ParentBeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"`
} }
// field type overrides for gencodec // field type overrides for gencodec
@ -300,9 +300,9 @@ func CopyHeader(h *Header) *Header {
cpy.BlobGasUsed = new(uint64) cpy.BlobGasUsed = new(uint64)
*cpy.BlobGasUsed = *h.BlobGasUsed *cpy.BlobGasUsed = *h.BlobGasUsed
} }
if h.BeaconRoot != nil { if h.ParentBeaconRoot != nil {
cpy.BeaconRoot = new(common.Hash) cpy.ParentBeaconRoot = new(common.Hash)
*cpy.BeaconRoot = *h.BeaconRoot *cpy.ParentBeaconRoot = *h.ParentBeaconRoot
} }
return &cpy return &cpy
} }
@ -383,7 +383,7 @@ func (b *Block) BaseFee() *big.Int {
return new(big.Int).Set(b.header.BaseFee) return new(big.Int).Set(b.header.BaseFee)
} }
func (b *Block) BeaconRoot() *common.Hash { return b.header.BeaconRoot } func (b *Block) BeaconRoot() *common.Hash { return b.header.ParentBeaconRoot }
func (b *Block) ExcessBlobGas() *uint64 { func (b *Block) ExcessBlobGas() *uint64 {
var excessBlobGas *uint64 var excessBlobGas *uint64

View file

@ -35,7 +35,7 @@ func (h Header) MarshalJSON() ([]byte, error) {
WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"` WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"`
BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed" rlp:"optional"` BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed" rlp:"optional"`
ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas" rlp:"optional"` ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas" rlp:"optional"`
BeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"` ParentBeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"`
Hash common.Hash `json:"hash"` Hash common.Hash `json:"hash"`
} }
var enc Header var enc Header
@ -58,7 +58,7 @@ func (h Header) MarshalJSON() ([]byte, error) {
enc.WithdrawalsHash = h.WithdrawalsHash enc.WithdrawalsHash = h.WithdrawalsHash
enc.BlobGasUsed = (*hexutil.Uint64)(h.BlobGasUsed) enc.BlobGasUsed = (*hexutil.Uint64)(h.BlobGasUsed)
enc.ExcessBlobGas = (*hexutil.Uint64)(h.ExcessBlobGas) enc.ExcessBlobGas = (*hexutil.Uint64)(h.ExcessBlobGas)
enc.BeaconRoot = h.BeaconRoot enc.ParentBeaconRoot = h.ParentBeaconRoot
enc.Hash = h.Hash() enc.Hash = h.Hash()
return json.Marshal(&enc) return json.Marshal(&enc)
} }
@ -85,7 +85,7 @@ func (h *Header) UnmarshalJSON(input []byte) error {
WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"` WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"`
BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed" rlp:"optional"` BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed" rlp:"optional"`
ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas" rlp:"optional"` ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas" rlp:"optional"`
BeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"` ParentBeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"`
} }
var dec Header var dec Header
if err := json.Unmarshal(input, &dec); err != nil { if err := json.Unmarshal(input, &dec); err != nil {
@ -160,8 +160,8 @@ func (h *Header) UnmarshalJSON(input []byte) error {
if dec.ExcessBlobGas != nil { if dec.ExcessBlobGas != nil {
h.ExcessBlobGas = (*uint64)(dec.ExcessBlobGas) h.ExcessBlobGas = (*uint64)(dec.ExcessBlobGas)
} }
if dec.BeaconRoot != nil { if dec.ParentBeaconRoot != nil {
h.BeaconRoot = dec.BeaconRoot h.ParentBeaconRoot = dec.ParentBeaconRoot
} }
return nil return nil
} }

View file

@ -44,7 +44,7 @@ func (obj *Header) EncodeRLP(_w io.Writer) error {
_tmp2 := obj.WithdrawalsHash != nil _tmp2 := obj.WithdrawalsHash != nil
_tmp3 := obj.BlobGasUsed != nil _tmp3 := obj.BlobGasUsed != nil
_tmp4 := obj.ExcessBlobGas != nil _tmp4 := obj.ExcessBlobGas != nil
_tmp5 := obj.BeaconRoot != nil _tmp5 := obj.ParentBeaconRoot != nil
if _tmp1 || _tmp2 || _tmp3 || _tmp4 || _tmp5 { if _tmp1 || _tmp2 || _tmp3 || _tmp4 || _tmp5 {
if obj.BaseFee == nil { if obj.BaseFee == nil {
w.Write(rlp.EmptyString) w.Write(rlp.EmptyString)
@ -77,10 +77,10 @@ func (obj *Header) EncodeRLP(_w io.Writer) error {
} }
} }
if _tmp5 { if _tmp5 {
if obj.BeaconRoot == nil { if obj.ParentBeaconRoot == nil {
w.Write([]byte{0x80}) w.Write([]byte{0x80})
} else { } else {
w.WriteBytes(obj.BeaconRoot[:]) w.WriteBytes(obj.ParentBeaconRoot[:])
} }
} }
w.ListEnd(_tmp0) w.ListEnd(_tmp0)

View file

@ -1345,8 +1345,8 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} {
if head.ExcessBlobGas != nil { if head.ExcessBlobGas != nil {
result["excessBlobGas"] = hexutil.Uint64(*head.ExcessBlobGas) result["excessBlobGas"] = hexutil.Uint64(*head.ExcessBlobGas)
} }
if head.BeaconRoot != nil { if head.ParentBeaconRoot != nil {
result["parentBeaconBlockRoot"] = head.BeaconRoot result["parentBeaconBlockRoot"] = head.ParentBeaconRoot
} }
return result return result
} }

View file

@ -947,7 +947,7 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
} }
header.BlobGasUsed = new(uint64) header.BlobGasUsed = new(uint64)
header.ExcessBlobGas = &excessBlobGas header.ExcessBlobGas = &excessBlobGas
header.BeaconRoot = genParams.beaconRoot header.ParentBeaconRoot = genParams.beaconRoot
} }
// Run the consensus preparation with the default or customized consensus engine. // Run the consensus preparation with the default or customized consensus engine.
if err := w.engine.Prepare(w.chain, header); err != nil { if err := w.engine.Prepare(w.chain, header); err != nil {
@ -962,10 +962,10 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
log.Error("Failed to create sealing context", "err", err) log.Error("Failed to create sealing context", "err", err)
return nil, err return nil, err
} }
if header.BeaconRoot != nil { if header.ParentBeaconRoot != nil {
context := core.NewEVMBlockContext(header, w.chain, nil) context := core.NewEVMBlockContext(header, w.chain, nil)
vmenv := vm.NewEVM(context, vm.TxContext{}, env.state, w.chainConfig, vm.Config{}) vmenv := vm.NewEVM(context, vm.TxContext{}, env.state, w.chainConfig, vm.Config{})
core.ProcessBeaconBlockRoot(*header.BeaconRoot, vmenv, env.state) core.ProcessBeaconBlockRoot(*header.ParentBeaconRoot, vmenv, env.state)
} }
return env, nil return env, nil
} }