aboutsummaryrefslogtreecommitdiffstats
path: root/eth/fetcher/fetcher.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-06-22 23:08:28 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-06-22 23:08:28 +0800
commitb53f701c2791e7becba74c1efd4800fe68a06707 (patch)
tree2458a25e3b480e6e6ab790d81e62961fc7d82328 /eth/fetcher/fetcher.go
parent1989d1491a21ec1dd8adb20906e07badc5a2f9c9 (diff)
downloaddexon-b53f701c2791e7becba74c1efd4800fe68a06707.tar
dexon-b53f701c2791e7becba74c1efd4800fe68a06707.tar.gz
dexon-b53f701c2791e7becba74c1efd4800fe68a06707.tar.bz2
dexon-b53f701c2791e7becba74c1efd4800fe68a06707.tar.lz
dexon-b53f701c2791e7becba74c1efd4800fe68a06707.tar.xz
dexon-b53f701c2791e7becba74c1efd4800fe68a06707.tar.zst
dexon-b53f701c2791e7becba74c1efd4800fe68a06707.zip
eth/fetcher: remove test sleeps (15s -> 2.8s)
Diffstat (limited to 'eth/fetcher/fetcher.go')
-rw-r--r--eth/fetcher/fetcher.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/eth/fetcher/fetcher.go b/eth/fetcher/fetcher.go
index ceca79df0..7b5804ab2 100644
--- a/eth/fetcher/fetcher.go
+++ b/eth/fetcher/fetcher.go
@@ -92,6 +92,10 @@ type Fetcher struct {
chainHeight chainHeightFn // Retrieves the current chain's height
insertChain chainInsertFn // Injects a batch of blocks into the chain
dropPeer peerDropFn // Drops a peer for misbehaving
+
+ // Testing hooks
+ fetchingHook func([]common.Hash) // Method to call upon starting a block fetch
+ importedHook func(*types.Block) // Method to call upon successful block import
}
// New creates a block fetcher to retrieve blocks based on hash announcements.
@@ -277,7 +281,13 @@ func (f *Fetcher) loop() {
glog.V(logger.Detail).Infof("Peer %s: fetching %s", peer, list)
}
- go f.fetching[hashes[0]].fetch(hashes)
+ hashes := hashes // closure!
+ go func() {
+ if f.fetchingHook != nil {
+ f.fetchingHook(hashes)
+ }
+ f.fetching[hashes[0]].fetch(hashes)
+ }()
}
// Schedule the next fetch if blocks are still pending
f.reschedule(fetch)
@@ -402,6 +412,11 @@ func (f *Fetcher) insert(peer string, block *types.Block) {
}
// If import succeeded, broadcast the block
go f.broadcastBlock(block, false)
+
+ // Invoke the testing hook if needed
+ if f.importedHook != nil {
+ f.importedHook(block)
+ }
}()
}