1
1
import itertools
2
2
from typing import (
3
3
cast ,
4
- Any ,
5
- Dict ,
6
4
Iterable ,
7
5
Set ,
8
6
Type ,
33
31
from eth .beacon .types .blocks import BaseBeaconBlock
34
32
35
33
from trinity .protocol .common .servers import BaseRequestServer
36
- from trinity .protocol .bcc import commands
34
+ from trinity .protocol .bcc .commands import (
35
+ GetBeaconBlocks ,
36
+ GetBeaconBlocksMessage ,
37
+ )
37
38
from trinity .protocol .bcc .peer import (
38
39
BCCPeer ,
39
40
BCCPeerPool ,
42
43
43
44
class BCCRequestServer (BaseRequestServer ):
44
45
subscription_msg_types : Set [Type [Command ]] = {
45
- commands . GetBeaconBlocks ,
46
+ GetBeaconBlocks ,
46
47
}
47
48
48
49
def __init__ (self ,
@@ -56,16 +57,16 @@ async def _handle_msg(self, base_peer: BasePeer, cmd: Command,
56
57
msg : protocol ._DecodedMsgType ) -> None :
57
58
peer = cast (BCCPeer , base_peer )
58
59
59
- if isinstance (cmd , commands . GetBeaconBlocks ):
60
- await self ._handle_get_beacon_blocks (peer , cast (Dict [ str , Any ] , msg ))
60
+ if isinstance (cmd , GetBeaconBlocks ):
61
+ await self ._handle_get_beacon_blocks (peer , cast (GetBeaconBlocksMessage , msg ))
61
62
else :
62
63
raise Exception ("Invariant: Only subscribed to GetBeaconBlocks" )
63
64
64
- async def _handle_get_beacon_blocks (self , peer : BCCPeer , msg : Dict [ str , Any ] ) -> None :
65
+ async def _handle_get_beacon_blocks (self , peer : BCCPeer , msg : GetBeaconBlocksMessage ) -> None :
65
66
if not peer .is_operational :
66
67
return
67
68
68
- max_blocks = cast ( int , msg ["max_blocks" ])
69
+ max_blocks = msg ["max_blocks" ]
69
70
block_slot_or_hash = msg ["block_slot_or_hash" ]
70
71
71
72
try :
0 commit comments