Skip to content
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

Routing table #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Routing table #13

wants to merge 1 commit into from

Conversation

hide-on-bush-x
Copy link
Collaborator

@hide-on-bush-x hide-on-bush-x commented Jan 29, 2025

Summary

This pull request introduces significant improvements to the routing table and node management functionalities within the validator. The changes include the implementation of a new RoutingTable class, updates to the NodeManager for better handling of TEE addresses, and comprehensive test coverage for the new features.

Key Changes

  1. RoutingTable Class:

    • Implemented a new RoutingTable class to manage miner addresses.
    • Added methods to add, remove, and clear miner addresses.
    • Implemented methods to retrieve all addresses or addresses associated with a specific miner hotkey.
  2. NodeManager Updates:

    • Updated the NodeManager to use the RoutingTable for managing TEE addresses.
    • Added logic to clear existing addresses for a hotkey before adding new ones.
    • Improved logging for better traceability of address management.
  3. Database Schema:

    • Updated the RoutingTableDatabase schema to enforce a unique constraint on the address column.
    • Allowed multiple records with the same uid and hotkey.
  4. Test Coverage:

    • Added comprehensive tests for the RoutingTable and RoutingTableDatabase classes.
    • Ensured tests cover adding, updating, deleting, and retrieving addresses.
    • Verified unique constraint enforcement through test cases.

Testing

  • All new features are covered by unit tests.
  • Tests are run using an in-memory SQLite database to ensure isolation and repeatability.
  • The test suite can be executed using the command: python -m unittest discover tests.

Additional Notes

  • The .gitignore file has been updated to exclude database files generated during testing.
  • The Validator class now initializes a RoutingTable instance for managing TEE addresses.

closes #7

@hide-on-bush-x hide-on-bush-x changed the title feat: #7 adding routing table Routing table Jan 29, 2025
@hide-on-bush-x
Copy link
Collaborator Author

Edge case found:
When a hotkey get deregistered, their addresses are not being cleaned

for hotkey, _ in self.connected_nodes.items():
if hotkey in self.validator.metagraph.nodes:
node = self.validator.metagraph.nodes[hotkey]
tee_address = await self.get_tee_address(node)
tee_addresses = await self.get_tee_address(node)

Choose a reason for hiding this comment

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

should be self.get_tee_addresses(node) for clarity

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch

logger.info(
f"Hotkey: {hotkey} stored address {tee_address} into DB successfuly."
)
except sqlite3.IntegrityError:

Choose a reason for hiding this comment

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

not familiar w/ sqlite - are there other potential errors that could happen here? And, if so, do we want some retry logic?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there must be some other errors to catch, will take a look

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.

feat(routing table): Store miners tee address in a SQLite and keep it in sync with the Metagraph
2 participants