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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
4e1c6a8a
Commit
4e1c6a8a
authored
May 21, 2014
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
Added start / stopping methods
parent
f8f84ef0
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ethminer/miner.go
+31
-21
31 additions, 21 deletions
ethminer/miner.go
with
31 additions
and
21 deletions
ethminer/miner.go
+
31
−
21
View file @
4e1c6a8a
...
@@ -16,13 +16,14 @@ type Miner struct {
...
@@ -16,13 +16,14 @@ type Miner struct {
uncles
[]
*
ethchain
.
Block
uncles
[]
*
ethchain
.
Block
block
*
ethchain
.
Block
block
*
ethchain
.
Block
powChan
chan
[]
byte
powChan
chan
[]
byte
quitChan
chan
ethutil
.
React
powQuitChan
chan
ethutil
.
React
quitChan
chan
bool
}
}
func
NewDefaultMiner
(
coinbase
[]
byte
,
ethereum
ethchain
.
EthManager
)
Miner
{
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
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
powChan
:=
make
(
chan
[]
byte
,
1
)
// This is the channel that receives valid sha hases for a given block
q
uitChan
:=
make
(
chan
ethutil
.
React
,
1
)
// This is the channel that can exit the miner thread
powQ
uitChan
:=
make
(
chan
ethutil
.
React
,
1
)
// This is the channel that can exit the miner thread
ethereum
.
Reactor
()
.
Subscribe
(
"newBlock"
,
reactChan
)
ethereum
.
Reactor
()
.
Subscribe
(
"newBlock"
,
reactChan
)
ethereum
.
Reactor
()
.
Subscribe
(
"newTx:pre"
,
reactChan
)
ethereum
.
Reactor
()
.
Subscribe
(
"newTx:pre"
,
reactChan
)
...
@@ -32,8 +33,8 @@ func NewDefaultMiner(coinbase []byte, ethereum ethchain.EthManager) Miner {
...
@@ -32,8 +33,8 @@ func NewDefaultMiner(coinbase []byte, ethereum ethchain.EthManager) Miner {
// listen to the reactor events inside of the pow itself
// listen to the reactor events inside of the pow itself
// The miner overseer will never get the reactor events themselves
// The miner overseer will never get the reactor events themselves
// Only after the miner will find the sha
// Only after the miner will find the sha
ethereum
.
Reactor
()
.
Subscribe
(
"newBlock"
,
q
uitChan
)
ethereum
.
Reactor
()
.
Subscribe
(
"newBlock"
,
powQ
uitChan
)
ethereum
.
Reactor
()
.
Subscribe
(
"newTx:pre"
,
q
uitChan
)
ethereum
.
Reactor
()
.
Subscribe
(
"newTx:pre"
,
powQ
uitChan
)
miner
:=
Miner
{
miner
:=
Miner
{
pow
:
&
ethchain
.
EasyPow
{},
pow
:
&
ethchain
.
EasyPow
{},
...
@@ -41,7 +42,8 @@ func NewDefaultMiner(coinbase []byte, ethereum ethchain.EthManager) Miner {
...
@@ -41,7 +42,8 @@ func NewDefaultMiner(coinbase []byte, ethereum ethchain.EthManager) Miner {
coinbase
:
coinbase
,
coinbase
:
coinbase
,
reactChan
:
reactChan
,
reactChan
:
reactChan
,
powChan
:
powChan
,
powChan
:
powChan
,
quitChan
:
quitChan
,
powQuitChan
:
powQuitChan
,
quitChan
:
make
(
chan
bool
),
}
}
// Insert initial TXs in our little miner 'pool'
// Insert initial TXs in our little miner 'pool'
...
@@ -56,8 +58,11 @@ func (miner *Miner) Start() {
...
@@ -56,8 +58,11 @@ func (miner *Miner) Start() {
go
miner
.
listener
()
go
miner
.
listener
()
}
}
func
(
miner
*
Miner
)
listener
()
{
func
(
miner
*
Miner
)
listener
()
{
out
:
for
{
for
{
select
{
select
{
case
<-
miner
.
quitChan
:
break
out
case
chanMessage
:=
<-
miner
.
reactChan
:
case
chanMessage
:=
<-
miner
.
reactChan
:
if
block
,
ok
:=
chanMessage
.
Resource
.
(
*
ethchain
.
Block
);
ok
{
if
block
,
ok
:=
chanMessage
.
Resource
.
(
*
ethchain
.
Block
);
ok
{
//ethutil.Config.Log.Infoln("[MINER] Got new block via Reactor")
//ethutil.Config.Log.Infoln("[MINER] Got new block via Reactor")
...
@@ -112,6 +117,11 @@ func (miner *Miner) listener() {
...
@@ -112,6 +117,11 @@ func (miner *Miner) listener() {
}
}
}
}
func
(
self
*
Miner
)
Stop
()
{
self
.
powQuitChan
<-
ethutil
.
React
{}
self
.
quitChan
<-
true
}
func
(
self
*
Miner
)
mineNewBlock
()
{
func
(
self
*
Miner
)
mineNewBlock
()
{
stateManager
:=
self
.
ethereum
.
StateManager
()
stateManager
:=
self
.
ethereum
.
StateManager
()
...
@@ -138,7 +148,7 @@ func (self *Miner) mineNewBlock() {
...
@@ -138,7 +148,7 @@ func (self *Miner) mineNewBlock() {
ethutil
.
Config
.
Log
.
Infoln
(
"[MINER] Mining on block. Includes"
,
len
(
self
.
txs
),
"transactions"
)
ethutil
.
Config
.
Log
.
Infoln
(
"[MINER] Mining on block. Includes"
,
len
(
self
.
txs
),
"transactions"
)
// Find a valid nonce
// 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
{
if
self
.
block
.
Nonce
!=
nil
{
err
:=
self
.
ethereum
.
StateManager
()
.
Process
(
self
.
block
,
true
)
err
:=
self
.
ethereum
.
StateManager
()
.
Process
(
self
.
block
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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