bittensor.core.chain_data

Contents

bittensor.core.chain_data#

This module provides data structures and functions for working with the Bittensor network, including neuron and subnet information, SCALE encoding/decoding, and custom RPC type registry.

Submodules#

Attributes#

Classes#

AxonInfo

The AxonInfo class represents information about an axon endpoint in the bittensor network. This includes

DelegateInfo

Dataclass for delegate information. For a lighter version of this class, see DelegateInfoLite.

DelegateInfoLite

Dataclass for DelegateLiteInfo. This is a lighter version of :func:DelegateInfo.

IPInfo

Dataclass representing IP information.

NeuronInfo

Represents the metadata of a neuron including keys, UID, stake, rankings, and other attributes.

NeuronInfoLite

NeuronInfoLite is a dataclass representing neuron metadata without weights and bonds.

PrometheusInfo

Dataclass representing information related to Prometheus.

ProposalVoteData

This TypedDict represents the data structure for a proposal vote in the Senate.

ScheduledColdkeySwapInfo

The ScheduledColdkeySwapInfo class is a dataclass representing information about scheduled cold key swaps.

StakeInfo

Dataclass for representing stake information linked to hotkey and coldkey pairs.

SubnetHyperparameters

This class represents the hyperparameters for a subnet.

SubnetInfo

Dataclass for subnet info.

Functions#

decode_account_id(account_id_bytes)

Decodes an AccountId from bytes to a Base64 string using SS58 encoding.

process_stake_data(stake_data)

Processes stake data to decode account IDs and convert stakes from rao to Balance objects.

Package Contents#

class bittensor.core.chain_data.AxonInfo#

The AxonInfo class represents information about an axon endpoint in the bittensor network. This includes properties such as IP address, ports, and relevant keys.

Variables:
  • version (int) – The version of the axon endpoint.

  • ip (str) – The IP address of the axon endpoint.

  • port (int) – The port number the axon endpoint uses.

  • ip_type (int) – The type of IP protocol (e.g., IPv4 or IPv6).

  • hotkey (str) – The hotkey associated with the axon endpoint.

  • coldkey (str) – The coldkey associated with the axon endpoint.

  • protocol (int) – The protocol version (default is 4).

  • placeholder1 (int) – Reserved field (default is 0).

  • placeholder2 (int) – Reserved field (default is 0).

__eq__(other)#
Parameters:

other (AxonInfo)

__repr__()#
__str__()#
coldkey: str#
classmethod from_neuron_info(neuron_info)#

Converts a dictionary to an AxonInfo object.

Parameters:

neuron_info (dict) – A dictionary containing the neuron information.

Returns:

An instance of AxonInfo created from the dictionary.

Return type:

instance (AxonInfo)

classmethod from_parameter_dict(parameter_dict)#

Returns an axon_info object from a torch parameter_dict or a parameter dict.

Parameters:

parameter_dict (Union[dict[str, Any], bittensor.utils.registration.torch.nn.ParameterDict])

Return type:

AxonInfo

classmethod from_string(json_string)#

Creates an AxonInfo object from its string representation using JSON.

Parameters:

json_string (str) – The JSON string representation of the AxonInfo object.

Returns:

An instance of AxonInfo created from the JSON string. If decoding fails, returns a default AxonInfo object with default values.

Return type:

AxonInfo

Raises:
  • json.JSONDecodeError – If there is an error in decoding the JSON string.

  • TypeError – If there is a type error when creating the AxonInfo object.

  • ValueError – If there is a value error when creating the AxonInfo object.

hotkey: str#
ip: str#
ip_str()#

Return the whole IP as string

Return type:

str

ip_type: int#
property is_serving: bool#

True if the endpoint is serving.

Return type:

bool

placeholder1: int = 0#
placeholder2: int = 0#
port: int#
protocol: int = 4#
to_parameter_dict()#

Returns a torch tensor or dict of the subnet info, depending on the USE_TORCH flag set.

Return type:

Union[dict[str, Union[int, str]], bittensor.utils.registration.torch.nn.ParameterDict]

to_string()#

Converts the AxonInfo object to a string representation using JSON.

Return type:

str

version: int#
class bittensor.core.chain_data.DelegateInfo#

Dataclass for delegate information. For a lighter version of this class, see DelegateInfoLite.

