Skip to content

Only use Runtime objects in AsyncSubstrateInterface #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: staging
Choose a base branch
from

Conversation

thewhaleking
Copy link
Collaborator

@thewhaleking thewhaleking commented Jun 24, 2025

AsyncSubstrateInterface has a problem. As it was ported from the synchronous version of SubstrateInterface, the self.runtime would always be valid in a synchronous context, but in an async context, where you may be concurrently querying multiple blocks with differing runtimes, there are potential issues. As the runtime version does not change often, this is unlikely to occur, but it certainly can, and when it does it's incredibly difficult to locate the source of the problems.

This PR addresses those issues by ensuring that we always create Runtime objects, and pass those around, rather than relying on the self.runtime to be correct at any given time.

The end-users will be completely unaffected negatively, as they do not need to specify Runtimes, but may see some speed improvements in various chained calls that call AsyncSubstrateInterface.init_runtime, in addition to better assurance of correctness.

The only issue I see may come from subscription handlers. Though I will investigate this further before finishing the PR and setting it R4R. Unaffected

Added benefit: this made it easy to add in legacy Metadata V14 support, which will resolve #112

@thewhaleking thewhaleking marked this pull request as ready for review June 25, 2025 20:49
@thewhaleking thewhaleking added run-bittensor-sdk-tests Runs Bittensor SDK tests. run-bittensor-cli-tests Runs BTCLI tests. labels Jun 25, 2025
@thewhaleking thewhaleking changed the title [WIP] Only use Runtime objects in AsyncSubstrateInterface Only use Runtime objects in AsyncSubstrateInterface Jun 25, 2025
@thewhaleking thewhaleking changed the title Only use Runtime objects in AsyncSubstrateInterface [WIP] Only use Runtime objects in AsyncSubstrateInterface Jun 25, 2025
@thewhaleking
Copy link
Collaborator Author

Still ironing out some issues. Don't review yet. Need it in "ready for review" for tests though.

@thewhaleking thewhaleking changed the title [WIP] Only use Runtime objects in AsyncSubstrateInterface Only use Runtime objects in AsyncSubstrateInterface Jun 26, 2025
@thewhaleking thewhaleking linked an issue Jun 27, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-bittensor-cli-tests Runs BTCLI tests. run-bittensor-sdk-tests Runs Bittensor SDK tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't get timestamp for old blocks
2 participants