Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
c134e00e
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,发现更多精彩内容 >>
未验证
提交
c134e00e
编写于
8月 23, 2018
作者:
P
Péter Szilágyi
提交者:
GitHub
8月 23, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17494 from karalabe/mined-block-uncle-check
miner: differentiate between uncle and lost block
上级
40a71f28
1136269a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
36 addition
and
14 deletion
+36
-14
miner/unconfirmed.go
miner/unconfirmed.go
+27
-8
miner/unconfirmed_test.go
miner/unconfirmed_test.go
+8
-5
miner/worker.go
miner/worker.go
+1
-1
未找到文件。
miner/unconfirmed.go
浏览文件 @
c134e00e
...
...
@@ -25,11 +25,14 @@ import (
"github.com/ethereum/go-ethereum/log"
)
//
header
Retriever is used by the unconfirmed block set to verify whether a previously
//
chain
Retriever is used by the unconfirmed block set to verify whether a previously
// mined block is part of the canonical chain or not.
type
header
Retriever
interface
{
type
chain
Retriever
interface
{
// GetHeaderByNumber retrieves the canonical header associated with a block number.
GetHeaderByNumber
(
number
uint64
)
*
types
.
Header
// GetBlockByNumber retrieves the canonical block associated with a block number.
GetBlockByNumber
(
number
uint64
)
*
types
.
Block
}
// unconfirmedBlock is a small collection of metadata about a locally mined block
...
...
@@ -44,14 +47,14 @@ type unconfirmedBlock struct {
// used by the miner to provide logs to the user when a previously mined block
// has a high enough guarantee to not be reorged out of the canonical chain.
type
unconfirmedBlocks
struct
{
chain
header
Retriever
// Blockchain to verify canonical status through
depth
uint
// Depth after which to discard previous blocks
blocks
*
ring
.
Ring
// Block infos to allow canonical chain cross checks
lock
sync
.
RWMutex
// Protects the fields from concurrent access
chain
chain
Retriever
// Blockchain to verify canonical status through
depth
uint
// Depth after which to discard previous blocks
blocks
*
ring
.
Ring
// Block infos to allow canonical chain cross checks
lock
sync
.
RWMutex
// Protects the fields from concurrent access
}
// newUnconfirmedBlocks returns new data structure to track currently unconfirmed blocks.
func
newUnconfirmedBlocks
(
chain
header
Retriever
,
depth
uint
)
*
unconfirmedBlocks
{
func
newUnconfirmedBlocks
(
chain
chain
Retriever
,
depth
uint
)
*
unconfirmedBlocks
{
return
&
unconfirmedBlocks
{
chain
:
chain
,
depth
:
depth
,
...
...
@@ -103,7 +106,23 @@ func (set *unconfirmedBlocks) Shift(height uint64) {
case
header
.
Hash
()
==
next
.
hash
:
log
.
Info
(
"🔗 block reached canonical chain"
,
"number"
,
next
.
index
,
"hash"
,
next
.
hash
)
default
:
log
.
Info
(
"⑂ block became a side fork"
,
"number"
,
next
.
index
,
"hash"
,
next
.
hash
)
// Block is not canonical, check whether we have an uncle or a lost block
included
:=
false
for
number
:=
next
.
index
;
!
included
&&
number
<
next
.
index
+
uint64
(
set
.
depth
)
&&
number
<=
height
;
number
++
{
if
block
:=
set
.
chain
.
GetBlockByNumber
(
number
);
block
!=
nil
{
for
_
,
uncle
:=
range
block
.
Uncles
()
{
if
uncle
.
Hash
()
==
next
.
hash
{
included
=
true
break
}
}
}
}
if
included
{
log
.
Info
(
"⑂ block became an uncle"
,
"number"
,
next
.
index
,
"hash"
,
next
.
hash
)
}
else
{
log
.
Info
(
"😱 block lost"
,
"number"
,
next
.
index
,
"hash"
,
next
.
hash
)
}
}
// Drop the block out of the ring
if
set
.
blocks
.
Value
==
set
.
blocks
.
Next
()
.
Value
{
...
...
miner/unconfirmed_test.go
浏览文件 @
c134e00e
...
...
@@ -23,11 +23,14 @@ import (
"github.com/ethereum/go-ethereum/core/types"
)
// noop
Header
Retriever is an implementation of headerRetriever that always
// noop
Chain
Retriever is an implementation of headerRetriever that always
// returns nil for any requested headers.
type
noop
Header
Retriever
struct
{}
type
noop
Chain
Retriever
struct
{}
func
(
r
*
noopHeaderRetriever
)
GetHeaderByNumber
(
number
uint64
)
*
types
.
Header
{
func
(
r
*
noopChainRetriever
)
GetHeaderByNumber
(
number
uint64
)
*
types
.
Header
{
return
nil
}
func
(
r
*
noopChainRetriever
)
GetBlockByNumber
(
number
uint64
)
*
types
.
Block
{
return
nil
}
...
...
@@ -36,7 +39,7 @@ func (r *noopHeaderRetriever) GetHeaderByNumber(number uint64) *types.Header {
func
TestUnconfirmedInsertBounds
(
t
*
testing
.
T
)
{
limit
:=
uint
(
10
)
pool
:=
newUnconfirmedBlocks
(
new
(
noop
Header
Retriever
),
limit
)
pool
:=
newUnconfirmedBlocks
(
new
(
noop
Chain
Retriever
),
limit
)
for
depth
:=
uint64
(
0
);
depth
<
2
*
uint64
(
limit
);
depth
++
{
// Insert multiple blocks for the same level just to stress it
for
i
:=
0
;
i
<
int
(
depth
);
i
++
{
...
...
@@ -58,7 +61,7 @@ func TestUnconfirmedShifts(t *testing.T) {
// Create a pool with a few blocks on various depths
limit
,
start
:=
uint
(
10
),
uint64
(
25
)
pool
:=
newUnconfirmedBlocks
(
new
(
noop
Header
Retriever
),
limit
)
pool
:=
newUnconfirmedBlocks
(
new
(
noop
Chain
Retriever
),
limit
)
for
depth
:=
start
;
depth
<
start
+
uint64
(
limit
);
depth
++
{
pool
.
Insert
(
depth
,
common
.
Hash
([
32
]
byte
{
byte
(
depth
)}))
}
...
...
miner/worker.go
浏览文件 @
c134e00e
...
...
@@ -55,7 +55,7 @@ const (
resubmitAdjustChanSize
=
10
// miningLogAtDepth is the number of confirmations before logging successful mining.
miningLogAtDepth
=
5
miningLogAtDepth
=
7
// minRecommitInterval is the minimal time interval to recreate the mining block with
// any newly arrived transactions.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录