Skip to content

Commit 4dcdb89

Browse files
committed
fix(testnet_cleanup): improve retry logic for fund return
Enhanced the retry mechanism in `return_funds_to_faucet` to handle `FeeTooSmallUTxO` errors by incrementally increasing witness count. Added multiple retry attempts with detailed logging for better debugging and error handling.
1 parent b96d25f commit 4dcdb89

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

cardano_node_tests/utils/testnet_cleanup.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -251,23 +251,34 @@ def return_funds_to_faucet(
251251
txins, skeys = flatten_tx_inputs(tx_inputs=batch)
252252
fund_tx_files = clusterlib.TxFiles(signing_key_files=skeys)
253253
batch_tx_name = f"{tx_name}_batch{batch_num}"
254-
witness_count_add = max(2, len(skeys) // 10)
255-
256-
# Try to return funds; don't mind if there's not enough funds for fees etc.
257-
try:
258-
cluster_obj.g_transaction.send_tx(
259-
src_address=txins[0].address,
260-
tx_name=batch_tx_name,
261-
txins=txins,
262-
txouts=fund_dst,
263-
tx_files=fund_tx_files,
264-
witness_count_add=witness_count_add,
265-
verify_tx=False,
266-
)
267-
except clusterlib.CLIError:
268-
LOGGER.exception(f"Failed to return funds from addresses for '{batch_tx_name}'")
254+
witness_count_add = max(2, len(skeys) // 20)
255+
256+
# Try to return funds
257+
last_excp = None
258+
for attempt in range(1, 4):
259+
try:
260+
cluster_obj.g_transaction.send_tx(
261+
src_address=txins[0].address,
262+
tx_name=f"{batch_tx_name}_try{attempt}",
263+
txins=txins,
264+
txouts=fund_dst,
265+
tx_files=fund_tx_files,
266+
witness_count_add=witness_count_add,
267+
verify_tx=False,
268+
)
269+
except clusterlib.CLIError as excp:
270+
last_excp = excp
271+
if "FeeTooSmallUTxO" in str(excp):
272+
witness_count_add += 5
273+
continue
274+
LOGGER.exception(f"Failed to return funds from addresses for '{batch_tx_name}'")
275+
else:
276+
LOGGER.debug(f"Returned funds from addresses '{batch_tx_name}'")
277+
break
269278
else:
270-
LOGGER.debug(f"Returned funds from addresses '{batch_tx_name}'")
279+
LOGGER.error(
280+
f"Failed to return funds from addresses for '{batch_tx_name}'", exc_info=last_excp
281+
)
271282
batch_num += 1
272283

273284
cluster_obj.wait_for_new_block(new_blocks=3)

0 commit comments

Comments
 (0)