Parameters:
  • hotkey_ss58 (str) – Hotkey of the delegate for which the information is being fetched.

  • total_stake (int) – Total stake of the delegate.

  • nominators (list[tuple[str, int]]) – List of nominators of the delegate and their stake.

  • take (float) – Take of the delegate as a percentage.

  • owner_ss58 (str) – Coldkey of the owner.

  • registrations (list[int]) – List of subnets that the delegate is registered on.

  • validator_permits (list[int]) – List of subnets that the delegate is allowed to validate on.

  • return_per_1000 (int) – Return per 1000 TAO, for the delegate over a day.

  • total_daily_return (int) – Total daily return of the delegate.

classmethod delegated_list_from_vec_u8(vec_u8)#
Parameters:

vec_u8 (bytes)

Return type:

list[tuple[DelegateInfo, bittensor.utils.balance.Balance]]

classmethod from_vec_u8(vec_u8)#
Parameters:

vec_u8 (bytes)

Return type:

Optional[DelegateInfo]

hotkey_ss58: str#
classmethod list_from_vec_u8(vec_u8)#
Parameters:

vec_u8 (bytes)

Return type:

list[DelegateInfo]

nominators: list[tuple[str, bittensor.utils.balance.Balance]]#
owner_ss58: str#
registrations: list[int]#
return_per_1000: bittensor.utils.balance.Balance#
take: float#
total_daily_return: bittensor.utils.balance.Balance#
total_stake: bittensor.utils.balance.Balance#
validator_permits: list[int]#
class bittensor.core.chain_data.DelegateInfoLite#

Dataclass for DelegateLiteInfo. This is a lighter version of :func:DelegateInfo.

Parameters:
  • delegate_ss58 (str) – Hotkey of the delegate for which the information is being fetched.

  • take (float) – Take of the delegate as a percentage.

  • nominators (int) – Count of the nominators of the delegate.

  • owner_ss58 (str) – Coldkey of the owner.

  • registrations (list[int]) – List of subnets that the delegate is registered on.

  • validator_permits (list[int]) – List of subnets that the delegate is allowed to validate on.

  • return_per_1000 (int) – Return per 1000 TAO, for the delegate over a day.

  • total_daily_return (int) – Total daily return of the delegate.

delegate_ss58: str#
nominators: int#
owner_ss58: str#
registrations: list[int]#
return_per_1000: int#
take: float#
total_daily_return: int#
validator_permits: list[int]#
class bittensor.core.chain_data.IPInfo#

Dataclass representing IP information.

Variables:
  • ip (str) – The IP address as a string.

  • ip_type (int) – The type of the IP address (e.g., IPv4, IPv6).

  • protocol (int) – The protocol associated with the IP (e.g., TCP, UDP).

encode()#

Returns a dictionary of the IPInfo object that can be encoded.

Return type:

dict[str, Any]

classmethod fix_decoded_values(decoded)#

Returns a SubnetInfo object from a decoded IPInfo dictionary.

Parameters:

decoded (dict)

Return type:

IPInfo

classmethod from_parameter_dict(parameter_dict)#

Creates a IPInfo instance from a parameter dictionary.

Parameters:

parameter_dict (Union[dict[str, Any], bittensor.utils.registration.torch.nn.ParameterDict])

Return type:

IPInfo

classmethod from_vec_u8(vec_u8)#

Returns a IPInfo object from a vec_u8.

Parameters:

vec_u8 (list[int])

Return type:

Optional[IPInfo]

ip: str#
ip_type: int#
classmethod list_from_vec_u8(vec_u8)#

Returns a list of IPInfo objects from a vec_u8.

Parameters:

vec_u8 (list[int])

Return type:

list[IPInfo]

protocol: int#
to_parameter_dict()#

Returns a torch tensor or dict of the subnet IP info.

Return type:

Union[dict[str, Union[str, int]], bittensor.utils.registration.torch.nn.ParameterDict]

class bittensor.core.chain_data.NeuronInfo#

Represents the metadata of a neuron including keys, UID, stake, rankings, and other attributes.

Variables:
  • hotkey (str) – The hotkey associated with the neuron.

  • coldkey (str) – The coldkey associated with the neuron.

  • uid (int) – The unique identifier for the neuron.

  • netuid (int) – The network unique identifier for the neuron.

  • active (int) – The active status of the neuron.

  • stake (Balance) – The balance staked to this neuron.

  • stake_dict (dict[str, Balance]) – A dictionary mapping coldkey to the amount staked.

  • total_stake (Balance) – The total amount of stake.

  • rank (float) – The rank score of the neuron.

  • emission (float) – The emission rate.

  • incentive (float) – The incentive value.

  • consensus (float) – The consensus score.

  • trust (float) – The trust score.

  • validator_trust (float) – The validation trust score.

  • dividends (float) – The dividends value.

  • last_update (int) – The timestamp of the last update.

  • validator_permit (bool) – Validator permit status.

  • weights (list[list[int]]) – List of weights associated with the neuron.

  • bonds (list[list[int]]) – List of bonds associated with the neuron.

  • pruning_score (int) – The pruning score of the neuron.

  • prometheus_info (Optional[PrometheusInfo]) – Information related to Prometheus.

  • axon_info (Optional[AxonInfo]) – Information related to Axon.

  • is_null (bool) – Indicator if this is a null neuron.

