bittensor
bittensor copied to clipboard
Migrate Delegate Info to onchain Indentities
Description
Currently, the delegation rewards distribution system in our blockchain project retrieves delegate identities from a GitHub link. We need to migrate this process to use the new blockchain RPC method delegateInfo_getDelegateIdentities.
This change will affect multiple parts of our codebase, including the delegate information retrieval, display, and related commands. The new RPC method will return delegate identity information in the IdentityInfo structure.
Acceptance Criteria
- Implement a new function to call the
delegateInfo_getDelegateIdentitiesRPC method. - Update the DelegatesDetails class to match the
IdentityInfostructure. - Update all relevant parts of the codebase to use the new RPC method instead of the GitHub link.
- Ensure backward compatibility or provide a migration path for existing users.
- Update documentation and comments to reflect the new method of retrieving delegate identities.
Tasks
- Update the DelegatesDetails class in bittensor/commands/utils.py to match the
IdentityInfostruct in subtensor:
@dataclass
class DelegatesDetails:
display: str
additional: List[Tuple[str, str]]
web: str
legal: Optional[str] = None
riot: Optional[str] = None
email: Optional[str] = None
pgp_fingerprint: Optional[str] = None
image: Optional[str] = None
twitter: Optional[str] = None
@classmethod
def from_chain_data(cls, data: Dict[str, Any]) -> "DelegatesDetails":
return cls(
display=data.get('display', ''),
additional=data.get('additional', []),
web=data.get('web', ''),
legal=data.get('legal'),
riot=data.get('riot'),
email=data.get('email'),
pgp_fingerprint=data.get('pgp_fingerprint'),
image=data.get('image'),
twitter=data.get('twitter')
)
- Implement a new function in the
Subtensorclass to call thedelegateInfo_getDelegateIdentitiesRPC method:
class Subtensor:
...
def get_delegate_identities(self, block: Optional[int] = None) -> Dict[str, DelegatesDetails]:
@retry(delay=1, tries=3, backoff=2, max_delay=4, logger=_logger)
def make_substrate_call_with_retry():
block_hash = None if block is None else self.substrate.get_block_hash(block)
return self.substrate.rpc_request(
method="delegateInfo_getDelegateIdentities",
params=[block_hash] if block_hash else [],
)
json_body = make_substrate_call_with_retry()
if not (result := json_body.get("result", None)):
return {}
return self._parse_delegate_identities(result)
def _parse_delegate_identities(self, raw_data: List[int]) -> Dict[str, DelegatesDetails]:
# Implement parsing logic here
# Convert the raw_data (Vec<u8>) into a dictionary of DelegatesDetails
# See how similar rpcs do this
pass
- Update the
get_delegates_detailsfunction inbittensor/commands/utils.py:
def get_delegates_details(subtensor: "bittensor.subtensor") -> Optional[Dict[str, DelegatesDetails]]:
try:
return subtensor.get_delegate_identities()
except Exception:
return None # Fail silently
-
Update any parts of the codebase that call
registered_delegate_infoand fetch it through the github link -
Update unit tests to mock the new RPC call instead of the GitHub API call and use the new
DelegatesDetailsstructure. -
Update documentation and comments throughout the codebase to reflect the new method of retrieving delegate identities and the new
DelegatesDetailsstructure.
Additional Considerations
- Do we need to implement a fallback mechanism to the GitHub method in case the RPC call fails?
- Should we implement caching for the delegate identities to reduce the number of RPC calls?
- How do we handle the case where a delegate's identity is not available through the RPC method?
- How should we handle the additional fields in the
IdentityInfostructure that weren't present in the GitHub data (legal, riot, email, pgp_fingerprint, image, twitter)?