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
4e1c6a8a
Commit
4e1c6a8a
authored
May 21, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added start / stopping methods
parent
f8f84ef0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
21 deletions
+31
-21
miner.go
ethminer/miner.go
+31
-21
No files found.
ethminer/miner.go
View file @
4e1c6a8a
...
...
@@ -8,21 +8,22 @@ import (
)
type
Miner
struct
{
pow
ethchain
.
PoW
ethereum
ethchain
.
EthManager
coinbase
[]
byte
reactChan
chan
ethutil
.
React
txs
[]
*
ethchain
.
Transaction
uncles
[]
*
ethchain
.
Block
block
*
ethchain
.
Block
powChan
chan
[]
byte
quitChan
chan
ethutil
.
React
pow
ethchain
.
PoW
ethereum
ethchain
.
EthManager
coinbase
[]
byte
reactChan
chan
ethutil
.
React
txs
[]
*
ethchain
.
Transaction
uncles
[]
*
ethchain
.
Block
block
*
ethchain
.
Block
powChan
chan
[]
byte
powQuitChan
chan
ethutil
.
React
quitChan
chan
bool
}
func
NewDefaultMiner
(
coinbase
[]
byte
,
ethereum
ethchain
.
EthManager
)
Miner
{
reactChan
:=
make
(
chan
ethutil
.
React
,
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
quitChan
:=
make
(
chan
ethutil
.
React
,
1
)
// This is the channel that can exit the miner thread
reactChan
:=
make
(
chan
ethutil
.
React
,
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
ethutil
.
React
,
1
)
// This is the channel that can exit the miner thread
ethereum
.
Reactor
()
.
Subscribe
(
"newBlock"
,
reactChan
)
ethereum
.
Reactor
()
.
Subscribe
(
"newTx:pre"
,
reactChan
)
...
...
@@ -32,16 +33,17 @@ func NewDefaultMiner(coinbase []byte, ethereum ethchain.EthManager) Miner {
// 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"
,
q
uitChan
)
ethereum
.
Reactor
()
.
Subscribe
(
"newTx:pre"
,
q
uitChan
)
ethereum
.
Reactor
()
.
Subscribe
(
"newBlock"
,
powQ
uitChan
)
ethereum
.
Reactor
()
.
Subscribe
(
"newTx:pre"
,
powQ
uitChan
)
miner
:=
Miner
{
pow
:
&
ethchain
.
EasyPow
{},
ethereum
:
ethereum
,
coinbase
:
coinbase
,
reactChan
:
reactChan
,
powChan
:
powChan
,
quitChan
:
quitChan
,
pow
:
&
ethchain
.
EasyPow
{},
ethereum
:
ethereum
,
coinbase
:
coinbase
,
reactChan
:
reactChan
,
powChan
:
powChan
,
powQuitChan
:
powQuitChan
,
quitChan
:
make
(
chan
bool
),
}
// Insert initial TXs in our little miner 'pool'
...
...
@@ -56,8 +58,11 @@ func (miner *Miner) Start() {
go
miner
.
listener
()
}
func
(
miner
*
Miner
)
listener
()
{
out
:
for
{
select
{
case
<-
miner
.
quitChan
:
break
out
case
chanMessage
:=
<-
miner
.
reactChan
:
if
block
,
ok
:=
chanMessage
.
Resource
.
(
*
ethchain
.
Block
);
ok
{
//ethutil.Config.Log.Infoln("[MINER] Got new block via Reactor")
...
...
@@ -112,6 +117,11 @@ func (miner *Miner) listener() {
}
}
func
(
self
*
Miner
)
Stop
()
{
self
.
powQuitChan
<-
ethutil
.
React
{}
self
.
quitChan
<-
true
}
func
(
self
*
Miner
)
mineNewBlock
()
{
stateManager
:=
self
.
ethereum
.
StateManager
()
...
...
@@ -138,7 +148,7 @@ func (self *Miner) mineNewBlock() {
ethutil
.
Config
.
Log
.
Infoln
(
"[MINER] Mining on block. Includes"
,
len
(
self
.
txs
),
"transactions"
)
// Find a valid nonce
self
.
block
.
Nonce
=
self
.
pow
.
Search
(
self
.
block
,
self
.
q
uitChan
)
self
.
block
.
Nonce
=
self
.
pow
.
Search
(
self
.
block
,
self
.
powQ
uitChan
)
if
self
.
block
.
Nonce
!=
nil
{
err
:=
self
.
ethereum
.
StateManager
()
.
Process
(
self
.
block
,
true
)
if
err
!=
nil
{
...
...
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