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
017d36e6
Commit
017d36e6
authored
Jul 15, 2014
by
zelig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
properly unsubscribe react channels when miner stops - fixes write on closed chan crash
parent
1735ec03
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
27 deletions
+31
-27
miner.go
ethminer/miner.go
+31
-27
No files found.
ethminer/miner.go
View file @
017d36e6
...
...
@@ -25,30 +25,10 @@ type Miner struct {
}
func
NewDefaultMiner
(
coinbase
[]
byte
,
ethereum
ethchain
.
EthManager
)
Miner
{
reactChan
:=
make
(
chan
ethreact
.
Event
,
1
)
// This is the channel that receives 'updates' when ever a new transaction or block comes in
powChan
:=
make
(
chan
[]
byte
,
1
)
// This is the channel that receives valid sha hases for a given block
powQuitChan
:=
make
(
chan
ethreact
.
Event
,
1
)
// This is the channel that can exit the miner thread
quitChan
:=
make
(
chan
bool
,
1
)
ethereum
.
Reactor
()
.
Subscribe
(
"newBlock"
,
reactChan
)
ethereum
.
Reactor
()
.
Subscribe
(
"newTx:pre"
,
reactChan
)
// We need the quit chan to be a Reactor event.
// The POW search method is actually blocking and if we don't
// listen to the reactor events inside of the pow itself
// The miner overseer will never get the reactor events themselves
// Only after the miner will find the sha
ethereum
.
Reactor
()
.
Subscribe
(
"newBlock"
,
powQuitChan
)
ethereum
.
Reactor
()
.
Subscribe
(
"newTx:pre"
,
powQuitChan
)
miner
:=
Miner
{
pow
:
&
ethchain
.
EasyPow
{},
ethereum
:
ethereum
,
coinbase
:
coinbase
,
reactChan
:
reactChan
,
powChan
:
powChan
,
powQuitChan
:
powQuitChan
,
quitChan
:
quitChan
,
pow
:
&
ethchain
.
EasyPow
{},
ethereum
:
ethereum
,
coinbase
:
coinbase
,
}
// Insert initial TXs in our little miner 'pool'
...
...
@@ -59,9 +39,27 @@ func NewDefaultMiner(coinbase []byte, ethereum ethchain.EthManager) Miner {
}
func
(
miner
*
Miner
)
Start
()
{
miner
.
reactChan
=
make
(
chan
ethreact
.
Event
,
1
)
// This is the channel that receives 'updates' when ever a new transaction or block comes in
miner
.
powChan
=
make
(
chan
[]
byte
,
1
)
// This is the channel that receives valid sha hashes for a given block
miner
.
powQuitChan
=
make
(
chan
ethreact
.
Event
,
1
)
// This is the channel that can exit the miner thread
miner
.
quitChan
=
make
(
chan
bool
,
1
)
// Prepare inital block
//miner.ethereum.StateManager().Prepare(miner.block.State(), miner.block.State())
go
miner
.
listener
()
reactor
:=
miner
.
ethereum
.
Reactor
()
reactor
.
Subscribe
(
"newBlock"
,
miner
.
reactChan
)
reactor
.
Subscribe
(
"newTx:pre"
,
miner
.
reactChan
)
// We need the quit chan to be a Reactor event.
// The POW search method is actually blocking and if we don't
// listen to the reactor events inside of the pow itself
// The miner overseer will never get the reactor events themselves
// Only after the miner will find the sha
reactor
.
Subscribe
(
"newBlock"
,
miner
.
powQuitChan
)
reactor
.
Subscribe
(
"newTx:pre"
,
miner
.
powQuitChan
)
logger
.
Infoln
(
"Started"
)
}
...
...
@@ -127,12 +125,18 @@ out:
}
}
func
(
self
*
Miner
)
Stop
()
{
func
(
miner
*
Miner
)
Stop
()
{
logger
.
Infoln
(
"Stopping..."
)
self
.
quitChan
<-
true
miner
.
quitChan
<-
true
reactor
:=
miner
.
ethereum
.
Reactor
()
reactor
.
Unsubscribe
(
"newBlock"
,
miner
.
powQuitChan
)
reactor
.
Unsubscribe
(
"newTx:pre"
,
miner
.
powQuitChan
)
reactor
.
Unsubscribe
(
"newBlock"
,
miner
.
reactChan
)
reactor
.
Unsubscribe
(
"newTx:pre"
,
miner
.
reactChan
)
close
(
self
.
powQuitChan
)
close
(
self
.
quitChan
)
close
(
miner
.
powQuitChan
)
close
(
miner
.
quitChan
)
}
func
(
self
*
Miner
)
mineNewBlock
()
{
...
...
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