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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
f15828e9
Commit
f15828e9
authored
8 years ago
by
Péter Szilágyi
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #3431 from karalabe/miner-race-fixes
Miner race fixes
parents
a98e8c08
dadd6893
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
miner/miner.go
+6
-10
6 additions, 10 deletions
miner/miner.go
miner/remote_agent.go
+14
-11
14 additions, 11 deletions
miner/remote_agent.go
miner/worker.go
+6
-0
6 additions, 0 deletions
miner/worker.go
with
26 additions
and
21 deletions
miner/miner.go
+
6
−
10
View file @
f15828e9
...
...
@@ -119,15 +119,14 @@ func (m *Miner) SetGasPrice(price *big.Int) {
func
(
self
*
Miner
)
Start
(
coinbase
common
.
Address
,
threads
int
)
{
atomic
.
StoreInt32
(
&
self
.
shouldStart
,
1
)
self
.
threads
=
threads
self
.
worker
.
coinbase
=
coinbase
self
.
worker
.
setEtherbase
(
coinbase
)
self
.
coinbase
=
coinbase
self
.
threads
=
threads
if
atomic
.
LoadInt32
(
&
self
.
canStart
)
==
0
{
glog
.
V
(
logger
.
Info
)
.
Infoln
(
"Can not start mining operation due to network sync (starts when finished)"
)
return
}
atomic
.
StoreInt32
(
&
self
.
mining
,
1
)
for
i
:=
0
;
i
<
threads
;
i
++
{
...
...
@@ -135,9 +134,7 @@ func (self *Miner) Start(coinbase common.Address, threads int) {
}
glog
.
V
(
logger
.
Info
)
.
Infof
(
"Starting mining operation (CPU=%d TOT=%d)
\n
"
,
threads
,
len
(
self
.
worker
.
agents
))
self
.
worker
.
start
()
self
.
worker
.
commitNewWork
()
}
...
...
@@ -177,8 +174,7 @@ func (self *Miner) SetExtra(extra []byte) error {
if
uint64
(
len
(
extra
))
>
params
.
MaximumExtraDataSize
.
Uint64
()
{
return
fmt
.
Errorf
(
"Extra exceeds max length. %d > %v"
,
len
(
extra
),
params
.
MaximumExtraDataSize
)
}
self
.
worker
.
extra
=
extra
self
.
worker
.
setExtra
(
extra
)
return
nil
}
...
...
@@ -188,9 +184,9 @@ func (self *Miner) Pending() (*types.Block, *state.StateDB) {
}
// PendingBlock returns the currently pending block.
//
// Note, to access both the pending block and the pending state
// simultaneously, please use Pending(), as the pending state can
//
// Note, to access both the pending block and the pending state
// simultaneously, please use Pending(), as the pending state can
// change between multiple method calls
func
(
self
*
Miner
)
PendingBlock
()
*
types
.
Block
{
return
self
.
worker
.
pendingBlock
()
...
...
This diff is collapsed.
Click to expand it.
miner/remote_agent.go
+
14
−
11
View file @
f15828e9
...
...
@@ -37,7 +37,7 @@ type hashrate struct {
type
RemoteAgent
struct
{
mu
sync
.
Mutex
quit
chan
struct
{}
quit
Ch
chan
struct
{}
workCh
chan
*
Work
returnCh
chan
<-
*
Result
...
...
@@ -76,18 +76,16 @@ func (a *RemoteAgent) Start() {
if
!
atomic
.
CompareAndSwapInt32
(
&
a
.
running
,
0
,
1
)
{
return
}
a
.
quit
=
make
(
chan
struct
{})
a
.
quitCh
=
make
(
chan
struct
{})
a
.
workCh
=
make
(
chan
*
Work
,
1
)
go
a
.
maintainLoop
(
)
go
a
.
loop
(
a
.
workCh
,
a
.
quitCh
)
}
func
(
a
*
RemoteAgent
)
Stop
()
{
if
!
atomic
.
CompareAndSwapInt32
(
&
a
.
running
,
1
,
0
)
{
return
}
close
(
a
.
quit
)
close
(
a
.
quitCh
)
close
(
a
.
workCh
)
}
...
...
@@ -148,15 +146,20 @@ func (a *RemoteAgent) SubmitWork(nonce uint64, mixDigest, hash common.Hash) bool
return
false
}
func
(
a
*
RemoteAgent
)
maintainLoop
()
{
// loop monitors mining events on the work and quit channels, updating the internal
// state of the rmeote miner until a termination is requested.
//
// Note, the reason the work and quit channels are passed as parameters is because
// RemoteAgent.Start() constantly recreates these channels, so the loop code cannot
// assume data stability in these member fields.
func
(
a
*
RemoteAgent
)
loop
(
workCh
chan
*
Work
,
quitCh
chan
struct
{})
{
ticker
:=
time
.
Tick
(
5
*
time
.
Second
)
out
:
for
{
select
{
case
<-
a
.
quit
:
b
re
ak
out
case
work
:=
<-
a
.
workCh
:
case
<-
quit
Ch
:
re
turn
case
work
:=
<-
workCh
:
a
.
mu
.
Lock
()
a
.
currentWork
=
work
a
.
mu
.
Unlock
()
...
...
This diff is collapsed.
Click to expand it.
miner/worker.go
+
6
−
0
View file @
f15828e9
...
...
@@ -161,6 +161,12 @@ func (self *worker) setEtherbase(addr common.Address) {
self
.
coinbase
=
addr
}
func
(
self
*
worker
)
setExtra
(
extra
[]
byte
)
{
self
.
mu
.
Lock
()
defer
self
.
mu
.
Unlock
()
self
.
extra
=
extra
}
func
(
self
*
worker
)
pending
()
(
*
types
.
Block
,
*
state
.
StateDB
)
{
self
.
currentMu
.
Lock
()
defer
self
.
currentMu
.
Unlock
()
...
...
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