Skip to content
This repository was archived by the owner on Jul 10, 2026. It is now read-only.

Cache inflight current chain-head requests#357

Merged
thewhaleking merged 9 commits into
stagingfrom
feat/thewhaleking/cache-inflight-hashes
Jun 1, 2026
Merged

Cache inflight current chain-head requests#357
thewhaleking merged 9 commits into
stagingfrom
feat/thewhaleking/cache-inflight-hashes

Conversation

@thewhaleking

Copy link
Copy Markdown
Contributor

Adds new functionality to CachedFetcher that will not cache the results of a request if specified cache_results=False.

This may seem to defeat the point, but in fact it does not. This allows using the current request caching, without needing to cache the result.

For example, we wouldn't want to cache get_block_hash(None) because the block hash changes often. But if we can utilise the same inflight request for two concurrent requests, we can stop writing:

block_hash = await substrate.get_chain_head()
q1, q2 = await asyncio.gather(
    substrate.query(bar, foo, block_hash=block_hash),
    substrate.query(bat, baz, block_hash=block_hash)
)

and instead write the much simpler:

q1, q2 = await asyncio.gather(
    substrate.query(bar, foo),
    substrate.query(bat, baz)
)

as both requests internally fetch the chain head, and will utilise the same head fetch request with this new functionality. (See tests/unit_tests/asyncio_/test_substrate_interface_async_unit.py:test_concurrent_block_hash_none_dedups_chain_head_request)

@github-actions github-actions Bot added run-bittensor-cli-tests Runs BTCLI tests. run-bittensor-sdk-tests Runs Bittensor SDK tests. labels Jun 1, 2026
@thewhaleking

Copy link
Copy Markdown
Contributor Author

Fix for flaky bittensor e2e tests:
RaoFoundation/bittensor#3366
RaoFoundation/bittensor#3367

@basfroman basfroman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, you might not have given it much thought, but this fixes the issue where a result of 0 was previously not cached. Now, it is.
Great!

@thewhaleking

Copy link
Copy Markdown
Contributor Author

btw, you might not have given it much thought, but this fixes the issue where a result of 0 was previously not cached. Now, it is. Great!

Ha. I totally didn't even realise that.

@thewhaleking thewhaleking merged commit 610d2a1 into staging Jun 1, 2026
182 of 185 checks passed
@thewhaleking thewhaleking deleted the feat/thewhaleking/cache-inflight-hashes branch June 1, 2026 17:14
@thewhaleking thewhaleking linked an issue Jun 1, 2026 that may be closed by this pull request
This was referenced Jun 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

CachedFetcher never caches falsy values — re-fetches forever

2 participants