From 3c557b110b10c905eb2f30fb7f93c03b80f1e61d Mon Sep 17 00:00:00 2001 From: Somnath Banerjee Date: Tue, 3 Dec 2024 23:09:00 +0400 Subject: [PATCH 1/6] Make merge.go append requests --- consensus/merge/merge.go | 14 +++++++------- core/blockchain.go | 1 - 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/consensus/merge/merge.go b/consensus/merge/merge.go index 1151b255549..c6dd5e3d8e6 100644 --- a/consensus/merge/merge.go +++ b/consensus/merge/merge.go @@ -187,7 +187,7 @@ func (s *Merge) Finalize(config *chain.Config, header *types.Header, state *stat var rs types.FlatRequests if config.IsPrague(header.Time) { - rs = make(types.FlatRequests, len(types.KnownRequestTypes)) + rs = make(types.FlatRequests, 0) allLogs := make(types.Logs, 0) for _, rec := range receipts { allLogs = append(allLogs, rec.Logs...) @@ -196,11 +196,11 @@ func (s *Merge) Finalize(config *chain.Config, header *types.Header, state *stat if err != nil { return nil, nil, nil, fmt.Errorf("error: could not parse requests logs: %v", err) } - rs[0] = *depositReqs + rs = append(rs, *depositReqs) withdrawalReq := misc.DequeueWithdrawalRequests7002(syscall) - rs[1] = *withdrawalReq + rs = append(rs, *withdrawalReq) consolidations := misc.DequeueConsolidationRequests7251(syscall) - rs[2] = *consolidations + rs = append(rs, *consolidations) if header.RequestsHash != nil { rh := rs.Hash() if *header.RequestsHash != *rh { @@ -219,15 +219,15 @@ func (s *Merge) FinalizeAndAssemble(config *chain.Config, header *types.Header, return s.eth1Engine.FinalizeAndAssemble(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, call, logger) } header.RequestsHash = nil - outTxs, outReceipts, rs, err := s.Finalize(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, logger) + outTxs, outReceipts, outRequests, err := s.Finalize(config, header, state, txs, uncles, receipts, withdrawals, chain, syscall, logger) if err != nil { return nil, nil, nil, nil, err } if config.IsPrague(header.Time) { - header.RequestsHash = rs.Hash() + header.RequestsHash = outRequests.Hash() } - return types.NewBlockForAsembling(header, outTxs, uncles, outReceipts, withdrawals), outTxs, outReceipts, rs, nil + return types.NewBlockForAsembling(header, outTxs, uncles, outReceipts, withdrawals), outTxs, outReceipts, outRequests, nil } func (s *Merge) SealHash(header *types.Header) (hash libcommon.Hash) { diff --git a/core/blockchain.go b/core/blockchain.go index 8d86276b636..520c473a88d 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -333,7 +333,6 @@ func FinalizeBlockExecution( if isMining { newBlock, newTxs, newReceipt, retRequests, err = engine.FinalizeAndAssemble(cc, header, ibs, txs, uncles, receipts, withdrawals, chainReader, syscall, nil, logger) } else { - // var rss types.Requests newTxs, newReceipt, retRequests, err = engine.Finalize(cc, header, ibs, txs, uncles, receipts, withdrawals, chainReader, syscall, logger) } if err != nil { From fc990665ef273b6e56673ca7259b4da3e5d27580 Mon Sep 17 00:00:00 2001 From: Somnath Banerjee Date: Wed, 4 Dec 2024 00:20:39 +0400 Subject: [PATCH 2/6] Adjust request log in block builder func --- turbo/builder/block_builder.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/turbo/builder/block_builder.go b/turbo/builder/block_builder.go index e28ab22cec2..fda0227d926 100644 --- a/turbo/builder/block_builder.go +++ b/turbo/builder/block_builder.go @@ -17,7 +17,6 @@ package builder import ( - "fmt" "sync" "sync/atomic" "time" @@ -50,11 +49,7 @@ func NewBlockBuilder(build BlockBuilderFunc, param *core.BlockBuilderParameters) log.Warn("Failed to build a block", "err", err) } else { block := result.Block - reqLenStr := "nil" - if len(result.Requests) == 3 { - reqLenStr = fmt.Sprint("Deposit Requests", len(result.Requests[0].RequestData), "Withdrawal Requests", len(result.Requests[1].RequestData), "Consolidation Requests", len(result.Requests[2].RequestData)) - } - log.Info("Built block", "hash", block.Hash(), "height", block.NumberU64(), "txs", len(block.Transactions()), "executionRequests", len(result.Requests), "Requests", reqLenStr, "gas used %", 100*float64(block.GasUsed())/float64(block.GasLimit()), "time", time.Since(t)) + log.Info("Built block", "hash", block.Hash(), "height", block.NumberU64(), "txs", len(block.Transactions()), "executionRequests", len(result.Requests), "gas used %", 100*float64(block.GasUsed())/float64(block.GasLimit()), "time", time.Since(t)) } builder.syncCond.L.Lock() From 4b974c3275fd6897c895292d8f85944a75a24034 Mon Sep 17 00:00:00 2001 From: Somnath Banerjee Date: Wed, 4 Dec 2024 01:01:12 +0400 Subject: [PATCH 3/6] Add empty hash test --- core/types/reqeusts_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 core/types/reqeusts_test.go diff --git a/core/types/reqeusts_test.go b/core/types/reqeusts_test.go new file mode 100644 index 00000000000..7fe7e2f979c --- /dev/null +++ b/core/types/reqeusts_test.go @@ -0,0 +1,37 @@ +// Copyright 2014 The go-ethereum Authors +// (original work) +// Copyright 2024 The Erigon Authors +// (modifications) +// This file is part of Erigon. +// +// Erigon is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Erigon is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with Erigon. If not, see . + +package types + +import ( + "crypto/sha256" + "testing" + + libcommon "github.com/erigontech/erigon-lib/common" +) + +func TestEmptyRequestsHashCalculation(t *testing.T) { + reqs := make(FlatRequests, 0) + h := reqs.Hash() + testHArr := sha256.Sum256([]byte("")) + testH := libcommon.BytesToHash(testHArr[:]) + if *h != testH { + t.Errorf("Requests Hash calculation error for empty hash, expected: %v, got: %v", testH, h) + } +} From 58c804ca4c6ad44a4b2024b177db6b1f008053d4 Mon Sep 17 00:00:00 2001 From: Somnath Banerjee Date: Wed, 4 Dec 2024 01:01:36 +0400 Subject: [PATCH 4/6] Change empty req hash string --- core/types/block.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/types/block.go b/core/types/block.go index 9c5d857f70b..5eda4385cd9 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -42,7 +42,7 @@ import ( var ( EmptyRootHash = libcommon.HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") - EmptyRequestsHash = libcommon.HexToHash("6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f") + EmptyRequestsHash = libcommon.HexToHash("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") EmptyUncleHash = rlpHash([]*Header(nil)) ExtraVanityLength = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity From 66202f5a2566734c4b14ccb442315bb16df6f961 Mon Sep 17 00:00:00 2001 From: Somnath Banerjee Date: Wed, 4 Dec 2024 01:01:59 +0400 Subject: [PATCH 5/6] Remove nil requests from being processed --- consensus/merge/merge.go | 12 +++++++++--- consensus/misc/eip6110.go | 5 ++++- consensus/misc/eip7002.go | 6 +++--- consensus/misc/eip7251.go | 6 +++--- core/types/eip7685_requests.go | 6 +++--- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/consensus/merge/merge.go b/consensus/merge/merge.go index c6dd5e3d8e6..69bd9156639 100644 --- a/consensus/merge/merge.go +++ b/consensus/merge/merge.go @@ -196,11 +196,17 @@ func (s *Merge) Finalize(config *chain.Config, header *types.Header, state *stat if err != nil { return nil, nil, nil, fmt.Errorf("error: could not parse requests logs: %v", err) } - rs = append(rs, *depositReqs) + if depositReqs != nil { + rs = append(rs, *depositReqs) + } withdrawalReq := misc.DequeueWithdrawalRequests7002(syscall) - rs = append(rs, *withdrawalReq) + if withdrawalReq != nil { + rs = append(rs, *withdrawalReq) + } consolidations := misc.DequeueConsolidationRequests7251(syscall) - rs = append(rs, *consolidations) + if consolidations != nil { + rs = append(rs, *consolidations) + } if header.RequestsHash != nil { rh := rs.Hash() if *header.RequestsHash != *rh { diff --git a/consensus/misc/eip6110.go b/consensus/misc/eip6110.go index be2d06ab050..f516fcb1164 100644 --- a/consensus/misc/eip6110.go +++ b/consensus/misc/eip6110.go @@ -85,5 +85,8 @@ func ParseDepositLogs(logs []*types.Log, depositContractAddress libcommon.Addres reqData = append(reqData, d...) } } - return &types.FlatRequest{Type: types.DepositRequestType, RequestData: reqData}, nil + if len(reqData) > 0 { + return &types.FlatRequest{Type: types.DepositRequestType, RequestData: reqData}, nil + } + return nil, nil } diff --git a/consensus/misc/eip7002.go b/consensus/misc/eip7002.go index faa4106c3a1..aa676f18056 100644 --- a/consensus/misc/eip7002.go +++ b/consensus/misc/eip7002.go @@ -29,9 +29,9 @@ func DequeueWithdrawalRequests7002(syscall consensus.SystemCall) *types.FlatRequ log.Warn("Err with syscall to WithdrawalRequestAddress", "err", err) return nil } - if res == nil { - res = make([]byte, 0) + if res != nil { + return &types.FlatRequest{Type: types.WithdrawalRequestType, RequestData: res} } + return nil // Just append the contract outputs - return &types.FlatRequest{Type: types.WithdrawalRequestType, RequestData: res} } diff --git a/consensus/misc/eip7251.go b/consensus/misc/eip7251.go index 3ef606d784c..7ef7cab5306 100644 --- a/consensus/misc/eip7251.go +++ b/consensus/misc/eip7251.go @@ -29,9 +29,9 @@ func DequeueConsolidationRequests7251(syscall consensus.SystemCall) *types.FlatR log.Warn("Err with syscall to ConsolidationRequestAddress", "err", err) return nil } - if res == nil { - res = make([]byte, 0) + if res != nil { + return &types.FlatRequest{Type: types.ConsolidationRequestType, RequestData: res} } + return nil // Just append the contract outputs as the encoded request data - return &types.FlatRequest{Type: types.ConsolidationRequestType, RequestData: res} } diff --git a/core/types/eip7685_requests.go b/core/types/eip7685_requests.go index bb5c31a10ac..a8c1172d1f7 100644 --- a/core/types/eip7685_requests.go +++ b/core/types/eip7685_requests.go @@ -52,12 +52,12 @@ func (f *FlatRequest) copy() *FlatRequest { type FlatRequests []FlatRequest func (r FlatRequests) Hash() *libcommon.Hash { - if r == nil || len(r) < len(KnownRequestTypes) { + if r == nil { return nil } sha := sha256.New() - for i, t := range KnownRequestTypes { - hi := sha256.Sum256(append([]byte{t}, r[i].RequestData...)) + for i, t := range r { + hi := sha256.Sum256(append([]byte{t.Type}, r[i].RequestData...)) sha.Write(hi[:]) } h := libcommon.BytesToHash(sha.Sum(nil)) From efb8ef6ca1c3c3236ca37d8e65e024ea044f4f48 Mon Sep 17 00:00:00 2001 From: Somnath Banerjee Date: Wed, 4 Dec 2024 01:12:15 +0400 Subject: [PATCH 6/6] Update GetAssembled block of EthereumExecutionModule --- turbo/execution/eth1/block_building.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/turbo/execution/eth1/block_building.go b/turbo/execution/eth1/block_building.go index cd8d326ecfb..88916266228 100644 --- a/turbo/execution/eth1/block_building.go +++ b/turbo/execution/eth1/block_building.go @@ -215,21 +215,15 @@ func (e *EthereumExecutionModule) GetAssembledBlock(ctx context.Context, req *ex } } - var requestsBundle types2.RequestsBundle + var requestsBundle *types2.RequestsBundle if blockWithReceipts.Requests != nil { - requests := make([][]byte, len(types.KnownRequestTypes)) - if len(blockWithReceipts.Requests) == len(types.KnownRequestTypes) { - for i, r := range blockWithReceipts.Requests { - requests[i] = make([]byte, 0) - requests[i] = append(requests[i], r.RequestData...) - } - } else { - e.logger.Error("Requests len SHOULD BE", "equal to", len(types.KnownRequestTypes), "got", len(blockWithReceipts.Requests)) - for i := 0; i < len(types.KnownRequestTypes); i++ { - requests[i] = make([]byte, 0) - } + requestsBundle = &types2.RequestsBundle{} + requests := make([][]byte, 0) + for i, r := range blockWithReceipts.Requests { + requests[i] = make([]byte, 0) + requests[i] = append(requests[i], r.RequestData...) } - requestsBundle = types2.RequestsBundle{Requests: requests} + requestsBundle.Requests = requests } return &execution.GetAssembledBlockResponse{ @@ -237,7 +231,7 @@ func (e *EthereumExecutionModule) GetAssembledBlock(ctx context.Context, req *ex ExecutionPayload: payload, BlockValue: gointerfaces.ConvertUint256IntToH256(blockValue), BlobsBundle: blobsBundle, - Requests: &requestsBundle, + Requests: requestsBundle, }, Busy: false, }, nil