From a38ed25c7b3f4e4ba6e1bdf29780ae9a67a410a8 Mon Sep 17 00:00:00 2001 From: Fynn Date: Thu, 7 Mar 2024 16:15:31 +0000 Subject: [PATCH 1/2] Add retry for `deploy_compiled_contract` --- eth_possim/contracts.py | 43 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/eth_possim/contracts.py b/eth_possim/contracts.py index a3dcd2a..a6724a8 100644 --- a/eth_possim/contracts.py +++ b/eth_possim/contracts.py @@ -6,10 +6,25 @@ import re import time from typing import List, Tuple +from web3.types import TxReceipt, HexStr logger = logging.getLogger(__name__) +def wait_for_transaction_receipt(w3: web3.Web3, signed_txn_hash: HexStr) -> TxReceipt: + for _ in range(1, 10): + try: + tx_receipt = w3.eth.wait_for_transaction_receipt(signed_txn_hash) + return tx_receipt + except ValueError as exc: + if exc.args[0]["message"] == "transaction indexing is in progress": + logger.info( + "Failed to get transaction receipt due to indexing, will retry" + ) + time.sleep(5) + continue + else: + raise def deploy_compiled_contract( cfg: dict, @@ -54,12 +69,9 @@ def deploy_compiled_contract( private_key=cfg["el"]["funder"]["private_key"], ) w3.eth.send_raw_transaction(signed_txn.rawTransaction) - tx_receipt = w3.eth.wait_for_transaction_receipt(signed_txn.hash) - - logger.info( - f"Contract from '{foundry_json_path}' was published at address '{tx_receipt['contractAddress']}' [block: {tx_receipt['blockNumber']}]" - ) + tx_receipt = wait_for_transaction_receipt(w3, signed_txn.hash) + logger.info(f"Contract from '{foundry_json_path}' was published at address '{tx_receipt['contractAddress']}' [block: {tx_receipt['blockNumber']}]") return tx_receipt["contractAddress"] @@ -105,21 +117,10 @@ def deploy_contract_onchain( private_key=cfg["el"]["funder"]["private_key"], ) w3.eth.send_raw_transaction(signed_txn.rawTransaction) - for _ in range(1, 10): - try: - tx_receipt = w3.eth.wait_for_transaction_receipt(signed_txn.hash) - except ValueError as exc: - if exc.args[0]["message"] == "transaction indexing is in progress": - logger.info( - "Failed to get transaction receipt due to indexing, will retry" - ) - time.sleep(5) - continue - else: - raise + tx_receipt = wait_for_transaction_receipt(w3, signed_txn.hash) - logger.info( - f"Contract from '{path}' was published at address '{tx_receipt['contractAddress']}' [block: {tx_receipt['blockNumber']}]" - ) + logger.info( + f"Contract from '{path}' was published at address '{tx_receipt['contractAddress']}' [block: {tx_receipt['blockNumber']}]" + ) - return tx_receipt["contractAddress"] + return tx_receipt["contractAddress"] From 7a5e97f75c01fcbfb76f5d16b7e36e4583338113 Mon Sep 17 00:00:00 2001 From: Maksym Kulish Date: Thu, 7 Mar 2024 19:17:14 +0200 Subject: [PATCH 2/2] Bump number of retries when deploying contract --- eth_possim/contracts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth_possim/contracts.py b/eth_possim/contracts.py index a6724a8..7f295be 100644 --- a/eth_possim/contracts.py +++ b/eth_possim/contracts.py @@ -12,7 +12,7 @@ logger = logging.getLogger(__name__) def wait_for_transaction_receipt(w3: web3.Web3, signed_txn_hash: HexStr) -> TxReceipt: - for _ in range(1, 10): + for _ in range(1, 100): try: tx_receipt = w3.eth.wait_for_transaction_receipt(signed_txn_hash) return tx_receipt