aboutsummaryrefslogtreecommitdiffstats
path: root/les
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-01-31 00:39:32 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-01-31 00:42:00 +0800
commit566d5c0777c2c5ee1a8fe3c0aee1e5c8c69053e2 (patch)
treed1b99b9caab92cce3f6a6a4f8dcafb66a892e13a /les
parent6198c53e28200b3a575f4545cbfa83c585e44b76 (diff)
downloadgo-tangerine-566d5c0777c2c5ee1a8fe3c0aee1e5c8c69053e2.tar
go-tangerine-566d5c0777c2c5ee1a8fe3c0aee1e5c8c69053e2.tar.gz
go-tangerine-566d5c0777c2c5ee1a8fe3c0aee1e5c8c69053e2.tar.bz2
go-tangerine-566d5c0777c2c5ee1a8fe3c0aee1e5c8c69053e2.tar.lz
go-tangerine-566d5c0777c2c5ee1a8fe3c0aee1e5c8c69053e2.tar.xz
go-tangerine-566d5c0777c2c5ee1a8fe3c0aee1e5c8c69053e2.tar.zst
go-tangerine-566d5c0777c2c5ee1a8fe3c0aee1e5c8c69053e2.zip
core, eth, les, light: get rid of redundant methods
Diffstat (limited to 'les')
-rw-r--r--les/handler.go22
-rw-r--r--les/helper_test.go9
2 files changed, 20 insertions, 11 deletions
diff --git a/les/handler.go b/les/handler.go
index 57657e84f..ad2e8058f 100644
--- a/les/handler.go
+++ b/les/handler.go
@@ -77,13 +77,11 @@ type BlockChain interface {
GetHeader(hash common.Hash, number uint64) *types.Header
GetHeaderByHash(hash common.Hash) *types.Header
CurrentHeader() *types.Header
- GetTdByHash(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.GetTdByHash(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,
}
}
diff --git a/les/helper_test.go b/les/helper_test.go
index b881b41ce..57e693996 100644
--- a/les/helper_test.go
+++ b/les/helper_test.go
@@ -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
}