Skip to content

Commit 8eaaf24

Browse files
committed
Merge pull request #1275 from karalabe/optimise-fetcher
eth/fetcher: separate the announce based sync into its own package
2 parents 2cea410 + 13c2503 commit 8eaaf24

File tree

8 files changed

+878
-274
lines changed

8 files changed

+878
-274
lines changed

eth/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func New(config *Config) (*Ethereum, error) {
313313

314314
eth.blockProcessor = core.NewBlockProcessor(stateDb, extraDb, eth.pow, eth.chainManager, eth.EventMux())
315315
eth.chainManager.SetProcessor(eth.blockProcessor)
316-
eth.protocolManager = NewProtocolManager(config.ProtocolVersion, config.NetworkId, eth.eventMux, eth.txPool, eth.chainManager)
316+
eth.protocolManager = NewProtocolManager(config.ProtocolVersion, config.NetworkId, eth.eventMux, eth.txPool, eth.pow, eth.chainManager)
317317

318318
eth.miner = miner.New(eth, eth.EventMux(), eth.pow)
319319
eth.miner.SetGasPrice(config.GasPrice)

eth/downloader/downloader.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package downloader contains the manual full chain synchronisation.
12
package downloader
23

34
import (
@@ -98,7 +99,7 @@ type Downloader struct {
9899
hasBlock hashCheckFn // Checks if a block is present in the chain
99100
getBlock blockRetrievalFn // Retrieves a block from the chain
100101
insertChain chainInsertFn // Injects a batch of blocks into the chain
101-
dropPeer peerDropFn // Retrieved the TD of our own chain
102+
dropPeer peerDropFn // Drops a peer for misbehaving
102103

103104
// Status
104105
synchroniseMock func(id string, hash common.Hash) error // Replacement for synchronise during testing

eth/downloader/downloader_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ func copyBlock(block *types.Block) *types.Block {
5252
return createBlock(int(block.Number().Int64()), block.ParentHeaderHash, block.HeaderHash)
5353
}
5454

55+
// createBlocksFromHashes assembles a collection of blocks, each having a correct
56+
// place in the given hash chain.
5557
func createBlocksFromHashes(hashes []common.Hash) map[common.Hash]*types.Block {
5658
blocks := make(map[common.Hash]*types.Block)
5759
for i := 0; i < len(hashes); i++ {
@@ -64,6 +66,7 @@ func createBlocksFromHashes(hashes []common.Hash) map[common.Hash]*types.Block {
6466
return blocks
6567
}
6668

69+
// downloadTester is a test simulator for mocking out local block chain.
6770
type downloadTester struct {
6871
downloader *Downloader
6972

@@ -75,16 +78,15 @@ type downloadTester struct {
7578
maxHashFetch int // Overrides the maximum number of retrieved hashes
7679
}
7780

81+
// newTester creates a new downloader test mocker.
7882
func newTester() *downloadTester {
7983
tester := &downloadTester{
8084
ownHashes: []common.Hash{knownHash},
8185
ownBlocks: map[common.Hash]*types.Block{knownHash: genesis},
8286
peerHashes: make(map[string][]common.Hash),
8387
peerBlocks: make(map[string]map[common.Hash]*types.Block),
8488
}
85-
var mux event.TypeMux
86-
downloader := New(&mux, tester.hasBlock, tester.getBlock, tester.insertChain, tester.dropPeer)
87-
tester.downloader = downloader
89+
tester.downloader = New(new(event.TypeMux), tester.hasBlock, tester.getBlock, tester.insertChain, tester.dropPeer)
8890

8991
return tester
9092
}

0 commit comments

Comments
 (0)