@@ -131,14 +131,15 @@ func (chain *BlockChain) OnChainTimeout(height int64) bool {
131
131
func (chain * BlockChain ) SynRoutine () {
132
132
//获取peerlist的定时器,默认1分钟
133
133
fetchPeerListTicker := time .NewTicker (time .Duration (fetchPeerListSeconds ) * time .Second )
134
+ defer fetchPeerListTicker .Stop ()
134
135
135
136
//向peer请求同步block的定时器,默认2s
136
137
blockSynTicker := time .NewTicker (chain .blockSynInterVal * time .Second )
137
-
138
+ defer blockSynTicker . Stop ()
138
139
//5分钟检测一次bestchain主链高度是否有增长,如果没有增长可能是目前主链在侧链上,
139
140
//需要从最高peer向后同步指定的headers用来获取分叉点,再后从指定peer获取分叉点以后的blocks
140
141
checkHeightNoIncreaseTicker := time .NewTicker (time .Duration (checkHeightNoIncSeconds ) * time .Second )
141
-
142
+ defer checkHeightNoIncreaseTicker . Stop ()
142
143
//目前暂定1分钟检测一次本bestchain的tiphash和最高peer的对应高度的blockshash是否一致。
143
144
//如果不一致可能两个节点在各自的链上挖矿,需要从peer的对应高度向后获取指定数量的headers寻找分叉点
144
145
//考虑叉后的第一个block没有广播到本节点,导致接下来广播过来的blocks都是孤儿节点,无法进行主侧链总难度对比
@@ -152,13 +153,13 @@ func (chain *BlockChain) SynRoutine() {
152
153
}
153
154
//3分钟尝试检测一次故障peer是否已经恢复
154
155
recoveryFaultPeerTicker := time .NewTicker (180 * time .Second )
155
-
156
+ defer recoveryFaultPeerTicker . Stop ()
156
157
//2分钟尝试检测一次最优链,确保本节点在最优链
157
158
checkBestChainTicker := time .NewTicker (120 * time .Second )
158
-
159
+ defer checkBestChainTicker . Stop ()
159
160
//30s尝试从peer节点请求ChunkRecord
160
161
chunkRecordSynTicker := time .NewTicker (30 * time .Second )
161
-
162
+ defer chunkRecordSynTicker . Stop ()
162
163
//节点下载模式
163
164
go chain .DownLoadBlocks ()
164
165
0 commit comments