Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
63352bf4
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
63352bf4
编写于
8月 28, 2018
作者:
F
Felföldi Zsolt
提交者:
Péter Szilágyi
8月 28, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core: safe indexer operation when syncing starts before the checkpoint (#17511)
上级
b69476b3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
14 deletion
+48
-14
core/chain_indexer.go
core/chain_indexer.go
+45
-11
light/lightchain.go
light/lightchain.go
+3
-3
未找到文件。
core/chain_indexer.go
浏览文件 @
63352bf4
...
@@ -85,6 +85,9 @@ type ChainIndexer struct {
...
@@ -85,6 +85,9 @@ type ChainIndexer struct {
knownSections
uint64
// Number of sections known to be complete (block wise)
knownSections
uint64
// Number of sections known to be complete (block wise)
cascadedHead
uint64
// Block number of the last completed section cascaded to subindexers
cascadedHead
uint64
// Block number of the last completed section cascaded to subindexers
checkpointSections
uint64
// Number of sections covered by the checkpoint
checkpointHead
common
.
Hash
// Section head belonging to the checkpoint
throttling
time
.
Duration
// Disk throttling to prevent a heavy upgrade from hogging resources
throttling
time
.
Duration
// Disk throttling to prevent a heavy upgrade from hogging resources
log
log
.
Logger
log
log
.
Logger
...
@@ -115,12 +118,19 @@ func NewChainIndexer(chainDb, indexDb ethdb.Database, backend ChainIndexerBacken
...
@@ -115,12 +118,19 @@ func NewChainIndexer(chainDb, indexDb ethdb.Database, backend ChainIndexerBacken
return
c
return
c
}
}
// AddKnownSectionHead marks a new section head as known/processed if it is newer
// AddCheckpoint adds a checkpoint. Sections are never processed and the chain
// than the already known best section head
// is not expected to be available before this point. The indexer assumes that
func
(
c
*
ChainIndexer
)
AddKnownSectionHead
(
section
uint64
,
shead
common
.
Hash
)
{
// the backend has sufficient information available to process subsequent sections.
//
// Note: knownSections == 0 and storedSections == checkpointSections until
// syncing reaches the checkpoint
func
(
c
*
ChainIndexer
)
AddCheckpoint
(
section
uint64
,
shead
common
.
Hash
)
{
c
.
lock
.
Lock
()
c
.
lock
.
Lock
()
defer
c
.
lock
.
Unlock
()
defer
c
.
lock
.
Unlock
()
c
.
checkpointSections
=
section
+
1
c
.
checkpointHead
=
shead
if
section
<
c
.
storedSections
{
if
section
<
c
.
storedSections
{
return
return
}
}
...
@@ -233,16 +243,23 @@ func (c *ChainIndexer) newHead(head uint64, reorg bool) {
...
@@ -233,16 +243,23 @@ func (c *ChainIndexer) newHead(head uint64, reorg bool) {
// If a reorg happened, invalidate all sections until that point
// If a reorg happened, invalidate all sections until that point
if
reorg
{
if
reorg
{
// Revert the known section number to the reorg point
// Revert the known section number to the reorg point
changed
:=
head
/
c
.
sectionSize
known
:=
head
/
c
.
sectionSize
if
changed
<
c
.
knownSections
{
stored
:=
known
c
.
knownSections
=
changed
if
known
<
c
.
checkpointSections
{
known
=
0
}
if
stored
<
c
.
checkpointSections
{
stored
=
c
.
checkpointSections
}
if
known
<
c
.
knownSections
{
c
.
knownSections
=
known
}
}
// Revert the stored sections from the database to the reorg point
// Revert the stored sections from the database to the reorg point
if
chang
ed
<
c
.
storedSections
{
if
stor
ed
<
c
.
storedSections
{
c
.
setValidSections
(
chang
ed
)
c
.
setValidSections
(
stor
ed
)
}
}
// Update the new head number to the finalized section end and notify children
// Update the new head number to the finalized section end and notify children
head
=
changed
*
c
.
sectionSize
head
=
known
*
c
.
sectionSize
if
head
<
c
.
cascadedHead
{
if
head
<
c
.
cascadedHead
{
c
.
cascadedHead
=
head
c
.
cascadedHead
=
head
...
@@ -256,7 +273,18 @@ func (c *ChainIndexer) newHead(head uint64, reorg bool) {
...
@@ -256,7 +273,18 @@ func (c *ChainIndexer) newHead(head uint64, reorg bool) {
var
sections
uint64
var
sections
uint64
if
head
>=
c
.
confirmsReq
{
if
head
>=
c
.
confirmsReq
{
sections
=
(
head
+
1
-
c
.
confirmsReq
)
/
c
.
sectionSize
sections
=
(
head
+
1
-
c
.
confirmsReq
)
/
c
.
sectionSize
if
sections
<
c
.
checkpointSections
{
sections
=
0
}
if
sections
>
c
.
knownSections
{
if
sections
>
c
.
knownSections
{
if
c
.
knownSections
<
c
.
checkpointSections
{
// syncing reached the checkpoint, verify section head
syncedHead
:=
rawdb
.
ReadCanonicalHash
(
c
.
chainDb
,
c
.
checkpointSections
*
c
.
sectionSize
-
1
)
if
syncedHead
!=
c
.
checkpointHead
{
c
.
log
.
Error
(
"Synced chain does not match checkpoint"
,
"number"
,
c
.
checkpointSections
*
c
.
sectionSize
-
1
,
"expected"
,
c
.
checkpointHead
,
"synced"
,
syncedHead
)
return
}
}
c
.
knownSections
=
sections
c
.
knownSections
=
sections
select
{
select
{
...
@@ -401,8 +429,14 @@ func (c *ChainIndexer) AddChildIndexer(indexer *ChainIndexer) {
...
@@ -401,8 +429,14 @@ func (c *ChainIndexer) AddChildIndexer(indexer *ChainIndexer) {
c
.
children
=
append
(
c
.
children
,
indexer
)
c
.
children
=
append
(
c
.
children
,
indexer
)
// Cascade any pending updates to new children too
// Cascade any pending updates to new children too
if
c
.
storedSections
>
0
{
sections
:=
c
.
storedSections
indexer
.
newHead
(
c
.
storedSections
*
c
.
sectionSize
-
1
,
false
)
if
c
.
knownSections
<
sections
{
// if a section is "stored" but not "known" then it is a checkpoint without
// available chain data so we should not cascade it yet
sections
=
c
.
knownSections
}
if
sections
>
0
{
indexer
.
newHead
(
sections
*
c
.
sectionSize
-
1
,
false
)
}
}
}
}
...
...
light/lightchain.go
浏览文件 @
63352bf4
...
@@ -121,14 +121,14 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, engine consensus.
...
@@ -121,14 +121,14 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, engine consensus.
func
(
self
*
LightChain
)
addTrustedCheckpoint
(
cp
TrustedCheckpoint
)
{
func
(
self
*
LightChain
)
addTrustedCheckpoint
(
cp
TrustedCheckpoint
)
{
if
self
.
odr
.
ChtIndexer
()
!=
nil
{
if
self
.
odr
.
ChtIndexer
()
!=
nil
{
StoreChtRoot
(
self
.
chainDb
,
cp
.
SectionIdx
,
cp
.
SectionHead
,
cp
.
CHTRoot
)
StoreChtRoot
(
self
.
chainDb
,
cp
.
SectionIdx
,
cp
.
SectionHead
,
cp
.
CHTRoot
)
self
.
odr
.
ChtIndexer
()
.
Add
KnownSectionHead
(
cp
.
SectionIdx
,
cp
.
SectionHead
)
self
.
odr
.
ChtIndexer
()
.
Add
Checkpoint
(
cp
.
SectionIdx
,
cp
.
SectionHead
)
}
}
if
self
.
odr
.
BloomTrieIndexer
()
!=
nil
{
if
self
.
odr
.
BloomTrieIndexer
()
!=
nil
{
StoreBloomTrieRoot
(
self
.
chainDb
,
cp
.
SectionIdx
,
cp
.
SectionHead
,
cp
.
BloomRoot
)
StoreBloomTrieRoot
(
self
.
chainDb
,
cp
.
SectionIdx
,
cp
.
SectionHead
,
cp
.
BloomRoot
)
self
.
odr
.
BloomTrieIndexer
()
.
Add
KnownSectionHead
(
cp
.
SectionIdx
,
cp
.
SectionHead
)
self
.
odr
.
BloomTrieIndexer
()
.
Add
Checkpoint
(
cp
.
SectionIdx
,
cp
.
SectionHead
)
}
}
if
self
.
odr
.
BloomIndexer
()
!=
nil
{
if
self
.
odr
.
BloomIndexer
()
!=
nil
{
self
.
odr
.
BloomIndexer
()
.
Add
KnownSectionHead
(
cp
.
SectionIdx
,
cp
.
SectionHead
)
self
.
odr
.
BloomIndexer
()
.
Add
Checkpoint
(
cp
.
SectionIdx
,
cp
.
SectionHead
)
}
}
log
.
Info
(
"Added trusted checkpoint"
,
"chain"
,
cp
.
name
,
"block"
,
(
cp
.
SectionIdx
+
1
)
*
self
.
indexerConfig
.
ChtSize
-
1
,
"hash"
,
cp
.
SectionHead
)
log
.
Info
(
"Added trusted checkpoint"
,
"chain"
,
cp
.
name
,
"block"
,
(
cp
.
SectionIdx
+
1
)
*
self
.
indexerConfig
.
ChtSize
-
1
,
"hash"
,
cp
.
SectionHead
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录