From 7bea014f1a88bb44829f9a8647734c8aa0626d18 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Mon, 29 Sep 2025 16:33:19 +0800 Subject: [PATCH] internal/ethapi: remove error return value of RPCMarshalBlock #27449 --- eth/api_debug.go | 5 +---- internal/ethapi/api.go | 11 ++++------- internal/ethapi/api_test.go | 6 +----- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/eth/api_debug.go b/eth/api_debug.go index 6b233317a9ad..22c1b0655d72 100644 --- a/eth/api_debug.go +++ b/eth/api_debug.go @@ -90,7 +90,6 @@ type BadBlockArgs struct { // and returns them as a JSON list of block-hashes func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error) { var ( - err error blocks = rawdb.ReadAllBadBlocks(api.eth.chainDb) results = make([]*BadBlockArgs, 0, len(blocks)) ) @@ -104,9 +103,7 @@ func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error) } else { blockRlp = fmt.Sprintf("%#x", rlpBytes) } - if blockJSON, err = ethapi.RPCMarshalBlock(block, true, true, api.eth.ApiBackend.ChainConfig()); err != nil { - blockJSON = map[string]interface{}{"error": err.Error()} - } + blockJSON = ethapi.RPCMarshalBlock(block, true, true, api.eth.ApiBackend.ChainConfig()) results = append(results, &BadBlockArgs{ Hash: block.Hash(), RLP: blockRlp, diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index ce617c271c1a..dcf48f138c55 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1340,7 +1340,7 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} { // RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are // returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain // transaction hashes. -func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig) (map[string]interface{}, error) { +func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig) map[string]interface{} { fields := RPCMarshalHeader(block.Header()) fields["size"] = hexutil.Uint64(block.Size()) @@ -1366,20 +1366,17 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param uncleHashes[i] = uncle.Hash() } fields["uncles"] = uncleHashes - return fields, nil + return fields } // rpcMarshalBlock uses the generalized output filler, then adds the total difficulty field, which requires // a `BlockChainAPI`. func (api *BlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) { - fields, err := RPCMarshalBlock(b, inclTx, fullTx, api.b.ChainConfig()) - if err != nil { - return nil, err - } + fields := RPCMarshalBlock(b, inclTx, fullTx, api.b.ChainConfig()) if inclTx { fields["totalDifficulty"] = (*hexutil.Big)(api.b.GetTd(ctx, b.Hash())) } - return fields, err + return fields, nil } // findNearestSignedBlock finds the nearest checkpoint from input block diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 10831b5b81e5..8f5eb95b4e35 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -110,11 +110,7 @@ func TestRPCMarshalBlock(t *testing.T) { } for i, tc := range testSuite { - resp, err := RPCMarshalBlock(block, tc.inclTx, tc.fullTx, params.MainnetChainConfig) - if err != nil { - t.Errorf("test %d: got error %v", i, err) - continue - } + resp := RPCMarshalBlock(block, tc.inclTx, tc.fullTx, params.MainnetChainConfig) out, err := json.Marshal(resp) if err != nil { t.Errorf("test %d: json marshal error: %v", i, err)