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
f6669db0
Commit
f6669db0
authored
May 15, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fixed mining strategy
parent
b71091e3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
10 deletions
+16
-10
chain_makers.go
core/chain_makers.go
+1
-1
chain_manager.go
core/chain_manager.go
+15
-9
No files found.
core/chain_makers.go
View file @
f6669db0
...
...
@@ -98,7 +98,7 @@ func makeChain(bman *BlockProcessor, parent *types.Block, max int, db common.Dat
fmt
.
Println
(
"process with parent failed"
,
err
)
panic
(
err
)
}
block
.
Td
=
Calc
ulate
TD
(
block
,
parent
)
block
.
Td
=
CalcTD
(
block
,
parent
)
blocks
[
i
]
=
block
parent
=
block
}
...
...
core/chain_manager.go
View file @
f6669db0
...
...
@@ -48,7 +48,7 @@ func CalcDifficulty(block, parent *types.Header) *big.Int {
return
diff
}
func
Calc
ulate
TD
(
block
,
parent
*
types
.
Block
)
*
big
.
Int
{
func
CalcTD
(
block
,
parent
*
types
.
Block
)
*
big
.
Int
{
if
parent
==
nil
{
return
block
.
Difficulty
()
}
...
...
@@ -59,14 +59,20 @@ func CalculateTD(block, parent *types.Block) *big.Int {
}
func
CalcGasLimit
(
parent
*
types
.
Block
)
*
big
.
Int
{
// ((1024-1) * parent.gasLimit + (gasUsed * 6 / 5)) / 1024
previous
:=
new
(
big
.
Int
)
.
Mul
(
big
.
NewInt
(
1024
-
1
),
parent
.
GasLimit
(
))
c
urrent
:=
new
(
big
.
Rat
)
.
Mul
(
new
(
big
.
Rat
)
.
SetInt
(
parent
.
GasUsed
()),
big
.
NewRat
(
6
,
5
))
c
urInt
:=
new
(
big
.
Int
)
.
Div
(
current
.
Num
(),
current
.
Denom
()
)
decay
:=
new
(
big
.
Int
)
.
Div
(
parent
.
GasLimit
(),
params
.
GasLimitBoundDivisor
)
contrib
:=
new
(
big
.
Int
)
.
Mul
(
parent
.
GasUsed
(),
big
.
NewInt
(
3
))
c
ontrib
=
contrib
.
Div
(
contrib
,
big
.
NewInt
(
2
))
c
ontrib
=
contrib
.
Div
(
contrib
,
params
.
GasLimitBoundDivisor
)
result
:=
new
(
big
.
Int
)
.
Add
(
previous
,
curInt
)
result
.
Div
(
result
,
big
.
NewInt
(
1024
))
return
common
.
BigMax
(
params
.
GenesisGasLimit
,
result
)
gl
:=
new
(
big
.
Int
)
.
Sub
(
parent
.
GasLimit
(),
decay
)
gl
=
gl
.
Add
(
gl
,
contrib
)
gl
=
common
.
BigMax
(
gl
,
params
.
MinGasLimit
)
if
gl
.
Cmp
(
params
.
GenesisGasLimit
)
<
0
{
gl2
:=
new
(
big
.
Int
)
.
Add
(
parent
.
GasLimit
(),
decay
)
return
common
.
BigMin
(
params
.
GenesisGasLimit
,
gl2
)
}
return
gl
}
type
ChainManager
struct
{
...
...
@@ -525,7 +531,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
}
// Setting block.Td regardless of error (known for example) prevents errors down the line
// in the protocol handler
block
.
Td
=
new
(
big
.
Int
)
.
Set
(
Calc
ulate
TD
(
block
,
self
.
GetBlock
(
block
.
ParentHash
())))
block
.
Td
=
new
(
big
.
Int
)
.
Set
(
CalcTD
(
block
,
self
.
GetBlock
(
block
.
ParentHash
())))
// Call in to the block processor and check for errors. It's likely that if one block fails
// all others will fail too (unless a known block is returned).
...
...
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