Fix UnboundLocalError when --all is combined with --include-hotkeys (#1021)#1025
Open
beyond-finance-agent wants to merge 1 commit into
Open
Conversation
In the stake_remove handler's unstake_all branch, the include_hotkeys sub-branch resolved hotkey_ss58_address but never called self.wallet_ask(...) to bind 'wallet'. The sibling branches (all_hotkeys, the bare-hotkey fallback, the 'all' alias) all do. When the call site at line ~5729 then tried to use 'wallet=wallet' inside remove_stake.unstake_all(...), Python raised UnboundLocalError: cannot access local variable 'wallet'. Adds the same wallet_ask call already used by the adjacent all_hotkeys branch, with ask_for=[WO.NAME, WO.PATH] since the hotkey is supplied via --include-hotkeys. Fixes RaoFoundation#1021 Repro before fix: btcli stake remove --wallet.name <w> --netuid 1 --safe \\ --tolerance 0.05 --no-partial --include-hotkeys <ss58> \\ --subtensor.network finney --no-prompt --all -> UnboundLocalError on cli.py line ~5730 Verified after fix on mainnet (finney): extrinsic 8487314-15, SN4 fully unstaked from delegate hotkey, +0.244 TAO recovered.
|
PRs must use signed commits. Unsigned commits:
|
|
PRs need to be open against staging. |
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
Fixes #1021 —
btcli stake remove --all --include-hotkeys <ss58>crashes withUnboundLocalError: cannot access local variable 'wallet'.Root cause
In
cli.pyaround line 5658, thestake_removehandler'sunstake_allbranch routes by hotkey-resolution mode. Three of the four sub-branches callself.wallet_ask(...)to bindwallet:wallet_askcalled?include_hotkeysall_hotkeyshotkey_or_ss58is valid ss58hotkey_or_ss58 == "all"hotkey_or_ss58is a hotkey nameWhen
--include-hotkeys <ss58>is used,hotkey_ss58_addressgets set butwalletis never bound. The subsequent call at L5729 (remove_stake.unstake_all(wallet=wallet, ...)) then raisesUnboundLocalError.Fix
Add the same
wallet_ask(ask_for=[WO.NAME, WO.PATH])call already used by the adjacentall_hotkeysbranch, since the hotkey is supplied via the--include-hotkeysss58 (we don't need to ask for it).Verification
Before:
UnboundLocalErrortraceback, no extrinsic submitted. Reproduced on9.22.3and9.23.0from PyPI, and confirmed still present onmainHEAD (350015a, v9.23.1).After (this PR): Tested live on mainnet (finney) by patching the fix into my local install and running:
Result: extrinsic
8487314-15finalized — SN4 fully unstaked from the delegate hotkey, +0.244 τ recovered. https://tao.app/extrinsic/8487314-15Notes
include_hotkeyspath.stake_removeflow has no test coverage I could extend cleanly — happy to add one in a follow-up if the maintainers point me at the right harness.