Skip to content

Commit

Permalink
Add retry for deploy_compiled_contract
Browse files Browse the repository at this point in the history
  • Loading branch information
enriquefynn committed Mar 7, 2024
1 parent fb232b0 commit 3f4b1fd
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions eth_possim/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(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,
Expand Down Expand Up @@ -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(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"]


Expand Down Expand Up @@ -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(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"]

0 comments on commit 3f4b1fd

Please sign in to comment.