forked from opentensor/bittensor
-
Notifications
You must be signed in to change notification settings - Fork 1
add neuron certificate discovery #2
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
andreea-popescu-reef
wants to merge
11
commits into
staging
Choose a base branch
from
encrypt
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
77753c1
remove duplicate types
andreea-popescu-reef dabd316
add neuron certificate discovery
andreea-popescu-reef ace187e
Update bittensor/core/chain_data/neuron_certificate.py
andreea-popescu-reef 90fc086
Update bittensor/core/chain_data/neuron_certificate.py
andreea-popescu-reef 1e57dc2
Update bittensor/core/subtensor.py
andreea-popescu-reef 1ba803f
Update tests/unit_tests/test_subtensor.py
andreea-popescu-reef ab54fdd
cleanup test
andreea-popescu-reef 9368030
add neuron certificate e2e test
andreea-popescu-reef 8840d3e
Merge branch 'staging' into encrypt
andreea-popescu-reef 9f92101
Merge branch 'staging' into encrypt
andreea-popescu-reef 4cbd0be
use burned_register
andreea-popescu-reef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| from dataclasses import dataclass | ||
| from typing import List | ||
|
|
||
| from bittensor.core.chain_data.utils import from_scale_encoding, ChainDataType | ||
| from bittensor.utils import Certificate | ||
|
|
||
|
|
||
| # Dataclasses for chain data. | ||
| @dataclass | ||
| class NeuronCertificate: | ||
| """ | ||
| Dataclass for neuron certificate. | ||
| """ | ||
|
|
||
| certificate: Certificate | ||
|
|
||
| @classmethod | ||
| def from_vec_u8(cls, vec_u8: List[int]) -> "NeuronCertificate": | ||
| """Returns a NeuronCertificate object from a ``vec_u8``.""" | ||
| return from_scale_encoding(vec_u8, ChainDataType.NeuronCertificate) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,8 @@ | |
| U16_MAX = 65535 | ||
| U64_MAX = 18446744073709551615 | ||
|
|
||
| Certificate = str | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't it be |
||
|
|
||
|
|
||
| UnlockStatus = namedtuple("UnlockStatus", ["success", "message"]) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import pytest | ||
| from bittensor.core.subtensor import Subtensor | ||
| from bittensor.core.axon import Axon | ||
| from bittensor.utils.btlogging import logging | ||
| from tests.e2e_tests.utils.chain_interactions import ( | ||
| wait_interval, | ||
| register_subnet, | ||
| ) | ||
| from tests.e2e_tests.utils.e2e_test_utils import ( | ||
| setup_wallet, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_neuron_certificate(local_chain): | ||
| """ | ||
| Tests the metagraph | ||
|
|
||
| Steps: | ||
| 1. Register a subnet through Alice | ||
| 2. Serve Alice axon with neuron certificate | ||
| 3. Verify neuron certificate can be retrieved | ||
| Raises: | ||
| AssertionError: If any of the checks or verifications fail | ||
| """ | ||
| logging.info("Testing neuron_certificate") | ||
| netuid = 1 | ||
|
|
||
| # Register root as Alice - the subnet owner and validator | ||
| alice_keypair, alice_wallet = setup_wallet("//Alice") | ||
| register_subnet(local_chain, alice_wallet) | ||
|
|
||
| # Verify subnet <netuid> created successfully | ||
| assert local_chain.query( | ||
| "SubtensorModule", "NetworksAdded", [netuid] | ||
| ).serialize(), "Subnet wasn't created successfully" | ||
|
|
||
| subtensor = Subtensor(network="ws://localhost:9945") | ||
|
|
||
| # Register Alice as a neuron on the subnet | ||
| assert subtensor.burned_register( | ||
| alice_wallet, netuid | ||
| ), "Unable to register Alice as a neuron" | ||
|
|
||
| # Serve Alice's axon with a certificate | ||
| axon = Axon(wallet=alice_wallet) | ||
| encoded_certificate = "?FAKE_ALICE_CERT" | ||
| axon.serve(netuid=netuid, subtensor=subtensor, certificate=encoded_certificate) | ||
|
|
||
| await wait_interval(tempo=1, subtensor=subtensor, netuid=netuid) | ||
|
|
||
| # Verify we are getting the correct certificate | ||
| assert ( | ||
| subtensor.get_neuron_certificate( | ||
| netuid=netuid, hotkey=alice_keypair.ss58_address | ||
| ) | ||
| == encoded_certificate | ||
| ) | ||
|
|
||
| logging.info("✅ Passed test_neuron_certificate") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can make a new type that inherits from str but is not str, so that mypy or something will be able to tell the difference between
strandCertificate(str)