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
2a1fc3d1
Commit
2a1fc3d1
authored
Apr 16, 2018
by
Ryan Schneider
Committed by
Péter Szilágyi
Apr 16, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
miner: remove contention on currentMu for pending data retrievals (#16497)
parent
60516c83
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
18 deletions
+33
-18
worker.go
miner/worker.go
+33
-18
No files found.
miner/worker.go
View file @
2a1fc3d1
...
@@ -117,6 +117,10 @@ type worker struct {
...
@@ -117,6 +117,10 @@ type worker struct {
currentMu
sync
.
Mutex
currentMu
sync
.
Mutex
current
*
Work
current
*
Work
snapshotMu
sync
.
RWMutex
snapshotBlock
*
types
.
Block
snapshotState
*
state
.
StateDB
uncleMu
sync
.
Mutex
uncleMu
sync
.
Mutex
possibleUncles
map
[
common
.
Hash
]
*
types
.
Block
possibleUncles
map
[
common
.
Hash
]
*
types
.
Block
...
@@ -171,32 +175,28 @@ func (self *worker) setExtra(extra []byte) {
...
@@ -171,32 +175,28 @@ func (self *worker) setExtra(extra []byte) {
}
}
func
(
self
*
worker
)
pending
()
(
*
types
.
Block
,
*
state
.
StateDB
)
{
func
(
self
*
worker
)
pending
()
(
*
types
.
Block
,
*
state
.
StateDB
)
{
self
.
currentMu
.
Lock
()
defer
self
.
currentMu
.
Unlock
()
if
atomic
.
LoadInt32
(
&
self
.
mining
)
==
0
{
if
atomic
.
LoadInt32
(
&
self
.
mining
)
==
0
{
return
types
.
NewBlock
(
// return a snapshot to avoid contention on currentMu mutex
self
.
current
.
header
,
self
.
snapshotMu
.
RLock
()
self
.
current
.
txs
,
defer
self
.
snapshotMu
.
RUnlock
()
nil
,
return
self
.
snapshotBlock
,
self
.
snapshotState
.
Copy
()
self
.
current
.
receipts
,
),
self
.
current
.
state
.
Copy
()
}
}
return
self
.
current
.
Block
,
self
.
current
.
state
.
Copy
()
}
func
(
self
*
worker
)
pendingBlock
()
*
types
.
Block
{
self
.
currentMu
.
Lock
()
self
.
currentMu
.
Lock
()
defer
self
.
currentMu
.
Unlock
()
defer
self
.
currentMu
.
Unlock
()
return
self
.
current
.
Block
,
self
.
current
.
state
.
Copy
()
}
func
(
self
*
worker
)
pendingBlock
()
*
types
.
Block
{
if
atomic
.
LoadInt32
(
&
self
.
mining
)
==
0
{
if
atomic
.
LoadInt32
(
&
self
.
mining
)
==
0
{
return
types
.
NewBlock
(
// return a snapshot to avoid contention on currentMu mutex
self
.
current
.
header
,
self
.
snapshotMu
.
RLock
()
self
.
current
.
txs
,
defer
self
.
snapshotMu
.
RUnlock
()
nil
,
return
self
.
snapshotBlock
self
.
current
.
receipts
,
)
}
}
self
.
currentMu
.
Lock
()
defer
self
.
currentMu
.
Unlock
()
return
self
.
current
.
Block
return
self
.
current
.
Block
}
}
...
@@ -268,6 +268,7 @@ func (self *worker) update() {
...
@@ -268,6 +268,7 @@ func (self *worker) update() {
txset
:=
types
.
NewTransactionsByPriceAndNonce
(
self
.
current
.
signer
,
txs
)
txset
:=
types
.
NewTransactionsByPriceAndNonce
(
self
.
current
.
signer
,
txs
)
self
.
current
.
commitTransactions
(
self
.
mux
,
txset
,
self
.
chain
,
self
.
coinbase
)
self
.
current
.
commitTransactions
(
self
.
mux
,
txset
,
self
.
chain
,
self
.
coinbase
)
self
.
updateSnapshot
()
self
.
currentMu
.
Unlock
()
self
.
currentMu
.
Unlock
()
}
else
{
}
else
{
// If we're mining, but nothing is being processed, wake on new transactions
// If we're mining, but nothing is being processed, wake on new transactions
...
@@ -489,6 +490,7 @@ func (self *worker) commitNewWork() {
...
@@ -489,6 +490,7 @@ func (self *worker) commitNewWork() {
self
.
unconfirmed
.
Shift
(
work
.
Block
.
NumberU64
()
-
1
)
self
.
unconfirmed
.
Shift
(
work
.
Block
.
NumberU64
()
-
1
)
}
}
self
.
push
(
work
)
self
.
push
(
work
)
self
.
updateSnapshot
()
}
}
func
(
self
*
worker
)
commitUncle
(
work
*
Work
,
uncle
*
types
.
Header
)
error
{
func
(
self
*
worker
)
commitUncle
(
work
*
Work
,
uncle
*
types
.
Header
)
error
{
...
@@ -506,6 +508,19 @@ func (self *worker) commitUncle(work *Work, uncle *types.Header) error {
...
@@ -506,6 +508,19 @@ func (self *worker) commitUncle(work *Work, uncle *types.Header) error {
return
nil
return
nil
}
}
func
(
self
*
worker
)
updateSnapshot
()
{
self
.
snapshotMu
.
Lock
()
defer
self
.
snapshotMu
.
Unlock
()
self
.
snapshotBlock
=
types
.
NewBlock
(
self
.
current
.
header
,
self
.
current
.
txs
,
nil
,
self
.
current
.
receipts
,
)
self
.
snapshotState
=
self
.
current
.
state
.
Copy
()
}
func
(
env
*
Work
)
commitTransactions
(
mux
*
event
.
TypeMux
,
txs
*
types
.
TransactionsByPriceAndNonce
,
bc
*
core
.
BlockChain
,
coinbase
common
.
Address
)
{
func
(
env
*
Work
)
commitTransactions
(
mux
*
event
.
TypeMux
,
txs
*
types
.
TransactionsByPriceAndNonce
,
bc
*
core
.
BlockChain
,
coinbase
common
.
Address
)
{
gp
:=
new
(
core
.
GasPool
)
.
AddGas
(
env
.
header
.
GasLimit
)
gp
:=
new
(
core
.
GasPool
)
.
AddGas
(
env
.
header
.
GasLimit
)
...
...
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