good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
b99fe27f
Commit
b99fe27f
authored
Sep 29, 2015
by
Péter Szilágyi
Browse files
Options
Downloads
Patches
Plain Diff
core: fix block canonical mark / content write race
parent
f186b390
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/blockchain.go
+11
-20
11 additions, 20 deletions
core/blockchain.go
with
11 additions
and
20 deletions
core/blockchain.go
+
11
−
20
View file @
b99fe27f
...
@@ -601,7 +601,7 @@ func (self *BlockChain) writeHeader(header *types.Header) error {
...
@@ -601,7 +601,7 @@ func (self *BlockChain) writeHeader(header *types.Header) error {
}
}
// InsertHeaderChain will attempt to insert the given header chain in to the
// InsertHeaderChain will attempt to insert the given header chain in to the
// local chain, possibly creating a
d
ork. If an error is returned, it will
// local chain, possibly creating a
f
ork. If an error is returned, it will
// return the index number of the failing header as well an error describing
// return the index number of the failing header as well an error describing
// what went wrong.
// what went wrong.
//
//
...
@@ -686,37 +686,31 @@ func (self *BlockChain) WriteBlock(block *types.Block) (status writeStatus, err
...
@@ -686,37 +686,31 @@ func (self *BlockChain) WriteBlock(block *types.Block) (status writeStatus, err
}
}
td
:=
new
(
big
.
Int
)
.
Add
(
block
.
Difficulty
(),
ptd
)
td
:=
new
(
big
.
Int
)
.
Add
(
block
.
Difficulty
(),
ptd
)
self
.
mu
.
RLock
()
// Make sure no inconsistent state is leaked during insertion
cblock
:=
self
.
currentBl
ock
self
.
mu
.
L
ock
()
self
.
mu
.
R
Unlock
()
defer
self
.
mu
.
Unlock
()
// Compare the TD of the last known block in the canonical chain to make sure it's greater.
// If the total difficulty is higher than our known, add it to the canonical chain
// At this point it's possible that a different chain (fork) becomes the new canonical chain.
if
td
.
Cmp
(
self
.
GetTd
(
self
.
currentBlock
.
Hash
()))
>
0
{
if
td
.
Cmp
(
self
.
GetTd
(
self
.
currentBlock
.
Hash
()))
>
0
{
// chain fork
// Reorganize the chain if the parent is not the head block
if
block
.
ParentHash
()
!=
cblock
.
Hash
()
{
if
block
.
ParentHash
()
!=
self
.
currentBlock
.
Hash
()
{
// during split we merge two different chains and create the new canonical chain
if
err
:=
self
.
reorg
(
self
.
currentBlock
,
block
);
err
!=
nil
{
err
:=
self
.
reorg
(
cblock
,
block
)
if
err
!=
nil
{
return
NonStatTy
,
err
return
NonStatTy
,
err
}
}
}
}
status
=
CanonStatTy
// Insert the block as the new head of the chain
self
.
mu
.
Lock
()
self
.
insert
(
block
)
self
.
insert
(
block
)
s
elf
.
mu
.
Unlock
()
s
tatus
=
CanonStatTy
}
else
{
}
else
{
status
=
SideStatTy
status
=
SideStatTy
}
}
// Irrelevant of the canonical status, write the block itself to the database
if
err
:=
WriteTd
(
self
.
chainDb
,
block
.
Hash
(),
td
);
err
!=
nil
{
if
err
:=
WriteTd
(
self
.
chainDb
,
block
.
Hash
(),
td
);
err
!=
nil
{
glog
.
Fatalf
(
"failed to write block total difficulty: %v"
,
err
)
glog
.
Fatalf
(
"failed to write block total difficulty: %v"
,
err
)
}
}
if
err
:=
WriteBlock
(
self
.
chainDb
,
block
);
err
!=
nil
{
if
err
:=
WriteBlock
(
self
.
chainDb
,
block
);
err
!=
nil
{
glog
.
Fatalf
(
"filed to write block contents: %v"
,
err
)
glog
.
Fatalf
(
"filed to write block contents: %v"
,
err
)
}
}
// Delete from future blocks
self
.
futureBlocks
.
Remove
(
block
.
Hash
())
self
.
futureBlocks
.
Remove
(
block
.
Hash
())
return
return
...
@@ -860,9 +854,6 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
...
@@ -860,9 +854,6 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
// to be part of the new canonical chain and accumulates potential missing transactions and post an
// to be part of the new canonical chain and accumulates potential missing transactions and post an
// event about them
// event about them
func
(
self
*
BlockChain
)
reorg
(
oldBlock
,
newBlock
*
types
.
Block
)
error
{
func
(
self
*
BlockChain
)
reorg
(
oldBlock
,
newBlock
*
types
.
Block
)
error
{
self
.
mu
.
Lock
()
defer
self
.
mu
.
Unlock
()
var
(
var
(
newChain
types
.
Blocks
newChain
types
.
Blocks
commonBlock
*
types
.
Block
commonBlock
*
types
.
Block
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment