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
667987e7
Commit
667987e7
authored
Oct 28, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: only reset head header/fastblock if stale
parent
2019ed71
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
11 deletions
+18
-11
blockchain.go
core/blockchain.go
+18
-11
No files found.
core/blockchain.go
View file @
667987e7
...
@@ -411,11 +411,14 @@ func (self *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
...
@@ -411,11 +411,14 @@ func (self *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
// insert injects a new head block into the current block chain. This method
// insert injects a new head block into the current block chain. This method
// assumes that the block is indeed a true head. It will also reset the head
// assumes that the block is indeed a true head. It will also reset the head
// header and the head fast sync block to this very same block
to prevent them
// header and the head fast sync block to this very same block
if they are older
//
from pointing to a possibly old canonical chain (i.e. side chain by now)
.
//
or if they are on a different side chain
.
//
//
// Note, this function assumes that the `mu` mutex is held!
// Note, this function assumes that the `mu` mutex is held!
func
(
bc
*
BlockChain
)
insert
(
block
*
types
.
Block
)
{
func
(
bc
*
BlockChain
)
insert
(
block
*
types
.
Block
)
{
// If the block is on a side chain or an unknown one, force other heads onto it too
updateHeads
:=
GetCanonicalHash
(
bc
.
chainDb
,
block
.
NumberU64
())
!=
block
.
Hash
()
// Add the block to the canonical chain number scheme and mark as the head
// Add the block to the canonical chain number scheme and mark as the head
if
err
:=
WriteCanonicalHash
(
bc
.
chainDb
,
block
.
Hash
(),
block
.
NumberU64
());
err
!=
nil
{
if
err
:=
WriteCanonicalHash
(
bc
.
chainDb
,
block
.
Hash
(),
block
.
NumberU64
());
err
!=
nil
{
glog
.
Fatalf
(
"failed to insert block number: %v"
,
err
)
glog
.
Fatalf
(
"failed to insert block number: %v"
,
err
)
...
@@ -423,16 +426,20 @@ func (bc *BlockChain) insert(block *types.Block) {
...
@@ -423,16 +426,20 @@ func (bc *BlockChain) insert(block *types.Block) {
if
err
:=
WriteHeadBlockHash
(
bc
.
chainDb
,
block
.
Hash
());
err
!=
nil
{
if
err
:=
WriteHeadBlockHash
(
bc
.
chainDb
,
block
.
Hash
());
err
!=
nil
{
glog
.
Fatalf
(
"failed to insert head block hash: %v"
,
err
)
glog
.
Fatalf
(
"failed to insert head block hash: %v"
,
err
)
}
}
if
err
:=
WriteHeadHeaderHash
(
bc
.
chainDb
,
block
.
Hash
());
err
!=
nil
{
glog
.
Fatalf
(
"failed to insert head header hash: %v"
,
err
)
}
if
err
:=
WriteHeadFastBlockHash
(
bc
.
chainDb
,
block
.
Hash
());
err
!=
nil
{
glog
.
Fatalf
(
"failed to insert head fast block hash: %v"
,
err
)
}
// Update the internal state with the head block
bc
.
currentBlock
=
block
bc
.
currentBlock
=
block
bc
.
currentHeader
=
block
.
Header
()
bc
.
currentFastBlock
=
block
// If the block is better than out head or is on a different chain, force update heads
if
updateHeads
{
if
err
:=
WriteHeadHeaderHash
(
bc
.
chainDb
,
block
.
Hash
());
err
!=
nil
{
glog
.
Fatalf
(
"failed to insert head header hash: %v"
,
err
)
}
bc
.
currentHeader
=
block
.
Header
()
if
err
:=
WriteHeadFastBlockHash
(
bc
.
chainDb
,
block
.
Hash
());
err
!=
nil
{
glog
.
Fatalf
(
"failed to insert head fast block hash: %v"
,
err
)
}
bc
.
currentFastBlock
=
block
}
}
}
// Accessors
// Accessors
...
...
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