Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
566d5c07
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,发现更多精彩内容 >>
未验证
提交
566d5c07
编写于
1月 30, 2018
作者:
P
Péter Szilágyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core, eth, les, light: get rid of redundant methods
上级
6198c53e
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
54 addition
and
65 deletion
+54
-65
core/blockchain.go
core/blockchain.go
+1
-18
eth/downloader/downloader.go
eth/downloader/downloader.go
+6
-4
eth/downloader/downloader_test.go
eth/downloader/downloader_test.go
+2
-2
eth/handler.go
eth/handler.go
+8
-2
eth/helper_test.go
eth/helper_test.go
+6
-2
eth/protocol_test.go
eth/protocol_test.go
+9
-5
les/handler.go
les/handler.go
+14
-8
les/helper_test.go
les/helper_test.go
+6
-3
light/lightchain.go
light/lightchain.go
+1
-20
tests/block_test_util.go
tests/block_test_util.go
+1
-1
未找到文件。
core/blockchain.go
浏览文件 @
566d5c07
...
...
@@ -312,14 +312,6 @@ func (bc *BlockChain) GasLimit() uint64 {
return
bc
.
currentBlock
.
GasLimit
()
}
// LastBlockHash return the hash of the HEAD block.
func
(
bc
*
BlockChain
)
LastBlockHash
()
common
.
Hash
{
bc
.
mu
.
RLock
()
defer
bc
.
mu
.
RUnlock
()
return
bc
.
currentBlock
.
Hash
()
}
// CurrentBlock retrieves the current head block of the canonical chain. The
// block is retrieved from the blockchain's internal cache.
func
(
bc
*
BlockChain
)
CurrentBlock
()
*
types
.
Block
{
...
...
@@ -338,15 +330,6 @@ func (bc *BlockChain) CurrentFastBlock() *types.Block {
return
bc
.
currentFastBlock
}
// Status returns status information about the current chain such as the HEAD Td,
// the HEAD hash and the hash of the genesis block.
func
(
bc
*
BlockChain
)
Status
()
(
td
*
big
.
Int
,
currentBlock
common
.
Hash
,
genesisBlock
common
.
Hash
)
{
bc
.
mu
.
RLock
()
defer
bc
.
mu
.
RUnlock
()
return
bc
.
GetTd
(
bc
.
currentBlock
.
Hash
(),
bc
.
currentBlock
.
NumberU64
()),
bc
.
currentBlock
.
Hash
(),
bc
.
genesisBlock
.
Hash
()
}
// SetProcessor sets the processor required for making state modifications.
func
(
bc
*
BlockChain
)
SetProcessor
(
processor
Processor
)
{
bc
.
procmu
.
Lock
()
...
...
@@ -1006,7 +989,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty
stats
.
report
(
chain
,
i
)
}
// Append a single chain head event if we've progressed the chain
if
lastCanon
!=
nil
&&
bc
.
LastBlock
Hash
()
==
lastCanon
.
Hash
()
{
if
lastCanon
!=
nil
&&
bc
.
CurrentBlock
()
.
Hash
()
==
lastCanon
.
Hash
()
{
events
=
append
(
events
,
ChainHeadEvent
{
lastCanon
})
}
return
0
,
events
,
coalescedLogs
,
nil
...
...
eth/downloader/downloader.go
浏览文件 @
566d5c07
...
...
@@ -164,8 +164,8 @@ type LightChain interface {
// CurrentHeader retrieves the head header from the local chain.
CurrentHeader
()
*
types
.
Header
// GetTd
ByHash
returns the total difficulty of a local block.
GetTd
ByHash
(
common
.
Hash
)
*
big
.
Int
// GetTd returns the total difficulty of a local block.
GetTd
(
common
.
Hash
,
uint64
)
*
big
.
Int
// InsertHeaderChain inserts a batch of headers into the local chain.
InsertHeaderChain
([]
*
types
.
Header
,
int
)
(
int
,
error
)
...
...
@@ -1218,7 +1218,8 @@ func (d *Downloader) processHeaders(origin uint64, td *big.Int) error {
// L: Request new headers up from 11 (R's TD was higher, it must have something)
// R: Nothing to give
if
d
.
mode
!=
LightSync
{
if
!
gotHeaders
&&
td
.
Cmp
(
d
.
blockchain
.
GetTdByHash
(
d
.
blockchain
.
CurrentBlock
()
.
Hash
()))
>
0
{
head
:=
d
.
blockchain
.
CurrentBlock
()
if
!
gotHeaders
&&
td
.
Cmp
(
d
.
blockchain
.
GetTd
(
head
.
Hash
(),
head
.
NumberU64
()))
>
0
{
return
errStallingPeer
}
}
...
...
@@ -1230,7 +1231,8 @@ func (d *Downloader) processHeaders(origin uint64, td *big.Int) error {
// queued for processing when the header download completes. However, as long as the
// peer gave us something useful, we're already happy/progressed (above check).
if
d
.
mode
==
FastSync
||
d
.
mode
==
LightSync
{
if
td
.
Cmp
(
d
.
lightchain
.
GetTdByHash
(
d
.
lightchain
.
CurrentHeader
()
.
Hash
()))
>
0
{
head
:=
d
.
lightchain
.
CurrentHeader
()
if
td
.
Cmp
(
d
.
lightchain
.
GetTd
(
head
.
Hash
(),
head
.
Number
.
Uint64
()))
>
0
{
return
errStallingPeer
}
}
...
...
eth/downloader/downloader_test.go
浏览文件 @
566d5c07
...
...
@@ -299,8 +299,8 @@ func (dl *downloadTester) FastSyncCommitHead(hash common.Hash) error {
return
fmt
.
Errorf
(
"non existent block: %x"
,
hash
[
:
4
])
}
// GetTd
ByHash
retrieves the block's total difficulty from the canonical chain.
func
(
dl
*
downloadTester
)
GetTd
ByHash
(
hash
common
.
Hash
)
*
big
.
Int
{
// GetTd retrieves the block's total difficulty from the canonical chain.
func
(
dl
*
downloadTester
)
GetTd
(
hash
common
.
Hash
,
number
uint64
)
*
big
.
Int
{
dl
.
lock
.
RLock
()
defer
dl
.
lock
.
RUnlock
()
...
...
eth/handler.go
浏览文件 @
566d5c07
...
...
@@ -257,8 +257,14 @@ func (pm *ProtocolManager) handle(p *peer) error {
p
.
Log
()
.
Debug
(
"Ethereum peer connected"
,
"name"
,
p
.
Name
())
// Execute the Ethereum handshake
td
,
head
,
genesis
:=
pm
.
blockchain
.
Status
()
if
err
:=
p
.
Handshake
(
pm
.
networkId
,
td
,
head
,
genesis
);
err
!=
nil
{
var
(
genesis
=
pm
.
blockchain
.
Genesis
()
head
=
pm
.
blockchain
.
CurrentHeader
()
hash
=
head
.
Hash
()
number
=
head
.
Number
.
Uint64
()
td
=
pm
.
blockchain
.
GetTd
(
hash
,
number
)
)
if
err
:=
p
.
Handshake
(
pm
.
networkId
,
td
,
hash
,
genesis
.
Hash
());
err
!=
nil
{
p
.
Log
()
.
Debug
(
"Ethereum handshake failed"
,
"err"
,
err
)
return
err
}
...
...
eth/helper_test.go
浏览文件 @
566d5c07
...
...
@@ -166,8 +166,12 @@ func newTestPeer(name string, version int, pm *ProtocolManager, shake bool) (*te
tp
:=
&
testPeer
{
app
:
app
,
net
:
net
,
peer
:
peer
}
// Execute any implicitly requested handshakes and return
if
shake
{
td
,
head
,
genesis
:=
pm
.
blockchain
.
Status
()
tp
.
handshake
(
nil
,
td
,
head
,
genesis
)
var
(
genesis
=
pm
.
blockchain
.
Genesis
()
head
=
pm
.
blockchain
.
CurrentHeader
()
td
=
pm
.
blockchain
.
GetTd
(
head
.
Hash
(),
head
.
Number
.
Uint64
())
)
tp
.
handshake
(
nil
,
td
,
head
.
Hash
(),
genesis
.
Hash
())
}
return
tp
,
errc
}
...
...
eth/protocol_test.go
浏览文件 @
566d5c07
...
...
@@ -42,7 +42,11 @@ func TestStatusMsgErrors63(t *testing.T) { testStatusMsgErrors(t, 63) }
func
testStatusMsgErrors
(
t
*
testing
.
T
,
protocol
int
)
{
pm
:=
newTestProtocolManagerMust
(
t
,
downloader
.
FullSync
,
0
,
nil
,
nil
)
td
,
currentBlock
,
genesis
:=
pm
.
blockchain
.
Status
()
var
(
genesis
=
pm
.
blockchain
.
Genesis
()
head
=
pm
.
blockchain
.
CurrentHeader
()
td
=
pm
.
blockchain
.
GetTd
(
head
.
Hash
(),
head
.
Number
.
Uint64
())
)
defer
pm
.
Stop
()
tests
:=
[]
struct
{
...
...
@@ -55,16 +59,16 @@ func testStatusMsgErrors(t *testing.T, protocol int) {
wantError
:
errResp
(
ErrNoStatusMsg
,
"first msg has code 2 (!= 0)"
),
},
{
code
:
StatusMsg
,
data
:
statusData
{
10
,
DefaultConfig
.
NetworkId
,
td
,
currentBlock
,
genesis
},
code
:
StatusMsg
,
data
:
statusData
{
10
,
DefaultConfig
.
NetworkId
,
td
,
head
.
Hash
(),
genesis
.
Hash
()
},
wantError
:
errResp
(
ErrProtocolVersionMismatch
,
"10 (!= %d)"
,
protocol
),
},
{
code
:
StatusMsg
,
data
:
statusData
{
uint32
(
protocol
),
999
,
td
,
currentBlock
,
genesis
},
code
:
StatusMsg
,
data
:
statusData
{
uint32
(
protocol
),
999
,
td
,
head
.
Hash
(),
genesis
.
Hash
()
},
wantError
:
errResp
(
ErrNetworkIdMismatch
,
"999 (!= 1)"
),
},
{
code
:
StatusMsg
,
data
:
statusData
{
uint32
(
protocol
),
DefaultConfig
.
NetworkId
,
td
,
currentBlock
,
common
.
Hash
{
3
}},
wantError
:
errResp
(
ErrGenesisBlockMismatch
,
"0300000000000000 (!= %x)"
,
genesis
[
:
8
]),
code
:
StatusMsg
,
data
:
statusData
{
uint32
(
protocol
),
DefaultConfig
.
NetworkId
,
td
,
head
.
Hash
()
,
common
.
Hash
{
3
}},
wantError
:
errResp
(
ErrGenesisBlockMismatch
,
"0300000000000000 (!= %x)"
,
genesis
.
Hash
()
.
Bytes
()
[
:
8
]),
},
}
...
...
les/handler.go
浏览文件 @
566d5c07
...
...
@@ -77,13 +77,11 @@ type BlockChain interface {
GetHeader
(
hash
common
.
Hash
,
number
uint64
)
*
types
.
Header
GetHeaderByHash
(
hash
common
.
Hash
)
*
types
.
Header
CurrentHeader
()
*
types
.
Header
GetTd
ByHash
(
hash
common
.
Hash
)
*
big
.
Int
GetTd
(
hash
common
.
Hash
,
number
uint64
)
*
big
.
Int
InsertHeaderChain
(
chain
[]
*
types
.
Header
,
checkFreq
int
)
(
int
,
error
)
Rollback
(
chain
[]
common
.
Hash
)
Status
()
(
td
*
big
.
Int
,
currentBlock
common
.
Hash
,
genesisBlock
common
.
Hash
)
GetHeaderByNumber
(
number
uint64
)
*
types
.
Header
GetBlockHashesFromHash
(
hash
common
.
Hash
,
max
uint64
)
[]
common
.
Hash
LastBlockHash
()
common
.
Hash
Genesis
()
*
types
.
Block
SubscribeChainHeadEvent
(
ch
chan
<-
core
.
ChainHeadEvent
)
event
.
Subscription
}
...
...
@@ -262,9 +260,14 @@ func (pm *ProtocolManager) handle(p *peer) error {
p
.
Log
()
.
Debug
(
"Light Ethereum peer connected"
,
"name"
,
p
.
Name
())
// Execute the LES handshake
td
,
head
,
genesis
:=
pm
.
blockchain
.
Status
()
headNum
:=
core
.
GetBlockNumber
(
pm
.
chainDb
,
head
)
if
err
:=
p
.
Handshake
(
td
,
head
,
headNum
,
genesis
,
pm
.
server
);
err
!=
nil
{
var
(
genesis
=
pm
.
blockchain
.
Genesis
()
head
=
pm
.
blockchain
.
CurrentHeader
()
hash
=
head
.
Hash
()
number
=
head
.
Number
.
Uint64
()
td
=
pm
.
blockchain
.
GetTd
(
hash
,
number
)
)
if
err
:=
p
.
Handshake
(
td
,
hash
,
number
,
genesis
.
Hash
(),
pm
.
server
);
err
!=
nil
{
p
.
Log
()
.
Debug
(
"Light Ethereum handshake failed"
,
"err"
,
err
)
return
err
}
...
...
@@ -1135,12 +1138,15 @@ type NodeInfo struct {
// NodeInfo retrieves some protocol metadata about the running host node.
func
(
self
*
ProtocolManager
)
NodeInfo
()
*
NodeInfo
{
head
:=
self
.
blockchain
.
CurrentHeader
()
hash
:=
head
.
Hash
()
return
&
NodeInfo
{
Network
:
self
.
networkId
,
Difficulty
:
self
.
blockchain
.
GetTd
ByHash
(
self
.
blockchain
.
LastBlockHash
()),
Difficulty
:
self
.
blockchain
.
GetTd
(
hash
,
head
.
Number
.
Uint64
()),
Genesis
:
self
.
blockchain
.
Genesis
()
.
Hash
(),
Config
:
self
.
blockchain
.
Config
(),
Head
:
self
.
blockchain
.
LastBlockHash
()
,
Head
:
hash
,
}
}
...
...
les/helper_test.go
浏览文件 @
566d5c07
...
...
@@ -227,9 +227,12 @@ func newTestPeer(t *testing.T, name string, version int, pm *ProtocolManager, sh
}
// Execute any implicitly requested handshakes and return
if
shake
{
td
,
head
,
genesis
:=
pm
.
blockchain
.
Status
()
headNum
:=
pm
.
blockchain
.
CurrentHeader
()
.
Number
.
Uint64
()
tp
.
handshake
(
t
,
td
,
head
,
headNum
,
genesis
)
var
(
genesis
=
pm
.
blockchain
.
Genesis
()
head
=
pm
.
blockchain
.
CurrentHeader
()
td
=
pm
.
blockchain
.
GetTd
(
head
.
Hash
(),
head
.
Number
.
Uint64
())
)
tp
.
handshake
(
t
,
td
,
head
.
Hash
(),
head
.
Number
.
Uint64
(),
genesis
.
Hash
())
}
return
tp
,
errc
}
...
...
light/lightchain.go
浏览文件 @
566d5c07
...
...
@@ -176,25 +176,6 @@ func (self *LightChain) GasLimit() uint64 {
return
self
.
hc
.
CurrentHeader
()
.
GasLimit
}
// LastBlockHash return the hash of the HEAD block.
func
(
self
*
LightChain
)
LastBlockHash
()
common
.
Hash
{
self
.
mu
.
RLock
()
defer
self
.
mu
.
RUnlock
()
return
self
.
hc
.
CurrentHeader
()
.
Hash
()
}
// Status returns status information about the current chain such as the HEAD Td,
// the HEAD hash and the hash of the genesis block.
func
(
self
*
LightChain
)
Status
()
(
td
*
big
.
Int
,
currentBlock
common
.
Hash
,
genesisBlock
common
.
Hash
)
{
self
.
mu
.
RLock
()
defer
self
.
mu
.
RUnlock
()
header
:=
self
.
hc
.
CurrentHeader
()
hash
:=
header
.
Hash
()
return
self
.
GetTd
(
hash
,
header
.
Number
.
Uint64
()),
hash
,
self
.
genesisBlock
.
Hash
()
}
// Reset purges the entire blockchain, restoring it to its genesis state.
func
(
bc
*
LightChain
)
Reset
()
{
bc
.
ResetWithGenesisBlock
(
bc
.
genesisBlock
)
...
...
@@ -337,7 +318,7 @@ func (self *LightChain) postChainEvents(events []interface{}) {
for
_
,
event
:=
range
events
{
switch
ev
:=
event
.
(
type
)
{
case
core
.
ChainEvent
:
if
self
.
LastBlock
Hash
()
==
ev
.
Hash
{
if
self
.
CurrentHeader
()
.
Hash
()
==
ev
.
Hash
{
self
.
chainHeadFeed
.
Send
(
core
.
ChainHeadEvent
{
Block
:
ev
.
Block
})
}
self
.
chainFeed
.
Send
(
ev
)
...
...
tests/block_test_util.go
浏览文件 @
566d5c07
...
...
@@ -120,7 +120,7 @@ func (t *BlockTest) Run() error {
if
err
!=
nil
{
return
err
}
cmlast
:=
chain
.
LastBlock
Hash
()
cmlast
:=
chain
.
CurrentBlock
()
.
Hash
()
if
common
.
Hash
(
t
.
json
.
BestBlock
)
!=
cmlast
{
return
fmt
.
Errorf
(
"last block hash validation mismatch: want: %x, have: %x"
,
t
.
json
.
BestBlock
,
cmlast
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录