active: int#
axon_info: bittensor.core.chain_data.axon_info.AxonInfo | None = None#
bonds: list[list[int]]#
coldkey: str#
consensus: float#
dividends: float#
emission: float#
classmethod from_vec_u8(vec_u8)#

Instantiates NeuronInfo from a byte vector.

Parameters:

vec_u8 (bytes)

Return type:

NeuronInfo

classmethod from_weights_bonds_and_neuron_lite(neuron_lite, weights_as_dict, bonds_as_dict)#

Creates an instance of NeuronInfo from NeuronInfoLite and dictionaries of weights and bonds.

Parameters:
  • neuron_lite (NeuronInfoLite) – A lite version of the neuron containing basic attributes.

  • weights_as_dict (dict[int, list[tuple[int, int]]]) – A dictionary where the key is the UID and the value is a list of weight tuples associated with the neuron.

  • bonds_as_dict (dict[int, list[tuple[int, int]]]) – A dictionary where the key is the UID and the value is a list of bond tuples associated with the neuron.

Returns:

An instance of NeuronInfo populated with the provided weights and bonds.

Return type:

NeuronInfo

static get_null_neuron()#

Returns a null NeuronInfo instance.

Return type:

NeuronInfo

hotkey: str#
incentive: float#
is_null: bool = False#
last_update: int#
netuid: int#
prometheus_info: bittensor.core.chain_data.prometheus_info.PrometheusInfo | None = None#
pruning_score: int#
rank: float#
stake: bittensor.utils.balance.Balance#
stake_dict: dict[str, bittensor.utils.balance.Balance]#
total_stake: bittensor.utils.balance.Balance#
trust: float#
uid: int#
validator_permit: bool#
validator_trust: float#
weights: list[list[int]]#
class bittensor.core.chain_data.NeuronInfoLite#

NeuronInfoLite is a dataclass representing neuron metadata without weights and bonds.

Variables:
  • hotkey (str) – The hotkey string for the neuron.

  • coldkey (str) – The coldkey string for the neuron.

  • uid (int) – A unique identifier for the neuron.

  • netuid (int) – Network unique identifier for the neuron.

  • active (int) – Indicates whether the neuron is active.

  • stake (Balance) – The stake amount associated with the neuron.

  • stake_dict (dict) – Mapping of coldkey to the amount staked to this Neuron.

  • total_stake (Balance) – Total amount of the stake.

  • rank (float) – The rank of the neuron.

  • emission (float) – The emission value of the neuron.

  • incentive (float) – The incentive value of the neuron.

  • consensus (float) – The consensus value of the neuron.

  • trust (float) – Trust value of the neuron.

  • validator_trust (float) – Validator trust value of the neuron.

  • dividends (float) – Dividends associated with the neuron.

  • last_update (int) – Timestamp of the last update.

  • validator_permit (bool) – Indicates if the neuron has a validator permit.

  • prometheus_info (Optional[PrometheusInfo]) – Prometheus information associated with the neuron.

  • axon_info (Optional[AxonInfo]) – Axon information associated with the neuron.

  • pruning_score (int) – The pruning score of the neuron.

  • is_null (bool) – Indicates whether the neuron is null.

get_null_neuron()#

Returns a NeuronInfoLite object representing a null neuron.

Return type:

NeuronInfoLite

list_from_vec_u8()#

Decodes a bytes object into a list of NeuronInfoLite instances.

Parameters:

vec_u8 (bytes)

Return type:

list[NeuronInfoLite]

active: int#
axon_info: bittensor.core.chain_data.axon_info.AxonInfo | None#
coldkey: str#
consensus: float#
dividends: float#
emission: float#
static get_null_neuron()#

Returns a null NeuronInfoLite instance.

Return type:

NeuronInfoLite

hotkey: str#
incentive: float#
is_null: bool = False#
last_update: int#
classmethod list_from_vec_u8(vec_u8)#

