aboutsummaryrefslogtreecommitdiffstats
path: root/eth/handler.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-19 00:55:50 +0800
committerobscuren <geffobscura@gmail.com>2015-04-19 00:57:59 +0800
commit0d536734fe10e62dce86db1a6128b383ef66921d (patch)
tree1254ba614e724ee04df3035515e2597d70f6f26c /eth/handler.go
parentc2c24b3bb419a8ffffb58ec25788b951bef779f9 (diff)
downloaddexon-0d536734fe10e62dce86db1a6128b383ef66921d.tar.gz
dexon-0d536734fe10e62dce86db1a6128b383ef66921d.tar.zst
dexon-0d536734fe10e62dce86db1a6128b383ef66921d.zip
eth: adapted to new synchronous api of downloader's AddBlock
Diffstat (limited to 'eth/handler.go')
-rw-r--r--eth/handler.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/eth/handler.go b/eth/handler.go
index 3aa9815f1..749809175 100644
--- a/eth/handler.go
+++ b/eth/handler.go
@@ -265,10 +265,12 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
if self.chainman.HasBlock(hash) {
break
}
- if self.chainman.Td().Cmp(request.TD) > 0 {
+ /* XXX unsure about this
+ if self.chainman.Td().Cmp(request.TD) > 0 && new(big.Int).Add(request.Block.Number(), big.NewInt(7)).Cmp(self.chainman.CurrentBlock().Number()) < 0 {
glog.V(logger.Debug).Infoln("dropped block", request.Block.Number(), "due to low TD", request.TD)
break
}
+ */
// Attempt to insert the newly received by checking if the parent exists.
// if the parent exists we process the block and propagate to our peers
@@ -281,7 +283,15 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
}
self.BroadcastBlock(hash, request.Block)
} else {
- self.downloader.AddBlock(p.id, request.Block, request.TD)
+ // adding blocks is synchronous
+ go func() {
+ err := self.downloader.AddBlock(p.id, request.Block, request.TD)
+ if err != nil {
+ glog.V(logger.Detail).Infoln("downloader err:", err)
+ return
+ }
+ self.BroadcastBlock(hash, request.Block)
+ }()
}
default:
return errResp(ErrInvalidMsgCode, "%v", msg.Code)