good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
c4d28aee
Unverified
Commit
c4d28aee
authored
Jun 30, 2017
by
Jeffrey Wilcke
Committed by
Péter Szilágyi
Jun 30, 2017
Browse files
Options
Downloads
Patches
Plain Diff
consensus/ethash: implement Metropolis EIP 100
parent
a0aa071c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
consensus/ethash/consensus.go
+48
-0
48 additions, 0 deletions
consensus/ethash/consensus.go
with
48 additions
and
0 deletions
consensus/ethash/consensus.go
+
48
−
0
View file @
c4d28aee
...
@@ -289,6 +289,8 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
...
@@ -289,6 +289,8 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainReader, header, parent *
func
CalcDifficulty
(
config
*
params
.
ChainConfig
,
time
uint64
,
parent
*
types
.
Header
)
*
big
.
Int
{
func
CalcDifficulty
(
config
*
params
.
ChainConfig
,
time
uint64
,
parent
*
types
.
Header
)
*
big
.
Int
{
next
:=
new
(
big
.
Int
)
.
Add
(
parent
.
Number
,
common
.
Big1
)
next
:=
new
(
big
.
Int
)
.
Add
(
parent
.
Number
,
common
.
Big1
)
switch
{
switch
{
case
config
.
IsMetropolis
(
next
)
:
return
calcDifficultyMetropolis
(
time
,
parent
)
case
config
.
IsHomestead
(
next
)
:
case
config
.
IsHomestead
(
next
)
:
return
calcDifficultyHomestead
(
time
,
parent
)
return
calcDifficultyHomestead
(
time
,
parent
)
default
:
default
:
...
@@ -299,10 +301,56 @@ func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Heade
...
@@ -299,10 +301,56 @@ func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Heade
// Some weird constants to avoid constant memory allocs for them.
// Some weird constants to avoid constant memory allocs for them.
var
(
var
(
expDiffPeriod
=
big
.
NewInt
(
100000
)
expDiffPeriod
=
big
.
NewInt
(
100000
)
big9
=
big
.
NewInt
(
9
)
big10
=
big
.
NewInt
(
10
)
big10
=
big
.
NewInt
(
10
)
bigMinus99
=
big
.
NewInt
(
-
99
)
bigMinus99
=
big
.
NewInt
(
-
99
)
)
)
func
calcDifficultyMetropolis
(
time
uint64
,
parent
*
types
.
Header
)
*
big
.
Int
{
bigTime
:=
new
(
big
.
Int
)
.
SetUint64
(
time
)
bigParentTime
:=
new
(
big
.
Int
)
.
Set
(
parent
.
Time
)
// adj_factor = max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) // 9), -99)
var
x
*
big
.
Int
if
parent
.
UncleHash
==
types
.
EmptyUncleHash
{
x
=
big
.
NewInt
(
1
)
}
else
{
x
=
big
.
NewInt
(
2
)
}
z
:=
new
(
big
.
Int
)
.
Sub
(
bigTime
,
bigParentTime
)
z
.
Div
(
z
,
big9
)
x
.
Sub
(
x
,
z
)
// max(1 - (block_timestamp - parent_timestamp) // 10, -99)))
if
x
.
Cmp
(
bigMinus99
)
<
0
{
x
.
Set
(
bigMinus99
)
}
// (parent_diff + parent_diff // 2048 * max(1 - (block_timestamp - parent_timestamp) // 10, -99))
y
:=
new
(
big
.
Int
)
.
Div
(
parent
.
Difficulty
,
params
.
DifficultyBoundDivisor
)
x
.
Mul
(
y
,
x
)
x
.
Add
(
parent
.
Difficulty
,
x
)
// minimum difficulty can ever be (before exponential factor)
if
x
.
Cmp
(
params
.
MinimumDifficulty
)
<
0
{
x
.
Set
(
params
.
MinimumDifficulty
)
}
// for the exponential factor
periodCount
:=
new
(
big
.
Int
)
.
Add
(
parent
.
Number
,
common
.
Big1
)
periodCount
.
Div
(
periodCount
,
expDiffPeriod
)
// the exponential factor, commonly referred to as "the bomb"
// diff = diff + 2^(periodCount - 2)
if
periodCount
.
Cmp
(
common
.
Big1
)
>
0
{
y
.
Sub
(
periodCount
,
common
.
Big2
)
y
.
Exp
(
common
.
Big2
,
y
,
nil
)
x
.
Add
(
x
,
y
)
}
return
x
}
// calcDifficultyHomestead is the difficulty adjustment algorithm. It returns
// calcDifficultyHomestead is the difficulty adjustment algorithm. It returns
// the difficulty that a new block should have when created at time given the
// the difficulty that a new block should have when created at time given the
// parent block's time and difficulty. The calculation uses the Homestead rules.
// parent block's time and difficulty. The calculation uses the Homestead rules.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment