Skip to content

Commit aa45020

Browse files
committed
Merge pull request #1400 from obscuren/badblock-reporting
core, miner, tests: added test, implemented bad block reporting
2 parents b533aaa + bcc1660 commit aa45020

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

core/bad_block.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package core
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"io/ioutil"
7+
"net/http"
8+
9+
"github.com/ethereum/go-ethereum/common"
10+
"github.com/ethereum/go-ethereum/core/types"
11+
"github.com/ethereum/go-ethereum/logger"
12+
"github.com/ethereum/go-ethereum/logger/glog"
13+
"github.com/ethereum/go-ethereum/rlp"
14+
)
15+
16+
// DisabledBadBlockReporting can be set to prevent blocks being reported.
17+
var DisableBadBlockReporting = true
18+
19+
// ReportBlock reports the block to the block reporting tool found at
20+
// badblocks.ethdev.com
21+
func ReportBlock(block *types.Block, err error) {
22+
if DisableBadBlockReporting {
23+
return
24+
}
25+
26+
const url = "https://badblocks.ethdev.com"
27+
28+
blockRlp, _ := rlp.EncodeToBytes(block)
29+
data := map[string]interface{}{
30+
"block": common.Bytes2Hex(blockRlp),
31+
"errortype": err.Error(),
32+
"hints": map[string]interface{}{
33+
"receipts": "NYI",
34+
"vmtrace": "NYI",
35+
},
36+
}
37+
jsonStr, _ := json.Marshal(map[string]interface{}{"method": "eth_badBlock", "params": []interface{}{data}, "id": "1", "jsonrpc": "2.0"})
38+
39+
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
40+
req.Header.Set("Content-Type", "application/json")
41+
42+
client := &http.Client{}
43+
resp, err := client.Do(req)
44+
if err != nil {
45+
glog.V(logger.Error).Infoln("POST err:", err)
46+
return
47+
}
48+
defer resp.Body.Close()
49+
50+
if glog.V(logger.Debug) {
51+
glog.Infoln("response Status:", resp.Status)
52+
glog.Infoln("response Headers:", resp.Header)
53+
body, _ := ioutil.ReadAll(resp.Body)
54+
glog.Infoln("response Body:", string(body))
55+
}
56+
}

core/chain_manager.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,8 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
611611

612612
blockErr(block, err)
613613

614+
go ReportBlock(block, err)
615+
614616
return i, err
615617
}
616618

miner/worker.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,6 @@ func (self *worker) push() {
298298

299299
if agent.Work() != nil {
300300
agent.Work() <- self.current.block
301-
} else {
302-
common.Report(fmt.Sprintf("%v %T\n", agent, agent))
303301
}
304302
}
305303
}

tests/init.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"net/http"
99
"os"
1010
"path/filepath"
11+
12+
"github.com/ethereum/go-ethereum/core"
1113
)
1214

1315
var (
@@ -43,6 +45,7 @@ func readJson(reader io.Reader, value interface{}) error {
4345
return fmt.Errorf("Error reading JSON file", err.Error())
4446
}
4547

48+
core.DisableBadBlockReporting = true
4649
if err = json.Unmarshal(data, &value); err != nil {
4750
if syntaxerr, ok := err.(*json.SyntaxError); ok {
4851
line := findLine(data, syntaxerr.Offset)

0 commit comments

Comments
 (0)