Skip to content

Conversation

mvds00
Copy link

@mvds00 mvds00 commented Sep 7, 2025

Description of the Change

This PR implements a new, simple way of interacting with bittensor runtime data. It was pushed 8 months ago but got some renewed attention recently and is now discussed in CoR channel btcli-btsdk. An async version was added.

The core ideas are that:

  • you should need only one line to get a particular value from the runtime
  • you only need the name of the storage item
  • ideally, accessing data from the runtime looks like accessing a local object property
  • you should be able to specify the block number in that one line
  • the code should rely on on-chain metadata so that it is always up to date and backward compatible
  • error messages should be self explanatory and use metadata to give useful hints
  • __repr__() should be helpful as well
  • we should be welcoming new developers, and make life easy for them; more sophisticated/reliable/faster/better methods of accessing the same data may exist, but there should be a straightforward way that requires no explanation

The PR contains ample examples, but here are a few that highlight how the points above are met, in a python -i instance:

>>> import bittensor
>>> ck = bittensor.runtime.SubtensorModule.SubnetOwner[29]
>>> ck
'5HHHHHzgLnYRvnKkHd45cRUDMHXTSwx7MjUzxBrKbY4JfZWn'
>>> bittensor.runtime.System.Account[ck]['data']['free']
205451
>>> bittensor.runtime.SubtensorModule.TotalHotkeyAlpha(ck,29)
2235109938216
>>> bittensor.runtime.SubtensorModule.TotalHotkeyAlpha(ck,29,block=6000000)
1336928150710

Alternate Designs

No alternate designs were considered, as it can't get any simpler than this.

Possible Drawbacks

More code to maintain. The magic code mapping the metadata to magical objects isn't easy to digest.

Verification Process

N/A, this is just a first request for feedback.

Release Notes

Improved interface to allow python access to subtensor runtime variables.

Branch Acknowledgement

[ ] I am acknowledging that I am opening this branch against staging Branch is built on top of branch SDKv10

Roman and others added 30 commits August 19, 2025 17:17
…elockedWeightCommits-instead-of-CRV3WeightCommitsV2

Use `TimelockedWeightCommits` instead of `CRV3WeightCommitsV2`
…t-types-for-get_delegated

fix: reflect correct return types for get_delegated
…y-behavior-for-test-safe-staking-scenario

Fix `flaky` e2e test (tests.e2e_tests.test_staking.test_safe_staking_scenarios)
@basfroman basfroman force-pushed the SDKv10 branch 3 times, most recently from 610045f to 5f13fcd Compare October 2, 2025 19:53
@thewhaleking
Copy link
Contributor

thewhaleking commented Oct 6, 2025

I really like the way JS does it where they use api.at(blockNumber), as the pallets/calls/etc. are all going to change depending on the particular runtime at that block. May be worth considering adding these to the Runtime object in async-substrate-interface: https://github.com/opentensor/async-substrate-interface/blob/d731dd55435f7588fc677458e428b7170caf97dc/async_substrate_interface/types.py#L103

@basfroman
Copy link
Collaborator

Hey @mvds00 feels like it's time to update your PR. Pls locate your implementation in bittensor.extras directory. This directory is specifically designed to house all Bittensor logic extensions. I think your logic is perfectly suited for this.
Also, pls pay attention to Ben's comment.

@basfroman basfroman force-pushed the SDKv10 branch 4 times, most recently from 7528cbb to 2a4f978 Compare October 10, 2025 02:03
@mvds00
Copy link
Author

mvds00 commented Oct 10, 2025

I will look into it and update the PR. In the meantime the code evolved a bit further, as I have used it in various personal projects.

@basfroman
Copy link
Collaborator

I will look into it and update the PR. In the meantime the code evolved a bit further, as I have used it in various personal projects.

It's great that the code is already working. That means it's improved. You can close this PR and open a new one. Just please take into account all the comments above in this PR.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants