aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-06-19 02:14:26 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-06-19 02:14:26 +0800
commit8eaaf24b1e3d205c790f3803eaf333802284d50f (patch)
tree42d3d92416235a54db325967b2b2430c5918be30 /eth/downloader
parent2cea41065609dbebdd3856a00e9333566945ebee (diff)
parent13c25036ea6afc0b13d1d07be6bc298f2ee24216 (diff)
downloaddexon-8eaaf24b1e3d205c790f3803eaf333802284d50f.tar
dexon-8eaaf24b1e3d205c790f3803eaf333802284d50f.tar.gz
dexon-8eaaf24b1e3d205c790f3803eaf333802284d50f.tar.bz2
dexon-8eaaf24b1e3d205c790f3803eaf333802284d50f.tar.lz
dexon-8eaaf24b1e3d205c790f3803eaf333802284d50f.tar.xz
dexon-8eaaf24b1e3d205c790f3803eaf333802284d50f.tar.zst
dexon-8eaaf24b1e3d205c790f3803eaf333802284d50f.zip
Merge pull request #1275 from karalabe/optimise-fetcher
eth/fetcher: separate the announce based sync into its own package
Diffstat (limited to 'eth/downloader')
-rw-r--r--eth/downloader/downloader.go3
-rw-r--r--eth/downloader/downloader_test.go8
2 files changed, 7 insertions, 4 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index 9866a5b46..39976aae1 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -1,3 +1,4 @@
+// Package downloader contains the manual full chain synchronisation.
package downloader
import (
@@ -98,7 +99,7 @@ type Downloader struct {
hasBlock hashCheckFn // Checks if a block is present in the chain
getBlock blockRetrievalFn // Retrieves a block from the chain
insertChain chainInsertFn // Injects a batch of blocks into the chain
- dropPeer peerDropFn // Retrieved the TD of our own chain
+ dropPeer peerDropFn // Drops a peer for misbehaving
// Status
synchroniseMock func(id string, hash common.Hash) error // Replacement for synchronise during testing
diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go
index 484cc3218..4fc4e1434 100644
--- a/eth/downloader/downloader_test.go
+++ b/eth/downloader/downloader_test.go
@@ -52,6 +52,8 @@ func copyBlock(block *types.Block) *types.Block {
return createBlock(int(block.Number().Int64()), block.ParentHeaderHash, block.HeaderHash)
}
+// createBlocksFromHashes assembles a collection of blocks, each having a correct
+// place in the given hash chain.
func createBlocksFromHashes(hashes []common.Hash) map[common.Hash]*types.Block {
blocks := make(map[common.Hash]*types.Block)
for i := 0; i < len(hashes); i++ {
@@ -64,6 +66,7 @@ func createBlocksFromHashes(hashes []common.Hash) map[common.Hash]*types.Block {
return blocks
}
+// downloadTester is a test simulator for mocking out local block chain.
type downloadTester struct {
downloader *Downloader
@@ -75,6 +78,7 @@ type downloadTester struct {
maxHashFetch int // Overrides the maximum number of retrieved hashes
}
+// newTester creates a new downloader test mocker.
func newTester() *downloadTester {
tester := &downloadTester{
ownHashes: []common.Hash{knownHash},
@@ -82,9 +86,7 @@ func newTester() *downloadTester {
peerHashes: make(map[string][]common.Hash),
peerBlocks: make(map[string]map[common.Hash]*types.Block),
}
- var mux event.TypeMux
- downloader := New(&mux, tester.hasBlock, tester.getBlock, tester.insertChain, tester.dropPeer)
- tester.downloader = downloader
+ tester.downloader = New(new(event.TypeMux), tester.hasBlock, tester.getBlock, tester.insertChain, tester.dropPeer)
return tester
}