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

SKD implementation for Subtensor Feat/RPC Upgrades. PR #1205 #2627

Merged
7 changes: 4 additions & 3 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,7 @@ async def neurons_lite(

async def query_identity(
self,
key: str,
coldkey_ss58: str,
block: Optional[int] = None,
block_hash: Optional[str] = None,
reuse_block: bool = False,
Expand All @@ -2467,7 +2467,8 @@ async def query_identity(
decentralized identity and governance system.

Arguments:
key (str): The key used to query the neuron's identity, typically the neuron's SS58 address.
coldkey_ss58 (str): The coldkey used to query the neuron's identity (technically the neuron's coldkey SS58
address).
block (Optional[int]): The blockchain block number for the query.
block_hash (str): The hash of the blockchain block number at which to perform the query.
reuse_block (bool): Whether to reuse the last-used blockchain block hash.
Expand All @@ -2486,7 +2487,7 @@ async def query_identity(
identity_info = await self.substrate.query(
module="Registry",
storage_function="IdentityOf",
params=[key],
params=[coldkey_ss58],
block_hash=block_hash,
reuse_block_hash=reuse_block,
)
Expand Down
20 changes: 16 additions & 4 deletions bittensor/core/chain_data/chain_identity.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
from dataclasses import dataclass
from bittensor.core.chain_data.info_base import InfoBase


@dataclass
class ChainIdentity:
class ChainIdentity(InfoBase):
"""Dataclass for chain identity information."""

# In `bittensor.core.chain_data.utils.custom_rpc_type_registry` represents as `ChainIdentityOf` structure.

name: str
github: str
contact: str
url: str
image: str
discord: str
description: str
additional: str

@classmethod
def _from_dict(cls, decoded: dict) -> "ChainIdentity":
return cls(
name=decoded["subnet_name"],
github=decoded["github_repo"],
contact=decoded["subnet_contact"],
url=decoded["subnet_url"],
discord=decoded["discord"],
description=decoded["description"],
additional=decoded["additional"],
)
6 changes: 3 additions & 3 deletions bittensor/core/chain_data/subnet_hyperparameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SubnetHyperparameters(InfoBase):
max_validators (int): Maximum number of validators.
adjustment_alpha (int): Alpha value for adjustments.
difficulty (int): Difficulty level.
commit_reveal_weights_interval (int): Interval for commit-reveal weights.
commit_reveal_period (int): Interval for commit-reveal weights.
commit_reveal_weights_enabled (bool): Flag indicating if commit-reveal weights are enabled.
alpha_high (int): High value of alpha.
alpha_low (int): Low value of alpha.
Expand Down Expand Up @@ -60,7 +60,7 @@ class SubnetHyperparameters(InfoBase):
max_validators: int
adjustment_alpha: int
difficulty: int
commit_reveal_weights_interval: int
commit_reveal_period: int
commit_reveal_weights_enabled: bool
alpha_high: int
alpha_low: int
Expand Down Expand Up @@ -89,7 +89,7 @@ def _from_dict(cls, decoded: dict) -> "SubnetHyperparameters":
alpha_low=decoded["alpha_low"],
bonds_moving_avg=decoded["bonds_moving_avg"],
commit_reveal_weights_enabled=decoded["commit_reveal_weights_enabled"],
commit_reveal_weights_interval=decoded["commit_reveal_weights_interval"],
commit_reveal_period=decoded["commit_reveal_period"],
difficulty=decoded["difficulty"],
immunity_period=decoded["immunity_period"],
kappa=decoded["kappa"],
Expand Down
2 changes: 1 addition & 1 deletion bittensor/core/chain_data/subnet_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _from_dict(cls, decoded: Any) -> "SubnetInfo":
for (netuid, req) in decoded["network_connect"]
},
difficulty=decoded["difficulty"],
emission_value=decoded["emission_values"],
emission_value=decoded["emission_value"],
immunity_period=decoded["immunity_period"],
kappa=decoded["kappa"],
max_allowed_validators=decoded["max_allowed_validators"],
Expand Down
4 changes: 1 addition & 3 deletions bittensor/core/extrinsics/asyncex/commit_reveal.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ async def commit_reveal_v3_extrinsic(
netuid, block_hash=current_block["header"]["hash"]
)
tempo = subnet_hyperparameters.tempo
subnet_reveal_period_epochs = (
subnet_hyperparameters.commit_reveal_weights_interval
)
subnet_reveal_period_epochs = subnet_hyperparameters.commit_reveal_period

# Encrypt `commit_hash` with t-lock and `get reveal_round`
commit_for_reveal, reveal_round = get_encrypted_commit(
Expand Down
4 changes: 1 addition & 3 deletions bittensor/core/extrinsics/commit_reveal.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ def commit_reveal_v3_extrinsic(
netuid, block=current_block
)
tempo = subnet_hyperparameters.tempo
subnet_reveal_period_epochs = (
subnet_hyperparameters.commit_reveal_weights_interval
)
subnet_reveal_period_epochs = subnet_hyperparameters.commit_reveal_period

# Encrypt `commit_hash` with t-lock and `get reveal_round`
commit_for_reveal, reveal_round = get_encrypted_commit(
Expand Down
7 changes: 4 additions & 3 deletions bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1883,14 +1883,15 @@ def neurons_lite(

return NeuronInfoLite.list_from_dicts(result)

def query_identity(self, key: str, block: Optional[int] = None) -> dict:
def query_identity(self, coldkey_ss58: str, block: Optional[int] = None) -> dict:
"""
Queries the identity of a neuron on the Bittensor blockchain using the given key. This function retrieves
detailed identity information about a specific neuron, which is a crucial aspect of the network's
decentralized identity and governance system.

Arguments:
key (str): The key used to query the neuron's identity, typically the neuron's SS58 address.
coldkey_ss58 (str): The coldkey used to query the neuron's identity (technically the neuron's coldkey SS58
address).
block (Optional[int]): The blockchain block number for the query.

Returns:
Expand All @@ -1906,7 +1907,7 @@ def query_identity(self, key: str, block: Optional[int] = None) -> dict:
identity_info = self.substrate.query(
module="Registry",
storage_function="IdentityOf",
params=[key],
params=[coldkey_ss58],
block_hash=self.determine_block_hash(block),
)
try:
Expand Down
10 changes: 2 additions & 8 deletions tests/e2e_tests/test_commit_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ async def test_commit_and_reveal_weights_legacy(local_chain):
)

assert (
subtensor.get_subnet_hyperparameters(
netuid=netuid
).commit_reveal_weights_interval
== 1
subtensor.get_subnet_hyperparameters(netuid=netuid).commit_reveal_period == 1
), "Failed to set commit/reveal periods"

assert (
Expand Down Expand Up @@ -233,10 +230,7 @@ async def test_commit_weights_uses_next_nonce(local_chain):
)

assert (
subtensor.get_subnet_hyperparameters(
netuid=netuid
).commit_reveal_weights_interval
== 1
subtensor.get_subnet_hyperparameters(netuid=netuid).commit_reveal_period == 1
), "Failed to set commit/reveal periods"

assert (
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/extrinsics/asyncex/test_commit_reveal.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def hyperparams():
max_validators=0,
adjustment_alpha=0,
difficulty=0,
commit_reveal_weights_interval=0,
commit_reveal_period=0,
commit_reveal_weights_enabled=True,
alpha_high=0,
alpha_low=0,
Expand Down Expand Up @@ -223,7 +223,7 @@ async def test_commit_reveal_v3_extrinsic_success_with_torch(
mocked_get_encrypted_commit.assert_called_once_with(
uids=mocked_uids,
weights=mocked_weights,
subnet_reveal_period_epochs=mock_hyperparams.return_value.commit_reveal_weights_interval,
subnet_reveal_period_epochs=mock_hyperparams.return_value.commit_reveal_period,
version_key=async_commit_reveal.version_as_int,
tempo=mock_hyperparams.return_value.tempo,
netuid=fake_netuid,
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/extrinsics/test_commit_reveal.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def hyperparams():
max_validators=0,
adjustment_alpha=0,
difficulty=0,
commit_reveal_weights_interval=0,
commit_reveal_period=0,
commit_reveal_weights_enabled=True,
alpha_high=0,
alpha_low=0,
Expand Down Expand Up @@ -209,7 +209,7 @@ def test_commit_reveal_v3_extrinsic_success_with_torch(mocker, subtensor, hyperp
mocked_get_encrypted_commit.assert_called_once_with(
uids=mocked_uids,
weights=mocked_weights,
subnet_reveal_period_epochs=mock_hyperparams.return_value.commit_reveal_weights_interval,
subnet_reveal_period_epochs=mock_hyperparams.return_value.commit_reveal_period,
version_key=commit_reveal.version_as_int,
tempo=mock_hyperparams.return_value.tempo,
netuid=fake_netuid,
Expand Down