Skip to content

Commit

Permalink
Even more tx broadcast debug (#173)
Browse files Browse the repository at this point in the history
- `wait_and_broadcast_multiple_nodes` will now raise the last exception if there is a failed transaction
  • Loading branch information
miohtama authored Oct 26, 2023
1 parent 088c4e6 commit a5547fd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.22.30

- API change: Handle `wait_and_broadcast_multiple_nodes()` so that it will attempt
to retry multiple providers multiple times before raising the last exception

# 0.22.29

- Add `launch_anvil(fork_block_number)` option to create mainnet works on a specific block number.
Expand Down
33 changes: 30 additions & 3 deletions eth_defi/confirmation.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,20 @@ def wait_and_broadcast_multiple_nodes(
Starting nonce does not match what we see on chain.
When ``check_nonce_validity`` is set.
:raise Exception:
If all nodes fail to broadcast the transaction, then raise an exception.
It's likely that there is a problem with a transaction.
The exception is raised after we try multiple nodes multiple times,
based on ``node_switch_timeout`` and other arguments.
A reverted transaction is not an exception, but will be returned
in the receipts.
In the case of multiple exceptions, the last one is raised.
The exception is whatever lower stack is giving us.
"""

assert isinstance(poll_delay, datetime.timedelta)
Expand All @@ -474,7 +488,7 @@ def wait_and_broadcast_multiple_nodes(
if check_nonce_validity:
check_nonce_mismatch(web3, txs)

provider = get_fallback_provider(web3)
provider = get_fallback_provider(web3) # Will raise if fallback provider is not configured
providers = provider.providers

logger.info(
Expand Down Expand Up @@ -505,9 +519,15 @@ def wait_and_broadcast_multiple_nodes(

next_node_switch = started_at + node_switch_timeout

last_exception: Exception | None = None

# Initial broadcast of txs
for tx in txs:
_broadcast_multiple_nodes(providers, tx)
try:
_broadcast_multiple_nodes(providers, tx)
last_exception = None
except Exception as e:
last_exception = e

while len(unconfirmed_txs) > 0:
# Transaction hashes that receive confirmation on this round
Expand Down Expand Up @@ -577,7 +597,14 @@ def wait_and_broadcast_multiple_nodes(

# Rebroadcast txs again if we suspect a broadcast failed
for tx in txs:
_broadcast_multiple_nodes(providers, tx)
try:
_broadcast_multiple_nodes(providers, tx)
last_exception = None
except Exception as e:
last_exception = e

if last_exception:
raise last_exception

return receipts_received

Expand Down

0 comments on commit a5547fd

Please sign in to comment.