Decodes a bytes object into a list of NeuronInfoLite instances.

Parameters:

vec_u8 (bytes) – The bytes object to decode into NeuronInfoLite instances.

Returns:

A list of NeuronInfoLite instances decoded from the provided bytes object.

Return type:

list[NeuronInfoLite]

netuid: int#
prometheus_info: bittensor.core.chain_data.prometheus_info.PrometheusInfo | None#
pruning_score: int#
rank: float#
stake: bittensor.utils.balance.Balance#
stake_dict: dict[str, bittensor.utils.balance.Balance]#
total_stake: bittensor.utils.balance.Balance#
trust: float#
uid: int#
validator_permit: bool#
validator_trust: float#
class bittensor.core.chain_data.PrometheusInfo#

Dataclass representing information related to Prometheus.

Variables:
  • block (int) – The block number associated with the Prometheus data.

  • version (int) – The version of the Prometheus data.

  • ip (str) – The IP address associated with Prometheus.

  • port (int) – The port number for Prometheus.

  • ip_type (int) – The type of IP address (e.g., IPv4, IPv6).

block: int#
classmethod fix_decoded_values(prometheus_info_decoded)#

Returns a PrometheusInfo object from a prometheus_info_decoded dictionary.

Parameters:

prometheus_info_decoded (dict)

Return type:

PrometheusInfo

ip: str#
ip_type: int#
port: int#
version: int#
bittensor.core.chain_data.ProposalCallData#
class bittensor.core.chain_data.ProposalVoteData#

Bases: TypedDict

This TypedDict represents the data structure for a proposal vote in the Senate.

Variables:
  • index (int) – The index of the proposal.

  • threshold (int) – The threshold required for the proposal to pass.

  • ayes (List[str]) – List of senators who voted ‘aye’.

  • nays (List[str]) – List of senators who voted ‘nay’.

  • end (int) – The ending timestamp of the voting period.

Initialize self. See help(type(self)) for accurate signature.

ayes: list[str]#
end: int#
index: int#
nays: list[str]#
threshold: int#
class bittensor.core.chain_data.ScheduledColdkeySwapInfo#

The ScheduledColdkeySwapInfo class is a dataclass representing information about scheduled cold key swaps.

Variables:
  • old_coldkey (str) – The old cold key before the swap.

  • new_coldkey (str) – The new cold key after the swap.

  • arbitration_block (int) – The block number at which the arbitration of the swap will take place.

arbitration_block: int#
classmethod decode_account_id_list(vec_u8)#

Decodes a list of AccountIds from vec_u8.

Parameters:

vec_u8 (list[int])

Return type:

Optional[list[str]]

classmethod fix_decoded_values(decoded)#

Fixes the decoded values.

Parameters:

decoded (Any)

Return type:

ScheduledColdkeySwapInfo

classmethod from_vec_u8(vec_u8)#

Returns a ScheduledColdkeySwapInfo object from a vec_u8.

Parameters:

vec_u8 (list[int])

Return type:

Optional[ScheduledColdkeySwapInfo]

classmethod list_from_vec_u8(vec_u8)#

Returns a list of ScheduledColdkeySwapInfo objects from a vec_u8.

Parameters:

vec_u8 (list[int])

Return type:

list[ScheduledColdkeySwapInfo]

new_coldkey: str#
old_coldkey: str#
class bittensor.core.chain_data.StakeInfo#

Dataclass for representing stake information linked to hotkey and coldkey pairs.

Variables:
  • hotkey_ss58 (str) – The SS58 encoded hotkey address.

  • coldkey_ss58 (str) – The SS58 encoded coldkey address.

  • stake (Balance) – The stake associated with the hotkey-coldkey pair, represented as a Balance object.

coldkey_ss58: str#
classmethod fix_decoded_values(decoded)#

Fixes the decoded values.

Parameters:

decoded (Any)

Return type:

StakeInfo

classmethod from_vec_u8(vec_u8)#

Returns a StakeInfo object from a vec_u8.

Parameters:

vec_u8 (list[int])

Return type:

Optional[StakeInfo]

hotkey_ss58: str#
classmethod list_from_vec_u8(vec_u8)#

Returns a list of StakeInfo objects from a vec_u8.

Parameters:

vec_u8 (list[int])

Return type:

list[StakeInfo]

classmethod list_of_tuple_from_vec_u8(vec_u8)#

Returns a list of StakeInfo objects from a vec_u8.

Parameters:

vec_u8 (list[int])

