From 78551c9a2cad9fea3e48dcae1ba26d82fc201807 Mon Sep 17 00:00:00 2001 From: ia Date: Thu, 14 Jun 2018 13:02:45 +0200 Subject: [PATCH] problem: bad block reporting is defunct solution: remove all references of it (reporting, that is, not bad blocks in general) Fixes #624 --- cmd/geth/main.go | 7 ----- eth/bad_block.go | 75 ------------------------------------------------ eth/handler.go | 20 ++----------- 3 files changed, 3 insertions(+), 99 deletions(-) delete mode 100644 eth/bad_block.go diff --git a/cmd/geth/main.go b/cmd/geth/main.go index b97fe1cae..ec4f96773 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -31,7 +31,6 @@ import ( "github.com/ethereumproject/go-ethereum/common" "github.com/ethereumproject/go-ethereum/console" "github.com/ethereumproject/go-ethereum/core" - "github.com/ethereumproject/go-ethereum/eth" "github.com/ethereumproject/go-ethereum/logger" "github.com/ethereumproject/go-ethereum/metrics" ) @@ -283,12 +282,6 @@ func makeCLIApp() (app *cli.App) { go metrics.CollectToFile(s) } - // This should be the only place where reporting is enabled - // because it is not intended to run while testing. - // In addition to this check, bad block reports are sent only - // for chains with the main network genesis block and network id 1. - eth.EnableBadBlockReporting = true - // (whilei): I use `log` instead of `glog` because git diff tells me: // > The output of this command is supposed to be machine-readable. gasLimit := ctx.GlobalString(aliasableName(TargetGasLimitFlag.Name, ctx)) diff --git a/eth/bad_block.go b/eth/bad_block.go deleted file mode 100644 index d941fc5c3..000000000 --- a/eth/bad_block.go +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2015 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see . - -package eth - -import ( - "bytes" - "encoding/json" - "fmt" - "net/http" - "time" - - "github.com/ethereumproject/go-ethereum/common" - "github.com/ethereumproject/go-ethereum/core/types" - "github.com/ethereumproject/go-ethereum/logger" - "github.com/ethereumproject/go-ethereum/logger/glog" - "github.com/ethereumproject/go-ethereum/rlp" -) - -const ( - // The Ethereum main network genesis block. - defaultGenesisHash = "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" - // !EPROJECT We will need a bad block API - badBlocksURL = "https://badblocks.ethdev.com" -) - -var EnableBadBlockReporting = false - -func sendBadBlockReport(block *types.Block, err error) { - if !EnableBadBlockReporting { - return - } - - var ( - blockRLP, _ = rlp.EncodeToBytes(block) - params = map[string]interface{}{ - "block": common.Bytes2Hex(blockRLP), - "blockHash": block.Hash().Hex(), - "errortype": err.Error(), - "client": "go", - } - ) - if !block.ReceivedAt.IsZero() { - params["receivedAt"] = block.ReceivedAt.UTC().String() - } - if p, ok := block.ReceivedFrom.(*peer); ok { - params["receivedFrom"] = map[string]interface{}{ - "enode": fmt.Sprintf("enode://%x@%v", p.ID(), p.RemoteAddr()), - "name": p.Name(), - "protocolVersion": p.version, - } - } - jsonStr, _ := json.Marshal(map[string]interface{}{"method": "eth_badBlock", "id": "1", "jsonrpc": "2.0", "params": []interface{}{params}}) - client := http.Client{Timeout: 8 * time.Second} - resp, err := client.Post(badBlocksURL, "application/json", bytes.NewReader(jsonStr)) - if err != nil { - glog.V(logger.Debug).Infoln(err) - return - } - glog.V(logger.Debug).Infof("Bad Block Report posted (%d)", resp.StatusCode) - resp.Body.Close() -} diff --git a/eth/handler.go b/eth/handler.go index e8372fd6c..83e4bf2f7 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -93,8 +93,6 @@ type ProtocolManager struct { // wait group is used for graceful shutdowns during downloading // and processing wg sync.WaitGroup - - badBlockReportingEnabled bool } // NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable @@ -176,27 +174,15 @@ func NewProtocolManager(config *core.ChainConfig, mode downloader.SyncMode, netw glog.V(logger.Warn).Warnf("Discarded bad propagated block", "number", blocks[0].Number(), "hash", blocks[0].Hash().Hex()[:9]) glog.D(logger.Warn).Warnf("Discarded bad propagated block", "number", blocks[0].Number(), "hash", blocks[0].Hash().Hex()[:9]) } - atomic.StoreUint32(&manager.acceptsTxs, 1) // Mark initial sync done on any fetcher import - return manager.insertChain(blocks) + // Mark initial sync done on any fetcher import + atomic.StoreUint32(&manager.acceptsTxs, 1) + return manager.blockchain.InsertChain(blocks) } manager.fetcher = fetcher.New(mux, blockchain.GetBlock, validator, manager.BroadcastBlock, heighter, inserter, manager.removePeer) - if blockchain.Genesis().Hash().Hex() == defaultGenesisHash && networkId == 1 { - manager.badBlockReportingEnabled = false - } - return manager, nil } -func (pm *ProtocolManager) insertChain(blocks types.Blocks) *core.ChainInsertResult { - res := pm.blockchain.InsertChain(blocks) - err := res.Error - if err != nil && pm.badBlockReportingEnabled && core.IsValidateError(err) { - go sendBadBlockReport(blocks[res.Index], err) - } - return res -} - func (pm *ProtocolManager) removePeer(id string) { // Short circuit if the peer was already removed peer := pm.peers.Peer(id)