From d4cd712da0a7f540b361f45052f8bc8b76e83d29 Mon Sep 17 00:00:00 2001 From: Andrew Ashikhmin <34320705+yperbasis@users.noreply.github.com> Date: Fri, 17 Nov 2023 13:04:02 +0100 Subject: [PATCH] Revisit getPayloadBodiesByHash (#8758) Revisit PR #8750 --- .../execution_client_direct.go | 5 ++-- turbo/engineapi/engine_server.go | 24 +++++++++++-------- .../eth1/eth1_chain_reader.go/chain_reader.go | 14 +++++------ 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/cl/phase1/execution_client/execution_client_direct.go b/cl/phase1/execution_client/execution_client_direct.go index 1d817dfca..9f8eb1f50 100644 --- a/cl/phase1/execution_client/execution_client_direct.go +++ b/cl/phase1/execution_client/execution_client_direct.go @@ -88,13 +88,12 @@ func (cc *ExecutionClientDirect) Ready() (bool, error) { // GetBodiesByRange gets block bodies in given block range func (cc *ExecutionClientDirect) GetBodiesByRange(start, count uint64) ([]*types.RawBody, error) { - return cc.chainRW.GetBodiesByRange(start, count), nil - + return cc.chainRW.GetBodiesByRange(start, count) } // GetBodiesByHashes gets block bodies with given hashes func (cc *ExecutionClientDirect) GetBodiesByHashes(hashes []libcommon.Hash) ([]*types.RawBody, error) { - return cc.chainRW.GetBodiesByHases(hashes), nil + return cc.chainRW.GetBodiesByHashes(hashes) } func (cc *ExecutionClientDirect) FrozenBlocks() uint64 { diff --git a/turbo/engineapi/engine_server.go b/turbo/engineapi/engine_server.go index 7aaf120ac..ccb013f9c 100644 --- a/turbo/engineapi/engine_server.go +++ b/turbo/engineapi/engine_server.go @@ -534,13 +534,15 @@ func (s *EngineServer) forkchoiceUpdated(ctx context.Context, forkchoiceState *e } func (s *EngineServer) getPayloadBodiesByHash(ctx context.Context, request []libcommon.Hash, _ clparams.StateVersion) ([]*engine_types.ExecutionPayloadBodyV1, error) { - bodies := s.chainRW.GetBodiesByHases(request) - - resp := make([]*engine_types.ExecutionPayloadBodyV1, 0, len(request)) - for idx := range request { - resp = append(resp, extractPayloadBodyFromBody(bodies[idx])) + bodies, err := s.chainRW.GetBodiesByHashes(request) + if err != nil { + return nil, err } + resp := make([]*engine_types.ExecutionPayloadBodyV1, len(bodies)) + for idx, body := range bodies { + resp[idx] = extractPayloadBodyFromBody(body) + } return resp, nil } @@ -558,13 +560,15 @@ func extractPayloadBodyFromBody(body *types.RawBody) *engine_types.ExecutionPayl } func (s *EngineServer) getPayloadBodiesByRange(ctx context.Context, start, count uint64, _ clparams.StateVersion) ([]*engine_types.ExecutionPayloadBodyV1, error) { - bodies := s.chainRW.GetBodiesByRange(start, count) - - resp := make([]*engine_types.ExecutionPayloadBodyV1, len(bodies)) - for idx := range bodies { - resp[idx] = extractPayloadBodyFromBody(bodies[idx]) + bodies, err := s.chainRW.GetBodiesByRange(start, count) + if err != nil { + return nil, err } + resp := make([]*engine_types.ExecutionPayloadBodyV1, len(bodies)) + for idx, body := range bodies { + resp[idx] = extractPayloadBodyFromBody(body) + } return resp, nil } diff --git a/turbo/execution/eth1/eth1_chain_reader.go/chain_reader.go b/turbo/execution/eth1/eth1_chain_reader.go/chain_reader.go index c538c2802..756352b7d 100644 --- a/turbo/execution/eth1/eth1_chain_reader.go/chain_reader.go +++ b/turbo/execution/eth1/eth1_chain_reader.go/chain_reader.go @@ -182,7 +182,7 @@ func (c ChainReaderWriterEth1) GetTd(hash libcommon.Hash, number uint64) *big.In return eth1_utils.ConvertBigIntFromRpc(resp.Td) } -func (c ChainReaderWriterEth1) GetBodiesByHases(hashes []libcommon.Hash) []*types.RawBody { +func (c ChainReaderWriterEth1) GetBodiesByHashes(hashes []libcommon.Hash) ([]*types.RawBody, error) { grpcHashes := make([]*types2.H256, len(hashes)) for i := range grpcHashes { grpcHashes[i] = gointerfaces.ConvertHashToH256(hashes[i]) @@ -191,30 +191,28 @@ func (c ChainReaderWriterEth1) GetBodiesByHases(hashes []libcommon.Hash) []*type Hashes: grpcHashes, }) if err != nil { - log.Error("GetBodiesByHases failed", "err", err) - return nil + return nil, err } ret := make([]*types.RawBody, len(resp.Bodies)) for i := range ret { ret[i] = eth1_utils.ConvertRawBlockBodyFromRpc(resp.Bodies[i]) } - return ret + return ret, nil } -func (c ChainReaderWriterEth1) GetBodiesByRange(start, count uint64) []*types.RawBody { +func (c ChainReaderWriterEth1) GetBodiesByRange(start, count uint64) ([]*types.RawBody, error) { resp, err := c.executionModule.GetBodiesByRange(c.ctx, &execution.GetBodiesByRangeRequest{ Start: start, Count: count, }) if err != nil { - log.Error("GetBodiesByHases failed", "err", err) - return nil + return nil, err } ret := make([]*types.RawBody, len(resp.Bodies)) for i := range ret { ret[i] = eth1_utils.ConvertRawBlockBodyFromRpc(resp.Bodies[i]) } - return ret + return ret, nil } func (c ChainReaderWriterEth1) Ready() (bool, error) {