Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
f55c26ae
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,发现更多精彩内容 >>
未验证
提交
f55c26ae
编写于
9月 20, 2018
作者:
P
Péter Szilágyi
提交者:
GitHub
9月 20, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17719 from karalabe/update-chts
les, light, params: update light client CHTs
上级
d6254f82
af890931
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
80 addition
and
68 deletion
+80
-68
les/commons.go
les/commons.go
+12
-12
les/odr_requests.go
les/odr_requests.go
+8
-8
light/lightchain.go
light/lightchain.go
+7
-7
light/odr.go
light/odr.go
+8
-8
light/odr_util.go
light/odr_util.go
+1
-1
light/postprocess.go
light/postprocess.go
+5
-32
params/config.go
params/config.go
+39
-0
未找到文件。
les/commons.go
浏览文件 @
f55c26ae
...
...
@@ -42,12 +42,12 @@ type lesCommons struct {
// NodeInfo represents a short summary of the Ethereum sub-protocol metadata
// known about the host peer.
type
NodeInfo
struct
{
Network
uint64
`json:"network"`
// Ethereum network ID (1=Frontier, 2=Morden, Ropsten=3, Rinkeby=4)
Difficulty
*
big
.
Int
`json:"difficulty"`
// Total difficulty of the host's blockchain
Genesis
common
.
Hash
`json:"genesis"`
// SHA3 hash of the host's genesis block
Config
*
params
.
ChainConfig
`json:"config"`
// Chain configuration for the fork rules
Head
common
.
Hash
`json:"head"`
// SHA3 hash of the host's best owned block
CHT
light
.
TrustedCheckpoint
`json:"cht"`
// Trused CHT checkpoint for fast catchup
Network
uint64
`json:"network"`
// Ethereum network ID (1=Frontier, 2=Morden, Ropsten=3, Rinkeby=4)
Difficulty
*
big
.
Int
`json:"difficulty"`
// Total difficulty of the host's blockchain
Genesis
common
.
Hash
`json:"genesis"`
// SHA3 hash of the host's genesis block
Config
*
params
.
ChainConfig
`json:"config"`
// Chain configuration for the fork rules
Head
common
.
Hash
`json:"head"`
// SHA3 hash of the host's best owned block
CHT
params
.
TrustedCheckpoint
`json:"cht"`
// Trused CHT checkpoint for fast catchup
}
// makeProtocols creates protocol descriptors for the given LES versions.
...
...
@@ -76,7 +76,7 @@ func (c *lesCommons) makeProtocols(versions []uint) []p2p.Protocol {
// nodeInfo retrieves some protocol metadata about the running host node.
func
(
c
*
lesCommons
)
nodeInfo
()
interface
{}
{
var
cht
light
.
TrustedCheckpoint
var
cht
params
.
TrustedCheckpoint
sections
,
_
,
_
:=
c
.
chtIndexer
.
Sections
()
sections2
,
_
,
_
:=
c
.
bloomTrieIndexer
.
Sections
()
...
...
@@ -98,11 +98,11 @@ func (c *lesCommons) nodeInfo() interface{} {
idxV2
:=
(
sectionIndex
+
1
)
*
c
.
iConfig
.
PairChtSize
/
c
.
iConfig
.
ChtSize
-
1
chtRoot
=
light
.
GetChtRoot
(
c
.
chainDb
,
idxV2
,
sectionHead
)
}
cht
=
light
.
TrustedCheckpoint
{
SectionI
dx
:
sectionIndex
,
SectionHead
:
sectionHead
,
CHTRoot
:
chtRoot
,
BloomRoot
:
light
.
GetBloomTrieRoot
(
c
.
chainDb
,
sectionIndex
,
sectionHead
),
cht
=
params
.
TrustedCheckpoint
{
SectionI
ndex
:
sectionIndex
,
SectionHead
:
sectionHead
,
CHTRoot
:
chtRoot
,
BloomRoot
:
light
.
GetBloomTrieRoot
(
c
.
chainDb
,
sectionIndex
,
sectionHead
),
}
}
...
...
les/odr_requests.go
浏览文件 @
f55c26ae
...
...
@@ -478,7 +478,7 @@ func (r *ChtRequest) Validate(db ethdb.Database, msg *Msg) error {
}
type
BloomReq
struct
{
BloomTrieNum
,
BitIdx
,
SectionI
d
x
,
FromLevel
uint64
BloomTrieNum
,
BitIdx
,
SectionI
nde
x
,
FromLevel
uint64
}
// ODR request type for requesting headers by Canonical Hash Trie, see LesOdrRequest interface
...
...
@@ -487,7 +487,7 @@ type BloomRequest light.BloomRequest
// GetCost returns the cost of the given ODR request according to the serving
// peer's cost table (implementation of LesOdrRequest)
func
(
r
*
BloomRequest
)
GetCost
(
peer
*
peer
)
uint64
{
return
peer
.
GetRequestCost
(
GetHelperTrieProofsMsg
,
len
(
r
.
SectionI
d
xList
))
return
peer
.
GetRequestCost
(
GetHelperTrieProofsMsg
,
len
(
r
.
SectionI
nde
xList
))
}
// CanSend tells if a certain peer is suitable for serving the given request
...
...
@@ -503,13 +503,13 @@ func (r *BloomRequest) CanSend(peer *peer) bool {
// Request sends an ODR request to the LES network (implementation of LesOdrRequest)
func
(
r
*
BloomRequest
)
Request
(
reqID
uint64
,
peer
*
peer
)
error
{
peer
.
Log
()
.
Debug
(
"Requesting BloomBits"
,
"bloomTrie"
,
r
.
BloomTrieNum
,
"bitIdx"
,
r
.
BitIdx
,
"sections"
,
r
.
SectionI
d
xList
)
reqs
:=
make
([]
HelperTrieReq
,
len
(
r
.
SectionI
d
xList
))
peer
.
Log
()
.
Debug
(
"Requesting BloomBits"
,
"bloomTrie"
,
r
.
BloomTrieNum
,
"bitIdx"
,
r
.
BitIdx
,
"sections"
,
r
.
SectionI
nde
xList
)
reqs
:=
make
([]
HelperTrieReq
,
len
(
r
.
SectionI
nde
xList
))
var
encNumber
[
10
]
byte
binary
.
BigEndian
.
PutUint16
(
encNumber
[
:
2
],
uint16
(
r
.
BitIdx
))
for
i
,
sectionIdx
:=
range
r
.
SectionI
d
xList
{
for
i
,
sectionIdx
:=
range
r
.
SectionI
nde
xList
{
binary
.
BigEndian
.
PutUint64
(
encNumber
[
2
:
],
sectionIdx
)
reqs
[
i
]
=
HelperTrieReq
{
Type
:
htBloomBits
,
...
...
@@ -524,7 +524,7 @@ func (r *BloomRequest) Request(reqID uint64, peer *peer) error {
// returns true and stores results in memory if the message was a valid reply
// to the request (implementation of LesOdrRequest)
func
(
r
*
BloomRequest
)
Validate
(
db
ethdb
.
Database
,
msg
*
Msg
)
error
{
log
.
Debug
(
"Validating BloomBits"
,
"bloomTrie"
,
r
.
BloomTrieNum
,
"bitIdx"
,
r
.
BitIdx
,
"sections"
,
r
.
SectionI
d
xList
)
log
.
Debug
(
"Validating BloomBits"
,
"bloomTrie"
,
r
.
BloomTrieNum
,
"bitIdx"
,
r
.
BitIdx
,
"sections"
,
r
.
SectionI
nde
xList
)
// Ensure we have a correct message with a single proof element
if
msg
.
MsgType
!=
MsgHelperTrieProofs
{
...
...
@@ -535,13 +535,13 @@ func (r *BloomRequest) Validate(db ethdb.Database, msg *Msg) error {
nodeSet
:=
proofs
.
NodeSet
()
reads
:=
&
readTraceDB
{
db
:
nodeSet
}
r
.
BloomBits
=
make
([][]
byte
,
len
(
r
.
SectionI
d
xList
))
r
.
BloomBits
=
make
([][]
byte
,
len
(
r
.
SectionI
nde
xList
))
// Verify the proofs
var
encNumber
[
10
]
byte
binary
.
BigEndian
.
PutUint16
(
encNumber
[
:
2
],
uint16
(
r
.
BitIdx
))
for
i
,
idx
:=
range
r
.
SectionI
d
xList
{
for
i
,
idx
:=
range
r
.
SectionI
nde
xList
{
binary
.
BigEndian
.
PutUint64
(
encNumber
[
2
:
],
idx
)
value
,
_
,
err
:=
trie
.
VerifyProof
(
r
.
BloomTrieRoot
,
encNumber
[
:
],
reads
)
if
err
!=
nil
{
...
...
light/lightchain.go
浏览文件 @
f55c26ae
...
...
@@ -118,19 +118,19 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, engine consensus.
}
// addTrustedCheckpoint adds a trusted checkpoint to the blockchain
func
(
self
*
LightChain
)
addTrustedCheckpoint
(
cp
TrustedCheckpoint
)
{
func
(
self
*
LightChain
)
addTrustedCheckpoint
(
cp
*
params
.
TrustedCheckpoint
)
{
if
self
.
odr
.
ChtIndexer
()
!=
nil
{
StoreChtRoot
(
self
.
chainDb
,
cp
.
SectionI
d
x
,
cp
.
SectionHead
,
cp
.
CHTRoot
)
self
.
odr
.
ChtIndexer
()
.
AddCheckpoint
(
cp
.
SectionI
d
x
,
cp
.
SectionHead
)
StoreChtRoot
(
self
.
chainDb
,
cp
.
SectionI
nde
x
,
cp
.
SectionHead
,
cp
.
CHTRoot
)
self
.
odr
.
ChtIndexer
()
.
AddCheckpoint
(
cp
.
SectionI
nde
x
,
cp
.
SectionHead
)
}
if
self
.
odr
.
BloomTrieIndexer
()
!=
nil
{
StoreBloomTrieRoot
(
self
.
chainDb
,
cp
.
SectionI
d
x
,
cp
.
SectionHead
,
cp
.
BloomRoot
)
self
.
odr
.
BloomTrieIndexer
()
.
AddCheckpoint
(
cp
.
SectionI
d
x
,
cp
.
SectionHead
)
StoreBloomTrieRoot
(
self
.
chainDb
,
cp
.
SectionI
nde
x
,
cp
.
SectionHead
,
cp
.
BloomRoot
)
self
.
odr
.
BloomTrieIndexer
()
.
AddCheckpoint
(
cp
.
SectionI
nde
x
,
cp
.
SectionHead
)
}
if
self
.
odr
.
BloomIndexer
()
!=
nil
{
self
.
odr
.
BloomIndexer
()
.
AddCheckpoint
(
cp
.
SectionI
d
x
,
cp
.
SectionHead
)
self
.
odr
.
BloomIndexer
()
.
AddCheckpoint
(
cp
.
SectionI
nde
x
,
cp
.
SectionHead
)
}
log
.
Info
(
"Added trusted checkpoint"
,
"chain"
,
cp
.
name
,
"block"
,
(
cp
.
SectionId
x
+
1
)
*
self
.
indexerConfig
.
ChtSize
-
1
,
"hash"
,
cp
.
SectionHead
)
log
.
Info
(
"Added trusted checkpoint"
,
"chain"
,
cp
.
Name
,
"block"
,
(
cp
.
SectionInde
x
+
1
)
*
self
.
indexerConfig
.
ChtSize
-
1
,
"hash"
,
cp
.
SectionHead
)
}
func
(
self
*
LightChain
)
getProcInterrupt
()
bool
{
...
...
light/odr.go
浏览文件 @
f55c26ae
...
...
@@ -157,18 +157,18 @@ func (req *ChtRequest) StoreResult(db ethdb.Database) {
// BloomRequest is the ODR request type for retrieving bloom filters from a CHT structure
type
BloomRequest
struct
{
OdrRequest
Config
*
IndexerConfig
BloomTrieNum
uint64
BitIdx
uint
SectionI
d
xList
[]
uint64
BloomTrieRoot
common
.
Hash
BloomBits
[][]
byte
Proofs
*
NodeSet
Config
*
IndexerConfig
BloomTrieNum
uint64
BitIdx
uint
SectionI
nde
xList
[]
uint64
BloomTrieRoot
common
.
Hash
BloomBits
[][]
byte
Proofs
*
NodeSet
}
// StoreResult stores the retrieved data in local database
func
(
req
*
BloomRequest
)
StoreResult
(
db
ethdb
.
Database
)
{
for
i
,
sectionIdx
:=
range
req
.
SectionI
d
xList
{
for
i
,
sectionIdx
:=
range
req
.
SectionI
nde
xList
{
sectionHead
:=
rawdb
.
ReadCanonicalHash
(
db
,
(
sectionIdx
+
1
)
*
req
.
Config
.
BloomTrieSize
-
1
)
// if we don't have the canonical hash stored for this section head number, we'll still store it under
// a key with a zero sectionHead. GetBloomBits will look there too if we still don't have the canonical
...
...
light/odr_util.go
浏览文件 @
f55c26ae
...
...
@@ -222,7 +222,7 @@ func GetBloomBits(ctx context.Context, odr OdrBackend, bitIdx uint, sectionIdxLi
}
r
:=
&
BloomRequest
{
BloomTrieRoot
:
GetBloomTrieRoot
(
db
,
bloomTrieCount
-
1
,
sectionHead
),
BloomTrieNum
:
bloomTrieCount
-
1
,
BitIdx
:
bitIdx
,
SectionI
d
xList
:
reqList
,
Config
:
odr
.
IndexerConfig
()}
BitIdx
:
bitIdx
,
SectionI
nde
xList
:
reqList
,
Config
:
odr
.
IndexerConfig
()}
if
err
:=
odr
.
Retrieve
(
ctx
,
r
);
err
!=
nil
{
return
nil
,
err
}
else
{
...
...
light/postprocess.go
浏览文件 @
f55c26ae
...
...
@@ -104,38 +104,11 @@ var (
}
)
// trustedCheckpoint represents a set of post-processed trie roots (CHT and BloomTrie) associated with
// the appropriate section index and head hash. It is used to start light syncing from this checkpoint
// and avoid downloading the entire header chain while still being able to securely access old headers/logs.
type
TrustedCheckpoint
struct
{
name
string
SectionIdx
uint64
SectionHead
,
CHTRoot
,
BloomRoot
common
.
Hash
}
// trustedCheckpoints associates each known checkpoint with the genesis hash of the chain it belongs to
var
trustedCheckpoints
=
map
[
common
.
Hash
]
TrustedCheckpoint
{
params
.
MainnetGenesisHash
:
{
name
:
"mainnet"
,
SectionIdx
:
187
,
SectionHead
:
common
.
HexToHash
(
"e6baa034efa31562d71ff23676512dec6562c1ad0301e08843b907e81958c696"
),
CHTRoot
:
common
.
HexToHash
(
"28001955219719cf06de1b08648969139d123a9835fc760547a1e4dabdabc15a"
),
BloomRoot
:
common
.
HexToHash
(
"395ca2373fc662720ac6b58b3bbe71f68aa0f38b63b2d3553dd32ff3c51eebc4"
),
},
params
.
TestnetGenesisHash
:
{
name
:
"ropsten"
,
SectionIdx
:
117
,
SectionHead
:
common
.
HexToHash
(
"9529b38631ae30783f56cbe4c3b9f07575b770ecba4f6e20a274b1e2f40fede1"
),
CHTRoot
:
common
.
HexToHash
(
"6f48e9f101f1fac98e7d74fbbcc4fda138358271ffd974d40d2506f0308bb363"
),
BloomRoot
:
common
.
HexToHash
(
"8242342e66e942c0cd893484e6736b9862ceb88b43ca344bb06a8285ac1b6d64"
),
},
params
.
RinkebyGenesisHash
:
{
name
:
"rinkeby"
,
SectionIdx
:
85
,
SectionHead
:
common
.
HexToHash
(
"92cfa67afc4ad8ab0dcbc6fa49efd14b5b19402442e7317e6bc879d85f89d64d"
),
CHTRoot
:
common
.
HexToHash
(
"2802ec92cd7a54a75bca96afdc666ae7b99e5d96cf8192dcfb09588812f51564"
),
BloomRoot
:
common
.
HexToHash
(
"ebefeb31a9a42866d8cf2d2477704b4c3d7c20d0e4e9b5aaa77f396e016a1263"
),
},
var
trustedCheckpoints
=
map
[
common
.
Hash
]
*
params
.
TrustedCheckpoint
{
params
.
MainnetGenesisHash
:
params
.
MainnetTrustedCheckpoint
,
params
.
TestnetGenesisHash
:
params
.
TestnetTrustedCheckpoint
,
params
.
RinkebyGenesisHash
:
params
.
RinkebyTrustedCheckpoint
,
}
var
(
...
...
@@ -329,7 +302,7 @@ func (b *BloomTrieIndexerBackend) fetchMissingNodes(ctx context.Context, section
for
i
:=
0
;
i
<
20
;
i
++
{
go
func
()
{
for
bitIndex
:=
range
indexCh
{
r
:=
&
BloomRequest
{
BloomTrieRoot
:
root
,
BloomTrieNum
:
section
-
1
,
BitIdx
:
bitIndex
,
SectionI
d
xList
:
[]
uint64
{
section
-
1
},
Config
:
b
.
odr
.
IndexerConfig
()}
r
:=
&
BloomRequest
{
BloomTrieRoot
:
root
,
BloomTrieNum
:
section
-
1
,
BitIdx
:
bitIndex
,
SectionI
nde
xList
:
[]
uint64
{
section
-
1
},
Config
:
b
.
odr
.
IndexerConfig
()}
for
{
if
err
:=
b
.
odr
.
Retrieve
(
ctx
,
r
);
err
==
ErrNoPeers
{
// if there are no peers to serve, retry later
...
...
params/config.go
浏览文件 @
f55c26ae
...
...
@@ -46,6 +46,15 @@ var (
Ethash
:
new
(
EthashConfig
),
}
// MainnetTrustedCheckpoint contains the light client trusted checkpoint for the main network.
MainnetTrustedCheckpoint
=
&
TrustedCheckpoint
{
Name
:
"mainnet"
,
SectionIndex
:
193
,
SectionHead
:
common
.
HexToHash
(
"0xc2d574295ecedc4d58530ae24c31a5a98be7d2b3327fba0dd0f4ed3913828a55"
),
CHTRoot
:
common
.
HexToHash
(
"0x5d1027dfae688c77376e842679ceada87fd94738feb9b32ef165473bfbbb317b"
),
BloomRoot
:
common
.
HexToHash
(
"0xd38be1a06aabd568e10957fee4fcc523bc64996bcf31bae3f55f86e0a583919f"
),
}
// TestnetChainConfig contains the chain parameters to run a node on the Ropsten test network.
TestnetChainConfig
=
&
ChainConfig
{
ChainID
:
big
.
NewInt
(
3
),
...
...
@@ -61,6 +70,15 @@ var (
Ethash
:
new
(
EthashConfig
),
}
// TestnetTrustedCheckpoint contains the light client trusted checkpoint for the Ropsten test network.
TestnetTrustedCheckpoint
=
&
TrustedCheckpoint
{
Name
:
"testnet"
,
SectionIndex
:
123
,
SectionHead
:
common
.
HexToHash
(
"0xa372a53decb68ce453da12bea1c8ee7b568b276aa2aab94d9060aa7c81fc3dee"
),
CHTRoot
:
common
.
HexToHash
(
"0x6b02e7fada79cd2a80d4b3623df9c44384d6647fc127462e1c188ccd09ece87b"
),
BloomRoot
:
common
.
HexToHash
(
"0xf2d27490914968279d6377d42868928632573e823b5d1d4a944cba6009e16259"
),
}
// RinkebyChainConfig contains the chain parameters to run a node on the Rinkeby test network.
RinkebyChainConfig
=
&
ChainConfig
{
ChainID
:
big
.
NewInt
(
4
),
...
...
@@ -79,6 +97,15 @@ var (
},
}
// RinkebyTrustedCheckpoint contains the light client trusted checkpoint for the Rinkeby test network.
RinkebyTrustedCheckpoint
=
&
TrustedCheckpoint
{
Name
:
"rinkeby"
,
SectionIndex
:
91
,
SectionHead
:
common
.
HexToHash
(
"0x435b7b2d8a7922f3b9a522f2fb02730e95e0e1782f0f5443894d5415bba37154"
),
CHTRoot
:
common
.
HexToHash
(
"0x0664bf7ecccfb6775c4eca6f0f264fb5282a22754a2135a1ac4bff2ef02898dd"
),
BloomRoot
:
common
.
HexToHash
(
"0x2a64df2400c3a2cb6400639bb6ed29389abdb4d93e2e525aa7c21f38767cd96f"
),
}
// AllEthashProtocolChanges contains every protocol change (EIPs) introduced
// and accepted by the Ethereum core developers into the Ethash consensus.
//
...
...
@@ -97,6 +124,18 @@ var (
TestRules
=
TestChainConfig
.
Rules
(
new
(
big
.
Int
))
)
// TrustedCheckpoint represents a set of post-processed trie roots (CHT and
// BloomTrie) associated with the appropriate section index and head hash. It is
// used to start light syncing from this checkpoint and avoid downloading the
// entire header chain while still being able to securely access old headers/logs.
type
TrustedCheckpoint
struct
{
Name
string
`json:"-"`
SectionIndex
uint64
`json:"sectionIndex"`
SectionHead
common
.
Hash
`json:"sectionHead"`
CHTRoot
common
.
Hash
`json:"chtRoot"`
BloomRoot
common
.
Hash
`json:"bloomRoot"`
}
// ChainConfig is the core config which determines the blockchain settings.
//
// ChainConfig is stored in the database on a per block basis. This means
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录