Skip to content

Commit b53f701

Browse files
committed
eth/fetcher: remove test sleeps (15s -> 2.8s)
1 parent 1989d14 commit b53f701

File tree

2 files changed

+167
-59
lines changed

2 files changed

+167
-59
lines changed

eth/fetcher/fetcher.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ type Fetcher struct {
9292
chainHeight chainHeightFn // Retrieves the current chain's height
9393
insertChain chainInsertFn // Injects a batch of blocks into the chain
9494
dropPeer peerDropFn // Drops a peer for misbehaving
95+
96+
// Testing hooks
97+
fetchingHook func([]common.Hash) // Method to call upon starting a block fetch
98+
importedHook func(*types.Block) // Method to call upon successful block import
9599
}
96100

97101
// New creates a block fetcher to retrieve blocks based on hash announcements.
@@ -277,7 +281,13 @@ func (f *Fetcher) loop() {
277281

278282
glog.V(logger.Detail).Infof("Peer %s: fetching %s", peer, list)
279283
}
280-
go f.fetching[hashes[0]].fetch(hashes)
284+
hashes := hashes // closure!
285+
go func() {
286+
if f.fetchingHook != nil {
287+
f.fetchingHook(hashes)
288+
}
289+
f.fetching[hashes[0]].fetch(hashes)
290+
}()
281291
}
282292
// Schedule the next fetch if blocks are still pending
283293
f.reschedule(fetch)
@@ -402,6 +412,11 @@ func (f *Fetcher) insert(peer string, block *types.Block) {
402412
}
403413
// If import succeeded, broadcast the block
404414
go f.broadcastBlock(block, false)
415+
416+
// Invoke the testing hook if needed
417+
if f.importedHook != nil {
418+
f.importedHook(block)
419+
}
405420
}()
406421
}
407422

0 commit comments

Comments
 (0)