diff options
author | Felix Lange <fjl@twurst.com> | 2016-05-25 00:49:54 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-05-25 08:02:51 +0800 |
commit | ca18202eb9a94de1d4b51c1572fa74edfa2773bf (patch) | |
tree | 7c56ac08aa0feb3221241959ed2eeff1ef1ff097 /eth/handler.go | |
parent | 5bcdbb1ce4ac576cab778e9772fabdcc7cbfbb5f (diff) | |
download | go-tangerine-ca18202eb9a94de1d4b51c1572fa74edfa2773bf.tar.gz go-tangerine-ca18202eb9a94de1d4b51c1572fa74edfa2773bf.tar.zst go-tangerine-ca18202eb9a94de1d4b51c1572fa74edfa2773bf.zip |
eth: enable bad block reports
We used to have reporting of bad blocks, but it was disabled
before the Frontier release. We need it back because users
are usually unable to provide the full RLP data of a bad
block when it occurs.
A shortcoming of this particular implementation is that the
origin peer is not tracked for blocks received during eth/63
sync. No origin peer info is still better than no report at
all though.
Diffstat (limited to 'eth/handler.go')
-rw-r--r-- | eth/handler.go | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/eth/handler.go b/eth/handler.go index 202acdc78..58869a2ee 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -83,6 +83,8 @@ 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 @@ -150,7 +152,7 @@ func NewProtocolManager(config *core.ChainConfig, fastSync bool, networkId int, // Construct the different synchronisation mechanisms manager.downloader = downloader.New(chaindb, manager.eventMux, blockchain.HasHeader, blockchain.HasBlockAndState, blockchain.GetHeader, blockchain.GetBlock, blockchain.CurrentHeader, blockchain.CurrentBlock, blockchain.CurrentFastBlock, blockchain.FastSyncCommitHead, - blockchain.GetTd, blockchain.InsertHeaderChain, blockchain.InsertChain, blockchain.InsertReceiptChain, blockchain.Rollback, + blockchain.GetTd, blockchain.InsertHeaderChain, manager.insertChain, blockchain.InsertReceiptChain, blockchain.Rollback, manager.removePeer) validator := func(block *types.Block, parent *types.Block) error { @@ -159,11 +161,24 @@ func NewProtocolManager(config *core.ChainConfig, fastSync bool, networkId int, heighter := func() uint64 { return blockchain.CurrentBlock().NumberU64() } - manager.fetcher = fetcher.New(blockchain.GetBlock, validator, manager.BroadcastBlock, heighter, blockchain.InsertChain, manager.removePeer) + manager.fetcher = fetcher.New(blockchain.GetBlock, validator, manager.BroadcastBlock, heighter, manager.insertChain, manager.removePeer) + + if blockchain.Genesis().Hash().Hex() == defaultGenesisHash && networkId == 1 { + glog.V(logger.Debug).Infoln("Bad Block Reporting is enabled") + manager.badBlockReportingEnabled = true + } return manager, nil } +func (pm *ProtocolManager) insertChain(blocks types.Blocks) (i int, err error) { + i, err = pm.blockchain.InsertChain(blocks) + if pm.badBlockReportingEnabled && core.IsValidationErr(err) && i < len(blocks) { + go sendBadBlockReport(blocks[i], err) + } + return i, err +} + func (pm *ProtocolManager) removePeer(id string) { // Short circuit if the peer was already removed peer := pm.peers.Peer(id) @@ -378,6 +393,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { // Update the receive timestamp of each block for _, block := range blocks { block.ReceivedAt = msg.ReceivedAt + block.ReceivedFrom = p } // Filter out any explicitly requested blocks, deliver the rest to the downloader if blocks := pm.fetcher.FilterBlocks(blocks); len(blocks) > 0 { @@ -664,6 +680,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { return errResp(ErrDecode, "block validation %v: %v", msg, err) } request.Block.ReceivedAt = msg.ReceivedAt + request.Block.ReceivedFrom = p // Mark the peer as owning the block and schedule it for import p.MarkBlock(request.Block.Hash()) |