Skip to content

Commit 4a99e72

Browse files
committed
Add service timeouts to all light peer requests
1 parent 8dadf4b commit 4a99e72

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

p2p/lightchain.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ def callback(r: protocol._DecodedMsgType) -> None:
116116
return cast(Dict[str, Any], reply)
117117

118118
@alru_cache(maxsize=1024, cache_exceptions=False)
119+
@service_timeout(COMPLETION_TIMEOUT)
119120
async def get_block_header_by_hash(self, block_hash: Hash32) -> BlockHeader:
120121
peer = cast(LESPeer, self.peer_pool.highest_td_peer)
121122
return await self._get_block_header_by_hash(peer, block_hash)
122123

123124
@alru_cache(maxsize=1024, cache_exceptions=False)
125+
@service_timeout(COMPLETION_TIMEOUT)
124126
async def get_block_body_by_hash(self, block_hash: Hash32) -> BlockBody:
125127
peer = cast(LESPeer, self.peer_pool.highest_td_peer)
126128
self.logger.debug("Fetching block %s from %s", encode_hex(block_hash), peer)
@@ -134,6 +136,7 @@ async def get_block_body_by_hash(self, block_hash: Hash32) -> BlockBody:
134136
# TODO add a get_receipts() method to BaseChain API, and dispatch to this, as needed
135137

136138
@alru_cache(maxsize=1024, cache_exceptions=False)
139+
@service_timeout(COMPLETION_TIMEOUT)
137140
async def get_receipts(self, block_hash: Hash32) -> List[Receipt]:
138141
peer = cast(LESPeer, self.peer_pool.highest_td_peer)
139142
self.logger.debug("Fetching %s receipts from %s", encode_hex(block_hash), peer)
@@ -148,6 +151,7 @@ async def get_receipts(self, block_hash: Hash32) -> List[Receipt]:
148151
# request accounts and code (and storage?)
149152

150153
@alru_cache(maxsize=1024, cache_exceptions=False)
154+
@service_timeout(COMPLETION_TIMEOUT)
151155
async def get_account(self, block_hash: Hash32, address: Address) -> Account:
152156
return await self._retry_on_bad_response(
153157
partial(self._get_account_from_peer, block_hash, address)

0 commit comments

Comments
 (0)