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
941018b5
Commit
941018b5
authored
Aug 06, 2018
by
gary rong
Committed by
Péter Szilágyi
Aug 06, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
miner: seperate state, receipts for different mining work (#17323)
parent
a72ba5a5
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
64 deletions
+67
-64
agent.go
miner/agent.go
+17
-12
worker.go
miner/worker.go
+50
-52
No files found.
miner/agent.go
View file @
941018b5
...
...
@@ -27,10 +27,10 @@ import (
type
CpuAgent
struct
{
mu
sync
.
Mutex
workCh
chan
*
Work
taskCh
chan
*
Package
returnCh
chan
<-
*
Package
stop
chan
struct
{}
quitCurrentOp
chan
struct
{}
returnCh
chan
<-
*
Result
chain
consensus
.
ChainReader
engine
consensus
.
Engine
...
...
@@ -43,13 +43,17 @@ func NewCpuAgent(chain consensus.ChainReader, engine consensus.Engine) *CpuAgent
chain
:
chain
,
engine
:
engine
,
stop
:
make
(
chan
struct
{},
1
),
workCh
:
make
(
chan
*
Work
,
1
),
taskCh
:
make
(
chan
*
Package
,
1
),
}
return
agent
}
func
(
self
*
CpuAgent
)
Work
()
chan
<-
*
Work
{
return
self
.
workCh
}
func
(
self
*
CpuAgent
)
SetReturnCh
(
ch
chan
<-
*
Result
)
{
self
.
returnCh
=
ch
}
func
(
self
*
CpuAgent
)
AssignTask
(
p
*
Package
)
{
if
atomic
.
LoadInt32
(
&
self
.
started
)
==
1
{
self
.
taskCh
<-
p
}
}
func
(
self
*
CpuAgent
)
DeliverTo
(
ch
chan
<-
*
Package
)
{
self
.
returnCh
=
ch
}
func
(
self
*
CpuAgent
)
Start
()
{
if
!
atomic
.
CompareAndSwapInt32
(
&
self
.
started
,
0
,
1
)
{
...
...
@@ -67,7 +71,7 @@ done:
// Empty work channel
for
{
select
{
case
<-
self
.
wor
kCh
:
case
<-
self
.
tas
kCh
:
default
:
break
done
}
...
...
@@ -78,13 +82,13 @@ func (self *CpuAgent) update() {
out
:
for
{
select
{
case
work
:=
<-
self
.
wor
kCh
:
case
p
:=
<-
self
.
tas
kCh
:
self
.
mu
.
Lock
()
if
self
.
quitCurrentOp
!=
nil
{
close
(
self
.
quitCurrentOp
)
}
self
.
quitCurrentOp
=
make
(
chan
struct
{})
go
self
.
mine
(
work
,
self
.
quitCurrentOp
)
go
self
.
mine
(
p
,
self
.
quitCurrentOp
)
self
.
mu
.
Unlock
()
case
<-
self
.
stop
:
self
.
mu
.
Lock
()
...
...
@@ -98,10 +102,11 @@ out:
}
}
func
(
self
*
CpuAgent
)
mine
(
work
*
Work
,
stop
<-
chan
struct
{})
{
if
result
,
err
:=
self
.
engine
.
Seal
(
self
.
chain
,
work
.
Block
,
stop
);
result
!=
nil
{
log
.
Info
(
"Successfully sealed new block"
,
"number"
,
result
.
Number
(),
"hash"
,
result
.
Hash
())
self
.
returnCh
<-
&
Result
{
work
,
result
}
func
(
self
*
CpuAgent
)
mine
(
p
*
Package
,
stop
<-
chan
struct
{})
{
var
err
error
if
p
.
Block
,
err
=
self
.
engine
.
Seal
(
self
.
chain
,
p
.
Block
,
stop
);
p
.
Block
!=
nil
{
log
.
Info
(
"Successfully sealed new block"
,
"number"
,
p
.
Block
.
Number
(),
"hash"
,
p
.
Block
.
Hash
())
self
.
returnCh
<-
p
}
else
{
if
err
!=
nil
{
log
.
Warn
(
"Block sealing failed"
,
"err"
,
err
)
...
...
miner/worker.go
View file @
941018b5
This diff is collapsed.
Click to expand it.
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