core: persist bad blocks (#21827)
* core: persist bad blocks * core, eth, internal: address comments * core/rawdb: add badblocks to inspector * core, eth: update * internal: revert * core, eth: only save 10 bad blocks * core/rawdb: address comments * core/rawdb: fix * core: address comments
This commit is contained in:
31
eth/api.go
31
eth/api.go
@ -331,22 +331,29 @@ type BadBlockArgs struct {
|
||||
// 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) ([]*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(),
|
||||
}
|
||||
var (
|
||||
err error
|
||||
blocks = rawdb.ReadAllBadBlocks(api.eth.chainDb)
|
||||
results = make([]*BadBlockArgs, 0, len(blocks))
|
||||
)
|
||||
for _, block := range blocks {
|
||||
var (
|
||||
blockRlp string
|
||||
blockJSON map[string]interface{}
|
||||
)
|
||||
if rlpBytes, err := rlp.EncodeToBytes(block); err != nil {
|
||||
results[i].RLP = err.Error() // Hacky, but hey, it works
|
||||
blockRlp = err.Error() // Hacky, but hey, it works
|
||||
} else {
|
||||
results[i].RLP = fmt.Sprintf("0x%x", rlpBytes)
|
||||
blockRlp = 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()}
|
||||
if blockJSON, err = ethapi.RPCMarshalBlock(block, true, true); err != nil {
|
||||
blockJSON = map[string]interface{}{"error": err.Error()}
|
||||
}
|
||||
results = append(results, &BadBlockArgs{
|
||||
Hash: block.Hash(),
|
||||
RLP: blockRlp,
|
||||
Block: blockJSON,
|
||||
})
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
@ -404,8 +404,7 @@ func (api *PrivateDebugAPI) TraceBlockFromFile(ctx context.Context, file string,
|
||||
// EVM against a block pulled from the pool of bad ones and returns them as a JSON
|
||||
// object.
|
||||
func (api *PrivateDebugAPI) TraceBadBlock(ctx context.Context, hash common.Hash, config *TraceConfig) ([]*txTraceResult, error) {
|
||||
blocks := api.eth.blockchain.BadBlocks()
|
||||
for _, block := range blocks {
|
||||
for _, block := range rawdb.ReadAllBadBlocks(api.eth.chainDb) {
|
||||
if block.Hash() == hash {
|
||||
return api.traceBlock(ctx, block, config)
|
||||
}
|
||||
@ -428,8 +427,7 @@ func (api *PrivateDebugAPI) StandardTraceBlockToFile(ctx context.Context, hash c
|
||||
// execution of EVM against a block pulled from the pool of bad ones to the
|
||||
// local file system and returns a list of files to the caller.
|
||||
func (api *PrivateDebugAPI) StandardTraceBadBlockToFile(ctx context.Context, hash common.Hash, config *StdTraceConfig) ([]string, error) {
|
||||
blocks := api.eth.blockchain.BadBlocks()
|
||||
for _, block := range blocks {
|
||||
for _, block := range rawdb.ReadAllBadBlocks(api.eth.chainDb) {
|
||||
if block.Hash() == hash {
|
||||
return api.standardTraceBlockToFile(ctx, block, config)
|
||||
}
|
||||
|
Reference in New Issue
Block a user