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
17f1c2dc
Unverified
Commit
17f1c2dc
authored
3 years ago
by
Péter Szilágyi
Committed by
GitHub
3 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #23949 from karalabe/fix-repair-heuristic
core, eth/downloader: fix resetting below freezer threshold
parents
441c7f2b
d9c13d40
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
9 deletions
+9
-9
blockchain.go
core/blockchain.go
+8
-8
downloader.go
eth/downloader/downloader.go
+1
-1
No files found.
core/blockchain.go
View file @
17f1c2dc
...
...
@@ -296,7 +296,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
if
diskRoot
!=
(
common
.
Hash
{})
{
log
.
Warn
(
"Head state missing, repairing"
,
"number"
,
head
.
Number
(),
"hash"
,
head
.
Hash
(),
"snaproot"
,
diskRoot
)
snapDisk
,
err
:=
bc
.
SetHeadBeyondRoot
(
head
.
NumberU64
(),
diskRoot
)
snapDisk
,
err
:=
bc
.
setHeadBeyondRoot
(
head
.
NumberU64
(),
diskRoot
,
true
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -306,7 +306,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
}
}
else
{
log
.
Warn
(
"Head state missing, repairing"
,
"number"
,
head
.
Number
(),
"hash"
,
head
.
Hash
())
if
err
:=
bc
.
SetHead
(
head
.
NumberU64
()
);
err
!=
nil
{
if
_
,
err
:=
bc
.
setHeadBeyondRoot
(
head
.
NumberU64
(),
common
.
Hash
{},
true
);
err
!=
nil
{
return
nil
,
err
}
}
...
...
@@ -482,11 +482,11 @@ func (bc *BlockChain) loadLastState() error {
// was fast synced or full synced and in which state, the method will try to
// delete minimal data from disk whilst retaining chain consistency.
func
(
bc
*
BlockChain
)
SetHead
(
head
uint64
)
error
{
_
,
err
:=
bc
.
SetHeadBeyondRoot
(
head
,
common
.
Hash
{}
)
_
,
err
:=
bc
.
setHeadBeyondRoot
(
head
,
common
.
Hash
{},
false
)
return
err
}
//
S
etHeadBeyondRoot rewinds the local chain to a new head with the extra condition
//
s
etHeadBeyondRoot rewinds the local chain to a new head with the extra condition
// that the rewind must pass the specified state root. This method is meant to be
// used when rewinding with snapshots enabled to ensure that we go back further than
// persistent disk layer. Depending on whether the node was fast synced or full, and
...
...
@@ -494,7 +494,7 @@ func (bc *BlockChain) SetHead(head uint64) error {
// retaining chain consistency.
//
// The method returns the block number where the requested root cap was found.
func
(
bc
*
BlockChain
)
SetHeadBeyondRoot
(
head
uint64
,
root
common
.
Hash
)
(
uint64
,
error
)
{
func
(
bc
*
BlockChain
)
setHeadBeyondRoot
(
head
uint64
,
root
common
.
Hash
,
repair
bool
)
(
uint64
,
error
)
{
if
!
bc
.
chainmu
.
TryLock
()
{
return
0
,
errChainStopped
}
...
...
@@ -509,7 +509,7 @@ func (bc *BlockChain) SetHeadBeyondRoot(head uint64, root common.Hash) (uint64,
frozen
,
_
:=
bc
.
db
.
Ancients
()
updateFn
:=
func
(
db
ethdb
.
KeyValueWriter
,
header
*
types
.
Header
)
(
uint64
,
bool
)
{
// Rewind the block
chain, ensuring we don't end up with a stateless head
// Rewind the blockchain, ensuring we don't end up with a stateless head
// block. Note, depth equality is permitted to allow using SetHead as a
// chain reparation mechanism without deleting any data!
if
currentBlock
:=
bc
.
CurrentBlock
();
currentBlock
!=
nil
&&
header
.
Number
.
Uint64
()
<=
currentBlock
.
NumberU64
()
{
...
...
@@ -610,8 +610,8 @@ func (bc *BlockChain) SetHeadBeyondRoot(head uint64, root common.Hash) (uint64,
}
// If SetHead was only called as a chain reparation method, try to skip
// touching the header chain altogether, unless the freezer is broken
if
block
:=
bc
.
CurrentBlock
();
block
.
NumberU64
()
==
head
{
if
target
,
force
:=
updateFn
(
bc
.
db
,
b
lock
.
Header
());
force
{
if
repair
{
if
target
,
force
:=
updateFn
(
bc
.
db
,
b
c
.
CurrentBlock
()
.
Header
());
force
{
bc
.
hc
.
SetHead
(
target
,
updateFn
,
delFn
)
}
}
else
{
...
...
This diff is collapsed.
Click to expand it.
eth/downloader/downloader.go
View file @
17f1c2dc
...
...
@@ -535,7 +535,7 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td *big.I
}
// Rewind the ancient store and blockchain if reorg happens.
if
origin
+
1
<
frozen
{
if
err
:=
d
.
lightchain
.
SetHead
(
origin
+
1
);
err
!=
nil
{
if
err
:=
d
.
lightchain
.
SetHead
(
origin
);
err
!=
nil
{
return
err
}
}
...
...
This diff is collapsed.
Click to expand it.
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