perf(cli): reuse subtensor connection in issues pending-harvest#1391
Open
plind-junior wants to merge 1 commit into
Open
perf(cli): reuse subtensor connection in issues pending-harvest#1391plind-junior wants to merge 1 commit into
plind-junior wants to merge 1 commit into
Conversation
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.
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.
Why this is necessary:
gitt issues pending-harvestopens two WebSocketconnections to the same node for a single command — a
bt.Subtensor(used for thetreasury-stake read via the contract client) and then a separate
SubstrateInterface(url=ws_endpoint)for the issue read:The bittensor
Subtensoralready wraps aSubstrateInterfaceatsubtensor.substrate, exposing the exactrpc_request/queryAPI the issueread uses (the contract client reads through
subtensor.substratealready). Sothe second connection is pure redundancy — extra socket setup/teardown against
the same endpoint for one command.
The fix: read issues through
subtensor.substrateand drop the secondSubstrateInterfaceplus 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
Testing
tests/cli/test_pending_harvest_single_connection.py: assertspending-harvest --jsonsucceeds, opens no secondSubstrateInterface,and the issue read reuses
subtensor.substrate.--jsonexception-path regression (pending-harvest) still passes.uv run pytest— 882 passed.uv run pyright/ruff check/vultureon changed files — clean.Checklist