From 0cd0f085862b543b86d01d1e57fe17d6e687221e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=BA=C3=B1ez?= Date: Thu, 4 Jun 2020 16:21:42 +0200 Subject: [PATCH] Introduce a cooling time when trying to get confirmations --- nucypher/blockchain/eth/clients.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nucypher/blockchain/eth/clients.py b/nucypher/blockchain/eth/clients.py index 868e1995f..fa2be6599 100644 --- a/nucypher/blockchain/eth/clients.py +++ b/nucypher/blockchain/eth/clients.py @@ -111,7 +111,8 @@ class EthereumClient: SYNC_TIMEOUT_DURATION = 60 # seconds to wait for various blockchain syncing endeavors SYNC_SLEEP_DURATION = 5 # seconds BLOCK_CONFIRMATIONS_POLLING_TIME = 3 # seconds - TRANSACTION_POLLING_TIME = 0.5 # seconds # TODO: Override this in InfuraClient + TRANSACTION_POLLING_TIME = 0.5 # seconds + COOLING_TIME = 5 # seconds class ConnectionNotEstablished(RuntimeError): pass @@ -287,6 +288,10 @@ class EthereumClient: confirmations: int = 0) -> TxReceipt: receipt = None if confirmations: + # If we're waiting for confirmations, we may as well let pass some time initially to make everything easier + time.sleep(self.COOLING_TIME) + + # We'll keep trying to get receipts until there are enough confirmations or the timeout happens with Timeout(seconds=timeout, exception=self.TransactionTimeout) as timeout_context: while not receipt: try: @@ -511,6 +516,7 @@ class GanacheClient(EthereumClient): class InfuraClient(EthereumClient): is_local = False + TRANSACTION_POLLING_TIME = 2 # seconds def unlock_account(self, *args, **kwargs) -> bool: return True