@@ -77,13 +77,11 @@ type BlockChain interface {
7777 GetHeader (hash common.Hash , number uint64 ) * types.Header
7878 GetHeaderByHash (hash common.Hash ) * types.Header
7979 CurrentHeader () * types.Header
80- GetTdByHash (hash common.Hash ) * big.Int
80+ GetTd (hash common.Hash , number uint64 ) * big.Int
8181 InsertHeaderChain (chain []* types.Header , checkFreq int ) (int , error )
8282 Rollback (chain []common.Hash )
83- Status () (td * big.Int , currentBlock common.Hash , genesisBlock common.Hash )
8483 GetHeaderByNumber (number uint64 ) * types.Header
8584 GetBlockHashesFromHash (hash common.Hash , max uint64 ) []common.Hash
86- LastBlockHash () common.Hash
8785 Genesis () * types.Block
8886 SubscribeChainHeadEvent (ch chan <- core.ChainHeadEvent ) event.Subscription
8987}
@@ -262,9 +260,14 @@ func (pm *ProtocolManager) handle(p *peer) error {
262260 p .Log ().Debug ("Light Ethereum peer connected" , "name" , p .Name ())
263261
264262 // Execute the LES handshake
265- td , head , genesis := pm .blockchain .Status ()
266- headNum := core .GetBlockNumber (pm .chainDb , head )
267- if err := p .Handshake (td , head , headNum , genesis , pm .server ); err != nil {
263+ var (
264+ genesis = pm .blockchain .Genesis ()
265+ head = pm .blockchain .CurrentHeader ()
266+ hash = head .Hash ()
267+ number = head .Number .Uint64 ()
268+ td = pm .blockchain .GetTd (hash , number )
269+ )
270+ if err := p .Handshake (td , hash , number , genesis .Hash (), pm .server ); err != nil {
268271 p .Log ().Debug ("Light Ethereum handshake failed" , "err" , err )
269272 return err
270273 }
@@ -1135,12 +1138,15 @@ type NodeInfo struct {
11351138
11361139// NodeInfo retrieves some protocol metadata about the running host node.
11371140func (self * ProtocolManager ) NodeInfo () * NodeInfo {
1141+ head := self .blockchain .CurrentHeader ()
1142+ hash := head .Hash ()
1143+
11381144 return & NodeInfo {
11391145 Network : self .networkId ,
1140- Difficulty : self .blockchain .GetTdByHash ( self . blockchain . LastBlockHash ()),
1146+ Difficulty : self .blockchain .GetTd ( hash , head . Number . Uint64 ()),
11411147 Genesis : self .blockchain .Genesis ().Hash (),
11421148 Config : self .blockchain .Config (),
1143- Head : self . blockchain . LastBlockHash () ,
1149+ Head : hash ,
11441150 }
11451151}
11461152
0 commit comments