Revert "internal/ethapi: remove error return on RPCMarshalBlock (#27449)"

This reverts commit e2e4193003.
This commit is contained in:
devopsbo3 2023-11-10 12:27:53 -06:00 committed by GitHub
parent eb0e6eb73a
commit 33e614b4ab
3 changed files with 16 additions and 6 deletions

View file

@ -104,6 +104,7 @@ type BadBlockArgs struct {
// and returns them as a JSON list of block hashes. // and returns them as a JSON list of block hashes.
func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error) { func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error) {
var ( var (
err error
blocks = rawdb.ReadAllBadBlocks(api.eth.chainDb) blocks = rawdb.ReadAllBadBlocks(api.eth.chainDb)
results = make([]*BadBlockArgs, 0, len(blocks)) results = make([]*BadBlockArgs, 0, len(blocks))
) )
@ -117,7 +118,9 @@ func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error)
} else { } else {
blockRlp = fmt.Sprintf("%#x", rlpBytes) blockRlp = fmt.Sprintf("%#x", rlpBytes)
} }
blockJSON = ethapi.RPCMarshalBlock(block, true, true, api.eth.APIBackend.ChainConfig()) if blockJSON, err = ethapi.RPCMarshalBlock(block, true, true, api.eth.APIBackend.ChainConfig()); err != nil {
blockJSON = map[string]interface{}{"error": err.Error()}
}
results = append(results, &BadBlockArgs{ results = append(results, &BadBlockArgs{
Hash: block.Hash(), Hash: block.Hash(),
RLP: blockRlp, RLP: blockRlp,

View file

@ -1281,7 +1281,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 // 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 // returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain
// transaction hashes. // transaction hashes.
func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig) map[string]interface{} { func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig) (map[string]interface{}, error) {
fields := RPCMarshalHeader(block.Header()) fields := RPCMarshalHeader(block.Header())
fields["size"] = hexutil.Uint64(block.Size()) fields["size"] = hexutil.Uint64(block.Size())
@ -1310,7 +1310,7 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param
if block.Header().WithdrawalsHash != nil { if block.Header().WithdrawalsHash != nil {
fields["withdrawals"] = block.Withdrawals() fields["withdrawals"] = block.Withdrawals()
} }
return fields return fields, nil
} }
// rpcMarshalHeader uses the generalized output filler, then adds the total difficulty field, which requires // 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
// rpcMarshalBlock uses the generalized output filler, then adds the total difficulty field, which requires // rpcMarshalBlock uses the generalized output filler, then adds the total difficulty field, which requires
// a `BlockchainAPI`. // a `BlockchainAPI`.
func (s *BlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) { func (s *BlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) {
fields := RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig()) fields, err := RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig())
if err != nil {
return nil, err
}
if inclTx { if inclTx {
fields["totalDifficulty"] = (*hexutil.Big)(s.b.GetTd(ctx, b.Hash())) fields["totalDifficulty"] = (*hexutil.Big)(s.b.GetTd(ctx, b.Hash()))
} }
return fields, nil return fields, err
} }
// RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction // RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction

View file

@ -758,7 +758,11 @@ func TestRPCMarshalBlock(t *testing.T) {
} }
for i, tc := range testSuite { for i, tc := range testSuite {
resp := RPCMarshalBlock(block, tc.inclTx, tc.fullTx, params.MainnetChainConfig) resp, err := RPCMarshalBlock(block, tc.inclTx, tc.fullTx, params.MainnetChainConfig)
if err != nil {
t.Errorf("test %d: got error %v", i, err)
continue
}
out, err := json.Marshal(resp) out, err := json.Marshal(resp)
if err != nil { if err != nil {
t.Errorf("test %d: json marshal error: %v", i, err) t.Errorf("test %d: json marshal error: %v", i, err)