Skip to content

Commit 073bad6

Browse files
committed
internal/ethapi: rm error when marshal block to rpc type
1 parent 281e8cd commit 073bad6

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

eth/api_debug.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ type BadBlockArgs struct {
104104
// and returns them as a JSON list of block hashes.
105105
func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error) {
106106
var (
107-
err error
108107
blocks = rawdb.ReadAllBadBlocks(api.eth.chainDb)
109108
results = make([]*BadBlockArgs, 0, len(blocks))
110109
)
@@ -118,9 +117,7 @@ func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error)
118117
} else {
119118
blockRlp = fmt.Sprintf("%#x", rlpBytes)
120119
}
121-
if blockJSON, err = ethapi.RPCMarshalBlock(block, true, true, api.eth.APIBackend.ChainConfig()); err != nil {
122-
blockJSON = map[string]interface{}{"error": err.Error()}
123-
}
120+
blockJSON = ethapi.RPCMarshalBlock(block, true, true, api.eth.APIBackend.ChainConfig())
124121
results = append(results, &BadBlockArgs{
125122
Hash: block.Hash(),
126123
RLP: blockRlp,

internal/ethapi/api.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} {
12811281
// RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are
12821282
// returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain
12831283
// transaction hashes.
1284-
func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig) (map[string]interface{}, error) {
1284+
func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig) map[string]interface{} {
12851285
fields := RPCMarshalHeader(block.Header())
12861286
fields["size"] = hexutil.Uint64(block.Size())
12871287

@@ -1310,7 +1310,7 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param
13101310
if block.Header().WithdrawalsHash != nil {
13111311
fields["withdrawals"] = block.Withdrawals()
13121312
}
1313-
return fields, nil
1313+
return fields
13141314
}
13151315

13161316
// rpcMarshalHeader uses the generalized output filler, then adds the total difficulty field, which requires
@@ -1324,14 +1324,11 @@ func (s *BlockChainAPI) rpcMarshalHeader(ctx context.Context, header *types.Head
13241324
// rpcMarshalBlock uses the generalized output filler, then adds the total difficulty field, which requires
13251325
// a `BlockchainAPI`.
13261326
func (s *BlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
1327-
fields, err := RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig())
1328-
if err != nil {
1329-
return nil, err
1330-
}
1327+
fields := RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig())
13311328
if inclTx {
13321329
fields["totalDifficulty"] = (*hexutil.Big)(s.b.GetTd(ctx, b.Hash()))
13331330
}
1334-
return fields, err
1331+
return fields, nil
13351332
}
13361333

13371334
// RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction

internal/ethapi/api_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -758,11 +758,7 @@ func TestRPCMarshalBlock(t *testing.T) {
758758
}
759759

760760
for i, tc := range testSuite {
761-
resp, err := RPCMarshalBlock(block, tc.inclTx, tc.fullTx, params.MainnetChainConfig)
762-
if err != nil {
763-
t.Errorf("test %d: got error %v", i, err)
764-
continue
765-
}
761+
resp := RPCMarshalBlock(block, tc.inclTx, tc.fullTx, params.MainnetChainConfig)
766762
out, err := json.Marshal(resp)
767763
if err != nil {
768764
t.Errorf("test %d: json marshal error: %v", i, err)

0 commit comments

Comments
 (0)