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
df219e23
Unverified
Commit
df219e23
authored
Sep 11, 2020
by
Marius van der Wijden
Committed by
GitHub
Sep 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
miner: fix regression, add test for starting while download (#21547)
Fixes a regression introduced in #21536
parent
7cf56d6f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
2 deletions
+22
-2
miner.go
miner/miner.go
+9
-2
miner_test.go
miner/miner_test.go
+13
-0
No files found.
miner/miner.go
View file @
df219e23
...
...
@@ -88,6 +88,7 @@ func (miner *Miner) update() {
defer
events
.
Unsubscribe
()
shouldStart
:=
false
canStart
:=
true
for
{
select
{
case
ev
:=
<-
events
.
Chan
()
:
...
...
@@ -98,21 +99,27 @@ func (miner *Miner) update() {
case
downloader
.
StartEvent
:
wasMining
:=
miner
.
Mining
()
miner
.
worker
.
stop
()
canStart
=
false
if
wasMining
{
// Resume mining after sync was finished
shouldStart
=
true
log
.
Info
(
"Mining aborted due to sync"
)
}
case
downloader
.
DoneEvent
,
downloader
.
FailedEvent
:
canStart
=
true
if
shouldStart
{
miner
.
SetEtherbase
(
miner
.
coinbase
)
miner
.
worker
.
start
()
}
}
case
addr
:=
<-
miner
.
startCh
:
miner
.
SetEtherbase
(
addr
)
miner
.
worker
.
start
()
if
canStart
{
miner
.
SetEtherbase
(
addr
)
miner
.
worker
.
start
()
}
shouldStart
=
true
case
<-
miner
.
stopCh
:
shouldStart
=
false
miner
.
worker
.
stop
()
case
<-
miner
.
exitCh
:
miner
.
worker
.
close
()
...
...
miner/miner_test.go
View file @
df219e23
...
...
@@ -97,6 +97,19 @@ func TestMiner(t *testing.T) {
waitForMiningState
(
t
,
miner
,
true
)
}
func
TestStartWhileDownload
(
t
*
testing
.
T
)
{
miner
,
mux
:=
createMiner
(
t
)
waitForMiningState
(
t
,
miner
,
false
)
miner
.
Start
(
common
.
HexToAddress
(
"0x12345"
))
waitForMiningState
(
t
,
miner
,
true
)
// Stop the downloader and wait for the update loop to run
mux
.
Post
(
downloader
.
StartEvent
{})
waitForMiningState
(
t
,
miner
,
false
)
// Starting the miner after the downloader should not work
miner
.
Start
(
common
.
HexToAddress
(
"0x12345"
))
waitForMiningState
(
t
,
miner
,
false
)
}
func
TestStartStopMiner
(
t
*
testing
.
T
)
{
miner
,
_
:=
createMiner
(
t
)
waitForMiningState
(
t
,
miner
,
false
)
...
...
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