Fixed a bug in the get_subnets function
Bug
The get_subnets function was truncating to max. 100 results due to list comprehensions handling of iterators. The bug has been described in https://github.com/opentensor/bittensor/issues/2208.
Description of the Change
Replaced list comprehension with a manual iteration to ensure all subnet UIDs are retrieved, addressing the issue of truncated results.
Alternate Designs
Considered increasing fetch limits but chose manual iteration for more reliable results.
Possible Drawbacks
No significant drawbacks, just a minor increase in code complexity.
Verification Process
Added a test to check the length of the result list, ensuring all records are processed correctly. Ran all existing tests to confirm no regressions.
Release Notes
Fixed an issue in get_subnets where the result list was being truncated, ensuring complete retrieval of subnets.
Thanks for the contribution! How was this fix tested? The issue can be reproduced on the testnet and I don't believe this fixes it.
See example:
import bittensor
subtensor = bittensor.subtensor(network="wss://test.chain.opentensor.ai:443")
s = subtensor.get_subnets()
len(s)
# 100; Expected > 100
I would consider using the paging functionality of pysub-interface
Thanks for the contribution! How was this fix tested?
I initially tested the fix using your snippet from the bug report issue. However, during the cleanup process, I introduced an issue that wasn't caught even with 500 networks. I've now pushed a working version and thoroughly tested it with the snippet, though the solution is a bit more barebones.
I would consider using the paging functionality of pysub-interface.
I can certainly rewrite the function to use pysub-interface. However, this would also require modifying the query_map_subtensor function and incorporating a start_key. This way, we can leverage the substrate to retrieve results page by page as QueryMapResults. If this approach is preferred, let me know and I will implement it.
Hi. Taking a look at this today.
implemented in SDK