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
badbaf66
Commit
badbaf66
authored
Apr 08, 2017
by
Péter Szilágyi
Committed by
GitHub
Apr 08, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13880 from karalabe/remote-miner-fix
consensus/ethash, eth: don't mine if 0 threads are set
parents
cc13d576
b801be99
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
12 deletions
+31
-12
ethash.go
consensus/ethash/ethash.go
+8
-1
sealer.go
consensus/ethash/sealer.go
+3
-0
api.go
eth/api.go
+17
-10
backend.go
eth/backend.go
+3
-1
No files found.
consensus/ethash/ethash.go
View file @
badbaf66
...
...
@@ -555,11 +555,18 @@ func (ethash *Ethash) Threads() int {
// SetThreads updates the number of mining threads currently enabled. Calling
// this method does not start mining, only sets the thread count. If zero is
// specified, the miner will use all cores of the machine.
// specified, the miner will use all cores of the machine. Setting a thread
// count below zero is allowed and will cause the miner to idle, without any
// work being done.
func
(
ethash
*
Ethash
)
SetThreads
(
threads
int
)
{
ethash
.
lock
.
Lock
()
defer
ethash
.
lock
.
Unlock
()
// If we're running a shared PoW, set the thread count on that instead
if
ethash
.
shared
!=
nil
{
ethash
.
shared
.
SetThreads
(
threads
)
return
}
// Update the threads and ping any running seal to pull in any changes
ethash
.
threads
=
threads
select
{
...
...
consensus/ethash/sealer.go
View file @
badbaf66
...
...
@@ -61,6 +61,9 @@ func (ethash *Ethash) Seal(chain consensus.ChainReader, block *types.Block, stop
if
threads
==
0
{
threads
=
runtime
.
NumCPU
()
}
if
threads
<
0
{
threads
=
0
// Allows disabling local mining without extra logic around local/remote
}
var
pend
sync
.
WaitGroup
for
i
:=
0
;
i
<
threads
;
i
++
{
pend
.
Add
(
1
)
...
...
eth/api.go
View file @
badbaf66
...
...
@@ -139,16 +139,17 @@ func NewPrivateMinerAPI(e *Ethereum) *PrivateMinerAPI {
// threads allowed to use.
func
(
api
*
PrivateMinerAPI
)
Start
(
threads
*
int
)
error
{
// Set the number of threads if the seal engine supports it
if
threads
!=
nil
{
type
threaded
interface
{
SetThreads
(
threads
int
)
}
if
th
,
ok
:=
api
.
e
.
engine
.
(
threaded
);
ok
{
log
.
Info
(
"Updated mining threads"
,
"threads"
,
*
threads
)
th
.
SetThreads
(
*
threads
)
}
else
{
log
.
Warn
(
"Current seal engine isn't threaded"
)
}
if
threads
==
nil
{
threads
=
new
(
int
)
}
else
if
*
threads
==
0
{
*
threads
=
-
1
// Disable the miner from within
}
type
threaded
interface
{
SetThreads
(
threads
int
)
}
if
th
,
ok
:=
api
.
e
.
engine
.
(
threaded
);
ok
{
log
.
Info
(
"Updated mining threads"
,
"threads"
,
*
threads
)
th
.
SetThreads
(
*
threads
)
}
// Start the miner and return
if
!
api
.
e
.
IsMining
()
{
...
...
@@ -159,6 +160,12 @@ func (api *PrivateMinerAPI) Start(threads *int) error {
// Stop the miner
func
(
api
*
PrivateMinerAPI
)
Stop
()
bool
{
type
threaded
interface
{
SetThreads
(
threads
int
)
}
if
th
,
ok
:=
api
.
e
.
engine
.
(
threaded
);
ok
{
th
.
SetThreads
(
-
1
)
}
api
.
e
.
StopMining
()
return
true
}
...
...
eth/backend.go
View file @
badbaf66
...
...
@@ -240,8 +240,10 @@ func CreateConsensusEngine(ctx *node.ServiceContext, config *Config, chainConfig
log
.
Warn
(
"Ethash used in shared mode"
)
return
ethash
.
NewShared
()
default
:
return
ethash
.
New
(
ctx
.
ResolvePath
(
config
.
EthashCacheDir
),
config
.
EthashCachesInMem
,
config
.
EthashCachesOnDisk
,
engine
:=
ethash
.
New
(
ctx
.
ResolvePath
(
config
.
EthashCacheDir
),
config
.
EthashCachesInMem
,
config
.
EthashCachesOnDisk
,
config
.
EthashDatasetDir
,
config
.
EthashDatasetsInMem
,
config
.
EthashDatasetsOnDisk
)
engine
.
SetThreads
(
-
1
)
// Disable CPU mining
return
engine
}
}
...
...
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