Skip to content

Commit 42179f7

Browse files
authored
Revert "internal/ethapi: remove error return on RPCMarshalBlock (ethereum#27449)"
This reverts commit e2e4193.
1 parent 1c38dbe commit 42179f7

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

eth/api_debug.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ 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
107108
blocks = rawdb.ReadAllBadBlocks(api.eth.chainDb)
108109
results = make([]*BadBlockArgs, 0, len(blocks))
109110
)
@@ -117,7 +118,9 @@ func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error)
117118
} else {
118119
blockRlp = fmt.Sprintf("%#x", rlpBytes)
119120
}
120-
blockJSON = ethapi.RPCMarshalBlock(block, true, true, api.eth.APIBackend.ChainConfig())
121+
if blockJSON, err = ethapi.RPCMarshalBlock(block, true, true, api.eth.APIBackend.ChainConfig()); err != nil {
122+
blockJSON = map[string]interface{}{"error": err.Error()}
123+
}
121124
results = append(results, &BadBlockArgs{
122125
Hash: block.Hash(),
123126
RLP: blockRlp,

internal/ethapi/api.go

Lines changed: 7 additions & 4 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{} {
1284+
func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig) (map[string]interface{}, error) {
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
1313+
return fields, nil
13141314
}
13151315

13161316
// rpcMarshalHeader uses the generalized output filler, then adds the total difficulty field, which requires
@@ -1324,11 +1324,14 @@ 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 := RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig())
1327+
fields, err := RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig())
1328+
if err != nil {
1329+
return nil, err
1330+
}
13281331
if inclTx {
13291332
fields["totalDifficulty"] = (*hexutil.Big)(s.b.GetTd(ctx, b.Hash()))
13301333
}
1331-
return fields, nil
1334+
return fields, err
13321335
}
13331336

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

internal/ethapi/api_test.go

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

760760
for i, tc := range testSuite {
761-
resp := RPCMarshalBlock(block, tc.inclTx, tc.fullTx, params.MainnetChainConfig)
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+
}
762766
out, err := json.Marshal(resp)
763767
if err != nil {
764768
t.Errorf("test %d: json marshal error: %v", i, err)

0 commit comments

Comments
 (0)