Skip to content

Commit

Permalink
Implement a delay to pause and retry in case of network errors (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
trizin authored Jan 10, 2024
1 parent 106c506 commit e93c4be
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pdr_backend/util/web3_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

from typing import Optional

from enforce_typing import enforce_types
Expand Down Expand Up @@ -44,5 +46,8 @@ def get_block(
print(f"An error occured while getting block, error: {e}")
if tries < WEB3_MAX_TRIES:
print("Trying again...")
# sleep times for the first 5 tries:
# 2.5, 10.0, 22.5, 40.0, 62.5
time.sleep(((tries + 1) / 2) ** (2) * 10)
return self.get_block(block, full_transactions, tries + 1)
raise Exception("Couldn't get block") from e

0 comments on commit e93c4be

Please sign in to comment.