From be377ae0f7ded05e5e840d2abe7a654c713cd8d6 Mon Sep 17 00:00:00 2001 From: jeffrey701 Date: Fri, 12 Jun 2026 11:51:25 -0400 Subject: [PATCH] fix(cli): recognize an initiated swap in post-tx instead of reporting expiry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After a swap initiates, vote_initiate clears the reservation row, so get_miner_reserved_until returns 0 and the `reserved_until <= current_block` guard in `alw swap post-tx` reads it as an expired reservation — it deletes pending_swap.json and tells the user to start a new swap, severing the link to the now-live swap. Before assuming expiry, look up the miner's active swap via resolve_recent_swap_id. If one exists, point the user at it (swap id + `alw view swap --watch`), matching the post-confirm success path, rather than reporting expiry. Genuine expiry (no swap) is unchanged. Closes #473 --- allways/cli/swap_commands/post_tx.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/allways/cli/swap_commands/post_tx.py b/allways/cli/swap_commands/post_tx.py index 2429b739..4614c6ed 100644 --- a/allways/cli/swap_commands/post_tx.py +++ b/allways/cli/swap_commands/post_tx.py @@ -17,7 +17,12 @@ print_contract_error, resolve_source_tx_block, ) -from allways.cli.swap_commands.swap import from_smallest_unit, poll_for_swap_creation, sign_and_broadcast_confirm +from allways.cli.swap_commands.swap import ( + from_smallest_unit, + poll_for_swap_creation, + resolve_recent_swap_id, + sign_and_broadcast_confirm, +) from allways.constants import NETUID_FINNEY from allways.contract_client import ContractError @@ -70,6 +75,20 @@ def post_tx_command(tx_hash: str, tx_block: int): return if reserved_until <= current_block: + # reserved_until drops to 0 the moment the swap initiates (the contract clears + # the reservation row in vote_initiate), which by block number alone is + # indistinguishable from a genuine expiry. Check for a live swap first so we + # don't tell the user their reservation expired — and delete the pending + # record — when it actually advanced into a swap. + try: + swap_id = resolve_recent_swap_id(client, state.miner_hotkey) + except ContractError: + swap_id = None + if swap_id is not None: + clear_pending_swap() + console.print(f'\n[green]Your reservation has advanced into a swap. ID: {swap_id}[/green]') + console.print(f'[dim]Watch with: alw view swap {swap_id} --watch[/dim]\n') + return clear_pending_swap() console.print('[red]Reservation has expired.[/red]') console.print('[dim]Run `alw swap now` to start a new swap.[/dim]')