Skip to content

perf(cli): reuse subtensor connection in issues pending-harvest#1391

Open
plind-junior wants to merge 1 commit into
entrius:testfrom
plind-junior:perf/cli-pending-harvest-reuse-connection
Open

perf(cli): reuse subtensor connection in issues pending-harvest#1391
plind-junior wants to merge 1 commit into
entrius:testfrom
plind-junior:perf/cli-pending-harvest-reuse-connection

Conversation

@plind-junior
Copy link
Copy Markdown
Contributor

Why this is necessary: gitt issues pending-harvest opens two WebSocket
connections to the same node for a single command — a bt.Subtensor (used for the
treasury-stake read via the contract client) and then a separate
SubstrateInterface(url=ws_endpoint) for the issue read:

subtensor = bt.Subtensor(network=ws_endpoint)
...
treasury_stake = client.get_treasury_stake()

substrate = SubstrateInterface(url=ws_endpoint)   # second connection to the same node
issues = _read_issues_from_child_storage(substrate, contract_addr, verbose)

The bittensor Subtensor already wraps a SubstrateInterface at
subtensor.substrate, exposing the exact rpc_request / query API the issue
read uses (the contract client reads through subtensor.substrate already). So
the second connection is pure redundancy — extra socket setup/teardown against
the same endpoint for one command.

The fix: read issues through subtensor.substrate and drop the second
SubstrateInterface plus its now-unused import. One command, one connection.
Behavior is unchanged — same data, same code path, just one fewer socket.

Related Issues

N/A

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Documentation
  • Other (performance)

Testing

  • New tests/cli/test_pending_harvest_single_connection.py: asserts
    pending-harvest --json succeeds, opens no second SubstrateInterface,
    and the issue read reuses subtensor.substrate.
  • Existing --json exception-path regression (pending-harvest) still passes.
  • uv run pytest — 882 passed.
  • uv run pyright / ruff check / vulture on changed files — clean.

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Changes are documented (if applicable)

pending-harvest opened a bt.Subtensor and then a second SubstrateInterface to the same node. Reuse subtensor.substrate for the issue read so the command holds one WebSocket connection instead of two.
@xiao-xiao-mao xiao-xiao-mao Bot added the enhancement New feature or request label May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant