Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
cd88f697
Commit
cd88f697
authored
7 years ago
by
Péter Szilágyi
Committed by
GitHub
7 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14596 from markya0616/valid_clique_vote
consensus/clique: choose valid votes
parents
46d0d04f
514659a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
10 deletions
+23
-10
clique.go
consensus/clique/clique.go
+15
-8
snapshot.go
consensus/clique/snapshot.go
+8
-2
No files found.
consensus/clique/clique.go
View file @
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
{
addresses
:=
make
([]
common
.
Address
,
0
,
len
(
c
.
proposals
))
for
address
:=
range
c
.
proposals
{
// Gather all the proposals that make sense voting on
addresses
:=
make
([]
common
.
Address
,
0
,
len
(
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
...
...
This diff is collapsed.
Click to expand it.
consensus/clique/snapshot.go
View file @
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
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment