Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
cd88f697
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,发现更多精彩内容 >>
提交
cd88f697
编写于
6月 23, 2017
作者:
P
Péter Szilágyi
提交者:
GitHub
6月 23, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14596 from markya0616/valid_clique_vote
consensus/clique: choose valid votes
上级
46d0d04f
514659a0
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
23 addition
and
10 deletion
+23
-10
consensus/clique/clique.go
consensus/clique/clique.go
+15
-8
consensus/clique/snapshot.go
consensus/clique/snapshot.go
+8
-2
未找到文件。
consensus/clique/clique.go
浏览文件 @
cd88f697
...
...
@@ -503,13 +503,24 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro
header
.
Nonce
=
types
.
BlockNonce
{}
number
:=
header
.
Number
.
Uint64
()
// Assemble the voting snapshot to check which votes make sense
snap
,
err
:=
c
.
snapshot
(
chain
,
number
-
1
,
header
.
ParentHash
,
nil
)
if
err
!=
nil
{
return
err
}
if
number
%
c
.
config
.
Epoch
!=
0
{
c
.
lock
.
RLock
()
if
len
(
c
.
proposals
)
>
0
{
// Gather all the proposals that make sense voting on
addresses
:=
make
([]
common
.
Address
,
0
,
len
(
c
.
proposals
))
for
address
:=
range
c
.
proposals
{
for
address
,
authorize
:=
range
c
.
proposals
{
if
snap
.
validVote
(
address
,
authorize
)
{
addresses
=
append
(
addresses
,
address
)
}
}
// If there's pending proposals, cast a vote on them
if
len
(
addresses
)
>
0
{
header
.
Coinbase
=
addresses
[
rand
.
Intn
(
len
(
addresses
))]
if
c
.
proposals
[
header
.
Coinbase
]
{
copy
(
header
.
Nonce
[
:
],
nonceAuthVote
)
...
...
@@ -519,11 +530,7 @@ func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) erro
}
c
.
lock
.
RUnlock
()
}
// Assemble the voting snapshot and set the correct difficulty
snap
,
err
:=
c
.
snapshot
(
chain
,
number
-
1
,
header
.
ParentHash
,
nil
)
if
err
!=
nil
{
return
err
}
// Set the correct difficulty
header
.
Difficulty
=
diffNoTurn
if
snap
.
inturn
(
header
.
Number
.
Uint64
(),
c
.
signer
)
{
header
.
Difficulty
=
diffInTurn
...
...
consensus/clique/snapshot.go
浏览文件 @
cd88f697
...
...
@@ -126,11 +126,17 @@ func (s *Snapshot) copy() *Snapshot {
return
cpy
}
// validVote returns whether it makes sense to cast the specified vote in the
// given snapshot context (e.g. don't try to add an already authorized signer).
func
(
s
*
Snapshot
)
validVote
(
address
common
.
Address
,
authorize
bool
)
bool
{
_
,
signer
:=
s
.
Signers
[
address
]
return
(
signer
&&
!
authorize
)
||
(
!
signer
&&
authorize
)
}
// cast adds a new vote into the tally.
func
(
s
*
Snapshot
)
cast
(
address
common
.
Address
,
authorize
bool
)
bool
{
// Ensure the vote is meaningful
_
,
signer
:=
s
.
Signers
[
address
]
if
(
signer
&&
authorize
)
||
(
!
signer
&&
!
authorize
)
{
if
!
s
.
validVote
(
address
,
authorize
)
{
return
false
}
// Cast the vote into an existing or new tally
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录