fix(swap): abort TAO transfer when receipt parse fails (#297)#298
Open
RUNECTZ33 wants to merge 1 commit into
Open
fix(swap): abort TAO transfer when receipt parse fails (#297)#298RUNECTZ33 wants to merge 1 commit into
RUNECTZ33 wants to merge 1 commit into
Conversation
S0 funds-stranding bug: send_tao_transfer() and SubtensorProvider.send_tao
both fell back to the literal string 'tao_transfer' as the tx hash when
parsing receipt.extrinsic_hash threw or returned empty.
That literal then propagated through pending_swap.json,
SwapConfirmSynapse, and the proof_message ('allways-swap:tao_transfer').
Validators tried to look up a TAO tx with the hex-decoded version of that
literal, found nothing, and the user's funds stranded with no recovery
path.
Fix at both sites: surface the parse failure as a clean None return
(both functions already type as Optional[Tuple[str, int]] and the swap
flow caller already branches on `if send_result is not None`). Operators
get a clear log + recovery message and pending_swap.json never sees the
bogus hash.
Sites patched:
- allways/cli/swap_commands/swap.py:567-577 (send_tao_transfer)
Returns None instead of `('tao_transfer', 0)`. Also guards the
'parse succeeded but tx_hash is empty' edge case.
- allways/chain_providers/subtensor.py:324-333 (SubtensorProvider.send_tao)
Returns None instead of substituting fallback hash + current_block.
Also guards the empty-tx_hash edge.
Closes entrius#297
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #297. S0 funds-stranding bug.
send_tao_transfer()andSubtensorProvider.send_tao()both fell back to the literal string'tao_transfer'as the tx hash when parsingreceipt.extrinsic_hashthrew or returned empty:The literal then propagated through
pending_swap.json,SwapConfirmSynapse.from_tx_hash, and the proof_message'allways-swap:tao_transfer'. Validators looked up a TAO tx with the hex-decoded version of that literal, found nothing, and the user's funds stranded with no recovery path.Change
Surface the parse failure as a clean
Nonereturn at both sites. Both functions already type asOptional[Tuple[str, int]]and the swap flow caller atswap.py:1104-1106already branches onif send_result is not None, so this fits the existing contract.cli/swap_commands/swap.py:567-577tx_hash = '...' or 'tao_transfer'return Nonechain_providers/subtensor.py:324-333tx_hash = '...' or 'tao_transfer'bt.logging.error+return NoneBoth sites also guard the previously-unhandled "parse succeeded but
tx_hashis empty" edge — that path used to leak through to the success branch with an empty-string hash.Why
Noneand notraiseIssue suggested
raise RuntimeError(...). Verified at the call site (swap.py:1104):The retry-loop caller already understands
Noneas a clean failure and retries up to twice. Raising would crash the CLI and lose the retry semantics.Nonematches the function's existingOptional[...]signature and the existing failure path immediately above (if not response.success: return None).Scope
allways/cli/swap_commands/swap.py: +14 / -3allways/chain_providers/subtensor.py: +15 / -3Total: +29 / -6, two files. No new imports, no signature changes.
Test plan
python3 -c "import ast; ast.parse(...)")swap.py:1104confirmed to handleNone(retries up to twice, then exits gracefully)'tao_transfer'literal anywhere else in the repo (git grep "tao_transfer"only matches the function name and the test cassette filenames)(from_tx_hash, ...)and use the hash for chain lookups, so a missing tuple correctly skips that flow