Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
b7bbe66b
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 搜索 >>
提交
b7bbe66b
编写于
10月 01, 2018
作者:
F
Felföldi Zsolt
提交者:
Martin Holst Swende
10月 01, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
les: limit state ODR retrievals to the last 100 blocks (#17744)
上级
96fd50be
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
26 addition
and
19 deletion
+26
-19
les/fetcher.go
les/fetcher.go
+17
-10
les/odr_requests.go
les/odr_requests.go
+4
-4
les/odr_test.go
les/odr_test.go
+1
-1
les/peer.go
les/peer.go
+3
-3
les/request_test.go
les/request_test.go
+1
-1
未找到文件。
les/fetcher.go
浏览文件 @
b7bbe66b
...
...
@@ -32,8 +32,9 @@ import (
)
const
(
blockDelayTimeout
=
time
.
Second
*
10
// timeout for a peer to announce a head that has already been confirmed by others
maxNodeCount
=
20
// maximum number of fetcherTreeNode entries remembered for each peer
blockDelayTimeout
=
time
.
Second
*
10
// timeout for a peer to announce a head that has already been confirmed by others
maxNodeCount
=
20
// maximum number of fetcherTreeNode entries remembered for each peer
serverStateAvailable
=
100
// number of recent blocks where state availability is assumed
)
// lightFetcher implements retrieval of newly announced headers. It also provides a peerHasBlock function for the
...
...
@@ -215,8 +216,8 @@ func (f *lightFetcher) syncLoop() {
// registerPeer adds a new peer to the fetcher's peer set
func
(
f
*
lightFetcher
)
registerPeer
(
p
*
peer
)
{
p
.
lock
.
Lock
()
p
.
hasBlock
=
func
(
hash
common
.
Hash
,
number
uint64
)
bool
{
return
f
.
peerHasBlock
(
p
,
hash
,
number
)
p
.
hasBlock
=
func
(
hash
common
.
Hash
,
number
uint64
,
hasState
bool
)
bool
{
return
f
.
peerHasBlock
(
p
,
hash
,
number
,
hasState
)
}
p
.
lock
.
Unlock
()
...
...
@@ -344,21 +345,27 @@ func (f *lightFetcher) announce(p *peer, head *announceData) {
// peerHasBlock returns true if we can assume the peer knows the given block
// based on its announcements
func
(
f
*
lightFetcher
)
peerHasBlock
(
p
*
peer
,
hash
common
.
Hash
,
number
uint64
)
bool
{
func
(
f
*
lightFetcher
)
peerHasBlock
(
p
*
peer
,
hash
common
.
Hash
,
number
uint64
,
hasState
bool
)
bool
{
f
.
lock
.
Lock
()
defer
f
.
lock
.
Unlock
()
fp
:=
f
.
peers
[
p
]
if
fp
==
nil
||
fp
.
root
==
nil
{
return
false
}
if
hasState
{
if
fp
.
lastAnnounced
==
nil
||
fp
.
lastAnnounced
.
number
>
number
+
serverStateAvailable
{
return
false
}
}
if
f
.
syncing
{
// always return true when syncing
// false positives are acceptable, a more sophisticated condition can be implemented later
return
true
}
fp
:=
f
.
peers
[
p
]
if
fp
==
nil
||
fp
.
root
==
nil
{
return
false
}
if
number
>=
fp
.
root
.
number
{
// it is recent enough that if it is known, is should be in the peer's block tree
return
fp
.
nodeByHash
[
hash
]
!=
nil
...
...
les/odr_requests.go
浏览文件 @
b7bbe66b
...
...
@@ -84,7 +84,7 @@ func (r *BlockRequest) GetCost(peer *peer) uint64 {
// CanSend tells if a certain peer is suitable for serving the given request
func
(
r
*
BlockRequest
)
CanSend
(
peer
*
peer
)
bool
{
return
peer
.
HasBlock
(
r
.
Hash
,
r
.
Number
)
return
peer
.
HasBlock
(
r
.
Hash
,
r
.
Number
,
false
)
}
// Request sends an ODR request to the LES network (implementation of LesOdrRequest)
...
...
@@ -140,7 +140,7 @@ func (r *ReceiptsRequest) GetCost(peer *peer) uint64 {
// CanSend tells if a certain peer is suitable for serving the given request
func
(
r
*
ReceiptsRequest
)
CanSend
(
peer
*
peer
)
bool
{
return
peer
.
HasBlock
(
r
.
Hash
,
r
.
Number
)
return
peer
.
HasBlock
(
r
.
Hash
,
r
.
Number
,
false
)
}
// Request sends an ODR request to the LES network (implementation of LesOdrRequest)
...
...
@@ -202,7 +202,7 @@ func (r *TrieRequest) GetCost(peer *peer) uint64 {
// CanSend tells if a certain peer is suitable for serving the given request
func
(
r
*
TrieRequest
)
CanSend
(
peer
*
peer
)
bool
{
return
peer
.
HasBlock
(
r
.
Id
.
BlockHash
,
r
.
Id
.
BlockNumber
)
return
peer
.
HasBlock
(
r
.
Id
.
BlockHash
,
r
.
Id
.
BlockNumber
,
true
)
}
// Request sends an ODR request to the LES network (implementation of LesOdrRequest)
...
...
@@ -272,7 +272,7 @@ func (r *CodeRequest) GetCost(peer *peer) uint64 {
// CanSend tells if a certain peer is suitable for serving the given request
func
(
r
*
CodeRequest
)
CanSend
(
peer
*
peer
)
bool
{
return
peer
.
HasBlock
(
r
.
Id
.
BlockHash
,
r
.
Id
.
BlockNumber
)
return
peer
.
HasBlock
(
r
.
Id
.
BlockHash
,
r
.
Id
.
BlockNumber
,
true
)
}
// Request sends an ODR request to the LES network (implementation of LesOdrRequest)
...
...
les/odr_test.go
浏览文件 @
b7bbe66b
...
...
@@ -194,7 +194,7 @@ func testOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) {
client
.
peers
.
Register
(
client
.
rPeer
)
time
.
Sleep
(
time
.
Millisecond
*
10
)
// ensure that all peerSetNotify callbacks are executed
client
.
peers
.
lock
.
Lock
()
client
.
rPeer
.
hasBlock
=
func
(
common
.
Hash
,
uint64
)
bool
{
return
true
}
client
.
rPeer
.
hasBlock
=
func
(
common
.
Hash
,
uint64
,
bool
)
bool
{
return
true
}
client
.
peers
.
lock
.
Unlock
()
test
(
5
)
// still expect all retrievals to pass, now data should be cached locally
...
...
les/peer.go
浏览文件 @
b7bbe66b
...
...
@@ -67,7 +67,7 @@ type peer struct {
sendQueue
*
execQueue
poolEntry
*
poolEntry
hasBlock
func
(
common
.
Hash
,
uint64
)
bool
hasBlock
func
(
common
.
Hash
,
uint64
,
bool
)
bool
responseErrors
int
fcClient
*
flowcontrol
.
ClientNode
// nil if the peer is server only
...
...
@@ -171,11 +171,11 @@ func (p *peer) GetRequestCost(msgcode uint64, amount int) uint64 {
}
// HasBlock checks if the peer has a given block
func
(
p
*
peer
)
HasBlock
(
hash
common
.
Hash
,
number
uint64
)
bool
{
func
(
p
*
peer
)
HasBlock
(
hash
common
.
Hash
,
number
uint64
,
hasState
bool
)
bool
{
p
.
lock
.
RLock
()
hasBlock
:=
p
.
hasBlock
p
.
lock
.
RUnlock
()
return
hasBlock
!=
nil
&&
hasBlock
(
hash
,
number
)
return
hasBlock
!=
nil
&&
hasBlock
(
hash
,
number
,
hasState
)
}
// SendAnnounce announces the availability of a number of blocks through
...
...
les/request_test.go
浏览文件 @
b7bbe66b
...
...
@@ -115,7 +115,7 @@ func testAccess(t *testing.T, protocol int, fn accessTestFn) {
client
.
peers
.
Register
(
client
.
rPeer
)
time
.
Sleep
(
time
.
Millisecond
*
10
)
// ensure that all peerSetNotify callbacks are executed
client
.
rPeer
.
lock
.
Lock
()
client
.
rPeer
.
hasBlock
=
func
(
common
.
Hash
,
uint64
)
bool
{
return
true
}
client
.
rPeer
.
hasBlock
=
func
(
common
.
Hash
,
uint64
,
bool
)
bool
{
return
true
}
client
.
rPeer
.
lock
.
Unlock
()
// expect all retrievals to pass
test
(
5
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录