Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
6ee3b26f
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
6ee3b26f
编写于
10月 04, 2018
作者:
P
Péter Szilágyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
eth/downloader: fix invalid hash chain error due to head mini reorg
上级
89a32451
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
3 deletion
+40
-3
eth/downloader/downloader.go
eth/downloader/downloader.go
+38
-1
eth/downloader/downloader_test.go
eth/downloader/downloader_test.go
+2
-2
未找到文件。
eth/downloader/downloader.go
浏览文件 @
6ee3b26f
...
...
@@ -60,6 +60,9 @@ var (
maxHeadersProcess
=
2048
// Number of header download results to import at once into the chain
maxResultsProcess
=
2048
// Number of content download results to import at once into the chain
reorgProtThreshold
=
48
// Threshold number of recent blocks to disable mini reorg protection
reorgProtHeaderDelay
=
2
// Number of headers to delay delivering to cover mini reorgs
fsHeaderCheckFrequency
=
100
// Verification frequency of the downloaded headers during fast sync
fsHeaderSafetyNet
=
2048
// Number of headers to discard in case a chain violation is detected
fsHeaderForceVerify
=
24
// Number of headers to verify before and after the pivot to accept it
...
...
@@ -847,6 +850,30 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64, pivot uint64)
}
headers
=
filled
[
proced
:
]
from
+=
uint64
(
proced
)
}
else
{
// If we're closing in on the chain head, but haven't yet reached it, delay
// the last few headers so mini reorgs on the head don't cause invalid hash
// chain errors.
if
n
:=
len
(
headers
);
n
>
0
{
// Retrieve the current head we're at
head
:=
uint64
(
0
)
if
d
.
mode
==
LightSync
{
head
=
d
.
lightchain
.
CurrentHeader
()
.
Number
.
Uint64
()
}
else
{
head
=
d
.
blockchain
.
CurrentFastBlock
()
.
NumberU64
()
if
full
:=
d
.
blockchain
.
CurrentBlock
()
.
NumberU64
();
head
<
full
{
head
=
full
}
}
// If the head is way older than this batch, delay the last few headers
if
head
+
uint64
(
reorgProtThreshold
)
<
headers
[
n
-
1
]
.
Number
.
Uint64
()
{
delay
:=
reorgProtHeaderDelay
if
delay
>
n
{
delay
=
n
}
headers
=
headers
[
:
n
-
delay
]
}
}
}
// Insert all the new headers and fetch the next batch
if
len
(
headers
)
>
0
{
...
...
@@ -857,8 +884,18 @@ func (d *Downloader) fetchHeaders(p *peerConnection, from uint64, pivot uint64)
return
errCancelHeaderFetch
}
from
+=
uint64
(
len
(
headers
))
getHeaders
(
from
)
}
else
{
// No headers delivered, or all of them being delayed, sleep a bit and retry
p
.
log
.
Trace
(
"All headers delayed, waiting"
)
select
{
case
<-
time
.
After
(
fsHeaderContCheck
)
:
getHeaders
(
from
)
continue
case
<-
d
.
cancelCh
:
return
errCancelHeaderFetch
}
}
getHeaders
(
from
)
case
<-
timeout
.
C
:
if
d
.
dropPeer
==
nil
{
...
...
eth/downloader/downloader_test.go
浏览文件 @
6ee3b26f
...
...
@@ -744,7 +744,7 @@ func testThrottling(t *testing.T, protocol int, mode SyncMode) {
tester
.
downloader
.
queue
.
lock
.
Unlock
()
tester
.
lock
.
Unlock
()
if
cached
==
blockCacheItems
||
retrieved
+
cached
+
frozen
==
targetBlocks
+
1
{
if
cached
==
blockCacheItems
||
cached
==
blockCacheItems
-
reorgProtHeaderDelay
||
retrieved
+
cached
+
frozen
==
targetBlocks
+
1
||
retrieved
+
cached
+
frozen
==
targetBlocks
+
1
-
reorgProtHeaderDelay
{
break
}
}
...
...
@@ -754,7 +754,7 @@ func testThrottling(t *testing.T, protocol int, mode SyncMode) {
tester
.
lock
.
RLock
()
retrieved
=
len
(
tester
.
ownBlocks
)
tester
.
lock
.
RUnlock
()
if
cached
!=
blockCacheItems
&&
retrieved
+
cached
+
frozen
!=
targetBlocks
+
1
{
if
cached
!=
blockCacheItems
&&
cached
!=
blockCacheItems
-
reorgProtHeaderDelay
&&
retrieved
+
cached
+
frozen
!=
targetBlocks
+
1
&&
retrieved
+
cached
+
frozen
!=
targetBlocks
+
1
-
reorgProtHeaderDelay
{
t
.
Fatalf
(
"block count mismatch: have %v, want %v (owned %v, blocked %v, target %v)"
,
cached
,
blockCacheItems
,
retrieved
,
frozen
,
targetBlocks
+
1
)
}
// Permit the blocked blocks to import
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录