Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
96dad6b6
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,发现更多精彩内容 >>
未验证
提交
96dad6b6
编写于
2月 11, 2018
作者:
P
Péter Szilágyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
eth/downloader: don't require state for ancestor lookups
上级
5cf75a30
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
9 addition
and
13 deletion
+9
-13
eth/downloader/downloader.go
eth/downloader/downloader.go
+6
-5
eth/downloader/downloader_test.go
eth/downloader/downloader_test.go
+3
-8
未找到文件。
eth/downloader/downloader.go
浏览文件 @
96dad6b6
...
...
@@ -173,8 +173,8 @@ type LightChain interface {
type
BlockChain
interface
{
LightChain
// HasBlock
AndState verifies block and associated states'
presence in the local chain.
HasBlock
AndState
(
common
.
Hash
,
uint64
)
bool
// HasBlock
verifies a block's
presence in the local chain.
HasBlock
(
common
.
Hash
,
uint64
)
bool
// GetBlockByHash retrieves a block from the local chain.
GetBlockByHash
(
common
.
Hash
)
*
types
.
Block
...
...
@@ -582,7 +582,6 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err
// Figure out the valid ancestor range to prevent rewrite attacks
floor
,
ceil
:=
int64
(
-
1
),
d
.
lightchain
.
CurrentHeader
()
.
Number
.
Uint64
()
p
.
log
.
Debug
(
"Looking for common ancestor"
,
"local"
,
ceil
,
"remote"
,
height
)
if
d
.
mode
==
FullSync
{
ceil
=
d
.
blockchain
.
CurrentBlock
()
.
NumberU64
()
}
else
if
d
.
mode
==
FastSync
{
...
...
@@ -591,6 +590,8 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err
if
ceil
>=
MaxForkAncestry
{
floor
=
int64
(
ceil
-
MaxForkAncestry
)
}
p
.
log
.
Debug
(
"Looking for common ancestor"
,
"local"
,
ceil
,
"remote"
,
height
)
// Request the topmost blocks to short circuit binary ancestor lookup
head
:=
ceil
if
head
>
height
{
...
...
@@ -646,7 +647,7 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err
continue
}
// Otherwise check if we already know the header or not
if
(
d
.
mode
==
FullSync
&&
d
.
blockchain
.
HasBlock
AndState
(
headers
[
i
]
.
Hash
(),
headers
[
i
]
.
Number
.
Uint64
()))
||
(
d
.
mode
!=
FullSync
&&
d
.
lightchain
.
HasHeader
(
headers
[
i
]
.
Hash
(),
headers
[
i
]
.
Number
.
Uint64
()))
{
if
(
d
.
mode
==
FullSync
&&
d
.
blockchain
.
HasBlock
(
headers
[
i
]
.
Hash
(),
headers
[
i
]
.
Number
.
Uint64
()))
||
(
d
.
mode
!=
FullSync
&&
d
.
lightchain
.
HasHeader
(
headers
[
i
]
.
Hash
(),
headers
[
i
]
.
Number
.
Uint64
()))
{
number
,
hash
=
headers
[
i
]
.
Number
.
Uint64
(),
headers
[
i
]
.
Hash
()
// If every header is known, even future ones, the peer straight out lied about its head
...
...
@@ -711,7 +712,7 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err
arrived
=
true
// Modify the search interval based on the response
if
(
d
.
mode
==
FullSync
&&
!
d
.
blockchain
.
HasBlock
AndState
(
headers
[
0
]
.
Hash
(),
headers
[
0
]
.
Number
.
Uint64
()))
||
(
d
.
mode
!=
FullSync
&&
!
d
.
lightchain
.
HasHeader
(
headers
[
0
]
.
Hash
(),
headers
[
0
]
.
Number
.
Uint64
()))
{
if
(
d
.
mode
==
FullSync
&&
!
d
.
blockchain
.
HasBlock
(
headers
[
0
]
.
Hash
(),
headers
[
0
]
.
Number
.
Uint64
()))
||
(
d
.
mode
!=
FullSync
&&
!
d
.
lightchain
.
HasHeader
(
headers
[
0
]
.
Hash
(),
headers
[
0
]
.
Number
.
Uint64
()))
{
end
=
check
break
}
...
...
eth/downloader/downloader_test.go
浏览文件 @
96dad6b6
...
...
@@ -221,14 +221,9 @@ func (dl *downloadTester) HasHeader(hash common.Hash, number uint64) bool {
return
dl
.
GetHeaderByHash
(
hash
)
!=
nil
}
// HasBlockAndState checks if a block and associated state is present in the testers canonical chain.
func
(
dl
*
downloadTester
)
HasBlockAndState
(
hash
common
.
Hash
,
number
uint64
)
bool
{
block
:=
dl
.
GetBlockByHash
(
hash
)
if
block
==
nil
{
return
false
}
_
,
err
:=
dl
.
stateDb
.
Get
(
block
.
Root
()
.
Bytes
())
return
err
==
nil
// HasBlock checks if a block is present in the testers canonical chain.
func
(
dl
*
downloadTester
)
HasBlock
(
hash
common
.
Hash
,
number
uint64
)
bool
{
return
dl
.
GetBlockByHash
(
hash
)
!=
nil
}
// GetHeader retrieves a header from the testers canonical chain.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录