Skip to content

Commit c8a946d

Browse files
committed
Rename _requested_nodes to _active_requests
1 parent f181f8e commit c8a946d

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

p2p/state.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(self,
7373
self.root_hash = root_hash
7474
self.scheduler = StateSync(root_hash, account_db)
7575
self._handler = PeerRequestHandler(self.chaindb, self.logger, self.cancel_token)
76-
self._requested_nodes: Dict[ETHPeer, Tuple[float, List[Hash32]]] = {}
76+
self._active_requests: Dict[ETHPeer, Tuple[float, List[Hash32]]] = {}
7777
self._peer_missing_nodes: Dict[ETHPeer, List[Hash32]] = collections.defaultdict(list)
7878
self._executor = get_asyncio_executor()
7979

@@ -94,7 +94,7 @@ async def get_peer_for_request(self, node_keys: Set[Hash32]) -> ETHPeer:
9494
"""Return an idle peer that may have any of the trie nodes in node_keys."""
9595
async for peer in self.peer_pool:
9696
peer = cast(ETHPeer, peer)
97-
if peer in self._requested_nodes:
97+
if peer in self._active_requests:
9898
self.logger.trace("%s is not idle, skipping it", peer)
9999
continue
100100
if node_keys.difference(self._peer_missing_nodes[peer]):
@@ -141,7 +141,7 @@ async def _handle_msg(
141141
pass
142142
elif isinstance(cmd, eth.NodeData):
143143
msg = cast(List[bytes], msg)
144-
if peer not in self._requested_nodes:
144+
if peer not in self._active_requests:
145145
# This is probably a batch that we retried after a timeout and ended up receiving
146146
# more than once, so ignore but log as an INFO just in case.
147147
self.logger.info(
@@ -150,7 +150,7 @@ async def _handle_msg(
150150
return
151151

152152
self.logger.debug("Got %d NodeData entries from %s", len(msg), peer)
153-
_, requested_node_keys = self._requested_nodes.pop(peer)
153+
_, requested_node_keys = self._active_requests.pop(peer)
154154

155155
loop = asyncio.get_event_loop()
156156
node_keys = await loop.run_in_executor(self._executor, list, map(keccak, msg))
@@ -208,7 +208,7 @@ async def request_nodes(self, node_keys: Iterable[Hash32]) -> None:
208208
candidates = list(not_yet_requested.difference(self._peer_missing_nodes[peer]))
209209
batch = candidates[:eth.MAX_STATE_FETCH]
210210
not_yet_requested = not_yet_requested.difference(batch)
211-
self._requested_nodes[peer] = (time.time(), batch)
211+
self._active_requests[peer] = (time.time(), batch)
212212
self.logger.debug("Requesting %d trie nodes to %s", len(batch), peer)
213213
peer.sub_proto.send_get_node_data(batch)
214214

@@ -218,12 +218,12 @@ async def _periodically_retry_timedout(self) -> None:
218218
oldest_request_time = now
219219
timed_out = []
220220
# Iterate over a copy of our dict's items as we're going to mutate it.
221-
for peer, (req_time, node_keys) in list(self._requested_nodes.items()):
221+
for peer, (req_time, node_keys) in list(self._active_requests.items()):
222222
if now - req_time > self._reply_timeout:
223223
self.logger.debug(
224224
"Timed out waiting for %d nodes from %s", len(node_keys), peer)
225225
timed_out.extend(node_keys)
226-
self._requested_nodes.pop(peer)
226+
self._active_requests.pop(peer)
227227
elif req_time < oldest_request_time:
228228
oldest_request_time = req_time
229229
if timed_out:
@@ -276,7 +276,7 @@ async def _run(self) -> None:
276276
async def _periodically_report_progress(self) -> None:
277277
while self.is_running:
278278
requested_nodes = sum(
279-
len(node_keys) for _, node_keys in self._requested_nodes.values())
279+
len(node_keys) for _, node_keys in self._active_requests.values())
280280
self.logger.info("====== State sync progress ========")
281281
self.logger.info("Nodes processed: %d", self._total_processed_nodes)
282282
self.logger.info("Nodes processed per second (average): %d",

0 commit comments

Comments
 (0)