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

Add method for fetching all Neuron Certificates on a Netuid #2677

Merged
35 changes: 35 additions & 0 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,41 @@ async def get_neuron_certificate(
return None
return None

async def get_all_neuron_certificates(
self,
netuid: int,
block: Optional[int] = None,
block_hash: Optional[str] = None,
reuse_block: bool = False,
) -> dict[str, Certificate]:
"""
Retrieves the TLS certificates for neurons within a specified subnet (netuid) of the Bittensor network.

Arguments:
netuid: The unique identifier of the subnet.
block: The blockchain block number for the query.
block_hash: The hash of the block to retrieve the parameter from. Do not specify if using block or
reuse_block.
reuse_block: Whether to use the last-used block. Do not set if using block_hash or block.

Returns:
{ss58: Certificate} for the key/Certificate pairs on the subnet

This function is used for certificate discovery for setting up mutual tls communication between neurons.
"""
query_certificates = await self.query_map(
module="SubtensorModule",
name="NeuronCertificates",
params=[netuid],
block=block,
block_hash=block_hash,
reuse_block=reuse_block,
)
output = {}
async for key, item in query_certificates:
output[decode_account_id(key)] = Certificate(item.value)
return output

async def get_neuron_for_pubkey_and_subnet(
self,
hotkey_ss58: str,
Expand Down
26 changes: 26 additions & 0 deletions bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,32 @@ def get_neuron_certificate(
return None
return None

def get_all_neuron_certificates(
self, netuid: int, block: Optional[int] = None
) -> dict[str, Certificate]:
"""
Retrieves the TLS certificates for neurons within a specified subnet (netuid) of the Bittensor network.

Arguments:
netuid: The unique identifier of the subnet.
block: The blockchain block number for the query.

Returns:
{ss58: Certificate} for the key/Certificate pairs on the subnet

This function is used for certificate discovery for setting up mutual tls communication between neurons.
"""
query_certificates = self.query_map(
module="SubtensorModule",
name="NeuronCertificates",
params=[netuid],
block=block,
)
output = {}
for key, item in query_certificates:
output[decode_account_id(key)] = Certificate(item.value)
return output

def get_neuron_for_pubkey_and_subnet(
self, hotkey_ss58: str, netuid: int, block: Optional[int] = None
) -> Optional["NeuronInfo"]:
Expand Down
Loading