Revisit getPayloadBodiesByHash (#8758)

Revisit PR #8750
This commit is contained in:
Andrew Ashikhmin 2023-11-17 13:04:02 +01:00 committed by GitHub
parent f3ce5f8a36
commit d4cd712da0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 21 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -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) {