diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-05-26 19:00:21 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-05-26 19:00:21 +0800 |
commit | eafdc1f8e371fd698da33491a01799393249729a (patch) | |
tree | e834b1921a15767edf889d3bd2b9f9713c1101ed /eth/sync.go | |
parent | cc318ff8db20528cb567227c42c5d37dc892cc49 (diff) | |
download | dexon-eafdc1f8e371fd698da33491a01799393249729a.tar dexon-eafdc1f8e371fd698da33491a01799393249729a.tar.gz dexon-eafdc1f8e371fd698da33491a01799393249729a.tar.bz2 dexon-eafdc1f8e371fd698da33491a01799393249729a.tar.lz dexon-eafdc1f8e371fd698da33491a01799393249729a.tar.xz dexon-eafdc1f8e371fd698da33491a01799393249729a.tar.zst dexon-eafdc1f8e371fd698da33491a01799393249729a.zip |
eth, eth/downloader: surface downloaded block origin, drop on error
Diffstat (limited to 'eth/sync.go')
-rw-r--r-- | eth/sync.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/eth/sync.go b/eth/sync.go index 8a0da39ec..d93f83a78 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -5,6 +5,7 @@ import ( "sync/atomic" "time" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" @@ -57,13 +58,20 @@ func (pm *ProtocolManager) processBlocks() error { if len(blocks) == 0 { return nil } - glog.V(logger.Debug).Infof("Inserting chain with %d blocks (#%v - #%v)\n", len(blocks), blocks[0].Number(), blocks[len(blocks)-1].Number()) + glog.V(logger.Debug).Infof("Inserting chain with %d blocks (#%v - #%v)\n", len(blocks), blocks[0].RawBlock.Number(), blocks[len(blocks)-1].RawBlock.Number()) for len(blocks) != 0 && !pm.quit { + // Retrieve the first batch of blocks to insert max := int(math.Min(float64(len(blocks)), float64(blockProcAmount))) - _, err := pm.chainman.InsertChain(blocks[:max]) + raw := make(types.Blocks, 0, max) + for _, block := range blocks[:max] { + raw = append(raw, block.RawBlock) + } + // Try to inset the blocks, drop the originating peer if there's an error + index, err := pm.chainman.InsertChain(raw) if err != nil { glog.V(logger.Warn).Infof("Block insertion failed: %v", err) + pm.removePeer(blocks[index].OriginPeer) pm.downloader.Cancel() return err } @@ -105,7 +113,7 @@ func (pm *ProtocolManager) synchronise(peer *peer) { case downloader.ErrTimeout, downloader.ErrBadPeer, downloader.ErrInvalidChain, downloader.ErrCrossCheckFailed: glog.V(logger.Debug).Infof("Removing peer %v: %v", peer.id, err) - pm.removePeer(peer) + pm.removePeer(peer.id) case downloader.ErrPendingQueue: glog.V(logger.Debug).Infoln("Synchronisation aborted:", err) |