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
07baf662
Commit
07baf662
authored
Jun 09, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix data race in accessing ChainManager.td
parent
d09ead54
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
9 deletions
+8
-9
chain_manager.go
core/chain_manager.go
+8
-9
No files found.
core/chain_manager.go
View file @
07baf662
...
@@ -56,10 +56,7 @@ func CalcTD(block, parent *types.Block) *big.Int {
...
@@ -56,10 +56,7 @@ func CalcTD(block, parent *types.Block) *big.Int {
if
parent
==
nil
{
if
parent
==
nil
{
return
block
.
Difficulty
()
return
block
.
Difficulty
()
}
}
return
new
(
big
.
Int
)
.
Add
(
parent
.
Td
,
block
.
Header
()
.
Difficulty
)
td
:=
new
(
big
.
Int
)
.
Add
(
parent
.
Td
,
block
.
Header
()
.
Difficulty
)
return
td
}
}
func
CalcGasLimit
(
parent
*
types
.
Block
)
*
big
.
Int
{
func
CalcGasLimit
(
parent
*
types
.
Block
)
*
big
.
Int
{
...
@@ -178,7 +175,7 @@ func (self *ChainManager) Td() *big.Int {
...
@@ -178,7 +175,7 @@ func (self *ChainManager) Td() *big.Int {
self
.
mu
.
RLock
()
self
.
mu
.
RLock
()
defer
self
.
mu
.
RUnlock
()
defer
self
.
mu
.
RUnlock
()
return
self
.
td
return
new
(
big
.
Int
)
.
Set
(
self
.
td
)
}
}
func
(
self
*
ChainManager
)
GasLimit
()
*
big
.
Int
{
func
(
self
*
ChainManager
)
GasLimit
()
*
big
.
Int
{
...
@@ -204,7 +201,7 @@ func (self *ChainManager) Status() (td *big.Int, currentBlock common.Hash, genes
...
@@ -204,7 +201,7 @@ func (self *ChainManager) Status() (td *big.Int, currentBlock common.Hash, genes
self
.
mu
.
RLock
()
self
.
mu
.
RLock
()
defer
self
.
mu
.
RUnlock
()
defer
self
.
mu
.
RUnlock
()
return
self
.
td
,
self
.
currentBlock
.
Hash
(),
self
.
genesisBlock
.
Hash
()
return
new
(
big
.
Int
)
.
Set
(
self
.
td
)
,
self
.
currentBlock
.
Hash
(),
self
.
genesisBlock
.
Hash
()
}
}
func
(
self
*
ChainManager
)
SetProcessor
(
proc
types
.
BlockProcessor
)
{
func
(
self
*
ChainManager
)
SetProcessor
(
proc
types
.
BlockProcessor
)
{
...
@@ -488,8 +485,10 @@ func (self *ChainManager) GetAncestors(block *types.Block, length int) (blocks [
...
@@ -488,8 +485,10 @@ func (self *ChainManager) GetAncestors(block *types.Block, length int) (blocks [
}
}
func
(
bc
*
ChainManager
)
setTotalDifficulty
(
td
*
big
.
Int
)
{
func
(
bc
*
ChainManager
)
setTotalDifficulty
(
td
*
big
.
Int
)
{
//bc.blockDb.Put([]byte("LTD"), td.Bytes())
bc
.
mu
.
Lock
()
bc
.
td
=
td
defer
bc
.
mu
.
Unlock
()
bc
.
td
.
Set
(
td
)
}
}
func
(
self
*
ChainManager
)
CalcTotalDiff
(
block
*
types
.
Block
)
(
*
big
.
Int
,
error
)
{
func
(
self
*
ChainManager
)
CalcTotalDiff
(
block
*
types
.
Block
)
(
*
big
.
Int
,
error
)
{
...
@@ -626,7 +625,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
...
@@ -626,7 +625,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
cblock
:=
self
.
currentBlock
cblock
:=
self
.
currentBlock
// Compare the TD of the last known block in the canonical chain to make sure it's greater.
// 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.
// 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
// chain fork
if
block
.
ParentHash
()
!=
cblock
.
Hash
()
{
if
block
.
ParentHash
()
!=
cblock
.
Hash
()
{
// during split we merge two different chains and create the new canonical chain
// during split we merge two different chains and create the new canonical chain
...
...
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