Skip to content

Commit ecc2c2c

Browse files
committed
internal/ethapi: remove error return value of RPCMarshalBlock ethereum#27449
1 parent 3d7084a commit ecc2c2c

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

eth/api_debug.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ type BadBlockArgs struct {
9090
// and returns them as a JSON list of block-hashes
9191
func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error) {
9292
var (
93-
err error
9493
blocks = rawdb.ReadAllBadBlocks(api.eth.chainDb)
9594
results = make([]*BadBlockArgs, 0, len(blocks))
9695
)
@@ -104,9 +103,7 @@ func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error)
104103
} else {
105104
blockRlp = fmt.Sprintf("%#x", rlpBytes)
106105
}
107-
if blockJSON, err = ethapi.RPCMarshalBlock(block, true, true, api.eth.ApiBackend.ChainConfig()); err != nil {
108-
blockJSON = map[string]interface{}{"error": err.Error()}
109-
}
106+
blockJSON = ethapi.RPCMarshalBlock(block, true, true, api.eth.ApiBackend.ChainConfig())
110107
results = append(results, &BadBlockArgs{
111108
Hash: block.Hash(),
112109
RLP: blockRlp,

internal/ethapi/api.go

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

@@ -1469,18 +1469,17 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param
14691469
uncleHashes[i] = uncle.Hash()
14701470
}
14711471
fields["uncles"] = uncleHashes
1472-
return fields, nil
1472+
return fields
14731473
}
14741474

14751475
// rpcMarshalBlock uses the generalized output filler, then adds the total difficulty field, which requires
14761476
// a `BlockChainAPI`.
14771477
func (s *BlockChainAPI) rpcMarshalBlock(b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
1478-
fields, err := RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig())
1479-
if err != nil {
1480-
return nil, err
1478+
fields := RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig())
1479+
if inclTx {
1480+
fields["totalDifficulty"] = (*hexutil.Big)(s.b.GetTd(context.Background(), b.Hash()))
14811481
}
1482-
fields["totalDifficulty"] = (*hexutil.Big)(s.b.GetTd(context.Background(), b.Hash()))
1483-
return fields, err
1482+
return fields, nil
14841483
}
14851484

14861485
// findNearestSignedBlock finds the nearest checkpoint from input block

internal/ethapi/api_test.go

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

112112
for i, tc := range testSuite {
113-
resp, err := RPCMarshalBlock(block, tc.inclTx, tc.fullTx, params.MainnetChainConfig)
114-
if err != nil {
115-
t.Errorf("test %d: got error %v", i, err)
116-
continue
117-
}
113+
resp := RPCMarshalBlock(block, tc.inclTx, tc.fullTx, params.MainnetChainConfig)
118114
out, err := json.Marshal(resp)
119115
if err != nil {
120116
t.Errorf("test %d: json marshal error: %v", i, err)

0 commit comments

Comments
 (0)