From e93c4becafcf1bf3f81e8f7e4689754c9231ae85 Mon Sep 17 00:00:00 2001 From: trizin <25263018+trizin@users.noreply.github.com> Date: Wed, 10 Jan 2024 14:42:35 +0300 Subject: [PATCH] Implement a delay to pause and retry in case of network errors (#491) --- pdr_backend/util/web3_config.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pdr_backend/util/web3_config.py b/pdr_backend/util/web3_config.py index 33be53b32..c05e1cc03 100644 --- a/pdr_backend/util/web3_config.py +++ b/pdr_backend/util/web3_config.py @@ -1,3 +1,5 @@ +import time + from typing import Optional from enforce_typing import enforce_types @@ -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