Skip to content

Commit

Permalink
replace rpc call
Browse files Browse the repository at this point in the history
  • Loading branch information
andreea-popescu-reef committed Aug 26, 2024
1 parent 8d17046 commit b25a198
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions bittensor/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5039,13 +5039,13 @@ def make_substrate_call_with_retry():
return NeuronInfo.from_vec_u8(result)

def get_neuron_certificate(
self, uid: int, netuid: int, block: Optional[int] = None
self, hotkey: str, netuid: int, block: Optional[int] = None
) -> Optional[Certificate]:
"""
Retrieves the TLS certificate for a specific neuron identified by its unique identifier (UID)
within a specified subnet (netuid) of the Bittensor network.
Args:
uid (int): The unique identifier of the neuron.
hotkey (str): The hotkey to query.
netuid (int): The unique identifier of the subnet.
block (Optional[int], optional): The blockchain block number for the query.
Expand All @@ -5055,23 +5055,18 @@ def get_neuron_certificate(
This function is used for certificate discovery for setting up mutual tls communication between neurons
"""

@retry(delay=2, tries=3, backoff=2, max_delay=4, logger=_logger)
def make_substrate_call_with_retry():
block_hash = None if block == None else self.substrate.get_block_hash(block)
params = [netuid, uid]
if block_hash:
params = params + [block_hash]
return self.substrate.rpc_request(
method="neuronInfo_getNeuronCertificate",
params=params, # custom rpc method
)

json_body = make_substrate_call_with_retry()

if not (result := json_body.get("result", None)):
certificate = self.query_module(
module="SubtensorModule",
name="NeuronCertificates",
block=block,
params=[netuid, hotkey],
)
if not hasattr(certificate, "serialize"):
return None

return NeuronCertificate.from_vec_u8(result)
certificate = certificate.serialize()
if not certificate:
return None
return certificate.get("certificate", None)

def neurons(self, netuid: int, block: Optional[int] = None) -> List[NeuronInfo]:
"""
Expand Down

0 comments on commit b25a198

Please sign in to comment.