浏览代码

eth/fetcher: avoid spurious timer events at startup (#22652)

Co-authored-by: Felix Lange <fjl@twurst.com>
xD AKA Rapper King Of cn background diablo & revelations 4 年之前
父节点
当前提交
a50251e6cb
共有 1 个文件被更改,包括 6 次插入2 次删除
  1. 6 2
      eth/fetcher/block_fetcher.go

+ 6 - 2
eth/fetcher/block_fetcher.go

@@ -331,8 +331,12 @@ func (f *BlockFetcher) FilterBodies(peer string, transactions [][]*types.Transac
 // events.
 func (f *BlockFetcher) loop() {
 	// Iterate the block fetching until a quit is requested
-	fetchTimer := time.NewTimer(0)
-	completeTimer := time.NewTimer(0)
+	var (
+		fetchTimer    = time.NewTimer(0)
+		completeTimer = time.NewTimer(0)
+	)
+	<-fetchTimer.C // clear out the channel
+	<-completeTimer.C
 	defer fetchTimer.Stop()
 	defer completeTimer.Stop()