@@ -129,7 +129,7 @@ async def _process_nodes(self, nodes: Iterable[Tuple[Hash32, bytes]]) -> None:
129
129
# XXX: This is a quick workaround for
130
130
# https://github.com/ethereum/py-evm/issues/1074, which will be replaced soon
131
131
# with a proper fix.
132
- await self .wait ( asyncio . sleep (0 ) )
132
+ await self .sleep (0 )
133
133
134
134
async def _handle_msg (
135
135
self , peer : ETHPeer , cmd : protocol .Command , msg : protocol ._DecodedMsgType ) -> None :
@@ -192,6 +192,8 @@ async def _handle_get_block_headers(self, peer: ETHPeer, request: HeaderRequest)
192
192
async def _cleanup (self ) -> None :
193
193
# We don't need to cancel() anything, but we yield control just so that the coroutines we
194
194
# run in the background notice the cancel token has been triggered and return.
195
+ # Also, don't use self.sleep() here as the cancel token will be triggered and that will
196
+ # raise OperationCancelled.
195
197
await asyncio .sleep (0 )
196
198
197
199
async def request_nodes (self , node_keys : Iterable [Hash32 ]) -> None :
@@ -202,7 +204,7 @@ async def request_nodes(self, node_keys: Iterable[Hash32]) -> None:
202
204
except NoEligiblePeers :
203
205
self .logger .debug (
204
206
"No idle peers have any of the trie nodes we want, sleeping a bit" )
205
- await self .wait ( asyncio . sleep (0.2 ) )
207
+ await self .sleep (0.2 )
206
208
continue
207
209
208
210
candidates = list (not_yet_requested .difference (self ._peer_missing_nodes [peer ]))
@@ -238,7 +240,7 @@ async def _periodically_retry_timedout(self) -> None:
238
240
now = time .time ()
239
241
sleep_duration = (oldest_request_time + self ._reply_timeout ) - now
240
242
try :
241
- await self .wait ( asyncio . sleep (sleep_duration ) )
243
+ await self .sleep (sleep_duration )
242
244
except OperationCancelled :
243
245
break
244
246
@@ -257,7 +259,7 @@ async def _run(self) -> None:
257
259
# This ensures we yield control and give _handle_msg() a chance to process any nodes
258
260
# we may have received already, also ensuring we exit when our cancel token is
259
261
# triggered.
260
- await self .wait ( asyncio . sleep (0 ) )
262
+ await self .sleep (0 )
261
263
262
264
requests = self .scheduler .next_batch (eth .MAX_STATE_FETCH )
263
265
if not requests :
@@ -266,7 +268,7 @@ async def _run(self) -> None:
266
268
# pending nodes take a while to arrive thus causing the scheduler to run out
267
269
# of new requests for a while.
268
270
self .logger .debug ("Scheduler queue is empty, sleeping a bit" )
269
- await self .wait ( asyncio . sleep (0.5 ) )
271
+ await self .sleep (0.5 )
270
272
continue
271
273
272
274
await self .request_nodes ([request .node_key for request in requests ])
@@ -287,7 +289,7 @@ async def _periodically_report_progress(self) -> None:
287
289
"Nodes scheduled but not requested yet: %d" , len (self .scheduler .requests ))
288
290
self .logger .info ("Total nodes timed out: %d" , self ._total_timeouts )
289
291
try :
290
- await self .wait ( asyncio . sleep (self ._report_interval ) )
292
+ await self .sleep (self ._report_interval )
291
293
except OperationCancelled :
292
294
break
293
295
0 commit comments