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
94d1f588
Unverified
Commit
94d1f588
authored
Oct 13, 2020
by
mr_franklin
Committed by
GitHub
Oct 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
consensus/clique: unexport calcDifficulty and improve comment (#21619)
parent
c37e68e7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
8 deletions
+6
-8
clique.go
consensus/clique/clique.go
+6
-8
No files found.
consensus/clique/clique.go
View file @
94d1f588
...
@@ -520,7 +520,7 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header
...
@@ -520,7 +520,7 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header
c
.
lock
.
RUnlock
()
c
.
lock
.
RUnlock
()
}
}
// Set the correct difficulty
// Set the correct difficulty
header
.
Difficulty
=
C
alcDifficulty
(
snap
,
c
.
signer
)
header
.
Difficulty
=
c
alcDifficulty
(
snap
,
c
.
signer
)
// Ensure the extra data has all its components
// Ensure the extra data has all its components
if
len
(
header
.
Extra
)
<
extraVanity
{
if
len
(
header
.
Extra
)
<
extraVanity
{
...
@@ -652,20 +652,18 @@ func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
...
@@ -652,20 +652,18 @@ func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
}
}
// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
// that a new block should have based on the previous blocks in the chain and the
// that a new block should have:
// current signer.
// * DIFF_NOTURN(2) if BLOCK_NUMBER % SIGNER_COUNT != SIGNER_INDEX
// * DIFF_INTURN(1) if BLOCK_NUMBER % SIGNER_COUNT == SIGNER_INDEX
func
(
c
*
Clique
)
CalcDifficulty
(
chain
consensus
.
ChainHeaderReader
,
time
uint64
,
parent
*
types
.
Header
)
*
big
.
Int
{
func
(
c
*
Clique
)
CalcDifficulty
(
chain
consensus
.
ChainHeaderReader
,
time
uint64
,
parent
*
types
.
Header
)
*
big
.
Int
{
snap
,
err
:=
c
.
snapshot
(
chain
,
parent
.
Number
.
Uint64
(),
parent
.
Hash
(),
nil
)
snap
,
err
:=
c
.
snapshot
(
chain
,
parent
.
Number
.
Uint64
(),
parent
.
Hash
(),
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
return
nil
}
}
return
C
alcDifficulty
(
snap
,
c
.
signer
)
return
c
alcDifficulty
(
snap
,
c
.
signer
)
}
}
// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
func
calcDifficulty
(
snap
*
Snapshot
,
signer
common
.
Address
)
*
big
.
Int
{
// that a new block should have based on the previous blocks in the chain and the
// current signer.
func
CalcDifficulty
(
snap
*
Snapshot
,
signer
common
.
Address
)
*
big
.
Int
{
if
snap
.
inturn
(
snap
.
Number
+
1
,
signer
)
{
if
snap
.
inturn
(
snap
.
Number
+
1
,
signer
)
{
return
new
(
big
.
Int
)
.
Set
(
diffInTurn
)
return
new
(
big
.
Int
)
.
Set
(
diffInTurn
)
}
}
...
...
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