Skip to content

fix: prevent cross-network disk cache contamination#3

Open
lindsey-comet wants to merge 1 commit intounconst:mainfrom
lindsey-comet:fix/network-scoped-disk-cache
Open

fix: prevent cross-network disk cache contamination#3
lindsey-comet wants to merge 1 commit intounconst:mainfrom
lindsey-comet:fix/network-scoped-disk-cache

Conversation

@lindsey-comet
Copy link

Problem

The disk cache uses hardcoded keys like all_subnets and all_dynamic_info without any network scoping. This causes cache contamination when users switch between networks (e.g., finney ↔ testnet), where cached data from one network could be incorrectly used for another.

Solution

Add network scoping to disk cache keys:

  1. QueryCache now has an optional network_id field
  2. New QueryCache::with_network() constructor that accepts an endpoint URL
  3. scoped_disk_key() method generates namespaced keys like wss___entrypoint_finney_all_subnets
  4. Updated all disk cache operations to use scoped keys
  5. Updated Client::connect_once() and Client::reconnect() to use network-scoped cache

Changes

  • src/queries/query_cache.rs: Added network_id field, with_network() constructor, scoped_disk_key() method
  • src/chain/mod.rs: Updated connect_once() and reconnect() to use QueryCache::with_network()

Testing

  • ✅ All 136 existing tests pass
  • cargo check clean
  • ✅ Backward compatible — passes tests without network scoping (uses original keys)

Fixes

Fixes #2


🤖 Generated via Arbos | Gittensor contributor

Add network scoping to disk cache keys to prevent wrong-chain data
when switching networks (e.g., finney ↔ testnet).

Changes:
- QueryCache: add network_id field and with_network() constructor
- Add scoped_disk_key() method to namespace disk keys by endpoint
- Update disk cache operations to use scoped keys
- Update Client::connect_once() and Client::reconnect() to use network-scoped cache

The URL is sanitized to remove special characters for safe filesystem key usage.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross-network disk cache contamination can return wrong-chain data

1 participant