diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-06-16 19:02:43 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-06-18 20:56:07 +0800 |
commit | 2a1b722d048d00401084c37a5ca12612f1dd5fcd (patch) | |
tree | c6cfa196e671d562915f18c3a4d9e5fc0b50a5fb /eth/fetcher/fetcher.go | |
parent | 7c2af1c11722dc3175a98342c060afcfaf6a275f (diff) | |
download | go-tangerine-2a1b722d048d00401084c37a5ca12612f1dd5fcd.tar go-tangerine-2a1b722d048d00401084c37a5ca12612f1dd5fcd.tar.gz go-tangerine-2a1b722d048d00401084c37a5ca12612f1dd5fcd.tar.bz2 go-tangerine-2a1b722d048d00401084c37a5ca12612f1dd5fcd.tar.lz go-tangerine-2a1b722d048d00401084c37a5ca12612f1dd5fcd.tar.xz go-tangerine-2a1b722d048d00401084c37a5ca12612f1dd5fcd.tar.zst go-tangerine-2a1b722d048d00401084c37a5ca12612f1dd5fcd.zip |
eth/fetcher: fix timer reset bug, add initial tests
Diffstat (limited to 'eth/fetcher/fetcher.go')
-rw-r--r-- | eth/fetcher/fetcher.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/eth/fetcher/fetcher.go b/eth/fetcher/fetcher.go index 19c53048c..a8d1f2fb5 100644 --- a/eth/fetcher/fetcher.go +++ b/eth/fetcher/fetcher.go @@ -149,7 +149,8 @@ func (f *Fetcher) loop() { break } if len(announced) == 0 { - fetch.Reset(arriveTimeout) + glog.V(logger.Detail).Infof("Scheduling fetch in %v, at %v", arriveTimeout-time.Since(notification.time), notification.time.Add(arriveTimeout)) + fetch.Reset(arriveTimeout - time.Since(notification.time)) } announced[notification.hash] = append(announced[notification.hash], notification) @@ -181,11 +182,12 @@ func (f *Fetcher) loop() { if len(announced) > 0 { nearest := time.Now() for _, announces := range announced { - if nearest.Before(announces[0].time) { + if nearest.After(announces[0].time) { nearest = announces[0].time } } - fetch.Reset(arriveTimeout + time.Since(nearest)) + glog.V(logger.Detail).Infof("Rescheduling fetch in %v, at %v", arriveTimeout-time.Since(nearest), nearest.Add(arriveTimeout)) + fetch.Reset(arriveTimeout - time.Since(nearest)) } case filter := <-f.filter: |