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

Rao game changer #2370

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions bittensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@


if (NEST_ASYNCIO_ENV := os.getenv("NEST_ASYNCIO")) in ("1", None):

if NEST_ASYNCIO_ENV is None:
warnings.warn(
"NEST_ASYNCIO implicitly set to '1'. In the future, the default value will be '0'."
Expand Down Expand Up @@ -214,7 +213,29 @@ def debug(on: bool = True):
},
],
"type": "Vec<u8>",
}
},
"get_all_dynamic_info": {
"params": [],
"type": "Vec<u8>",
},
"get_subnet_info_v2": {
"params": [
{"name": "netuid", "type": "u16"},
],
"type": "Vec<u8>",
},
"get_dynamic_info": {
"params": [
{"name": "netuid", "type": "u16"},
],
"type": "Vec<u8>",
},
"get_subnet_state": {
"params": [
{"name": "netuid", "type": "u16"},
],
"type": "Vec<u8>",
},
}
},
"SubnetRegistrationRuntimeApi": {
Expand Down Expand Up @@ -250,6 +271,10 @@ def debug(on: bool = True):
"params": [{"name": "netuid", "type": "u16"}],
"type": "Vec<u8>",
},
"get_all_dynamic_info": {
"params": [],
"type": "Vec<u8>",
},
}
},
"ColdkeySwapRuntimeApi": {
Expand Down Expand Up @@ -418,11 +443,11 @@ def debug(on: bool = True):
"\u1685", # ᚅ (Nion, ash, 95)
"\u169b", # ᚛ (Forfeda, 96)
# Brahmi Script
"\u11000", # 𑀀 (A, 122)
"\u11001", # 𑀁 (Aa, 123)
"\u11002", # 𑀂 (I, 124)
"\u11003", # 𑀃 (Ii, 125)
"\u11005", # 𑀅 (U, 126)
chr(0x11000), # 𑀀 (A, 122)
chr(0x11001), # 𑀁 (Aa, 123)
chr(0x11002), # 𑀂 (I, 124)
chr(0x11003), # 𑀃 (Ii, 125)
chr(0x11005), # 𑀅 (U, 126)
# Tifinagh Alphabet
"\u2d30", # ⴰ (Ya, 127)
"\u2d31", # ⴱ (Yab, 128)
Expand Down
4 changes: 1 addition & 3 deletions bittensor/chain_data/delegate_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ def fix_decoded_values(cls, decoded: Any) -> "DelegateInfo":
"""Fixes the decoded values."""

return cls(
hotkey_ss58=ss58_encode(
decoded["delegate_ss58"], SS58_FORMAT
),
hotkey_ss58=ss58_encode(decoded["delegate_ss58"], SS58_FORMAT),
owner_ss58=ss58_encode(decoded["owner_ss58"], SS58_FORMAT),
take=U16_NORMALIZED_FLOAT(decoded["take"]),
nominators=[
Expand Down
4 changes: 1 addition & 3 deletions bittensor/chain_data/delegate_info_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def fix_decoded_values(cls, decoded: Any) -> "DelegateInfoLite":
fixed_take = U16_NORMALIZED_FLOAT(decoded_take)

return cls(
hotkey_ss58=ss58_encode(
decoded["delegate_ss58"], SS58_FORMAT
),
hotkey_ss58=ss58_encode(decoded["delegate_ss58"], SS58_FORMAT),
owner_ss58=ss58_encode(decoded["owner_ss58"], SS58_FORMAT),
take=fixed_take,
total_stake=Balance.from_rao(decoded["total_stake"]),
Expand Down
8 changes: 2 additions & 6 deletions bittensor/chain_data/dynamic_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,8 @@ def fix_decoded_values(cls, decoded: Dict) -> "DynamicInfo":
alpha_out = Balance.from_rao(decoded["alpha_out"]).set_unit(netuid)
alpha_in = Balance.from_rao(decoded["alpha_in"]).set_unit(netuid)
tao_in = Balance.from_rao(decoded["tao_in"]).set_unit(0)
total_locked = Balance.from_rao(decoded["total_locked"]).set_unit(
netuid
)
owner_locked = Balance.from_rao(decoded["owner_locked"]).set_unit(
netuid
)
total_locked = Balance.from_rao(decoded["total_locked"]).set_unit(netuid)
owner_locked = Balance.from_rao(decoded["owner_locked"]).set_unit(netuid)
price = (
Balance.from_tao(tao_in.tao / alpha_in.tao)
if alpha_in.tao > 0
Expand Down
10 changes: 6 additions & 4 deletions bittensor/chain_data/dynamic_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ def __init__(
self.price = Balance.from_tao(1.0)

def __str__(self) -> str:
return (f"DynamicPool( alpha_issuance={self.alpha_issuance}, "
f"alpha_outstanding={self.alpha_outstanding}, "
f"alpha_reserve={self.alpha_reserve}, "
f"tao_reserve={self.tao_reserve}, k={self.k}, price={self.price} )")
return (
f"DynamicPool( alpha_issuance={self.alpha_issuance}, "
f"alpha_outstanding={self.alpha_outstanding}, "
f"alpha_reserve={self.alpha_reserve}, "
f"tao_reserve={self.tao_reserve}, k={self.k}, price={self.price} )"
)

def __repr__(self) -> str:
return self.__str__()
Expand Down
17 changes: 13 additions & 4 deletions bittensor/chain_data/dynamic_pool_info_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@dataclass
class DynamicPoolInfoV2:
"""Dataclass for dynamic pool info."""

netuid: int
alpha_issuance: int
alpha_outstanding: int
Expand All @@ -22,7 +23,9 @@ def from_vec_u8(cls, vec_u8: List[int]) -> Optional["DynamicPoolInfoV2"]:
return None
return from_scale_encoding(vec_u8, ChainDataType.DynamicPoolInfoV2)

def _to_parameter_dict(self, return_type: str) -> Union[dict[str, Any], "torch.nn.ParameterDict"]:
def _to_parameter_dict(
self, return_type: str
) -> Union[dict[str, Any], "torch.nn.ParameterDict"]:
if return_type == "torch":
return torch.nn.ParameterDict(self.__dict__)
else:
Expand All @@ -36,17 +39,23 @@ def to_parameter_dict(self) -> Union[dict[str, Any], "torch.nn.ParameterDict"]:
return self._to_parameter_dict("numpy")

@classmethod
def _from_parameter_dict_torch(cls, parameter_dict: "torch.nn.ParameterDict") -> "DynamicPoolInfoV2":
def _from_parameter_dict_torch(
cls, parameter_dict: "torch.nn.ParameterDict"
) -> "DynamicPoolInfoV2":
"""Returns a DynamicPoolInfoV2 object from a torch parameter_dict."""
return cls(**dict(parameter_dict))

@classmethod
def _from_parameter_dict_numpy(cls, parameter_dict: dict[str, Any]) -> "DynamicPoolInfoV2":
def _from_parameter_dict_numpy(
cls, parameter_dict: dict[str, Any]
) -> "DynamicPoolInfoV2":
"""Returns a DynamicPoolInfoV2 object from a parameter_dict."""
return cls(**parameter_dict)

@classmethod
def from_parameter_dict(cls, parameter_dict: Union[dict[str, Any], "torch.nn.ParameterDict"]) -> "DynamicPoolInfoV2":
def from_parameter_dict(
cls, parameter_dict: Union[dict[str, Any], "torch.nn.ParameterDict"]
) -> "DynamicPoolInfoV2":
if use_torch():
return cls._from_parameter_dict_torch(parameter_dict)
else:
Expand Down
4 changes: 1 addition & 3 deletions bittensor/chain_data/neuron_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ def fix_decoded_values(cls, neuron_info_decoded: Any) -> "NeuronInfo":
neuron_info_decoded["coldkey"], SS58_FORMAT
)
stake_dict = {
ss58_encode(coldkey, SS58_FORMAT): Balance.from_rao(
int(stake)
)
ss58_encode(coldkey, SS58_FORMAT): Balance.from_rao(int(stake))
for coldkey, stake in neuron_info_decoded["stake"]
}
neuron_info_decoded["stake_dict"] = stake_dict
Expand Down
37 changes: 28 additions & 9 deletions bittensor/chain_data/neuron_info_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@dataclass
class NeuronInfoLite:
"""Dataclass for neuron metadata, but without the weights and bonds."""

hotkey: str
coldkey: str
uid: int
Expand All @@ -36,8 +37,12 @@ class NeuronInfoLite:
@classmethod
def fix_decoded_values(cls, neuron_info_decoded: Any) -> "NeuronInfoLite":
"""Fixes the values of the NeuronInfoLite object."""
neuron_info_decoded["hotkey"] = ss58_encode(neuron_info_decoded["hotkey"], SS58_FORMAT)
neuron_info_decoded["coldkey"] = ss58_encode(neuron_info_decoded["coldkey"], SS58_FORMAT)
neuron_info_decoded["hotkey"] = ss58_encode(
neuron_info_decoded["hotkey"], SS58_FORMAT
)
neuron_info_decoded["coldkey"] = ss58_encode(
neuron_info_decoded["coldkey"], SS58_FORMAT
)
stake_dict = {
ss58_encode(coldkey, SS58_FORMAT): Balance.from_rao(int(stake))
for coldkey, stake in neuron_info_decoded["stake"]
Expand All @@ -47,13 +52,27 @@ def fix_decoded_values(cls, neuron_info_decoded: Any) -> "NeuronInfoLite":
neuron_info_decoded["total_stake"] = neuron_info_decoded["stake"]
neuron_info_decoded["rank"] = U16_NORMALIZED_FLOAT(neuron_info_decoded["rank"])
neuron_info_decoded["emission"] = neuron_info_decoded["emission"] / RAOPERTAO
neuron_info_decoded["incentive"] = U16_NORMALIZED_FLOAT(neuron_info_decoded["incentive"])
neuron_info_decoded["consensus"] = U16_NORMALIZED_FLOAT(neuron_info_decoded["consensus"])
neuron_info_decoded["trust"] = U16_NORMALIZED_FLOAT(neuron_info_decoded["trust"])
neuron_info_decoded["validator_trust"] = U16_NORMALIZED_FLOAT(neuron_info_decoded["validator_trust"])
neuron_info_decoded["dividends"] = U16_NORMALIZED_FLOAT(neuron_info_decoded["dividends"])
neuron_info_decoded["prometheus_info"] = PrometheusInfo.fix_decoded_values(neuron_info_decoded["prometheus_info"])
neuron_info_decoded["axon_info"] = AxonInfo.from_neuron_info(neuron_info_decoded)
neuron_info_decoded["incentive"] = U16_NORMALIZED_FLOAT(
neuron_info_decoded["incentive"]
)
neuron_info_decoded["consensus"] = U16_NORMALIZED_FLOAT(
neuron_info_decoded["consensus"]
)
neuron_info_decoded["trust"] = U16_NORMALIZED_FLOAT(
neuron_info_decoded["trust"]
)
neuron_info_decoded["validator_trust"] = U16_NORMALIZED_FLOAT(
neuron_info_decoded["validator_trust"]
)
neuron_info_decoded["dividends"] = U16_NORMALIZED_FLOAT(
neuron_info_decoded["dividends"]
)
neuron_info_decoded["prometheus_info"] = PrometheusInfo.fix_decoded_values(
neuron_info_decoded["prometheus_info"]
)
neuron_info_decoded["axon_info"] = AxonInfo.from_neuron_info(
neuron_info_decoded
)
return cls(**neuron_info_decoded)

@classmethod
Expand Down
5 changes: 2 additions & 3 deletions bittensor/chain_data/scheduled_coldkey_swap_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@dataclass
class ScheduledColdkeySwapInfo:
"""Dataclass for scheduled coldkey swap information."""

old_coldkey: str
new_coldkey: str
arbitration_block: int
Expand Down Expand Up @@ -53,6 +54,4 @@ def decode_account_id_list(cls, vec_u8: List[int]) -> Optional[List[str]]:
)
if decoded is None:
return None
return [
ss58_encode(account_id, SS58_FORMAT) for account_id in decoded
]
return [ss58_encode(account_id, SS58_FORMAT) for account_id in decoded]
31 changes: 19 additions & 12 deletions bittensor/chain_data/stake_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,40 @@

from substrateinterface.utils.ss58 import ss58_encode

from bittensor.chain_data.utils import SS58_FORMAT, ChainDataType, from_scale_encoding, \
from_scale_encoding_using_type_string
from bittensor.chain_data.utils import (
SS58_FORMAT,
ChainDataType,
from_scale_encoding,
from_scale_encoding_using_type_string,
)
from bittensor.utils.balance import Balance


@dataclass
class StakeInfo:
"""Dataclass for stake info."""

hotkey_ss58: str # Hotkey address
coldkey_ss58: str # Coldkey address
netuid: int
stake: Balance # Stake for the hotkey-coldkey pair
locked: Balance # Stake which is locked.
emission: Balance # Emission for the hotkey-coldkey pair
emission: Balance # Emission for the hotkey-coldkey pair
drain: int
is_registered: bool

@classmethod
def fix_decoded_values(cls, decoded: Any) -> "StakeInfo":
"""Fixes the decoded values."""
return cls(
hotkey_ss58 =ss58_encode(decoded["hotkey"], SS58_FORMAT),
coldkey_ss58 = ss58_encode(decoded["coldkey"], SS58_FORMAT),
netuid = int(decoded["netuid"]),
stake = Balance.from_rao(decoded["stake"]).set_unit(decoded["netuid"]),
locked = Balance.from_rao(decoded["locked"]).set_unit(decoded["netuid"]),
emission = Balance.from_rao(decoded["emission"]).set_unit(decoded["netuid"]),
drain = int(decoded["drain"]),
is_registered = bool(decoded["is_registered"])
hotkey_ss58=ss58_encode(decoded["hotkey"], SS58_FORMAT),
coldkey_ss58=ss58_encode(decoded["coldkey"], SS58_FORMAT),
netuid=int(decoded["netuid"]),
stake=Balance.from_rao(decoded["stake"]).set_unit(decoded["netuid"]),
locked=Balance.from_rao(decoded["locked"]).set_unit(decoded["netuid"]),
emission=Balance.from_rao(decoded["emission"]).set_unit(decoded["netuid"]),
drain=int(decoded["drain"]),
is_registered=bool(decoded["is_registered"]),
)

@classmethod
Expand All @@ -52,7 +57,9 @@ def list_of_tuple_from_vec_u8(
) -> Dict[str, List["StakeInfo"]]:
"""Returns a list of StakeInfo objects from a ``vec_u8``."""
decoded: Optional[list[tuple[str, list[object]]]] = (
from_scale_encoding_using_type_string(vec_u8, type_string="Vec<(AccountId, Vec<StakeInfo>)>")
from_scale_encoding_using_type_string(
vec_u8, type_string="Vec<(AccountId, Vec<StakeInfo>)>"
)
)

if decoded is None:
Expand Down
1 change: 1 addition & 0 deletions bittensor/chain_data/subnet_hyperparameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@dataclass
class SubnetHyperparameters:
"""Dataclass for subnet hyperparameters."""

rho: int
kappa: int
immunity_period: int
Expand Down
1 change: 1 addition & 0 deletions bittensor/chain_data/subnet_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@dataclass
class SubnetInfo:
"""Dataclass for subnet info."""

netuid: int
rho: int
kappa: int
Expand Down
Loading