Skip to content

Commit

Permalink
Rename requestsRoot to requestsHash in block header (#12369)
Browse files Browse the repository at this point in the history
Header data will contain this different name now

Ref: ethereum/EIPs#8924
Issue board: #12106
  • Loading branch information
somnathb1 authored Oct 22, 2024
1 parent 8f3b14d commit 21562b6
Show file tree
Hide file tree
Showing 22 changed files with 94 additions and 94 deletions.
2 changes: 1 addition & 1 deletion cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type stEnv struct {
Withdrawals []*types.Withdrawal `json:"withdrawals,omitempty"`
WithdrawalsHash *libcommon.Hash `json:"withdrawalsRoot,omitempty"`
Requests types.Requests `json:"requests,omitempty"`
RequestsRoot *libcommon.Hash `json:"requestsRoot,omitempty"`
RequestsHash *libcommon.Hash `json:"requestsHash,omitempty"`
}

type stEnvMarshaling struct {
Expand Down
10 changes: 5 additions & 5 deletions cmd/evm/internal/t8ntool/gen_stenv.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ func NewHeader(env stEnv) *types.Header {

header.UncleHash = env.UncleHash
header.WithdrawalsHash = env.WithdrawalsHash
header.RequestsRoot = env.RequestsRoot
header.RequestsHash = env.RequestsHash

return &header
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/clique/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (c *Clique) verifyHeader(chain consensus.ChainHeaderReader, header *types.H
return consensus.ErrUnexpectedWithdrawals
}

if header.RequestsRoot != nil {
if header.RequestsHash != nil {
return consensus.ErrUnexpectedRequests
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func VerifyHeaderBasics(chain consensus.ChainHeaderReader, header, parent *types
return consensus.ErrUnexpectedWithdrawals
}

if header.RequestsRoot != nil {
if header.RequestsHash != nil {
return consensus.ErrUnexpectedRequests
}

Expand Down
16 changes: 8 additions & 8 deletions consensus/merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ func (s *Merge) Finalize(config *chain.Config, header *types.Header, state *stat
rs = append(rs, withdrawalReqs...)
consolidations := misc.DequeueConsolidationRequests7251(syscall)
rs = append(rs, consolidations...)
if requestsInBlock != nil || header.RequestsRoot != nil {
if requestsInBlock != nil || header.RequestsHash != nil {
rh := types.DeriveSha(rs)
if *header.RequestsRoot != rh {
return nil, nil, nil, fmt.Errorf("error: invalid requests root hash in header, expected: %v, got :%v", header.RequestsRoot, rh)
if *header.RequestsHash != rh {
return nil, nil, nil, fmt.Errorf("error: invalid requests root hash in header, expected: %v, got :%v", header.RequestsHash, rh)
}
if !reflect.DeepEqual(requestsInBlock.Deposits(), depositReqs.Deposits()) {
return nil, nil, nil, errors.New("error: invalid EIP-6110 Deposit Requests in block")
Expand All @@ -228,7 +228,7 @@ func (s *Merge) FinalizeAndAssemble(config *chain.Config, header *types.Header,
if !misc.IsPoSHeader(header) {
return s.eth1Engine.FinalizeAndAssemble(config, header, state, txs, uncles, receipts, withdrawals, requests, chain, syscall, call, logger)
}
header.RequestsRoot = nil
header.RequestsHash = nil
outTxs, outReceipts, rs, err := s.Finalize(config, header, state, txs, uncles, receipts, withdrawals, requests, chain, syscall, logger)
if err != nil {
return nil, nil, nil, err
Expand Down Expand Up @@ -318,12 +318,12 @@ func (s *Merge) verifyHeader(chain consensus.ChainHeaderReader, header, parent *
return fmt.Errorf("invalid excessBlobGas: have %d, want %d", *header.ExcessBlobGas, expectedExcessBlobGas)
}

// Verify existence / non-existence of requestsRoot
// Verify existence / non-existence of requestsHash
prague := chain.Config().IsPrague(header.Time)
if prague && header.RequestsRoot == nil {
return errors.New("missing requestsRoot")
if prague && header.RequestsHash == nil {
return errors.New("missing requestsHash")
}
if !prague && header.RequestsRoot != nil {
if !prague && header.RequestsHash != nil {
return consensus.ErrUnexpectedRequests
}

Expand Down
8 changes: 4 additions & 4 deletions core/genesis_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func GenesisToBlock(g *types.Genesis, dirs datadir.Dirs, logger log.Logger) (*ty
ExcessBlobGas: g.ExcessBlobGas,
AuRaStep: g.AuRaStep,
AuRaSeal: g.AuRaSeal,
RequestsRoot: g.RequestsRoot,
RequestsHash: g.RequestsHash,
}
if g.GasLimit == 0 {
head.GasLimit = params.GenesisGasLimit
Expand Down Expand Up @@ -491,10 +491,10 @@ func GenesisToBlock(g *types.Genesis, dirs datadir.Dirs, logger log.Logger) (*ty
requests = types.Requests{}

// TODO @somnathb1 - if later iterations and/or tests don't need this from genesis.json, remove the following
if g.RequestsRoot != nil {
head.RequestsRoot = g.RequestsRoot
if g.RequestsHash != nil {
head.RequestsHash = g.RequestsHash
} else {
head.RequestsRoot = &types.EmptyRootHash
head.RequestsHash = &types.EmptyRootHash
}
}

Expand Down
46 changes: 23 additions & 23 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type Header struct {

ParentBeaconBlockRoot *libcommon.Hash `json:"parentBeaconBlockRoot"` // EIP-4788

RequestsRoot *libcommon.Hash `json:"requestsRoot"` // EIP-7685
RequestsHash *libcommon.Hash `json:"requestsHash"` // EIP-7685

// The verkle proof is ignored in legacy headers
Verkle bool
Expand Down Expand Up @@ -179,7 +179,7 @@ func (h *Header) EncodingSize() int {
encodingSize += 33
}

if h.RequestsRoot != nil {
if h.RequestsHash != nil {
encodingSize += 33
}

Expand Down Expand Up @@ -332,12 +332,12 @@ func (h *Header) EncodeRLP(w io.Writer) error {
}
}

if h.RequestsRoot != nil {
if h.RequestsHash != nil {
b[0] = 128 + 32
if _, err := w.Write(b[:1]); err != nil {
return err
}
if _, err := w.Write(h.RequestsRoot.Bytes()); err != nil {
if _, err := w.Write(h.RequestsHash.Bytes()); err != nil {
return err
}
}
Expand Down Expand Up @@ -530,22 +530,22 @@ func (h *Header) DecodeRLP(s *rlp.Stream) error {
h.ParentBeaconBlockRoot = new(libcommon.Hash)
h.ParentBeaconBlockRoot.SetBytes(b)

// RequestsRoot
// RequestsHash
if b, err = s.Bytes(); err != nil {
if errors.Is(err, rlp.EOL) {
h.RequestsRoot = nil
h.RequestsHash = nil
if err := s.ListEnd(); err != nil {
return fmt.Errorf("close header struct (no RequestsRoot): %w", err)
return fmt.Errorf("close header struct (no RequestsHash): %w", err)
}
return nil
}
return fmt.Errorf("read RequestsRoot: %w", err)
return fmt.Errorf("read RequestsHash: %w", err)
}
if len(b) != 32 {
return fmt.Errorf("wrong size for RequestsRoot: %d", len(b))
return fmt.Errorf("wrong size for RequestsHash: %d", len(b))
}
h.RequestsRoot = new(libcommon.Hash)
h.RequestsRoot.SetBytes(b)
h.RequestsHash = new(libcommon.Hash)
h.RequestsHash.SetBytes(b)

if h.Verkle {
if h.VerkleProof, err = s.Bytes(); err != nil {
Expand Down Expand Up @@ -615,7 +615,7 @@ func (h *Header) Size() common.StorageSize {
if h.ParentBeaconBlockRoot != nil {
s += common.StorageSize(32)
}
if h.RequestsRoot != nil {
if h.RequestsHash != nil {
s += common.StorageSize(32)
}
return s
Expand Down Expand Up @@ -1100,13 +1100,13 @@ func NewBlock(header *Header, txs []Transaction, uncles []*Header, receipts []*R
b.header.ParentBeaconBlockRoot = header.ParentBeaconBlockRoot

if requests == nil {
b.header.RequestsRoot = nil
b.header.RequestsHash = nil
} else if len(requests) == 0 {
b.header.RequestsRoot = &EmptyRootHash
b.header.RequestsHash = &EmptyRootHash
b.requests = make(Requests, len(requests))
} else {
h := DeriveSha(requests)
b.header.RequestsRoot = &h
b.header.RequestsHash = &h
b.requests = make(Requests, len(requests))
for i, r := range requests {
rCopy := r.copy()
Expand Down Expand Up @@ -1190,9 +1190,9 @@ func CopyHeader(h *Header) *Header {
cpy.ParentBeaconBlockRoot = new(libcommon.Hash)
cpy.ParentBeaconBlockRoot.SetBytes(h.ParentBeaconBlockRoot.Bytes())
}
if h.RequestsRoot != nil {
cpy.RequestsRoot = new(libcommon.Hash)
cpy.RequestsRoot.SetBytes(h.RequestsRoot.Bytes())
if h.RequestsHash != nil {
cpy.RequestsHash = new(libcommon.Hash)
cpy.RequestsHash.SetBytes(h.RequestsHash.Bytes())
}
cpy.mutable = h.mutable
if hash := h.hash.Load(); hash != nil {
Expand Down Expand Up @@ -1344,7 +1344,7 @@ func (b *Block) BaseFee() *big.Int {
func (b *Block) WithdrawalsHash() *libcommon.Hash { return b.header.WithdrawalsHash }
func (b *Block) Withdrawals() Withdrawals { return b.withdrawals }
func (b *Block) ParentBeaconBlockRoot() *libcommon.Hash { return b.header.ParentBeaconBlockRoot }
func (b *Block) RequestsRoot() *libcommon.Hash { return b.header.RequestsRoot }
func (b *Block) RequestsHash() *libcommon.Hash { return b.header.RequestsHash }
func (b *Block) Requests() Requests { return b.requests }

// Header returns a deep-copy of the entire block header using CopyHeader()
Expand Down Expand Up @@ -1448,15 +1448,15 @@ func (b *Block) HashCheck(fullCheck bool) error {
return fmt.Errorf("block has invalid withdrawals hash: have %x, exp: %x", hash, b.WithdrawalsHash())
}

if b.RequestsRoot() == nil {
if b.RequestsHash() == nil {
if b.Requests() != nil {
return errors.New("header missing RequestsRoot")
return errors.New("header missing RequestsHash")
}
return nil
}

if hash := DeriveSha(b.Requests()); hash != *b.RequestsRoot() {
return fmt.Errorf("block has invalid requests root: have %x, exp: %x", hash, b.RequestsRoot())
if hash := DeriveSha(b.Requests()); hash != *b.RequestsHash() {
return fmt.Errorf("block has invalid requests root: have %x, exp: %x", hash, b.RequestsHash())
}

return nil
Expand Down
10 changes: 5 additions & 5 deletions core/types/gen_genesis.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions core/types/gen_header_json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type Genesis struct {
BlobGasUsed *uint64 `json:"blobGasUsed"` // EIP-4844
ExcessBlobGas *uint64 `json:"excessBlobGas"` // EIP-4844
ParentBeaconBlockRoot *common.Hash `json:"parentBeaconBlockRoot"` // EIP-4788
RequestsRoot *common.Hash `json:"requestsRoot"` // EIP-7685
RequestsHash *common.Hash `json:"requestsHash"` // EIP-7685
}

// GenesisAlloc specifies the initial state that is part of the genesis block.
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.0

require (
github.com/erigontech/erigon-snapshot v1.3.1-0.20240814160410-2ce37904b978
github.com/erigontech/interfaces v0.0.0-20241011102608-29c1d07f457d
github.com/erigontech/interfaces v0.0.0-20241018125732-814767d1b926
github.com/erigontech/mdbx-go v0.38.4
github.com/erigontech/secp256k1 v1.1.0
github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417
Expand Down
4 changes: 2 additions & 2 deletions erigon-lib/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/erigontech/erigon-snapshot v1.3.1-0.20240814160410-2ce37904b978 h1:7ECOf7Us3+/706WGZXIX84qQc6zmxQby8fGbFLiqFlU=
github.com/erigontech/erigon-snapshot v1.3.1-0.20240814160410-2ce37904b978/go.mod h1:ooHlCl+eEYzebiPu+FP6Q6SpPUeMADn8Jxabv3IKb9M=
github.com/erigontech/interfaces v0.0.0-20241011102608-29c1d07f457d h1:T0xEfGinQBrv1aV2WdIQCBoCPOn2CKKH5hi35o/V0m8=
github.com/erigontech/interfaces v0.0.0-20241011102608-29c1d07f457d/go.mod h1:N7OUkhkcagp9+7yb4ycHsG2VWCOmuJ1ONBecJshxtLE=
github.com/erigontech/interfaces v0.0.0-20241018125732-814767d1b926 h1:2H5vOO4LT+P0oB82f4AEK7AK+1QJYUL9VNz2KEvqknI=
github.com/erigontech/interfaces v0.0.0-20241018125732-814767d1b926/go.mod h1:N7OUkhkcagp9+7yb4ycHsG2VWCOmuJ1ONBecJshxtLE=
github.com/erigontech/mdbx-go v0.38.4 h1:S9T7mTe9KPcFe4dOoOtVdI6gPzht9y7wMnYfUBgrQLo=
github.com/erigontech/mdbx-go v0.38.4/go.mod h1:IcOLQDPw3VM/asP6T5JVPPN4FHHgJtY16XfYjzWKVNI=
github.com/erigontech/secp256k1 v1.1.0 h1:mO3YJMUSoASE15Ya//SoHiisptUhdXExuMUN1M0X9qY=
Expand Down
Loading

0 comments on commit 21562b6

Please sign in to comment.