aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/downloader.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-24 21:37:32 +0800
committerobscuren <geffobscura@gmail.com>2015-04-24 21:38:10 +0800
commitd84c2202e79c30ec906b1a078bfd9fdf5ae94a31 (patch)
treee05cfa5b69f82fe7bece8bee3b672522406733d3 /eth/downloader/downloader.go
parentbd9c76097d485b55ae808fee345d1d76801df1ea (diff)
downloadgo-tangerine-d84c2202e79c30ec906b1a078bfd9fdf5ae94a31.tar
go-tangerine-d84c2202e79c30ec906b1a078bfd9fdf5ae94a31.tar.gz
go-tangerine-d84c2202e79c30ec906b1a078bfd9fdf5ae94a31.tar.bz2
go-tangerine-d84c2202e79c30ec906b1a078bfd9fdf5ae94a31.tar.lz
go-tangerine-d84c2202e79c30ec906b1a078bfd9fdf5ae94a31.tar.xz
go-tangerine-d84c2202e79c30ec906b1a078bfd9fdf5ae94a31.tar.zst
go-tangerine-d84c2202e79c30ec906b1a078bfd9fdf5ae94a31.zip
eth, eth/downloader: simplified synchronisation process
Diffstat (limited to 'eth/downloader/downloader.go')
-rw-r--r--eth/downloader/downloader.go37
1 files changed, 13 insertions, 24 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index 00c4cd88f..9b8d7c0b2 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -96,14 +96,14 @@ func (d *Downloader) Stats() (current int, max int) {
return d.queue.blockHashes.Size(), d.queue.fetchPool.Size() + d.queue.hashPool.Size()
}
-func (d *Downloader) RegisterPeer(id string, td *big.Int, hash common.Hash, getHashes hashFetcherFn, getBlocks blockFetcherFn) error {
+func (d *Downloader) RegisterPeer(id string, hash common.Hash, getHashes hashFetcherFn, getBlocks blockFetcherFn) error {
d.mu.Lock()
defer d.mu.Unlock()
- glog.V(logger.Detail).Infoln("Register peer", id, "TD =", td)
+ glog.V(logger.Detail).Infoln("Register peer", id)
// Create a new peer and add it to the list of known peers
- peer := newPeer(id, td, hash, getHashes, getBlocks)
+ peer := newPeer(id, hash, getHashes, getBlocks)
// add peer to our peer set
d.peers[id] = peer
// broadcast new peer
@@ -133,7 +133,7 @@ out:
break
}
- d.process()
+ d.process(peer)
case <-d.quit:
break out
}
@@ -143,27 +143,27 @@ out:
// SynchroniseWithPeer will select the peer and use it for synchronising. If an empty string is given
// it will use the best peer possible and synchronise if it's TD is higher than our own. If any of the
// checks fail an error will be returned. This method is synchronous
-func (d *Downloader) Synchronise(id string, hash common.Hash) (types.Blocks, error) {
+func (d *Downloader) Synchronise(id string, hash common.Hash) error {
// Make sure it's doing neither. Once done we can restart the
// downloading process if the TD is higher. For now just get on
// with whatever is going on. This prevents unecessary switching.
if d.isBusy() {
- return nil, errBusy
+ return errBusy
}
// Fetch the peer using the id or throw an error if the peer couldn't be found
p := d.peers[id]
if p == nil {
- return nil, errUnknownPeer
+ return errUnknownPeer
}
// Get the hash from the peer and initiate the downloading progress.
err := d.getFromPeer(p, hash, false)
if err != nil {
- return nil, err
+ return err
}
- return d.queue.blocks, nil
+ return d.process(p)
}
func (d *Downloader) getFromPeer(p *peer, hash common.Hash, ignoreInitial bool) error {
@@ -405,13 +405,12 @@ func (d *Downloader) AddBlock(id string, block *types.Block, td *big.Int) error
}
peer.mu.Lock()
- peer.td = td
peer.recentHash = block.Hash()
peer.mu.Unlock()
peer.promote()
glog.V(logger.Detail).Infoln("Inserting new block from:", id)
- d.queue.addBlock(id, block, td)
+ d.queue.addBlock(id, block)
// if neither go ahead to process
if d.isBusy() {
@@ -431,10 +430,10 @@ func (d *Downloader) AddBlock(id string, block *types.Block, td *big.Int) error
}
}
- return d.process()
+ return d.process(peer)
}
-func (d *Downloader) process() error {
+func (d *Downloader) process(peer *peer) error {
atomic.StoreInt32(&d.processingBlocks, 1)
defer atomic.StoreInt32(&d.processingBlocks, 0)
@@ -460,18 +459,8 @@ func (d *Downloader) process() error {
// grandparents can be requested and queued.
err = d.insertChain(blocks[:max])
if err != nil && core.IsParentErr(err) {
- glog.V(logger.Debug).Infoln("Aborting process due to missing parent. Fetching hashes")
-
- // TODO change this. This shite
- for i, block := range blocks[:max] {
- if !d.hasBlock(block.ParentHash()) {
- d.syncCh <- syncPack{d.peers.bestPeer(), block.Hash(), true}
- // remove processed blocks
- blocks = blocks[i:]
+ glog.V(logger.Debug).Infoln("Aborting process due to missing parent.")
- break
- }
- }
break
} else if err != nil {
// immediatly unregister the false peer but do not disconnect