diff options
author | Martin Holst Swende <martin@swende.se> | 2018-06-11 16:03:40 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-06-11 16:03:40 +0800 |
commit | eac16f98243206bee99c3daaa8aef08695f5b69e (patch) | |
tree | b309897f09113b703e2ddd2bdd55352522cb6f6a /eth/api.go | |
parent | 69c52bde3f5e48a3b74264bf4854e9768ede75b2 (diff) | |
download | go-tangerine-eac16f98243206bee99c3daaa8aef08695f5b69e.tar.gz go-tangerine-eac16f98243206bee99c3daaa8aef08695f5b69e.tar.zst go-tangerine-eac16f98243206bee99c3daaa8aef08695f5b69e.zip |
core: improve getBadBlocks to return full block rlp (#16902)
* core: improve getBadBlocks to return full block rlp
* core, eth, ethapi: changes to getBadBlocks formatting
* ethapi: address review concerns
Diffstat (limited to 'eth/api.go')
-rw-r--r-- | eth/api.go | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/eth/api.go b/eth/api.go index 247ca7485..446161cc4 100644 --- a/eth/api.go +++ b/eth/api.go @@ -32,6 +32,7 @@ import ( "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/params" @@ -351,10 +352,34 @@ func (api *PrivateDebugAPI) Preimage(ctx context.Context, hash common.Hash) (hex return nil, errors.New("unknown preimage") } +// BadBlockArgs represents the entries in the list returned when bad blocks are queried. +type BadBlockArgs struct { + Hash common.Hash `json:"hash"` + Block map[string]interface{} `json:"block"` + RLP string `json:"rlp"` +} + // GetBadBLocks returns a list of the last 'bad blocks' that the client has seen on the network // and returns them as a JSON list of block-hashes -func (api *PrivateDebugAPI) GetBadBlocks(ctx context.Context) ([]core.BadBlockArgs, error) { - return api.eth.BlockChain().BadBlocks() +func (api *PrivateDebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error) { + blocks := api.eth.BlockChain().BadBlocks() + results := make([]*BadBlockArgs, len(blocks)) + + var err error + for i, block := range blocks { + results[i] = &BadBlockArgs{ + Hash: block.Hash(), + } + if rlpBytes, err := rlp.EncodeToBytes(block); err != nil { + results[i].RLP = err.Error() // Hacky, but hey, it works + } else { + results[i].RLP = fmt.Sprintf("0x%x", rlpBytes) + } + if results[i].Block, err = ethapi.RPCMarshalBlock(block, true, true); err != nil { + results[i].Block = map[string]interface{}{"error": err.Error()} + } + } + return results, nil } // StorageRangeResult is the result of a debug_storageRangeAt API call. |