aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorMartin Holst Swende <martin@swende.se>2018-06-11 16:03:40 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-06-11 16:03:40 +0800
commiteac16f98243206bee99c3daaa8aef08695f5b69e (patch)
treeb309897f09113b703e2ddd2bdd55352522cb6f6a /eth
parent69c52bde3f5e48a3b74264bf4854e9768ede75b2 (diff)
downloaddexon-eac16f98243206bee99c3daaa8aef08695f5b69e.tar
dexon-eac16f98243206bee99c3daaa8aef08695f5b69e.tar.gz
dexon-eac16f98243206bee99c3daaa8aef08695f5b69e.tar.bz2
dexon-eac16f98243206bee99c3daaa8aef08695f5b69e.tar.lz
dexon-eac16f98243206bee99c3daaa8aef08695f5b69e.tar.xz
dexon-eac16f98243206bee99c3daaa8aef08695f5b69e.tar.zst
dexon-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')
-rw-r--r--eth/api.go29
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.