@@ -69,36 +69,33 @@ async def _handle_get_beacon_blocks(self, peer: BCCPeer, msg: Dict[str, Any]) ->
69
69
max_blocks = cast (int , msg ["max_blocks" ])
70
70
block_slot_or_hash = msg ["block_slot_or_hash" ]
71
71
72
- if isinstance (block_slot_or_hash , int ):
73
- get_start_block = functools .partial (
74
- self .db .get_canonical_block_by_slot ,
75
- cast (int , block_slot_or_hash ),
76
- )
77
- elif isinstance (block_slot_or_hash , bytes ):
78
- get_start_block = functools .partial (
79
- self .db .get_block_by_hash ,
80
- cast (Hash32 , block_slot_or_hash ),
81
- )
82
- else :
83
- actual_type = type (block_slot_or_hash )
84
- raise TypeError (f"Invariant: unexpected type for 'block_slot_or_hash': { actual_type } " )
85
-
86
72
try :
87
- start_block = get_start_block ()
73
+ if isinstance (block_slot_or_hash , int ):
74
+ start_block = self .db .get_canonical_block_by_slot (block_slot_or_hash )
75
+ elif isinstance (block_slot_or_hash , bytes ):
76
+ start_block = self .db .get_block_by_hash (Hash32 (block_slot_or_hash ))
77
+ else :
78
+ raise TypeError (
79
+ f"Invariant: unexpected type for 'block_slot_or_hash': "
80
+ f"{ type (block_slot_or_hash )} "
81
+ )
88
82
except BlockNotFound :
89
- self . logger . debug2 ( "%s requested unknown block %s" , block_slot_or_hash )
90
- blocks = ()
91
- else :
83
+ start_block = None
84
+
85
+ if start_block is not None :
92
86
self .logger .debug2 (
93
87
"%s requested %d blocks starting with %s" ,
94
88
peer ,
95
89
max_blocks ,
96
90
start_block ,
97
91
)
98
92
blocks = self ._get_blocks (start_block , max_blocks )
99
- finally :
100
- self .logger .debug2 ("Replying to %s with %d blocks" , peer , len (blocks ))
101
- peer .sub_proto .send_blocks (blocks )
93
+ else :
94
+ self .logger .debug2 ("%s requested unknown block %s" , block_slot_or_hash )
95
+ blocks = ()
96
+
97
+ self .logger .debug2 ("Replying to %s with %d blocks" , peer , len (blocks ))
98
+ peer .sub_proto .send_blocks (blocks )
102
99
103
100
@to_tuple
104
101
def _get_blocks (self ,
0 commit comments