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
d36501a6
Commit
d36501a6
authored
Mar 26, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed miner
* Miners could stall because the worker wasn't aware the miner was done
parent
d0fa0a23
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
15 deletions
+35
-15
agent.go
miner/agent.go
+16
-7
remote_agent.go
miner/remote_agent.go
+1
-0
worker.go
miner/worker.go
+18
-8
No files found.
miner/agent.go
View file @
d36501a6
package
miner
import
(
"sync"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/pow"
)
type
CpuMiner
struct
{
chMu
sync
.
Mutex
c
chan
*
types
.
Block
quit
chan
struct
{}
quitCurrentOp
chan
struct
{}
...
...
@@ -43,16 +46,13 @@ func (self *CpuMiner) Start() {
}
func
(
self
*
CpuMiner
)
update
()
{
justStarted
:=
true
out
:
for
{
select
{
case
block
:=
<-
self
.
c
:
if
justStarted
{
justStarted
=
true
}
else
{
self
.
quitCurrentOp
<-
struct
{}{}
}
self
.
chMu
.
Lock
()
self
.
quitCurrentOp
<-
struct
{}{}
self
.
chMu
.
Unlock
()
go
self
.
mine
(
block
)
case
<-
self
.
quit
:
...
...
@@ -60,6 +60,7 @@ out:
}
}
close
(
self
.
quitCurrentOp
)
done
:
// Empty channel
for
{
...
...
@@ -75,12 +76,20 @@ done:
func
(
self
*
CpuMiner
)
mine
(
block
*
types
.
Block
)
{
minerlogger
.
Debugf
(
"(re)started agent[%d]. mining...
\n
"
,
self
.
index
)
// Reset the channel
self
.
chMu
.
Lock
()
self
.
quitCurrentOp
=
make
(
chan
struct
{},
1
)
self
.
chMu
.
Unlock
()
// Mine
nonce
,
mixDigest
,
_
:=
self
.
pow
.
Search
(
block
,
self
.
quitCurrentOp
)
if
nonce
!=
0
{
block
.
SetNonce
(
nonce
)
block
.
Header
()
.
MixDigest
=
common
.
BytesToHash
(
mixDigest
)
self
.
returnCh
<-
block
//self.returnCh <- Work{block.Number().Uint64(), nonce, mixDigest, seedHash}
}
else
{
self
.
returnCh
<-
nil
}
}
...
...
miner/remote_agent.go
View file @
d36501a6
...
...
@@ -50,6 +50,7 @@ out:
break
out
case
work
:=
<-
a
.
workCh
:
a
.
work
=
work
a
.
returnCh
<-
nil
}
}
}
...
...
miner/worker.go
View file @
d36501a6
...
...
@@ -5,6 +5,7 @@ import (
"math/big"
"sort"
"sync"
"sync/atomic"
"time"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -58,13 +59,14 @@ type Agent interface {
}
type
worker
struct
{
mu
sync
.
Mutex
mu
sync
.
Mutex
agents
[]
Agent
recv
chan
*
types
.
Block
mux
*
event
.
TypeMux
quit
chan
struct
{}
pow
pow
.
PoW
atWork
int
atWork
int
64
eth
core
.
Backend
chain
*
core
.
ChainManager
...
...
@@ -107,7 +109,7 @@ func (self *worker) start() {
func
(
self
*
worker
)
stop
()
{
self
.
mining
=
false
self
.
atWork
=
0
atomic
.
StoreInt64
(
&
self
.
atWork
,
0
)
close
(
self
.
quit
)
}
...
...
@@ -135,9 +137,6 @@ out:
self
.
uncleMu
.
Unlock
()
}
if
self
.
atWork
==
0
{
self
.
commitNewWork
()
}
case
<-
self
.
quit
:
// stop all agents
for
_
,
agent
:=
range
self
.
agents
{
...
...
@@ -146,6 +145,11 @@ out:
break
out
case
<-
timer
.
C
:
minerlogger
.
Infoln
(
"Hash rate:"
,
self
.
HashRate
(),
"Khash"
)
// XXX In case all mined a possible uncle
if
atomic
.
LoadInt64
(
&
self
.
atWork
)
==
0
{
self
.
commitNewWork
()
}
}
}
...
...
@@ -155,6 +159,12 @@ out:
func
(
self
*
worker
)
wait
()
{
for
{
for
block
:=
range
self
.
recv
{
atomic
.
AddInt64
(
&
self
.
atWork
,
-
1
)
if
block
==
nil
{
continue
}
if
err
:=
self
.
chain
.
InsertChain
(
types
.
Blocks
{
block
});
err
==
nil
{
for
_
,
uncle
:=
range
block
.
Uncles
()
{
delete
(
self
.
possibleUncles
,
uncle
.
Hash
())
...
...
@@ -170,7 +180,6 @@ func (self *worker) wait() {
}
else
{
self
.
commitNewWork
()
}
self
.
atWork
--
}
}
}
...
...
@@ -182,8 +191,9 @@ func (self *worker) push() {
// push new work to agents
for
_
,
agent
:=
range
self
.
agents
{
atomic
.
AddInt64
(
&
self
.
atWork
,
1
)
agent
.
Work
()
<-
self
.
current
.
block
.
Copy
()
self
.
atWork
++
}
}
}
...
...
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