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

Child Hotkeys #2071

Merged
merged 39 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6dda55b
init commit
opendansor Jun 26, 2024
783392f
Add child singular cli done
opendansor Jun 26, 2024
c8bd350
Set Child Hotkey
opendansor Jun 26, 2024
d2bc588
Set children multiple command.
opendansor Jun 26, 2024
f9d54d0
Remove merge conflict artifacts
opendansor Jun 26, 2024
de50693
Add GetChildrenHotkeysCommand
opendansor Jun 27, 2024
67cedd5
Add RevokeChildHotkey
opendansor Jun 27, 2024
3bc473f
lint
opendansor Jun 27, 2024
b3279ed
Revoke children multiple command
opendansor Jun 27, 2024
b8e2fa5
lint
opendansor Jun 27, 2024
5b2e595
CLI revoke multiple
opendansor Jun 27, 2024
36f7466
lint
opendansor Jun 27, 2024
8766851
Imports
opendansor Jun 27, 2024
f11fe3d
lint
opendansor Jun 27, 2024
156ee56
lint
opendansor Jun 27, 2024
2dcd6f9
imports in init
opendansor Jun 27, 2024
295cd4c
Refactor to follow new pattern
opendansor Jun 29, 2024
e77e688
Merge branch 'staging' into feature/opendansor/child_hotkeys
opendansor Jul 1, 2024
e4db609
U64 for all proportion values
opendansor Jul 1, 2024
79457b3
lint
opendansor Jul 1, 2024
5f6a754
debug
Jul 2, 2024
937f614
Clean up a bit.
opendansor Jul 2, 2024
c34cc8c
Merge pull request #2093 from opentensor/sam/debug_childkey
opendansor Jul 2, 2024
3053276
Clean up a bit.
opendansor Jul 2, 2024
2148dee
u16 to u64
opendansor Jul 3, 2024
2315d8b
un-refactor
opendansor Jul 3, 2024
70655e2
APY + other updates
opendansor Jul 8, 2024
4103cd4
lint
opendansor Jul 8, 2024
98d0768
lint
opendansor Jul 8, 2024
4c3bcbc
Extract Method, and params
opendansor Jul 8, 2024
a3ca5a5
Pr comments
opendansor Jul 10, 2024
26de88c
merge staging into child_hotkeys
opendansor Aug 5, 2024
04bbe9a
Update child hotkeys with new subtensor calls and remove ChildInfo ob…
opendansor Aug 8, 2024
dffb080
ruff
opendansor Aug 9, 2024
c7a95af
Merge branch 'staging' into feature/opendansor/child_hotkeys
opendansor Aug 9, 2024
a18fcd5
update
opendansor Aug 9, 2024
df6564b
update
opendansor Aug 9, 2024
432b503
ruff
opendansor Aug 9, 2024
36c42a0
mypy error
opendansor Aug 9, 2024
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
23 changes: 20 additions & 3 deletions bittensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ def debug(on: bool = True):
},
},
},
"ValidatorIPRuntimeApi": {
"ChildrenInfoRuntimeApi": {
"methods": {
"get_associated_validator_ip_info_for_subnet": {
"get_children_info": {
"params": [
{
"name": "netuid",
Expand All @@ -216,6 +216,23 @@ def debug(on: bool = True):
],
"type": "Vec<u8>",
},
"get_child_info": {
"params": [
{
"name": "netuid",
"type": "u16",
},
{
"name": "child",
"type": "Vec<u8>",
},
{
"name": "proportion",
"type": "u64",
},
],
"type": "Vec<u8>",
},
},
},
"SubnetInfoRuntimeApi": {
Expand Down Expand Up @@ -292,7 +309,6 @@ def debug(on: bool = True):
strtobool,
strtobool_with_default,
get_explorer_root_url_by_network_from_map,
get_explorer_root_url_by_network_from_map,
get_explorer_url_for_network,
ss58_address_to_bytes,
U16_NORMALIZED_FLOAT,
Expand All @@ -310,6 +326,7 @@ def debug(on: bool = True):
PrometheusInfo,
DelegateInfo,
StakeInfo,
ChildInfo,
SubnetInfo,
SubnetHyperparameters,
IPInfo,
Expand Down
117 changes: 115 additions & 2 deletions bittensor/chain_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@
["stake", "Compact<u64>"],
],
},
"ChildInfo": {
"type": "struct",
"type_mapping": [
["child_ss58", "AccountId"],
["proportion", "Compact<u64>"],
["total_stake", "Compact<u64>"],
["emissions_per_day", "Compact<u64>"],
["return_per_1000", "Compact<u64>"],
["take", "Compact<u16>"],
["parents", "Vec<(Compact<u64>, AccountId)>"],
],
},
"SubnetHyperparameters": {
"type": "struct",
"type_mapping": [
Expand Down Expand Up @@ -322,8 +334,9 @@ class ChainDataType(Enum):
NeuronInfoLite = 4
DelegatedInfo = 5
StakeInfo = 6
IPInfo = 7
SubnetHyperparameters = 8
ChildInfo = 7
IPInfo = 8
SubnetHyperparameters = 9


def from_scale_encoding(
Expand Down Expand Up @@ -802,6 +815,106 @@ def delegated_list_from_vec_u8(
]


@dataclass
class ChildInfo:
"""
Dataclass for child information.

Args:

child_ss58 (str): The AccountId of the child neuron
proportion (int): The proportion of stake allocated to this child
total_stake (int): The total stake of the child (including its own children and parents)
emissions_per_day (int): The emissions per day for this child
return_per_1000 (int): The return per 1000 TAO staked for this child
take (int): The take (commission) of the child
parents (List[Tuple[int, str]]: The parents of this child, each with their proportion

"""

child_ss58: str # The AccountId of the child neuron
proportion: int # The proportion of stake allocated to this child
total_stake: (
int # The total stake of the child (including its own children and parents)
)
emissions_per_day: int # The emissions per day for this child
return_per_1000: int # The return per 1000 TAO staked for this child
take: float # The take (commission) of the child
parents: List[
Tuple[int, str]
] # The parents of this child, each with their proportion

@classmethod
def fix_decoded_values(cls, decoded: Any) -> "ChildInfo":
"""Fixes the decoded values."""

child_ss58 = ss58_encode(decoded["child_ss58"], bittensor.__ss58_format__)
proportion = decoded["proportion"]
total_stake = decoded["total_stake"]
emissions_per_day = decoded["emissions_per_day"]
return_per_1000 = Balance.from_rao(decoded["return_per_1000"])
take = U16_NORMALIZED_FLOAT(decoded["take"])
parents = [
(
int(parent[0]),
ss58_encode(parent[1], bittensor.__ss58_format__),
)
for parent in decoded["parents"]
]

return cls(
child_ss58=child_ss58,
proportion=proportion,
total_stake=total_stake,
emissions_per_day=emissions_per_day,
return_per_1000=return_per_1000,
take=take,
parents=parents,
)

@classmethod
def from_vec_u8(cls, vec_u8: List[int]) -> Optional["ChildInfo"]:
"""Returns a ChildInfo object from a ``vec_u8``."""
if len(vec_u8) == 0:
return None

decoded = from_scale_encoding(vec_u8, ChainDataType.ChildInfo)
if decoded is None:
return None

return ChildInfo.fix_decoded_values(decoded)

@classmethod
def list_of_tuple_from_vec_u8(
cls, vec_u8: List[int]
) -> Dict[str, List["ChildInfo"]]:
"""Returns a list of ChildInfo objects from a ``vec_u8``."""
decoded: Optional[list[tuple[str, list[object]]]] = (
from_scale_encoding_using_type_string(
input_=vec_u8, type_string="Vec<(AccountId, Vec<ChildInfo>)>"
)
)

if decoded is None:
return {}

return {
ss58_encode(address=account_id, ss58_format=bittensor.__ss58_format__): [
ChildInfo.fix_decoded_values(d) for d in child_info
]
for account_id, child_info in decoded
}

@classmethod
def list_from_vec_u8(cls, vec_u8: List[int]) -> List["ChildInfo"]:
"""Returns a list of ChildInfo objects from a ``vec_u8``."""
decoded = from_scale_encoding(vec_u8, ChainDataType.ChildInfo, is_vec=True)
if decoded is None:
return []

return [ChildInfo.fix_decoded_values(d) for d in decoded]


@dataclass
class StakeInfo:
"""Dataclass for stake info."""
Expand Down
12 changes: 11 additions & 1 deletion bittensor/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
WalletCreateCommand,
CommitWeightCommand,
RevealWeightCommand,
SetChildCommand,
SetChildrenCommand,
GetChildrenCommand,
RevokeChildCommand,
RevokeChildrenCommand,
)

# Create a console instance for CLI display.
Expand Down Expand Up @@ -162,11 +167,16 @@
"stake": {
"name": "stake",
"aliases": ["st", "stakes"],
"help": "Commands for staking and removing stake from hotkey accounts.",
"help": "Commands for staking and removing stake and setting child hotkey accounts.",
"commands": {
"show": StakeShow,
"add": StakeCommand,
"remove": UnStakeCommand,
"get_children": GetChildrenCommand,
"set_child": SetChildCommand,
"revoke_child": RevokeChildCommand,
"set_children": SetChildrenCommand,
"revoke_children": RevokeChildrenCommand,
},
},
"weights": {
Expand Down
10 changes: 8 additions & 2 deletions bittensor/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@
}
)

from .stake import StakeCommand, StakeShow
from .unstake import UnStakeCommand
from .stake import (
StakeCommand,
StakeShow,
SetChildCommand,
SetChildrenCommand,
GetChildrenCommand,
)
from .unstake import UnStakeCommand, RevokeChildrenCommand, RevokeChildCommand
from .overview import OverviewCommand
from .register import (
PowRegisterCommand,
Expand Down
Loading
Loading