Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry for deploy_compiled_contract #12

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(w3: web3.Web3, signed_txn_hash: HexStr) -> TxReceipt:
for _ in range(1, 100):
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(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"]


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(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"]
Loading