Skip to content
Merged
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
16 changes: 15 additions & 1 deletion allways/commitments.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
from typing import List, Optional

import bittensor as bt
from substrateinterface.utils.ss58 import ss58_encode

from allways.chains import SUPPORTED_CHAINS, canonical_pair
from allways.classes import MinerPair
from allways.constants import COMMITMENT_VERSION

SS58_PREFIX = 42


def parse_commitment_data(raw: str, uid: int = 0, hotkey: str = '') -> Optional[MinerPair]:
"""Parse a commitment string into a MinerPair.
Expand Down Expand Up @@ -145,7 +148,18 @@ def read_miner_commitments(subtensor: bt.Subtensor, netuid: int) -> List[MinerPa
params=[netuid],
)
for key, metadata in result:
hotkey = str(key.value) if hasattr(key, 'value') else str(key)
# query_map returns the second-map key (hotkey AccountId) as raw
# bytes inside a single-element tuple, not an SS58 string. Encode
# it so we can look the miner up in the metagraph's hotkey index.
raw = key.value if hasattr(key, 'value') else key
if isinstance(raw, tuple) and len(raw) == 1:
raw = raw[0]
if isinstance(raw, (tuple, list)):
raw = bytes(raw)
if isinstance(raw, (bytes, bytearray)) and len(raw) == 32:
hotkey = ss58_encode(bytes(raw), SS58_PREFIX)
else:
hotkey = str(raw)
uid = hotkey_to_uid.get(hotkey)
if uid is None:
continue # miner dereg'd but commitment still in storage
Expand Down
Loading