3
3
cast ,
4
4
Dict ,
5
5
List ,
6
+ Union ,
7
+ )
8
+
9
+ from eth_typing import (
10
+ BlockNumber ,
11
+ Hash32 ,
6
12
)
7
13
8
14
from eth_utils import encode_hex
19
25
20
26
from .commands import (
21
27
Announce ,
22
- HeadInfo ,
23
28
Status ,
24
29
StatusV2 ,
25
30
)
@@ -38,10 +43,9 @@ class LESPeer(BasePeer):
38
43
39
44
_supported_sub_protocols = [LESProtocol , LESProtocolV2 ]
40
45
sub_proto : LESProtocol = None
41
- # TODO: This will no longer be needed once we've fixed #891, and then it should be removed.
42
- head_info : HeadInfo = None
43
46
44
47
_requests : LESExchangeHandler = None
48
+ head_number : BlockNumber = None
45
49
46
50
def get_extra_stats (self ) -> List [str ]:
47
51
stats_pairs = self .requests .get_stats ().items ()
@@ -54,10 +58,11 @@ def requests(self) -> LESExchangeHandler:
54
58
return self ._requests
55
59
56
60
def handle_sub_proto_msg (self , cmd : Command , msg : _DecodedMsgType ) -> None :
61
+ head_info = cast (Dict [str , Union [int , Hash32 , BlockNumber ]], msg )
57
62
if isinstance (cmd , Announce ):
58
- self .head_info = cmd . as_head_info ( msg )
59
- self .head_td = self . head_info . total_difficulty
60
- self .head_hash = self . head_info . block_hash
63
+ self .head_td = head_info [ 'head_td' ]
64
+ self .head_hash = head_info [ 'head_hash' ]
65
+ self .head_number = head_info [ 'head_number' ]
61
66
62
67
super ().handle_sub_proto_msg (cmd , msg )
63
68
@@ -83,6 +88,6 @@ async def process_sub_proto_handshake(
83
88
"{} genesis ({}) does not match ours ({}), disconnecting" .format (
84
89
self , encode_hex (msg ['genesisHash' ]), genesis .hex_hash ))
85
90
# TODO: Disconnect if the remote doesn't serve headers.
86
- self .head_info = cmd . as_head_info ( msg )
87
- self .head_td = self . head_info . total_difficulty
88
- self .head_hash = self . head_info . block_hash
91
+ self .head_td = msg [ 'headTd' ]
92
+ self .head_hash = msg [ 'headHash' ]
93
+ self .head_number = msg [ 'headNum' ]
0 commit comments