Skip to content

Commit

Permalink
Rename requestsRoot to requestsHash in block header (#12460)
Browse files Browse the repository at this point in the history
Cherry pick #12369 into `release/2.61`

Co-authored-by: Somnath <[email protected]>
  • Loading branch information
yperbasis and somnathb1 authored Oct 24, 2024
1 parent 4a2b0b5 commit 34d42e1
Show file tree
Hide file tree
Showing 22 changed files with 98 additions and 98 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 @@ -62,7 +62,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 @@ -606,7 +606,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 @@ -81,7 +81,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 @@ -249,7 +249,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 @@ -177,10 +177,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, fmt.Errorf("error: invalid EIP-6110 Deposit Requests in block")
Expand All @@ -204,7 +204,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 @@ -294,12 +294,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 fmt.Errorf("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 @@ -508,7 +508,7 @@ func GenesisToBlock(g *types.Genesis, tmpDir string, logger log.Logger) (*types.
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 @@ -552,10 +552,10 @@ func GenesisToBlock(g *types.Genesis, tmpDir string, logger log.Logger) (*types.
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 @@ -105,7 +105,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 @@ -163,7 +163,7 @@ func (h *Header) EncodingSize() int {
encodingSize += 33
}

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

Expand Down Expand Up @@ -316,12 +316,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 @@ -514,22 +514,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 @@ -590,7 +590,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 @@ -1041,13 +1041,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 @@ -1123,9 +1123,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())
}
return &cpy
}
Expand Down Expand Up @@ -1272,7 +1272,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 @@ -1371,15 +1371,15 @@ func (b *Block) HashCheck() 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 @@ -65,7 +65,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 @@ -5,7 +5,7 @@ go 1.22.0
require (
github.com/erigontech/mdbx-go v0.27.24
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20240805114253-42da880260bb
github.com/ledgerwatch/interfaces v0.0.0-20241024121018-582714adcf8a
github.com/ledgerwatch/interfaces v0.0.0-20241024124715-46d0f9679d5f
github.com/ledgerwatch/log/v3 v3.9.0
github.com/ledgerwatch/secp256k1 v1.0.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 @@ -270,8 +270,8 @@ github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20240805114253-42da880260bb h1:bsoVxjnQGxhOODRmkdrbkRTB9+sIduguoNMSZPRRoTI=
github.com/ledgerwatch/erigon-snapshot v1.3.1-0.20240805114253-42da880260bb/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/interfaces v0.0.0-20241024121018-582714adcf8a h1:2TsvVKrqykfCypZEqpG1ZphBu8wvmRgQsKGS+JQXhdg=
github.com/ledgerwatch/interfaces v0.0.0-20241024121018-582714adcf8a/go.mod h1:ugQv1QllJzBny3cKZKxUrSnykkjkBgm27eQM6dnGAcc=
github.com/ledgerwatch/interfaces v0.0.0-20241024124715-46d0f9679d5f h1:NCKhl9//nyPnWMDQySbusjctWyLjHj0WR+gtsEwcHgE=
github.com/ledgerwatch/interfaces v0.0.0-20241024124715-46d0f9679d5f/go.mod h1:ugQv1QllJzBny3cKZKxUrSnykkjkBgm27eQM6dnGAcc=
github.com/ledgerwatch/log/v3 v3.9.0 h1:iDwrXe0PVwBC68Dd94YSsHbMgQ3ufsgjzXtFNFVZFRk=
github.com/ledgerwatch/log/v3 v3.9.0/go.mod h1:EiAY6upmI/6LkNhOVxb4eVsmsP11HZCnZ3PlJMjYiqE=
github.com/ledgerwatch/secp256k1 v1.0.0 h1:Usvz87YoTG0uePIV8woOof5cQnLXGYa162rFf3YnwaQ=
Expand Down
Loading

0 comments on commit 34d42e1

Please sign in to comment.