Commit 0d536734 authored by obscuren's avatar obscuren

eth: adapted to new synchronous api of downloader's AddBlock

parent c2c24b3b
...@@ -173,8 +173,6 @@ out: ...@@ -173,8 +173,6 @@ out:
select { select {
case sync := <-d.syncCh: case sync := <-d.syncCh:
var peer *peer = sync.peer var peer *peer = sync.peer
d.activePeer = peer.id
err := d.getFromPeer(peer, sync.hash, sync.ignoreInitial) err := d.getFromPeer(peer, sync.hash, sync.ignoreInitial)
if err != nil { if err != nil {
break break
......
...@@ -50,6 +50,8 @@ func (d *Downloader) Synchronise() (types.Blocks, error) { ...@@ -50,6 +50,8 @@ func (d *Downloader) Synchronise() (types.Blocks, error) {
} }
func (d *Downloader) getFromPeer(p *peer, hash common.Hash, ignoreInitial bool) error { func (d *Downloader) getFromPeer(p *peer, hash common.Hash, ignoreInitial bool) error {
d.activePeer = p.id
glog.V(logger.Detail).Infoln("Synchronising with the network using:", p.id) glog.V(logger.Detail).Infoln("Synchronising with the network using:", p.id)
// Start the fetcher. This will block the update entirely // Start the fetcher. This will block the update entirely
// interupts need to be send to the appropriate channels // interupts need to be send to the appropriate channels
......
...@@ -265,10 +265,12 @@ func (self *ProtocolManager) handleMsg(p *peer) error { ...@@ -265,10 +265,12 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
if self.chainman.HasBlock(hash) { if self.chainman.HasBlock(hash) {
break 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) glog.V(logger.Debug).Infoln("dropped block", request.Block.Number(), "due to low TD", request.TD)
break break
} }
*/
// Attempt to insert the newly received by checking if the parent exists. // 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 // if the parent exists we process the block and propagate to our peers
...@@ -281,7 +283,15 @@ func (self *ProtocolManager) handleMsg(p *peer) error { ...@@ -281,7 +283,15 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
} }
self.BroadcastBlock(hash, request.Block) self.BroadcastBlock(hash, request.Block)
} else { } 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: default:
return errResp(ErrInvalidMsgCode, "%v", msg.Code) return errResp(ErrInvalidMsgCode, "%v", msg.Code)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment