Skip to content

fix(cli): honor configured wallet/hotkey for vote/admin/harvest signing#1425

Open
statxc wants to merge 1 commit into
entrius:testfrom
statxc:fix/cli-wallet-config-priority
Open

fix(cli): honor configured wallet/hotkey for vote/admin/harvest signing#1425
statxc wants to merge 1 commit into
entrius:testfrom
statxc:fix/cli-wallet-config-priority

Conversation

@statxc
Copy link
Copy Markdown
Contributor

@statxc statxc commented Jun 1, 2026

Summary

gitt config set wallet/hotkey writes canonical keys to ~/.gittensor/config.json,
and gitt issues register already honors them when wallet flags are omitted. The
other signed issue-contract write commands did not — gitt vote *, gitt admin *,
and gitt harvest passed their raw Click defaults straight into bt.Wallet(...), so
a user with a configured wallet/hotkey could silently sign with the wrong key (or fail
because the command's fallback wallet doesn't exist) for irreversible on-chain actions.

This is the wallet/hotkey member of the CLI config-priority family already fixed for
adjacent keys in #1035, #1200, and #1364.

Closes #1424

Affected commands

Shared _make_contract_client(...) path: gitt vote solution, gitt vote cancel,
gitt admin cancel-issue, gitt admin payout-issue, gitt admin set-owner,
gitt admin set-treasury, gitt admin add-vali, gitt admin remove-vali.

Inline wallet construction: gitt harvest.

Fix

Adds a shared resolve_wallet_config(...) helper applying the documented priority:

  1. Explicit --wallet-name / --wallet-hotkey CLI flags win.
  2. ~/.gittensor/config.json wallet / hotkey when the flag is omitted.
  3. The command's own Click default otherwise.

Whether a flag was supplied is detected via Click's ParameterSource, not a
!= "default" comparison. This matters because gitt harvest carries a non-"default"
fallback (validator), so a value comparison would mistake that fallback for an explicit
value and never consult config — and only a parameter-source check lets an explicit
--wallet default win over config. A no-Click-context fallback (value comparison) keeps
the helper usable in direct unit calls.

Wired into:

  • _make_contract_client(...) — the shared vote/admin path (default/default fallback).
  • gitt harvest — inline construction (validator/default fallback); the displayed
    Wallet: line now reflects the resolved key.

gitt issues register is intentionally left unchanged — it already honors config and has
special //Alice local-dev handling.

Tests

New TestWalletConfigResolution covering every scenario:

  • vote/admin without flags use configured wallet / hotkey
  • vote/admin explicit flags win
  • explicit --wallet default --hotkey default still beats config
  • vote/admin without config preserve default/default
  • harvest without flags uses configured wallet / hotkey
  • harvest without config preserves validator/default
  • harvest explicit flags win
  • direct (no-Click-context) fallback path

Verification

  • uv run pytest tests/918 passed (+8 new)
  • ruff lint + format, pyright (0 errors), vulture: all clean
  • Verified end-to-end against a real config.json file-read path

@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label Jun 1, 2026
Copy link
Copy Markdown
Collaborator

@anderdc anderdc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the tests, it's a simple fix

Vote, admin, and harvest commands constructed bt.Wallet(...) from raw Click
defaults, so a user with a configured wallet/hotkey in ~/.gittensor/config.json
could silently sign with the wrong key (vote/admin: default/default; harvest:
validator/default) — only `issues register` honored config.

Add a shared resolve_wallet_config() helper that applies the same priority
order used for other config keys (entrius#1035, entrius#1200, entrius#1364): explicit CLI flags win,
then config, then the command's own default. Explicit vs omitted is detected via
Click's ParameterSource rather than comparing against "default", so harvest's
non-"default" fallback (validator) is distinguishable from an explicit value and
`--wallet default` still beats config.

Wire it into the shared _make_contract_client() path (vote/admin) and harvest's
inline wallet construction; harvest's displayed wallet now reflects the resolved
key. `issues register` is left unchanged (already honors config).
@statxc statxc force-pushed the fix/cli-wallet-config-priority branch from b85abe1 to 4ec6c8d Compare June 1, 2026 17:56
@statxc
Copy link
Copy Markdown
Contributor Author

statxc commented Jun 1, 2026

Hi @anderdc how are you? I've removed all test. Thanks for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Issue-contract write commands ignore configured wallet/hotkey outside issues register

2 participants