Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
59cd60b2
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,发现更多精彩内容 >>
提交
59cd60b2
编写于
2月 10, 2016
作者:
P
Péter Szilágyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
eth, eth/downloader, jsre: surface state sync progress through the API
上级
be79b4aa
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
160 addition
and
143 deletion
+160
-143
eth/api.go
eth/api.go
+19
-13
eth/downloader/api.go
eth/downloader/api.go
+4
-3
eth/downloader/downloader.go
eth/downloader/downloader.go
+11
-3
eth/downloader/downloader_test.go
eth/downloader/downloader_test.go
+16
-16
jsre/ethereum_js.go
jsre/ethereum_js.go
+110
-108
未找到文件。
eth/api.go
浏览文件 @
59cd60b2
...
...
@@ -152,21 +152,27 @@ func (s *PublicEthereumAPI) Hashrate() *rpc.HexNumber {
}
// Syncing returns false in case the node is currently not synching with the network. It can be up to date or has not
// yet received the latest block headers from its pears. In case it is synchronizing an object with 3 properties is
// returned:
// yet received the latest block headers from its pears. In case it is synchronizing:
// - startingBlock: block number this node started to synchronise from
// - currentBlock: block number this node is currently importing
// - highestBlock: block number of the highest block header this node has received from peers
// - currentBlock: block number this node is currently importing
// - highestBlock: block number of the highest block header this node has received from peers
// - pulledStates: number of state entries processed until now
// - knownStates: number of known state entries that still need to be pulled
func
(
s
*
PublicEthereumAPI
)
Syncing
()
(
interface
{},
error
)
{
origin
,
current
,
height
:=
s
.
e
.
Downloader
()
.
Progress
()
if
current
<
height
{
return
map
[
string
]
interface
{}{
"startingBlock"
:
rpc
.
NewHexNumber
(
origin
),
"currentBlock"
:
rpc
.
NewHexNumber
(
current
),
"highestBlock"
:
rpc
.
NewHexNumber
(
height
),
},
nil
}
return
false
,
nil
origin
,
current
,
height
,
pulled
,
known
:=
s
.
e
.
Downloader
()
.
Progress
()
// Return not syncing if the synchronisation already completed
if
current
>=
height
{
return
false
,
nil
}
// Otherwise gather the block sync stats
return
map
[
string
]
interface
{}{
"startingBlock"
:
rpc
.
NewHexNumber
(
origin
),
"currentBlock"
:
rpc
.
NewHexNumber
(
current
),
"highestBlock"
:
rpc
.
NewHexNumber
(
height
),
"pulledStates"
:
rpc
.
NewHexNumber
(
pulled
),
"knownStates"
:
rpc
.
NewHexNumber
(
known
),
},
nil
}
// PublicMinerAPI provides an API to control the miner.
...
...
eth/downloader/api.go
浏览文件 @
59cd60b2
...
...
@@ -36,6 +36,8 @@ type Progress struct {
Origin
uint64
`json:"startingBlock"`
Current
uint64
`json:"currentBlock"`
Height
uint64
`json:"highestBlock"`
Pulled
uint64
`json:"pulledStates"`
Known
uint64
`json:"knownStates"`
}
// SyncingResult provides information about the current synchronisation status for this node.
...
...
@@ -44,7 +46,7 @@ type SyncingResult struct {
Status
Progress
`json:"status"`
}
// Syncing provides information when this nodes starts synchronising with the Ethereum
n
network and when it's finished.
// Syncing provides information when this nodes starts synchronising with the Ethereum network and when it's finished.
func
(
s
*
PublicDownloaderAPI
)
Syncing
()
(
rpc
.
Subscription
,
error
)
{
sub
:=
s
.
d
.
mux
.
Subscribe
(
StartEvent
{},
DoneEvent
{},
FailedEvent
{})
...
...
@@ -52,13 +54,12 @@ func (s *PublicDownloaderAPI) Syncing() (rpc.Subscription, error) {
switch
event
.
(
type
)
{
case
StartEvent
:
result
:=
&
SyncingResult
{
Syncing
:
true
}
result
.
Status
.
Origin
,
result
.
Status
.
Current
,
result
.
Status
.
Height
=
s
.
d
.
Progress
()
result
.
Status
.
Origin
,
result
.
Status
.
Current
,
result
.
Status
.
Height
,
result
.
Status
.
Pulled
,
result
.
Status
.
Known
=
s
.
d
.
Progress
()
return
result
case
DoneEvent
,
FailedEvent
:
return
false
}
return
nil
}
return
rpc
.
NewSubscriptionWithOutputFormat
(
sub
,
output
),
nil
}
eth/downloader/downloader.go
浏览文件 @
59cd60b2
...
...
@@ -196,7 +196,15 @@ func New(stateDb ethdb.Database, mux *event.TypeMux, hasHeader headerCheckFn, ha
// Progress retrieves the synchronisation boundaries, specifically the origin
// block where synchronisation started at (may have failed/suspended); the block
// or header sync is currently at; and the latest known block which the sync targets.
func
(
d
*
Downloader
)
Progress
()
(
uint64
,
uint64
,
uint64
)
{
//
// In addition, during the state download phase of fast synchonisation the number
// of processed and the total number of known states are also returned. Otherwise
// these are zero.
func
(
d
*
Downloader
)
Progress
()
(
uint64
,
uint64
,
uint64
,
uint64
,
uint64
)
{
// Fetch the pending state count outside of the lock to prevent unforeseen deadlocks
pendingStates
:=
uint64
(
d
.
queue
.
PendingNodeData
())
// Lock the current stats and return the progress
d
.
syncStatsLock
.
RLock
()
defer
d
.
syncStatsLock
.
RUnlock
()
...
...
@@ -209,7 +217,7 @@ func (d *Downloader) Progress() (uint64, uint64, uint64) {
case
LightSync
:
current
=
d
.
headHeader
()
.
Number
.
Uint64
()
}
return
d
.
syncStatsChainOrigin
,
current
,
d
.
syncStatsChainHeight
return
d
.
syncStatsChainOrigin
,
current
,
d
.
syncStatsChainHeight
,
d
.
syncStatsStateDone
,
d
.
syncStatsStateDone
+
pendingStates
}
// Synchronising returns whether the downloader is currently retrieving blocks.
...
...
@@ -296,7 +304,7 @@ func (d *Downloader) synchronise(id string, hash common.Hash, td *big.Int, mode
default
:
}
}
// Reset an
d
ephemeral sync statistics
// Reset an
y
ephemeral sync statistics
d
.
syncStatsLock
.
Lock
()
d
.
syncStatsStateTotal
=
0
d
.
syncStatsStateDone
=
0
...
...
eth/downloader/downloader_test.go
浏览文件 @
59cd60b2
...
...
@@ -1301,7 +1301,7 @@ func testSyncProgress(t *testing.T, protocol int, mode SyncMode) {
<-
progress
}
// Retrieve the sync progress and ensure they are zero (pristine sync)
if
origin
,
current
,
latest
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
!=
0
||
latest
!=
0
{
if
origin
,
current
,
latest
,
_
,
_
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
!=
0
||
latest
!=
0
{
t
.
Fatalf
(
"Pristine progress mismatch: have %v/%v/%v, want %v/%v/%v"
,
origin
,
current
,
latest
,
0
,
0
,
0
)
}
// Synchronise half the blocks and check initial progress
...
...
@@ -1316,7 +1316,7 @@ func testSyncProgress(t *testing.T, protocol int, mode SyncMode) {
}
}()
<-
starting
if
origin
,
current
,
latest
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
!=
0
||
latest
!=
uint64
(
targetBlocks
/
2
+
1
)
{
if
origin
,
current
,
latest
,
_
,
_
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
!=
0
||
latest
!=
uint64
(
targetBlocks
/
2
+
1
)
{
t
.
Fatalf
(
"Initial progress mismatch: have %v/%v/%v, want %v/%v/%v"
,
origin
,
current
,
latest
,
0
,
0
,
targetBlocks
/
2
+
1
)
}
progress
<-
struct
{}{}
...
...
@@ -1333,14 +1333,14 @@ func testSyncProgress(t *testing.T, protocol int, mode SyncMode) {
}
}()
<-
starting
if
origin
,
current
,
latest
:=
tester
.
downloader
.
Progress
();
origin
!=
uint64
(
targetBlocks
/
2
+
1
)
||
current
!=
uint64
(
targetBlocks
/
2
+
1
)
||
latest
!=
uint64
(
targetBlocks
)
{
if
origin
,
current
,
latest
,
_
,
_
:=
tester
.
downloader
.
Progress
();
origin
!=
uint64
(
targetBlocks
/
2
+
1
)
||
current
!=
uint64
(
targetBlocks
/
2
+
1
)
||
latest
!=
uint64
(
targetBlocks
)
{
t
.
Fatalf
(
"Completing progress mismatch: have %v/%v/%v, want %v/%v/%v"
,
origin
,
current
,
latest
,
targetBlocks
/
2
+
1
,
targetBlocks
/
2
+
1
,
targetBlocks
)
}
progress
<-
struct
{}{}
pending
.
Wait
()
// Check final progress after successful sync
if
origin
,
current
,
latest
:=
tester
.
downloader
.
Progress
();
origin
!=
uint64
(
targetBlocks
/
2
+
1
)
||
current
!=
uint64
(
targetBlocks
)
||
latest
!=
uint64
(
targetBlocks
)
{
if
origin
,
current
,
latest
,
_
,
_
:=
tester
.
downloader
.
Progress
();
origin
!=
uint64
(
targetBlocks
/
2
+
1
)
||
current
!=
uint64
(
targetBlocks
)
||
latest
!=
uint64
(
targetBlocks
)
{
t
.
Fatalf
(
"Final progress mismatch: have %v/%v/%v, want %v/%v/%v"
,
origin
,
current
,
latest
,
targetBlocks
/
2
+
1
,
targetBlocks
,
targetBlocks
)
}
}
...
...
@@ -1373,7 +1373,7 @@ func testForkedSyncProgress(t *testing.T, protocol int, mode SyncMode) {
<-
progress
}
// Retrieve the sync progress and ensure they are zero (pristine sync)
if
origin
,
current
,
latest
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
!=
0
||
latest
!=
0
{
if
origin
,
current
,
latest
,
_
,
_
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
!=
0
||
latest
!=
0
{
t
.
Fatalf
(
"Pristine progress mismatch: have %v/%v/%v, want %v/%v/%v"
,
origin
,
current
,
latest
,
0
,
0
,
0
)
}
// Synchronise with one of the forks and check progress
...
...
@@ -1388,7 +1388,7 @@ func testForkedSyncProgress(t *testing.T, protocol int, mode SyncMode) {
}
}()
<-
starting
if
origin
,
current
,
latest
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
!=
0
||
latest
!=
uint64
(
len
(
hashesA
)
-
1
)
{
if
origin
,
current
,
latest
,
_
,
_
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
!=
0
||
latest
!=
uint64
(
len
(
hashesA
)
-
1
)
{
t
.
Fatalf
(
"Initial progress mismatch: have %v/%v/%v, want %v/%v/%v"
,
origin
,
current
,
latest
,
0
,
0
,
len
(
hashesA
)
-
1
)
}
progress
<-
struct
{}{}
...
...
@@ -1408,14 +1408,14 @@ func testForkedSyncProgress(t *testing.T, protocol int, mode SyncMode) {
}
}()
<-
starting
if
origin
,
current
,
latest
:=
tester
.
downloader
.
Progress
();
origin
!=
uint64
(
common
)
||
current
!=
uint64
(
len
(
hashesA
)
-
1
)
||
latest
!=
uint64
(
len
(
hashesB
)
-
1
)
{
if
origin
,
current
,
latest
,
_
,
_
:=
tester
.
downloader
.
Progress
();
origin
!=
uint64
(
common
)
||
current
!=
uint64
(
len
(
hashesA
)
-
1
)
||
latest
!=
uint64
(
len
(
hashesB
)
-
1
)
{
t
.
Fatalf
(
"Forking progress mismatch: have %v/%v/%v, want %v/%v/%v"
,
origin
,
current
,
latest
,
common
,
len
(
hashesA
)
-
1
,
len
(
hashesB
)
-
1
)
}
progress
<-
struct
{}{}
pending
.
Wait
()
// Check final progress after successful sync
if
origin
,
current
,
latest
:=
tester
.
downloader
.
Progress
();
origin
!=
uint64
(
common
)
||
current
!=
uint64
(
len
(
hashesB
)
-
1
)
||
latest
!=
uint64
(
len
(
hashesB
)
-
1
)
{
if
origin
,
current
,
latest
,
_
,
_
:=
tester
.
downloader
.
Progress
();
origin
!=
uint64
(
common
)
||
current
!=
uint64
(
len
(
hashesB
)
-
1
)
||
latest
!=
uint64
(
len
(
hashesB
)
-
1
)
{
t
.
Fatalf
(
"Final progress mismatch: have %v/%v/%v, want %v/%v/%v"
,
origin
,
current
,
latest
,
common
,
len
(
hashesB
)
-
1
,
len
(
hashesB
)
-
1
)
}
}
...
...
@@ -1448,7 +1448,7 @@ func testFailedSyncProgress(t *testing.T, protocol int, mode SyncMode) {
<-
progress
}
// Retrieve the sync progress and ensure they are zero (pristine sync)
if
origin
,
current
,
latest
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
!=
0
||
latest
!=
0
{
if
origin
,
current
,
latest
,
_
,
_
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
!=
0
||
latest
!=
0
{
t
.
Fatalf
(
"Pristine progress mismatch: have %v/%v/%v, want %v/%v/%v"
,
origin
,
current
,
latest
,
0
,
0
,
0
)
}
// Attempt a full sync with a faulty peer
...
...
@@ -1468,7 +1468,7 @@ func testFailedSyncProgress(t *testing.T, protocol int, mode SyncMode) {
}
}()
<-
starting
if
origin
,
current
,
latest
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
!=
0
||
latest
!=
uint64
(
targetBlocks
)
{
if
origin
,
current
,
latest
,
_
,
_
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
!=
0
||
latest
!=
uint64
(
targetBlocks
)
{
t
.
Fatalf
(
"Initial progress mismatch: have %v/%v/%v, want %v/%v/%v"
,
origin
,
current
,
latest
,
0
,
0
,
targetBlocks
)
}
progress
<-
struct
{}{}
...
...
@@ -1485,14 +1485,14 @@ func testFailedSyncProgress(t *testing.T, protocol int, mode SyncMode) {
}
}()
<-
starting
if
origin
,
current
,
latest
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
>
uint64
(
targetBlocks
/
2
)
||
latest
!=
uint64
(
targetBlocks
)
{
if
origin
,
current
,
latest
,
_
,
_
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
>
uint64
(
targetBlocks
/
2
)
||
latest
!=
uint64
(
targetBlocks
)
{
t
.
Fatalf
(
"Completing progress mismatch: have %v/%v/%v, want %v/0-%v/%v"
,
origin
,
current
,
latest
,
0
,
targetBlocks
/
2
,
targetBlocks
)
}
progress
<-
struct
{}{}
pending
.
Wait
()
// Check final progress after successful sync
if
origin
,
current
,
latest
:=
tester
.
downloader
.
Progress
();
origin
>
uint64
(
targetBlocks
/
2
)
||
current
!=
uint64
(
targetBlocks
)
||
latest
!=
uint64
(
targetBlocks
)
{
if
origin
,
current
,
latest
,
_
,
_
:=
tester
.
downloader
.
Progress
();
origin
>
uint64
(
targetBlocks
/
2
)
||
current
!=
uint64
(
targetBlocks
)
||
latest
!=
uint64
(
targetBlocks
)
{
t
.
Fatalf
(
"Final progress mismatch: have %v/%v/%v, want 0-%v/%v/%v"
,
origin
,
current
,
latest
,
targetBlocks
/
2
,
targetBlocks
,
targetBlocks
)
}
}
...
...
@@ -1524,7 +1524,7 @@ func testFakedSyncProgress(t *testing.T, protocol int, mode SyncMode) {
<-
progress
}
// Retrieve the sync progress and ensure they are zero (pristine sync)
if
origin
,
current
,
latest
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
!=
0
||
latest
!=
0
{
if
origin
,
current
,
latest
,
_
,
_
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
!=
0
||
latest
!=
0
{
t
.
Fatalf
(
"Pristine progress mismatch: have %v/%v/%v, want %v/%v/%v"
,
origin
,
current
,
latest
,
0
,
0
,
0
)
}
// Create and sync with an attacker that promises a higher chain than available
...
...
@@ -1545,7 +1545,7 @@ func testFakedSyncProgress(t *testing.T, protocol int, mode SyncMode) {
}
}()
<-
starting
if
origin
,
current
,
latest
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
!=
0
||
latest
!=
uint64
(
targetBlocks
+
3
)
{
if
origin
,
current
,
latest
,
_
,
_
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
!=
0
||
latest
!=
uint64
(
targetBlocks
+
3
)
{
t
.
Fatalf
(
"Initial progress mismatch: have %v/%v/%v, want %v/%v/%v"
,
origin
,
current
,
latest
,
0
,
0
,
targetBlocks
+
3
)
}
progress
<-
struct
{}{}
...
...
@@ -1562,14 +1562,14 @@ func testFakedSyncProgress(t *testing.T, protocol int, mode SyncMode) {
}
}()
<-
starting
if
origin
,
current
,
latest
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
>
uint64
(
targetBlocks
)
||
latest
!=
uint64
(
targetBlocks
)
{
if
origin
,
current
,
latest
,
_
,
_
:=
tester
.
downloader
.
Progress
();
origin
!=
0
||
current
>
uint64
(
targetBlocks
)
||
latest
!=
uint64
(
targetBlocks
)
{
t
.
Fatalf
(
"Completing progress mismatch: have %v/%v/%v, want %v/0-%v/%v"
,
origin
,
current
,
latest
,
0
,
targetBlocks
,
targetBlocks
)
}
progress
<-
struct
{}{}
pending
.
Wait
()
// Check final progress after successful sync
if
origin
,
current
,
latest
:=
tester
.
downloader
.
Progress
();
origin
>
uint64
(
targetBlocks
)
||
current
!=
uint64
(
targetBlocks
)
||
latest
!=
uint64
(
targetBlocks
)
{
if
origin
,
current
,
latest
,
_
,
_
:=
tester
.
downloader
.
Progress
();
origin
>
uint64
(
targetBlocks
)
||
current
!=
uint64
(
targetBlocks
)
||
latest
!=
uint64
(
targetBlocks
)
{
t
.
Fatalf
(
"Final progress mismatch: have %v/%v/%v, want 0-%v/%v/%v"
,
origin
,
current
,
latest
,
targetBlocks
,
targetBlocks
,
targetBlocks
)
}
}
...
...
jsre/ethereum_js.go
浏览文件 @
59cd60b2
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录