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
5950755b
Commit
5950755b
authored
Jun 09, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1220 from karalabe/fix-chain-deadlock2
core: fix a lock annoyance and potential deadlock
parents
5f341e5d
4541c229
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
6 deletions
+18
-6
chain_manager.go
core/chain_manager.go
+12
-5
filter_test.go
event/filter/filter_test.go
+6
-1
No files found.
core/chain_manager.go
View file @
5950755b
...
...
@@ -179,7 +179,9 @@ func (self *ChainManager) Td() *big.Int {
}
func
(
self
*
ChainManager
)
GasLimit
()
*
big
.
Int
{
// return self.currentGasLimit
self
.
mu
.
RLock
()
defer
self
.
mu
.
RUnlock
()
return
self
.
currentBlock
.
GasLimit
()
}
...
...
@@ -376,6 +378,8 @@ func (self *ChainManager) ExportN(w io.Writer, first uint64, last uint64) error
return
nil
}
// insert injects a block into the current chain block chain. Note, this function
// assumes that the `mu` mutex is held!
func
(
bc
*
ChainManager
)
insert
(
block
*
types
.
Block
)
{
key
:=
append
(
blockNumPre
,
block
.
Number
()
.
Bytes
()
...
)
bc
.
blockDb
.
Put
(
key
,
block
.
Hash
()
.
Bytes
())
...
...
@@ -484,6 +488,8 @@ func (self *ChainManager) GetAncestors(block *types.Block, length int) (blocks [
return
}
// setTotalDifficulty updates the TD of the chain manager. Note, this function
// assumes that the `mu` mutex is held!
func
(
bc
*
ChainManager
)
setTotalDifficulty
(
td
*
big
.
Int
)
{
bc
.
td
=
new
(
big
.
Int
)
.
Set
(
td
)
}
...
...
@@ -540,9 +546,6 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
self
.
wg
.
Add
(
1
)
defer
self
.
wg
.
Done
()
self
.
mu
.
Lock
()
defer
self
.
mu
.
Unlock
()
self
.
chainmu
.
Lock
()
defer
self
.
chainmu
.
Unlock
()
...
...
@@ -625,7 +628,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
cblock
:=
self
.
currentBlock
// Compare the TD of the last known block in the canonical chain to make sure it's greater.
// At this point it's possible that a different chain (fork) becomes the new canonical chain.
if
block
.
Td
.
Cmp
(
self
.
td
)
>
0
{
if
block
.
Td
.
Cmp
(
self
.
Td
()
)
>
0
{
// chain fork
if
block
.
ParentHash
()
!=
cblock
.
Hash
()
{
// during split we merge two different chains and create the new canonical chain
...
...
@@ -638,8 +641,10 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
queueEvent
.
splitCount
++
}
self
.
mu
.
Lock
()
self
.
setTotalDifficulty
(
block
.
Td
)
self
.
insert
(
block
)
self
.
mu
.
Unlock
()
jsonlogger
.
LogJson
(
&
logger
.
EthChainNewHead
{
BlockHash
:
block
.
Hash
()
.
Hex
(),
...
...
@@ -747,9 +752,11 @@ func (self *ChainManager) merge(oldBlock, newBlock *types.Block) error {
}
// insert blocks. Order does not matter. Last block will be written in ImportChain itself which creates the new head properly
self
.
mu
.
Lock
()
for
_
,
block
:=
range
newChain
{
self
.
insert
(
block
)
}
self
.
mu
.
Unlock
()
return
nil
}
...
...
event/filter/filter_test.go
View file @
5950755b
package
filter
import
"testing"
import
(
"testing"
"time"
)
func
TestFilters
(
t
*
testing
.
T
)
{
var
success
bool
...
...
@@ -24,6 +27,8 @@ func TestFilters(t *testing.T) {
fm
.
Notify
(
Generic
{
Str1
:
"hello"
},
true
)
fm
.
Stop
()
time
.
Sleep
(
10
*
time
.
Millisecond
)
// yield to the notifier
if
!
success
{
t
.
Error
(
"expected 'hello' to be posted"
)
}
...
...
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