From 22adccb439bb4cb13d9630da08653b27c0b99ac6 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Sat, 26 Aug 2023 02:49:12 +0200 Subject: [PATCH] all: rename BeaconRoot -> ParentBeaconRoot --- beacon/engine/types.go | 38 +++++++-------- consensus/beacon/consensus.go | 6 +-- core/chain_makers.go | 2 +- core/genesis.go | 2 +- core/state_processor_test.go | 2 +- core/types/block.go | 12 ++--- core/types/gen_header_json.go | 88 +++++++++++++++++------------------ core/types/gen_header_rlp.go | 6 +-- internal/ethapi/api.go | 4 +- miner/worker.go | 6 +-- 10 files changed, 83 insertions(+), 83 deletions(-) diff --git a/beacon/engine/types.go b/beacon/engine/types.go index 9d335971d0..2c21b4a85d 100644 --- a/beacon/engine/types.go +++ b/beacon/engine/types.go @@ -208,25 +208,25 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash, withdrawalsRoot = &h } header := &types.Header{ - ParentHash: params.ParentHash, - UncleHash: types.EmptyUncleHash, - Coinbase: params.FeeRecipient, - Root: params.StateRoot, - TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)), - ReceiptHash: params.ReceiptsRoot, - Bloom: types.BytesToBloom(params.LogsBloom), - Difficulty: common.Big0, - Number: new(big.Int).SetUint64(params.Number), - GasLimit: params.GasLimit, - GasUsed: params.GasUsed, - Time: params.Timestamp, - BaseFee: params.BaseFeePerGas, - Extra: params.ExtraData, - MixDigest: params.Random, - WithdrawalsHash: withdrawalsRoot, - ExcessBlobGas: params.ExcessBlobGas, - BlobGasUsed: params.BlobGasUsed, - BeaconRoot: beaconRoot, + ParentHash: params.ParentHash, + UncleHash: types.EmptyUncleHash, + Coinbase: params.FeeRecipient, + Root: params.StateRoot, + TxHash: types.DeriveSha(types.Transactions(txs), trie.NewStackTrie(nil)), + ReceiptHash: params.ReceiptsRoot, + Bloom: types.BytesToBloom(params.LogsBloom), + Difficulty: common.Big0, + Number: new(big.Int).SetUint64(params.Number), + GasLimit: params.GasLimit, + GasUsed: params.GasUsed, + Time: params.Timestamp, + BaseFee: params.BaseFeePerGas, + Extra: params.ExtraData, + MixDigest: params.Random, + WithdrawalsHash: withdrawalsRoot, + ExcessBlobGas: params.ExcessBlobGas, + BlobGasUsed: params.BlobGasUsed, + ParentBeaconRoot: beaconRoot, } block := types.NewBlockWithHeader(header).WithBody(txs, nil /* uncles */).WithWithdrawals(params.Withdrawals) if block.Hash() != params.BlockHash { diff --git a/consensus/beacon/consensus.go b/consensus/beacon/consensus.go index 49dca8f520..e856f4e6ce 100644 --- a/consensus/beacon/consensus.go +++ b/consensus/beacon/consensus.go @@ -277,11 +277,11 @@ func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, pa return fmt.Errorf("invalid excessBlobGas: have %d, expected nil", header.ExcessBlobGas) case header.BlobGasUsed != nil: return fmt.Errorf("invalid blobGasUsed: have %d, expected nil", header.BlobGasUsed) - case header.BeaconRoot != nil: - return fmt.Errorf("invalid beaconRoot, have %#x, expected nil", header.BeaconRoot) + case header.ParentBeaconRoot != nil: + return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected nil", header.ParentBeaconRoot) } } else { - if header.BeaconRoot == nil { + if header.ParentBeaconRoot == nil { return errors.New("header is missing beaconRoot") } if err := eip4844.VerifyEIP4844Header(parent, header); err != nil { diff --git a/core/chain_makers.go b/core/chain_makers.go index 87985849b6..c9c880dd69 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -411,7 +411,7 @@ func makeHeader(chain consensus.ChainReader, parent *types.Block, state *state.S excessBlobGas := eip4844.CalcExcessBlobGas(parentExcessBlobGas, parentBlobGasUsed) header.ExcessBlobGas = &excessBlobGas header.BlobGasUsed = new(uint64) - header.BeaconRoot = new(common.Hash) + header.ParentBeaconRoot = new(common.Hash) } return header } diff --git a/core/genesis.go b/core/genesis.go index dbc60e50c9..86a3e42a62 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -486,7 +486,7 @@ func (g *Genesis) ToBlock() *types.Block { // EIP-4788: The parentBeaconBlockRoot of the genesis block is always // the zero hash. This is because the genesis block does not have a parent // by definition. - head.BeaconRoot = new(common.Hash) + head.ParentBeaconRoot = new(common.Hash) // EIP-4844 fields head.ExcessBlobGas = g.ExcessBlobGas head.BlobGasUsed = g.BlobGasUsed diff --git a/core/state_processor_test.go b/core/state_processor_test.go index 2318a129a0..aade2f6d73 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -412,7 +412,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr header.BlobGasUsed = &used beaconRoot := common.HexToHash("0xbeac00") - header.BeaconRoot = &beaconRoot + header.ParentBeaconRoot = &beaconRoot } // Assemble and return the final block for sealing if config.IsShanghai(header.Number, header.Time) { diff --git a/core/types/block.go b/core/types/block.go index 6f897121df..1a357baa3a 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -91,8 +91,8 @@ type Header struct { // ExcessBlobGas was added by EIP-4844 and is ignored in legacy headers. ExcessBlobGas *uint64 `json:"excessBlobGas" rlp:"optional"` - // BeaconRoot was added by EIP-4788 and is ignored in legacy headers. - BeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"` + // ParentBeaconRoot was added by EIP-4788 and is ignored in legacy headers. + ParentBeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"` } // field type overrides for gencodec @@ -300,9 +300,9 @@ func CopyHeader(h *Header) *Header { cpy.BlobGasUsed = new(uint64) *cpy.BlobGasUsed = *h.BlobGasUsed } - if h.BeaconRoot != nil { - cpy.BeaconRoot = new(common.Hash) - *cpy.BeaconRoot = *h.BeaconRoot + if h.ParentBeaconRoot != nil { + cpy.ParentBeaconRoot = new(common.Hash) + *cpy.ParentBeaconRoot = *h.ParentBeaconRoot } return &cpy } @@ -383,7 +383,7 @@ func (b *Block) BaseFee() *big.Int { 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 { var excessBlobGas *uint64 diff --git a/core/types/gen_header_json.go b/core/types/gen_header_json.go index bd97819f5b..fb1f915d01 100644 --- a/core/types/gen_header_json.go +++ b/core/types/gen_header_json.go @@ -16,27 +16,27 @@ var _ = (*headerMarshaling)(nil) // MarshalJSON marshals as JSON. func (h Header) MarshalJSON() ([]byte, error) { type Header struct { - ParentHash common.Hash `json:"parentHash" gencodec:"required"` - UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"` - Coinbase common.Address `json:"miner"` - Root common.Hash `json:"stateRoot" gencodec:"required"` - TxHash common.Hash `json:"transactionsRoot" gencodec:"required"` - ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"` - Bloom Bloom `json:"logsBloom" gencodec:"required"` - Difficulty *hexutil.Big `json:"difficulty" gencodec:"required"` - Number *hexutil.Big `json:"number" gencodec:"required"` - GasLimit hexutil.Uint64 `json:"gasLimit" gencodec:"required"` - GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"` - Time hexutil.Uint64 `json:"timestamp" gencodec:"required"` - Extra hexutil.Bytes `json:"extraData" gencodec:"required"` - MixDigest common.Hash `json:"mixHash"` - Nonce BlockNonce `json:"nonce"` - BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` - WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"` - BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed" rlp:"optional"` - ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas" rlp:"optional"` - BeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"` - Hash common.Hash `json:"hash"` + ParentHash common.Hash `json:"parentHash" gencodec:"required"` + UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"` + Coinbase common.Address `json:"miner"` + Root common.Hash `json:"stateRoot" gencodec:"required"` + TxHash common.Hash `json:"transactionsRoot" gencodec:"required"` + ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"` + Bloom Bloom `json:"logsBloom" gencodec:"required"` + Difficulty *hexutil.Big `json:"difficulty" gencodec:"required"` + Number *hexutil.Big `json:"number" gencodec:"required"` + GasLimit hexutil.Uint64 `json:"gasLimit" gencodec:"required"` + GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"` + Time hexutil.Uint64 `json:"timestamp" gencodec:"required"` + Extra hexutil.Bytes `json:"extraData" gencodec:"required"` + MixDigest common.Hash `json:"mixHash"` + Nonce BlockNonce `json:"nonce"` + BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` + WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"` + BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed" rlp:"optional"` + ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas" rlp:"optional"` + ParentBeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"` + Hash common.Hash `json:"hash"` } var enc Header enc.ParentHash = h.ParentHash @@ -58,7 +58,7 @@ func (h Header) MarshalJSON() ([]byte, error) { enc.WithdrawalsHash = h.WithdrawalsHash enc.BlobGasUsed = (*hexutil.Uint64)(h.BlobGasUsed) enc.ExcessBlobGas = (*hexutil.Uint64)(h.ExcessBlobGas) - enc.BeaconRoot = h.BeaconRoot + enc.ParentBeaconRoot = h.ParentBeaconRoot enc.Hash = h.Hash() return json.Marshal(&enc) } @@ -66,26 +66,26 @@ func (h Header) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshals from JSON. func (h *Header) UnmarshalJSON(input []byte) error { type Header struct { - ParentHash *common.Hash `json:"parentHash" gencodec:"required"` - UncleHash *common.Hash `json:"sha3Uncles" gencodec:"required"` - Coinbase *common.Address `json:"miner"` - Root *common.Hash `json:"stateRoot" gencodec:"required"` - TxHash *common.Hash `json:"transactionsRoot" gencodec:"required"` - ReceiptHash *common.Hash `json:"receiptsRoot" gencodec:"required"` - Bloom *Bloom `json:"logsBloom" gencodec:"required"` - Difficulty *hexutil.Big `json:"difficulty" gencodec:"required"` - Number *hexutil.Big `json:"number" gencodec:"required"` - GasLimit *hexutil.Uint64 `json:"gasLimit" gencodec:"required"` - GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"` - Time *hexutil.Uint64 `json:"timestamp" gencodec:"required"` - Extra *hexutil.Bytes `json:"extraData" gencodec:"required"` - MixDigest *common.Hash `json:"mixHash"` - Nonce *BlockNonce `json:"nonce"` - BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` - WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"` - BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed" rlp:"optional"` - ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas" rlp:"optional"` - BeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"` + ParentHash *common.Hash `json:"parentHash" gencodec:"required"` + UncleHash *common.Hash `json:"sha3Uncles" gencodec:"required"` + Coinbase *common.Address `json:"miner"` + Root *common.Hash `json:"stateRoot" gencodec:"required"` + TxHash *common.Hash `json:"transactionsRoot" gencodec:"required"` + ReceiptHash *common.Hash `json:"receiptsRoot" gencodec:"required"` + Bloom *Bloom `json:"logsBloom" gencodec:"required"` + Difficulty *hexutil.Big `json:"difficulty" gencodec:"required"` + Number *hexutil.Big `json:"number" gencodec:"required"` + GasLimit *hexutil.Uint64 `json:"gasLimit" gencodec:"required"` + GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"` + Time *hexutil.Uint64 `json:"timestamp" gencodec:"required"` + Extra *hexutil.Bytes `json:"extraData" gencodec:"required"` + MixDigest *common.Hash `json:"mixHash"` + Nonce *BlockNonce `json:"nonce"` + BaseFee *hexutil.Big `json:"baseFeePerGas" rlp:"optional"` + WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"` + BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed" rlp:"optional"` + ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas" rlp:"optional"` + ParentBeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"` } var dec Header if err := json.Unmarshal(input, &dec); err != nil { @@ -160,8 +160,8 @@ func (h *Header) UnmarshalJSON(input []byte) error { if dec.ExcessBlobGas != nil { h.ExcessBlobGas = (*uint64)(dec.ExcessBlobGas) } - if dec.BeaconRoot != nil { - h.BeaconRoot = dec.BeaconRoot + if dec.ParentBeaconRoot != nil { + h.ParentBeaconRoot = dec.ParentBeaconRoot } return nil } diff --git a/core/types/gen_header_rlp.go b/core/types/gen_header_rlp.go index 62e585bffb..b91a255a55 100644 --- a/core/types/gen_header_rlp.go +++ b/core/types/gen_header_rlp.go @@ -44,7 +44,7 @@ func (obj *Header) EncodeRLP(_w io.Writer) error { _tmp2 := obj.WithdrawalsHash != nil _tmp3 := obj.BlobGasUsed != nil _tmp4 := obj.ExcessBlobGas != nil - _tmp5 := obj.BeaconRoot != nil + _tmp5 := obj.ParentBeaconRoot != nil if _tmp1 || _tmp2 || _tmp3 || _tmp4 || _tmp5 { if obj.BaseFee == nil { w.Write(rlp.EmptyString) @@ -77,10 +77,10 @@ func (obj *Header) EncodeRLP(_w io.Writer) error { } } if _tmp5 { - if obj.BeaconRoot == nil { + if obj.ParentBeaconRoot == nil { w.Write([]byte{0x80}) } else { - w.WriteBytes(obj.BeaconRoot[:]) + w.WriteBytes(obj.ParentBeaconRoot[:]) } } w.ListEnd(_tmp0) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 9416216f8d..ceef482e7c 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1345,8 +1345,8 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} { if head.ExcessBlobGas != nil { result["excessBlobGas"] = hexutil.Uint64(*head.ExcessBlobGas) } - if head.BeaconRoot != nil { - result["parentBeaconBlockRoot"] = head.BeaconRoot + if head.ParentBeaconRoot != nil { + result["parentBeaconBlockRoot"] = head.ParentBeaconRoot } return result } diff --git a/miner/worker.go b/miner/worker.go index c3c9fe027d..711149232b 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -947,7 +947,7 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) { } header.BlobGasUsed = new(uint64) header.ExcessBlobGas = &excessBlobGas - header.BeaconRoot = genParams.beaconRoot + header.ParentBeaconRoot = genParams.beaconRoot } // Run the consensus preparation with the default or customized consensus engine. 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) return nil, err } - if header.BeaconRoot != nil { + if header.ParentBeaconRoot != nil { context := core.NewEVMBlockContext(header, w.chain, nil) 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 }