Return type:

dict[str, list[StakeInfo]]

stake: bittensor.utils.balance.Balance#
class bittensor.core.chain_data.SubnetHyperparameters#

This class represents the hyperparameters for a subnet.

Variables:
  • rho (int) – The rate of decay of some value.

  • kappa (int) – A constant multiplier used in calculations.

  • immunity_period (int) – The period during which immunity is active.

  • min_allowed_weights (int) – Minimum allowed weights.

  • max_weight_limit (float) – Maximum weight limit.

  • tempo (int) – The tempo or rate of operation.

  • min_difficulty (int) – Minimum difficulty for some operations.

  • max_difficulty (int) – Maximum difficulty for some operations.

  • weights_version (int) – The version number of the weights used.

  • weights_rate_limit (int) – Rate limit for processing weights.

  • adjustment_interval (int) – Interval at which adjustments are made.

  • activity_cutoff (int) – Activity cutoff threshold.

  • registration_allowed (bool) – Indicates if registration is allowed.

  • target_regs_per_interval (int) – Target number of registrations per interval.

  • min_burn (int) – Minimum burn value.

  • max_burn (int) – Maximum burn value.

  • bonds_moving_avg (int) – Moving average of bonds.

  • max_regs_per_block (int) – Maximum number of registrations per block.

  • serving_rate_limit (int) – Limit on the rate of service.

  • max_validators (int) – Maximum number of validators.

  • adjustment_alpha (int) – Alpha value for adjustments.

  • difficulty (int) – Difficulty level.

  • commit_reveal_weights_interval (int) – Interval for commit-reveal weights.

  • commit_reveal_weights_enabled (bool) – Flag indicating if commit-reveal weights are enabled.

  • alpha_high (int) – High value of alpha.

  • alpha_low (int) – Low value of alpha.

  • liquid_alpha_enabled (bool) – Flag indicating if liquid alpha is enabled.

activity_cutoff: int#
adjustment_alpha: int#
adjustment_interval: int#
alpha_high: int#
alpha_low: int#
bonds_moving_avg: int#
commit_reveal_weights_enabled: bool#
commit_reveal_weights_interval: int#
difficulty: int#
classmethod from_vec_u8(vec_u8)#

Create a SubnetHyperparameters instance from a vector of bytes.

This method decodes the given vector of bytes using the bt_decode module and creates a new instance of SubnetHyperparameters with the decoded values.

Parameters:

vec_u8 (bytes) – A vector of bytes to decode into SubnetHyperparameters.

Returns:

An instance of SubnetHyperparameters if decoding is successful, None otherwise.

Return type:

Optional[SubnetHyperparameters]

immunity_period: int#
kappa: int#
liquid_alpha_enabled: bool#
max_burn: int#
max_difficulty: int#
max_regs_per_block: int#
max_validators: int#
max_weight_limit: float#
min_allowed_weights: int#
min_burn: int#
min_difficulty: int#
registration_allowed: bool#
rho: int#
serving_rate_limit: int#
target_regs_per_interval: int#
tempo: int#
weights_rate_limit: int#
weights_version: int#
class bittensor.core.chain_data.SubnetInfo#

Dataclass for subnet info.

blocks_since_epoch: int#
burn: bittensor.utils.balance.Balance#
connection_requirements: dict[str, float]#
difficulty: int#
emission_value: float#
immunity_period: int#
kappa: int#
classmethod list_from_vec_u8(vec_u8)#
Parameters:

vec_u8 (bytes)

Return type:

list[SubnetInfo]

max_allowed_validators: int#
max_n: int#
max_weight_limit: float#
min_allowed_weights: int#
modality: int#
netuid: int#
owner_ss58: str#
rho: int#
scaling_law_power: float#
subnetwork_n: int#
tempo: int#
bittensor.core.chain_data.custom_rpc_type_registry#
bittensor.core.chain_data.decode_account_id(account_id_bytes)#

Decodes an AccountId from bytes to a Base64 string using SS58 encoding.

Parameters:

account_id_bytes (bytes) – The AccountId in bytes that needs to be decoded.

Returns:

The decoded AccountId as a Base64 string.

Return type:

str

bittensor.core.chain_data.process_stake_data(stake_data)#

Processes stake data to decode account IDs and convert stakes from rao to Balance objects.

Parameters:

stake_data (list) – A list of tuples where each tuple contains an account ID in bytes and a stake in rao.

Returns:

A dictionary with account IDs as keys and their corresponding Balance objects as values.

Return type:

dict