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
0be6d340
Commit
0be6d340
authored
Mar 23, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finally merged *the missing*
parent
0846e156
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
15 deletions
+52
-15
block_cache.go
core/block_cache.go
+5
-0
events.go
core/events.go
+4
-0
worker.go
miner/worker.go
+43
-15
No files found.
core/block_cache.go
View file @
0be6d340
...
@@ -66,3 +66,8 @@ func (bc *BlockCache) Get(hash common.Hash) *types.Block {
...
@@ -66,3 +66,8 @@ func (bc *BlockCache) Get(hash common.Hash) *types.Block {
return
nil
return
nil
}
}
func
(
bc
*
BlockCache
)
Has
(
hash
common
.
Hash
)
bool
{
_
,
ok
:=
bc
.
blocks
[
hash
]
return
ok
}
core/events.go
View file @
0be6d340
...
@@ -38,6 +38,10 @@ type PendingBlockEvent struct {
...
@@ -38,6 +38,10 @@ type PendingBlockEvent struct {
Logs
state
.
Logs
Logs
state
.
Logs
}
}
type
ChainUncleEvent
struct
{
Block
*
types
.
Block
}
type
ChainHeadEvent
struct
{
Block
*
types
.
Block
}
type
ChainHeadEvent
struct
{
Block
*
types
.
Block
}
// Mining operation events
// Mining operation events
...
...
miner/worker.go
View file @
0be6d340
...
@@ -24,7 +24,7 @@ type environment struct {
...
@@ -24,7 +24,7 @@ type environment struct {
state
*
state
.
StateDB
state
*
state
.
StateDB
coinbase
*
state
.
StateObject
coinbase
*
state
.
StateObject
block
*
types
.
Block
block
*
types
.
Block
ancestors
*
set
.
Set
family
*
set
.
Set
uncles
*
set
.
Set
uncles
*
set
.
Set
}
}
...
@@ -34,13 +34,10 @@ func env(block *types.Block, eth core.Backend) *environment {
...
@@ -34,13 +34,10 @@ func env(block *types.Block, eth core.Backend) *environment {
totalUsedGas
:
new
(
big
.
Int
),
totalUsedGas
:
new
(
big
.
Int
),
state
:
state
,
state
:
state
,
block
:
block
,
block
:
block
,
ancestors
:
set
.
New
(),
family
:
set
.
New
(),
uncles
:
set
.
New
(),
uncles
:
set
.
New
(),
coinbase
:
state
.
GetOrNewStateObject
(
block
.
Coinbase
()),
coinbase
:
state
.
GetOrNewStateObject
(
block
.
Coinbase
()),
}
}
for
_
,
ancestor
:=
range
eth
.
ChainManager
()
.
GetAncestors
(
block
,
7
)
{
env
.
ancestors
.
Add
(
ancestor
.
Hash
())
}
return
env
return
env
}
}
...
@@ -75,17 +72,21 @@ type worker struct {
...
@@ -75,17 +72,21 @@ type worker struct {
current
*
environment
current
*
environment
uncleMu
sync
.
Mutex
possibleUncles
map
[
common
.
Hash
]
*
types
.
Block
mining
bool
mining
bool
}
}
func
newWorker
(
coinbase
common
.
Address
,
eth
core
.
Backend
)
*
worker
{
func
newWorker
(
coinbase
common
.
Address
,
eth
core
.
Backend
)
*
worker
{
return
&
worker
{
return
&
worker
{
eth
:
eth
,
eth
:
eth
,
mux
:
eth
.
EventMux
(),
mux
:
eth
.
EventMux
(),
recv
:
make
(
chan
Work
),
recv
:
make
(
chan
Work
),
chain
:
eth
.
ChainManager
(),
chain
:
eth
.
ChainManager
(),
proc
:
eth
.
BlockProcessor
(),
proc
:
eth
.
BlockProcessor
(),
coinbase
:
coinbase
,
possibleUncles
:
make
(
map
[
common
.
Hash
]
*
types
.
Block
),
coinbase
:
coinbase
,
}
}
}
}
...
@@ -115,7 +116,7 @@ func (self *worker) register(agent Agent) {
...
@@ -115,7 +116,7 @@ func (self *worker) register(agent Agent) {
}
}
func
(
self
*
worker
)
update
()
{
func
(
self
*
worker
)
update
()
{
events
:=
self
.
mux
.
Subscribe
(
core
.
ChainHeadEvent
{},
core
.
NewMinedBlockEvent
{})
events
:=
self
.
mux
.
Subscribe
(
core
.
ChainHeadEvent
{},
core
.
NewMinedBlockEvent
{}
,
core
.
ChainSideEvent
{}
)
timer
:=
time
.
NewTicker
(
2
*
time
.
Second
)
timer
:=
time
.
NewTicker
(
2
*
time
.
Second
)
...
@@ -130,6 +131,10 @@ out:
...
@@ -130,6 +131,10 @@ out:
}
}
case
core
.
NewMinedBlockEvent
:
case
core
.
NewMinedBlockEvent
:
self
.
commitNewWork
()
self
.
commitNewWork
()
case
core
.
ChainSplitEvent
:
self
.
uncleMu
.
Lock
()
self
.
possibleUncles
[
ev
.
Block
.
Hash
()]
=
ev
.
Block
self
.
uncleMu
.
Unlock
()
}
}
case
<-
self
.
quit
:
case
<-
self
.
quit
:
// stop all agents
// stop all agents
...
@@ -145,6 +150,9 @@ out:
...
@@ -145,6 +150,9 @@ out:
events
.
Unsubscribe
()
events
.
Unsubscribe
()
}
}
func
(
self
*
worker
)
addUncle
(
uncle
*
types
.
Block
)
{
}
func
(
self
*
worker
)
wait
()
{
func
(
self
*
worker
)
wait
()
{
for
{
for
{
for
work
:=
range
self
.
recv
{
for
work
:=
range
self
.
recv
{
...
@@ -191,6 +199,10 @@ func (self *worker) commitNewWork() {
...
@@ -191,6 +199,10 @@ func (self *worker) commitNewWork() {
block
:=
self
.
chain
.
NewBlock
(
self
.
coinbase
)
block
:=
self
.
chain
.
NewBlock
(
self
.
coinbase
)
self
.
current
=
env
(
block
,
self
.
eth
)
self
.
current
=
env
(
block
,
self
.
eth
)
for
_
,
ancestor
:=
range
self
.
chain
.
GetAncestors
(
block
,
7
)
{
self
.
current
.
family
.
Add
(
ancestor
.
Hash
())
}
parent
:=
self
.
chain
.
GetBlock
(
self
.
current
.
block
.
ParentHash
())
parent
:=
self
.
chain
.
GetBlock
(
self
.
current
.
block
.
ParentHash
())
self
.
current
.
coinbase
.
SetGasPool
(
core
.
CalcGasLimit
(
parent
,
self
.
current
.
block
))
self
.
current
.
coinbase
.
SetGasPool
(
core
.
CalcGasLimit
(
parent
,
self
.
current
.
block
))
...
@@ -221,6 +233,22 @@ gasLimit:
...
@@ -221,6 +233,22 @@ gasLimit:
}
}
self
.
eth
.
TxPool
()
.
RemoveSet
(
remove
)
self
.
eth
.
TxPool
()
.
RemoveSet
(
remove
)
ucount
:=
0
for
hash
,
uncle
:=
range
self
.
possibleUncles
{
if
ucount
==
2
{
break
}
if
err
:=
self
.
commitUncle
(
uncle
.
Header
());
err
!=
nil
{
minerlogger
.
Infof
(
"Bad uncle found and will be removed (%x)
\n
"
,
hash
[
:
4
])
minerlogger
.
Debugln
(
uncle
)
}
else
{
minerlogger
.
Infof
(
"Commiting %x as uncle
\n
"
,
hash
[
:
4
])
ucount
++
}
}
minerlogger
.
Infoln
(
"Included %d uncle(s)"
)
self
.
current
.
state
.
AddBalance
(
self
.
coinbase
,
core
.
BlockReward
)
self
.
current
.
state
.
AddBalance
(
self
.
coinbase
,
core
.
BlockReward
)
self
.
current
.
state
.
Update
(
common
.
Big0
)
self
.
current
.
state
.
Update
(
common
.
Big0
)
...
@@ -240,12 +268,12 @@ func (self *worker) commitUncle(uncle *types.Header) error {
...
@@ -240,12 +268,12 @@ func (self *worker) commitUncle(uncle *types.Header) error {
}
}
self
.
current
.
uncles
.
Add
(
uncle
.
Hash
())
self
.
current
.
uncles
.
Add
(
uncle
.
Hash
())
if
!
self
.
current
.
ancestors
.
Has
(
uncle
.
ParentHash
)
{
if
!
self
.
current
.
family
.
Has
(
uncle
.
ParentHash
)
{
return
core
.
UncleError
(
fmt
.
Sprintf
(
"Uncle's parent unknown (%x)"
,
uncle
.
ParentHash
[
0
:
4
]))
return
core
.
UncleError
(
fmt
.
Sprintf
(
"Uncle's parent unknown (%x)"
,
uncle
.
ParentHash
[
0
:
4
]))
}
}
if
!
self
.
pow
.
Verify
(
types
.
NewBlockWithHeader
(
uncle
))
{
if
self
.
current
.
family
.
Has
(
uncle
.
Hash
(
))
{
return
core
.
ValidationError
(
"Uncle's nonce is invalid (= %x)"
,
uncle
.
Nonce
)
return
core
.
UncleError
(
fmt
.
Sprintf
(
"Uncle already in family (%x)"
,
uncle
.
Hash
())
)
}
}
uncleAccount
:=
self
.
current
.
state
.
GetAccount
(
uncle
.
Coinbase
)
uncleAccount
:=
self
.
current
.
state
.
GetAccount
(
uncle
.
Coinbase
)
...
...
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